春风十里不如你 —— Taozi - 管家 https://www.xiongan.host/index.php/tag/%E7%AE%A1%E5%AE%B6/ 【centos】环境下keepalived管家的实际应用 https://www.xiongan.host/index.php/archives/37/ 2022-10-04T15:57:00+08:00 案例要求:一台web服务器宕机后,被keepalived检测到,切换到从服务器第二台备用,使服务正常运行,之后进行排错进行整改第一台机器准备:另外在准备好一台可以访问网页的机器便于测试1. Server端、client端都需要安装keepalived httpd服务yum install -y httpd keepalived2. Server端:mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bakvim /etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_defs {notification_email {root@localhost}notification_email_from Alexandre.Cassen@firewall.locsmtp_server 127.0.0.1smtp_connect_timeout 30router_id node3.tao.com}vrrp_instance websrv {state MASTER <==指定此节点为 Master 节点interface br0(修改成本机使用的网卡) <==指定监听的网卡virtual_router_id 51priority 100 <==指定优先级,数字越高约优先advert_int 1 <==心跳监测,单位为 sauthentication {auth_type PASS <==设定验证方式auth_pass 1111 <==设定密码为 1111}virtual_ipaddress {192.168.123.250 <==指定 VIP}}保存后 重启 keepalived服务之后在/var/www/html/中写一个测试页vi index.htmlserver.tao.com保存后 重启httpd服务3. Client端mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bakvim /etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_defs {notification_email {root@localhost}notification_email_from Alexandre.Cassen@firewall.locsmtp_server 127.0.0.1smtp_connect_timeout 30router_id node4.tao.com}vrrp_instance websrv {state MASTER <==指定此节点为 Master 节点interface br0(修改成本机使用的网卡) <==指定监听的网卡virtual_router_id 51priority 50 <==指定优先级,数字越高约优先advert_int 1 <==心跳监测,单位为 sauthentication {auth_type PASS <==设定验证方式auth_pass 1111 <==设定密码为 1111}virtual_ipaddress {192.168.123.250 <==指定 VIP}}保存后 重启 keepalived服务之后在/var/www/html/中写一个测试页Vi index.htmlServer.tao.com保存后 重启httpd服务4. 测试结果在server 和client端 keepalived都正常 显示的是server端页面Server端关闭keepalived模拟宕机 显示的就是client端