Keepalived 安装 配置 Nginx 高可用
Keepalived 安装
yum install -y keepalived
配置文件位置
/etc/keepalived/keepalived.conf
配置nginx高可用
vi /etc/keepalived/keepalived.conf
# /etc/keepalived/keepalived.conf
vrrp_script chk_nginx {
script "pidof nginx"
interval 2
}
vrrp_instance VI_1 {
state MASTER # 在一台服务器上设置为 MASTER,另一台设置为 BACKUP
interface eth0 # 修改网口为你的网口名称
virtual_router_id 51
priority 101 # 在 MASTER 上设置为更高的优先级,BACKUP 设置为较低的优先级
advert_int 1
authentication {
auth_type PASS
auth_pass YourAuthenticationPassword # 替换 YourAuthenticationPassword 为你的认证密码。
}
virtual_ipaddress {
192.168.1.130 # 替换为你的虚拟 IP 地址
}
track_script {
chk_nginx
}
}
启动服务
systemctl start keepalived
配置开机自启动
systemctl enable keepalived