Linux 实现双机热备
系统:opensuse 11.3 32位
热备服务软件:
LVS:
ipvsadm-1.26-3.1.i586.rpm
KeepAlived:
keepalived-1.2.2.tar.gz
安装步骤:
一,
lvs采用rpm包安装比较方便
#rpm -ivh ipvsadm-1.26-3.1.i586.rpm
二,
keepalived使用源码安装
#tar -zxvf keepalived-1.1.15.tar.gz
#cd keepalived-1.1.15
#./configure --prefix=/usr/local/keepalived
#make && make install
配置
编辑/etc/keepalived/keepalived.conf
#===================================配置开始====================================
! Configuration File for keepalived
#全局配置
global_defs {
notification_email {
hbyc@163.com
}
notification_email_from root@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
#VRRP配置
vrrp_instance VI_1 {
state MASTER
interface eth1
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.80
}
}
virtual_server 192.168.1.80 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.1.81 80 {
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.1.82 80 {
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
#===================================配置结束====================================
1,启动lvs
#ipvsadm
查看是否启动成功,
#lsmod |grep ip_v
ip_vs_rr 1122 1
ip_vs 106759 3 ip_vs_rr
libcrc32c 971 1 ip_vs
2,启动keepalive
#keepalived start
查看是否启动成功,
#ps -ef|grep keepalived
root 3242 1 0 23:35 ? 00:00:00 keepalived start
root 3243 3242 0 23:35 ? 00:00:00 keepalived start
root 3244 3242 0 23:35 ? 00:00:00 keepalived start
root 3280 3107 0 23:41 pts/0 00:00:00 grep keepalived
3,查看热备情况,
#ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.1.80:http rr persistent 50
#查看热备运行日志
#tail -f /var/log/message
Mar 12 23:35:24 linux-e1j0 avahi-daemon[2016]: Registering new address record for 192.168.1.80 on eth1.IPv4.
Mar 12 23:35:26 linux-e1j0 Keepalived_healthcheckers: TCP connection to [192.168.1.81]:80 failed !!!
Mar 12 23:35:26 linux-e1j0 Keepalived_healthcheckers: Removing service [192.168.1.81]:80 from VS [192.168.1.80]:80
Mar 12 23:35:26 linux-e1j0 Keepalived_healthcheckers: Remote SMTP server [127.0.0.1:25] connected.
4,查看虚拟地址是否正常加载到网卡上。
#ip a
2: eth1: mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ether 00:0c:29:cb:c8:7d brd ff:ff:ff:ff:ff:ff
inet 192.168.1.71/24 brd 192.168.1.255 scope global eth1
inet 192.168.1.80/32 scope global eth1
inet6 fe80::20c:29ff:fecb:c87d/64 scope link
valid_lft forever preferred_lft forever
可以看到 192.168.1.80/32 虚拟地址正常加载。
测试热备服务:
开启日志监控
#tail -f /var/log/message
关掉主服务
#killall -9 keepalived
可以看到备用服务日志输出:
Mar 13 23:00:27 linux-backup Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Mar 13 23:00:28 linux-backup Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Mar 13 23:00:28 linux-backup avahi-daemon[2053]: Registering new address record for 192.168.1.80 on eth2.IPv4.
Mar 13 23:00:28 linux-backup avahi-daemon[2053]: Withdrawing address record for fe80::20c:29ff:fec4:da16 on eth2.
Mar 13 23:00:28 linux-backup avahi-daemon[2053]: Withdrawing address record for 192.168.1.72 on eth2.
开启主服务器服务
#keepalived start
可以看到备用服务日志输出:
Mar 13 23:01:00 linux-backup Keepalived_vrrp: VRRP_Instance(VI_1) Received higher prio advert
Mar 13 23:01:00 linux-backup Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE
Mar 13 23:01:00 linux-backup avahi-daemon[2053]: Server startup complete. Host name is linux-backup-89.local. Local service cookie is 2700730627.
Mar 13 23:01:00 linux-backup avahi-daemon[2053]: Withdrawing address record for 192.168.1.80 on eth2.
这只是能看到服务正常切换了。真正测试双备服务的方法是,在主备服务上同时开启ftp服务。
#service vsftpd start
然后用第三方电脑访问虚拟地址 ftp 192.168.1.80,
可以看到当主备服务切换时,ftp客户端会分别登录到不同的服务器上(71或72),证明ftp服务双机热备正常搭建。
阅读(6823) | 评论(0) | 转发(5) |