centos7????????????nginx+keepalived??????
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7????????????nginx+keepalived??????相关的知识,希望对你有一定的参考价值。
?????????????????????nginx+keepalived
????????????????????????????????????????????????????????????????????????80????????????systemctl stop firewalld.service??????????????????????????????systemctl disable firewalld.service
??????????????????
cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
????????????
uname -r
3.10.0-862.3.2.el7.x86_64
????????????????????????
??????yum???yum update -y
???????????????
yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
??????nginx
(????????????????????????)
??????nginx1.14.0????????????
wget http://nginx.org/download/nginx-1.14.0.tar.gz
?????????tar -zxvf nginx-1.14.0.tar.gz -C /usr/local/
????????????????????????????????????cd /usr/local/nginx-1.14.0/
?????????????????????./configure
???????????????nginx???make && make install
??????nginx???/usr/local/nginx/sbin/nginx
????????????nginx???/usr/local/nginx/sbin/nginx -s stop
????????????nginx???????????????????????????????????????????????????/usr/local/nginx/sbin/nginx -s quit
???????????????????????????/usr/local/nginx/sbin/nginx -t
?????????????????????/usr/local/nginx/sbin/nginx -s reload
??????keepalived
yum -y install keepalived
vi /etc/keepalived/keepalived.conf
master??????????????????
! Configuration file for keepalived
global_defs {
notification_email {br/>[email protected]
<="">}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
#??????nginx
vrrp_script chk_nginx {
script "/etc/keepalived/monitor_nginx.sh"
interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER #???????????? MASTER
interface ens32 #?????????
virtual_router_id 100
mcast_src_ip 192.168.254.128 #??????ip
priority 51 #??????????????????
advert_int 1
authentication {
auth_type PASS
auth_pass chtopnet
}
virtual_ipaddress {
192.168.254.88 #VIP ???IP
}
track_script {
chk_nginx #????????????
}
}
backup??????????????????
! Configuration file for keepalived
global_defs {
notification_email {br/>[email protected]
<="">}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
#??????NGINX
vrrp_script chk_nginx {
script "/etc/keepalived/monitor_nginx.sh"
interval 2
weight 2
}
vrrp_instance VI_1 {
state BACKUP #???????????? MASTER
interface ens32 #?????????
virtual_router_id 100
mcast_src_ip 192.168.254.129 #??????ip
priority 50 #??????????????????
advert_int 1
authentication {
auth_type PASS
auth_pass chtopnet
}
virtual_ipaddress {
192.168.254.88 #VIP ???IP
}
track_script {
chk_nginx #????????????
}
}
??????????????????????????????
vi /etc/keepalived/monitor_nginx.sh
#!/bin/bash
a=ps -C nginx --no-header | wc -l
if [ $a -eq 0 ];then
/usr/local/nginx/sbin/nginx
if [ ps -C nginx --no-header| wc -l -eq 0 ];then
systemctl stop keepalived
fi
fi
?????????nginx?????????????????????????????????IP?????????ARP??????
vi ip-config
#!/bin/bash
#description: Config realserver
VIP=192.168.254.88 #?????????????????????VIP
/etc/rc.d/init.d/functions
case "$1" in
start)
/sbin/ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP
/sbin/route add -host $VIP dev lo:0
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p >/dev/null 2>&1
echo "RealServer Start OK"
;;
stop)
/sbin/ifconfig lo:0 down
/sbin/route del $VIP >/dev/null 2>&1
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
echo "RealServer Stoped"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
??????????????????(??????????????????????????????)
./ip-config start
??????????????????????????????
以上是关于centos7????????????nginx+keepalived??????的主要内容,如果未能解决你的问题,请参考以下文章