yum -y install ipvsadm yum -y install keepalived
#修改IP为192.168.2.137的DR vi /etc/keepalived/keepalived.conf #修改内容如下 ! Configuration File for keepalived global_defs { notification_email { root@localhost } notification_email_from lvs@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 51 priority 50 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.2.150/24 dev eth0 label eth0:1 } } virtual_server 192.168.2.150 8080 { delay_loop 6 lb_algo wlc lb_kind DR nat_mask 255.255.255.0 persistence_timeout 50 protocol TCP real_server 192.168.2.137 8080 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } real_server 192.168.2.138 8080 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } } #修改IP为192.168.2.138的DR vi /etc/keepalived/keepalived.conf #修改内容如下 ! Configuration File for keepalived global_defs { notification_email { root@localhost } notification_email_from lvs@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 110 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.2.150/24 dev eth0 label eth0:1 } } virtual_server 192.168.2.150 8080 { delay_loop 6 lb_algo wlc lb_kind DR nat_mask 255.255.255.0 persistence_timeout 50 protocol TCP real_server 192.168.2.137 8080 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } real_server 192.168.2.138 8080 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } }
IP为: 192.168.2.137 192.168.2.138
yum -y install httpd
service httpd start
service keepalived start #可以查看一个是主,一个是从 ifconfig
本文出自 “素颜” 博客,请务必保留此出处http://suyanzhu.blog.51cto.com/8050189/1945285
原文地址:http://suyanzhu.blog.51cto.com/8050189/1945285