Nginx+Keepalived+VIP漂移实现HA⾼可⽤技术之详细教程这个是nginx安装教程地址
这个是Keepalived的安装教程地址
1.⾸先把nginx、Keepalived安装好了,我们开始进⾏今天的技术分析话题
2.准备2台linux负载服务器,并且2台都要安装nginx、Keepalived程序。
准备⼀个虚拟IP,我这⾥⽤192.168.1.20
第⼀台linux的地址:192.168.2.2 (主 MASTER)
第⼆台linux的地址:192.168.2.3 (从 BACKUP)
4.开始对第⼀台linux的地址:192.168.2.2 (主 MASTER)的Keepalived的配置进⾏修改。
默认的配置路径在  /etc/f
global_defs {
router_id LVS_DEVEL
script_user root
enable_script_security
}
vrrp_script chk_nginx
{
script "/etc/keepalived/scripts/nginx_check.sh"
interval 2
timeout 2
fall 3
weight -20
}
vrrp_instance nginx {
state MASTER
interface eth0
virtual_router_id 100
priority  100
#nopreempt # no seize,must add
advert_int 1
authentication {  #all node must same
auth_type PASS
auth_pass 1111
}
unicast_src_ip 192.168.2.2
unicast_peer {
192.168.2.3
}
virtual_ipaddress {
192.168.1.20
}
track_script {
chk_nginx
}
}
在这个地⽅新增⼀个⽂件夹
mkdir  /etc/keepalived/scripts/
这个下⾯存放⼀个脚本  nginx_check.sh,代码如下
#!/bin/bash
A=`ps -C nginx --no-header |wc -l`
if [ $A -eq 0 ];then
systemctl start nginx
sleep 2
if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
systemctl stop keepalived.service
fi
fi
之后,对该scripts下脚本赋给权限
chmod  a+x  /etc/keepalived/scripts/*.sh
此时就可以启动keepalived、nginx
然后看看 ip add 这⾥的VIP就漂移到主负载地址下⾯了。
++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++
5.开始对第⼀台linux的地址:192.168.2.3 (主 BACKUP)的Keepalived的配置进⾏修改。
默认的配置路径在  /etc/f
global_defs {
router_id LVS_DEVEL
script_user root
enable_script_security
}
vrrp_script chk_nginx
{
script "/etc/keepalived/scripts/nginx_check.sh"
interval 2
timeout 2
fall 3
weight -20
}
vrrp_instance nginx {
state BACKUP
linux离线安装nginx详细教程interface eth0
virtual_router_id 100
priority  90
#nopreempt # no seize,must add
advert_int 1
authentication {  #all node must same
auth_type PASS
auth_pass 1111
}
unicast_src_ip 192.168.2.3
unicast_peer {
192.168.2.2
}
virtual_ipaddress {
192.168.1.20
}
track_script {
chk_nginx
}
}
在这个地⽅新增⼀个⽂件夹
mkdir  /etc/keepalived/scripts/
这个下⾯存放⼀个脚本  nginx_check.sh,代码如下
#!/bin/bash
A=`ps -C nginx --no-header |wc -l`
if [ $A -eq 0 ];then
systemctl start nginx
sleep 2
if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
systemctl stop keepalived.service
fi
fi
之后,对该scripts下脚本赋给权限
chmod  a+x  /etc/keepalived/scripts/*.sh
此时就可以启动keepalived、nginx
然后看看 ip add 这⾥的VIP不在此服务器上。
最后:
可以关闭主服务器的keepalived、nginx 然后看看从服务器的vip就漂移过来了。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。