Keepalived+nginx Nginx High Availability (personal simple not detailed record)

Source: Internet
Author: User

1, the installation is used by Yum

Nginx is the official latest source

[Nginx]

Name=nginx Repo

baseurl=http://nginx.org/packages/centos/$releasever/$basearch/

Gpgcheck=0

Enabled=1

Yum Install Nginx keepalived-y

2,keepalived configuration file.

Master: Configuration file contents

[Email protected] opt]# cat/etc/keepalived/keepalived.conf

! Configuration File for Keepalived

Vrrp_script Chk_http_port {

Script "/opt/nginx_pid.sh"

Interval 2

Weight-5

}

Vrrp_instance Vi_1 {

State MASTER

Interface eth0

VIRTUAL_ROUTER_ID 81

Priority 100

Advert_int 1

Authentication {

Auth_type PASS

Auth_pass 1111

}

Track_script {

Chk_http_port

}

virtual_ipaddress {

172.16.226.100

}

notify_master/tmp/keep.sh

notify_backup/tmp/keep.sh

notify_fault/tmp/keep.sh

notify_stop/tmp/keep.sh

}

From: Configuration file contents.

[Email protected] ~]# cat/etc/keepalived/keepalived.conf

! Configuration File for Keepalived

Vrrp_script Chk_http_port {

Script "/opt/nginx_pid.sh"

Interval 2

Weight-5

}

Vrrp_instance Vi_1 {

State BACKUP

Interface eth0

VIRTUAL_ROUTER_ID 81

Priority 99

Advert_int 1

Authentication {

Auth_type PASS

Auth_pass 1111

}

Track_script {

Chk_http_port

}

virtual_ipaddress {

172.16.226.100

}

notify_master/tmp/keep_master.sh

notify_backup/tmp/keep_backup.sh

notify_fault/tmp/keep_fault.sh

notify_stop/tmp/keep_stop.sh

}

Nginx Related script:

[Email protected] ~]# cat/opt/nginx_pid.sh

#!/bin/bash


A= ' ps-c nginx--no-header|wc-l '


If [$A-eq 0];then

/usr/sbin/nginx-c/etc/nginx/nginx.conf

Sleep 3

If [' Ps-c nginx--no-header|wc-l '-eq 0];then

Killall keepalived

Fi

Fi

Test Two servers VIP switch is smooth, nginx related script execution is normal, it should be noted that the script to have execute permissions.

Keepalived+nginx Nginx High Availability (personal simple not detailed record)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.