离线安裝keepalived
Centos7离线安装和配置Keepalived 链接:https://pan.baidu.com/s/1x7ucXNyOt9sB-M6r8x7_bw 提取码:ok3o
在线安装keepalived
yum install -y curl gcc openssl-devel libnl3-devel net-snmp-devel
yum install -y keepalived
卸载keepalived
keepalived 安装与卸载 Linux下卸载keepalived
cd /usr/local/src/keepalived
make uninstall
whereis keepalived
keepalived基础命令
systemctl enable keepalived
systemctl start keepalived
systemctl stop keepalived
systemctl restart keepalived
systemctl status keepalived
tail -f /var/log/messages
keepalived配置虚拟ip
Nginx配置——搭建 Nginx 高可用集群(双机热备) 安装完成之后, 在 /etc/keepalived 目录下有keepalived的配置文件
cat /etc/keepalived/keepalived.conf
global_defs 配置下,删除掉vrrp_strict配置 state :主节点为MASTER,备节点为BACKUP interface :需要绑定的?卡(可以通过ifconfig查看,我的是ens33) priority :主节点配置成100,备节点配置成99 virtual_ipaddress : 虚拟IP,两个节点需要相同
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.200.16
192.168.200.17
192.168.200.18
}
}
获取interface值, (自己服务器的网卡) 可以通过 ip a 命令
ip a
绑定Nginx进程和Keepalived服务
在路径/usr/local/src/ 下新建检测脚本 nginx_check.sh
#! /bin/bash
A=`ps -C nginx -no-header | wc - 1`
if [ $A -eq 0];then
/usr/local/nginx/sbin/nginx
sleep 2
if [`ps -C nginx --no-header| wc -1` -eq 0 ];then
killall keepalived
fi
fi
修改keepalived配置文件, 然后重启keepalived服务
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.20.61
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_script chk_http_ port {
script "/usr/local/src/nginx_check.sh"
interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER
interface ens160
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.200.16
}
}
|