Host information:
Nginx Agent: 192.168.1.201
Nginx Agent: 192.168.1.204
nginx_web_1:192.168.1.202
nginx_web_2:192.168.1.203
vip1:192.168.1.205
vip1:192.168.1.206
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>
1. Installation
___________________________________________________________
Cd/usr/local/src/wget Http://www.keepalived.org/software/keepalived-1.2.20.tar.gztar XF KEEPALIVED-1.2.20.TAR.GZCD keepalived-1.2.20./configure--prefix=/usr/local/keepalivedmake && make install Cp/usr/local/keepalived/etc/rc.d/init.d/keepalived/etc/init.d/keepalivedchmod +x/etc/init.d/keepalived
#启动脚本
-----------------------------------------------Configuration
Sed-i "15d;14a. /usr/local/keepalived/etc/sysconfig/keepalived "/etc/init.d/ Keepalived Add the following at the same time (import the path of the keepavlied main program into the environment variable path): Sed-i ' 15a path= "$PATH:/usr/local/keepalived/sbin" '/etc/ Init.d/keepalivedsed-i ' 16a export PATH '/etc/init.d/keepalived #修改/etc/init.d/keepalived, looking for about 15 rows or so. /etc/sysconfig/keepalivedsed-i ' 14d;13a keepalived_options= "-d-f/etc/keepalived/keepalived.conf" '/usr/local/ keepalived/etc/sysconfig/keepalived# Modify the/usr/local/keepalived/etc/sysconfig/keepalived file to set the correct service startup parameters
2. Single-instance configuration
___________________________________________________________
----------------------------------------------master Configuration
mkdir /etc/keepalivedcp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/ keepalived/keepalived.confvim /etc/keepalived/keepalived.conf #主配置文件! Configuration file for keepalivedglobal_defs { notification_email { [email protected] } notification_ Email_from [email protected] smtp_server 127.0.0.1 smtp_ connect_timeout 30 router_id 1 #不同keepalived. conf This ID needs to be unique }vrrp_instance VI_1 { #示例名字为VI-1, the same instance of the standby node name to be the same as this state master #状态为MASTER, standby node is backup interface eth0 #通信接口为eth0 virtual_router_id 1 #实例ID, the master and slave need to be configured consistently priority 150 #优先级为150, the standby node priority must be lower than this number advert_int 1 #通告检查间隔时间1秒 authentication { auth_type pass #PASS认证类型, this parameter has the same node settings as the master node auth_pass 1234 #密码是1234, this parameter has the same node settings as the master node } virtual_ Ipadderss { 192.168.1.205/24 dev eth0 label eth0:1 }}
-----------------------------------------Provisioning Profile
vim /etc/keepalived/keepalived.conf #备配置文件! configuration file for keepalivedglobal_defs { notification_email { [email protected] } notification_email_from [email protected] smtp_server 127.0.0.1 smtp_connect_timeout 30 router_ id 1}vrrp_instance vi_1 { state backup interface eth0 virtual_router_id 1 priority 100 advert_int 1 authentication { auth_type pass auth_pass 1111 } virtual_ipaddress { 192.168.1.205/24 dev eth0 label eth0:1 }}
-----------------------------------m/s switching test
[[email protected] keepalived-1.2.20]#/etc/init.d/keepalived stop
Stop keepalived: [OK]
[[Email protected] keepalived-1.2.20]# IP add
1:lo: <LOOPBACK,UP,LOWER_UP> MTU 16436 qdisc noqueue State UNKNOWN
Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00
inet 127.0.0.1/8 Scope host Lo
INET6:: 1/128 Scope Host
Valid_lft Forever Preferred_lft Forever
2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000
Link/ether 00:0C:29:4A:30:DD BRD FF:FF:FF:FF:FF:FF
inet 192.168.1.204/24 BRD 192.168.1.255 Scope Global eth0
inet 192.168.1.205/24 Scope Global Secondary eth0:1
Inet6 FE80::20C:29FF:FE4A:30DD/64 Scope link
Valid_lft Forever Preferred_lft Forever
Log:
Feb 11:35:41 lab-4-c6 keepalived_vrrp[2597]: vrrp_instance (vi_1) Entering BACKUP State
Feb 11:35:41 lab-4-c6 keepalived_vrrp[2597]: VRRP sockpool: [IfIndex (2), Proto (), unicast (0), FD (10,11)]
Feb 11:35:55 lab-4-c6 keepalived_vrrp[2597]: vrrp_instance (vi_1) Transition to MASTER State
Feb 11:35:56 lab-4-c6 keepalived_vrrp[2597]: vrrp_instance (vi_1) Entering MASTER State
Feb 11:35:56 lab-4-c6 keepalived_vrrp[2597]: vrrp_instance (vi_1) setting protocol VIPs.
Feb 11:35:56 lab-4-c6 keepalived_vrrp[2597]: vrrp_instance (vi_1) sending gratuitous ARPs on eth0 for 192.168.1.205
Feb 11:35:56 lab-4-c6 keepalived_healthcheckers[2596]: NetLink Reflector reports IP 192.168.1.205 added
3. Multi-instance Configuration
___________________________________________________________
#主配置
--------------------
#前面类似部分略vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 1 priority 150 advert_int 1 authentication { auth_type pass auth_pass 1111 } virtual_ipaddress { 192.168.1.205/24 dev eth0 label eth0:1 }vrrp_instance VI_2 { state BACKUP interface eth0 virtual_router_id 1 priority 100 advert_int 1 authentication { Auth_type pass auth_pass 1111 } Virtual_ipaddress { 192.168.1.206/24 dev eth0 label eth0:2 }
#备配置
---------------------------------
vrrp_instance vi_1 { state backup interface eth0 virtual_router_id 1 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.205/24 dev eth0 label eth0:1 }vrrp_instance vi_2 { state MASTER interface eth0 virtual_router_id 1 priority 150 advert_int 1 authentication { auth_type pass auth_pass 1111 } virtual_ Ipaddress { 192.168.1.206/24 dev eth0 label eth0:2 }
This article is from the "Fuqin Wine" blog, please make sure to keep this source http://szk5043.blog.51cto.com/8456440/1766216
Keepalived Single instance and multi-instance