CentOS 7 아래 keepalived 를 통 해 nginx 메 인 방식 의 더 블 열 비 를 설정 합 니 다.
6530 단어 유 닉 스 사용
- 설치 nginx
- keepalived 설치
- keepalived 설정
#
cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
vim /etc/keepalived/keepalived.conf
#
! Configuration File for keepalived
global_defs {
router_id nginx_server_1
}
vrrp_script chk_nginx {
script "/etc/keepalived/nginx_check.sh"
interval 2
weight 20
!weight
! 0,,Master:weight+priority>Backup:weight+priority( )
! 0,Master:priority:priority+weight( )
!weight
! 0,,Master:priority>Backup:priority( )
! 0,Master:priority+weight:priority( )
! ,weight Master Backup priority
}
vrrp_instance VI_1 {
state MASTER
interface eno16777984
virtual_router_id 51
mcast_src_ip 192.168.1.217
priority 100
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_nginx
}
virtual_ipaddress {
192.168.1.219/24
}
}
# nginx , nginx ,keepalived nginx
vim /etc/keepalived/nginx_check.sh
#
#!/bin/bash
A=`ps -C nginx --no-header |wc -l`
if [ $A -eq 0 ];then
/usr/sbin/nginx
sleep 2
if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
killall keepalived
fi
fi
#
chmod +xxx /etc/keepalived/nginx_check.sh
#
cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
vim /etc/keepalived/keepalived.conf
#
( :
state , BACKUP
route_id
priority
)
! Configuration File for keepalived
global_defs {
router_id nginx_server_2
}
vrrp_script chk_nginx {
script "/etc/keepalived/nginx_check.sh"
interval 2
weight 20
!weight
! 0,,Master:weight+priority>Backup:weight+priority( )
! 0,Master:priority:priority+weight( )
!weight
! 0,,Master:priority>Backup:priority( )
! 0,Master:priority+weight:priority( )
! ,weight Master Backup priority
}
vrrp_instance VI_1 {
state BACKUP
interface eno16777984
virtual_router_id 51
mcast_src_ip 192.168.1.218
priority 90
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_nginx
}
virtual_ipaddress {
192.168.1.219/24
}
}
- keepalived 시작
systemctl start keepalived
systemctl enable keepalived
- keepalived + nginx 의 주종 테스트