这里我们仅仅只利用Keepalived做双机热备,也就是保证服务器的高可用性,其他的不用管。

http://www.keepalived.org/download.html
大家可以到这里下载最新版本的keepalived(如果已经提供用提供的安装包keepalived-1.2.15.tar.gz)
mkdir -p /usr/local/HAsoft cd /usr/local/HAsoft tar -zxvf keepalived-1.2.15.tar.gz cd keepalived-1.2.15
./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.32-279.el6.x86_64/
Keepalived configuration ------------------------ Keepalived version : 1.2.15 Compiler : gcc Compiler flags : -g -O2 -DETHERTYPE_IPV6=0x86dd Extra Lib : -lssl -lcrypto -lcryptUse IPVS Framework : Yes IPVS sync daemon support : Yes IPVS use libnl : No Use VRRP Framework : Yes Use Debug flags : No
make && make install
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/ cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/ cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
mkdir -p /etc/keepalived/
配置 打开配置文件:(该文件不存在,需手动创建)
vim /etc/keepalived/keepalived.conf
global_defs { } vrrp_instance N1 { //定义一个vrrp组 state MASTER //指定哪个为master(主机),哪个为backup(备机)。 mcast_src_ip 192.166.66.80 //此处ip填写本机ip即可(非必要设置) interface eth2 //设置实例绑定的网卡 virtual_router_id 51 // VPID标记 (主机备机要一致) priority 100 //定义优先级,数字越大,优先级越高 authentication { //验证类型和密码 auth_type PASS auth_pass 123456 } virtual_ipaddress { //虚拟IP 192.166.66.85 } }
vim /etc/keepalived/keepalived.conf
global_defs { } vrrp_instance N1 { state BACKUP interface eth2 mcast_src_ip 192.166.66.81 virtual_router_id 51 priority 88 authentication { auth_type PASS auth_pass 123456 } virtual_ipaddress { 192.166.66.85 } }
/etc/init.d/keepalived start
tail -f /var/log/messages Sep 8 18:26:02 centosaKeepalived_vrrp: Registering Kernel netlink reflector Sep 8 18:26:02 centosaKeepalived_vrrp: Registering Kernel netlink command channel Sep 8 18:26:02 centosaKeepalived_vrrp: Registering gratutious ARP shared channel Sep 8 18:26:02 centosaKeepalived_vrrp: Opening file '/etc/keepalived/keepalived.conf'. Sep 8 18:26:02 centosaKeepalived_vrrp: Configuration is using : 36076 Bytes Sep 8 18:26:02 centosaKeepalived_vrrp: Using LinkWatch kernel netlink reflector... Sep 8 18:26:02 centosa Keepalived: Starting VRRP child process, pid=5606 Sep 8 18:26:07 centosaKeepalived_vrrp: VRRP_Instance(lnmp) Transition to MASTER STATE Sep 8 18:26:12 centosaKeepalived_vrrp: VRRP_Instance(lnmp) Entering MASTER STATE Sep 8 18:26:12 centosaavahi-daemon[2528]: Registering new address record for 192.168.17.200 on eth0.
/etc/init.d/keepalived start
tail -f /var/log/messages Sep 8 18:30:02 centosb Keepalived: Starting Keepalived v1.2.2 (09/08,2011) Sep 8 18:30:02 centosb Keepalived: Starting Healthcheck child process, pid=5837 Sep 8 18:30:02 centosbKeepalived_vrrp: Registering Kernel netlink reflector Sep 8 18:30:02 centosbKeepalived_vrrp: Registering Kernel netlink command channel Sep 8 18:30:02 centosbKeepalived_vrrp: Registering gratutious ARP shared channel Sep 8 18:30:02 centosb Keepalived: Starting VRRP child process, pid=5839 Sep 8 18:30:02 centosb kernel: IPVS: Registered protocols (TCP, UDP, AH, ESP) Sep 8 18:30:02 centosb kernel: IPVS: Connection hash table configured (size=4096, memory=32Kbytes) Sep 8 18:30:02 centosb kernel: IPVS: ipvs loaded. Sep 8 18:30:02 centosbKeepalived_healthcheckers: Registering Kernel netlink reflector Sep 8 18:30:02 centosbKeepalived_healthcheckers: Registering Kernel netlink command channel Sep 8 18:30:02 centosbKeepalived_healthcheckers: Opening file '/etc/keepalived/keepalived.conf'. Sep 8 18:30:02 centosbKeepalived_vrrp: Opening file '/etc/keepalived/keepalived.conf'. Sep 8 18:30:02 centosbKeepalived_vrrp: Configuration is using : 36252 Bytes Sep 8 18:30:02 centosbKeepalived_vrrp: Using LinkWatch kernel netlink reflector... Sep 8 18:30:02 centosbKeepalived_healthcheckers: Configuration is using : 6271 Bytes Sep 8 18:30:02 centosbKeepalived_healthcheckers: Using LinkWatch kernel netlink reflector... Sep 8 18:30:02 centosbKeepalived_vrrp: VRRP_Instance(lnmp) Entering BACKUP STATE
/etc/init.d/keepalived stop
Sep 8 18:32:55 centosbKeepalived_vrrp: VRRP_Instance(lnmp) Transition to MASTER STATE Sep 8 18:33:00 centosbKeepalived_vrrp: VRRP_Instance(lnmp) Entering MASTER STATE Sep 8 18:33:00 centosbavahi-daemon[2531]: Registering new address record for 192.168.17.200 on eth0.
/etc/init.d/keepalived start
Sep 8 18:33:31 centosbKeepalived_vrrp: VRRP_Instance(lnmp) Received higher prio advert Sep 8 18:33:31 centosbKeepalived_vrrp: VRRP_Instance(lnmp) Entering BACKUP STATE Sep 8 18:33:31 centosbavahi-daemon[2531]: Withdrawing address record for 192.168.17.200 on eth0.
vim /etc/rc.local
service keepalived start
来源:博客园
作者:老车更换新引擎
链接:https://www.cnblogs.com/szz1113/p/11769937.html