1. 程式人生 > >ipvsadm與keepalived整合

ipvsadm與keepalived整合

ipvsadm與keepalived整合

1.準備兩臺虛擬服務器(DR),分別安裝ipvsadm和keepalived

yum -y install ipvsadm
yum -y install keepalived


2.配置keepalived.conf

        #修改IP為192.168.2.137的DR
	vi /etc/keepalived/keepalived.conf
	#修改內容如下
	! Configuration File for keepalived

	global_defs {
	   notification_email {
		[email protected]
	   }
	   notification_email_from [email protected]
/* */ 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 { [email protected]
/* */ } notification_email_from [email protected] 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 } } }


3.準備兩臺RealServer(RS)

IP為:
		192.168.2.137
		192.168.2.138


4.分別為RealServer安裝httpd服務

yum -y install httpd


5.啟動httpd

service httpd start


6.啟動keepalived

service keepalived start
#可以查看一個是主,一個是從
ifconfig


7.請求192.168.2.150:8080可以看到訪問結果


本文出自 “素顏” 博客,請務必保留此出處http://suyanzhu.blog.51cto.com/8050189/1945285

ipvsadm與keepalived整合