系统部署之keepalived安装
文章目录
[隐藏]
- 安装文件
- 编译安装
- 修改配置
安装文件
- keepalived-1.3.5.tar.gz
编译安装
./configure make && make install
修改配置
机器1
/etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { notification_email { root@localhost } notification_email_from [email protected] smtp_server mail.example.com smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_script chk_nginx { script "/etc/keepalived/check_nginx.sh" interval 2 weight -5 fall 3 rise 2 } vrrp_instance VI_1 { state MASTER interface 网卡接口名 virtual_router_id 51 priority 101 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 虚拟地址1 } track_script { chk_nginx } } vrrp_instance VI_2 { state BACKUP interface 网卡接口名 virtual_router_id 52 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 虚拟地址2 } track_script { chk_nginx } }
机器2
! Configuration File for keepalived global_defs { notification_email { root@localhost } notification_email_from [email protected] smtp_server mail.example.com smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_script chk_nginx { script "/etc/keepalived/check_nginx.sh" interval 2 weight -5 fall 3 rise 2 } vrrp_instance VI_1 { state BACKUP interface 网卡接口名 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 虚拟地址1 } track_script { chk_nginx } } vrrp_instance VI_2 { state MASTER interface 网卡接口名 virtual_router_id 52 priority 101 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 虚拟地址2 } track_script { chk_nginx } }
nginx检查脚本
check_nginx.sh #!/bin/bash counter=$(ps -C nginx --no-heading|wc -l) if [ "${counter}" = "0" ]; then /usr/local/nginx/sbin/nginx sleep 2 counter=$(ps -C nginx --no-heading|wc -l) if [ "${counter}" = "0" ]; then service keepalived stop fi fi
系统服务
/lib/systemd/system/keepalived.service [Unit] Description=LVS and VRRP High Availability Monitor After=syslog.target network.target [Service] Type=simple PIDFile=/usr/local/var/run/keepalived.pid KillMode=process EnvironmentFile=-/usr/local/etc/sysconfig/keepalived ExecStart=/usr/local/sbin/keepalived --dont-fork -D ExecReload=/bin/kill -HUP $MAINPID [Install] WantedBy=multi-user.target
测试
尝试关闭一台keepalived服务,查看另一台网络端口情况
注意事项
- 防火墙启用状态下执行
firewall-cmd --direct --permanent --add-rule ipv4 filter INPUT 0 --in-interface enp0s8 --destination 224.0.0.18 --protocol vrrp -j ACCEPT firewall-cmd --direct --permanent --add-rule ipv4 filter OUTPUT 0 --out-interface enp0s8 --destination 224.0.0.18 --protocol vrrp -j ACCEPT firewall-cmd --reload
原文出处:shifei -> http://shifei.me/index.php/archives/7/
本站所发布的一切资源仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如果侵犯你的利益,请发送邮箱到 [email protected],我们会很快的为您处理。