keepalived+lvs(为lvs提供健康检查)
【注】:所有实验机的防火墙和sellinux都要关闭
keepalived+lvs+httpd
调度端(keepalived):server1(172.25.9.1) server2(172.25.9.2)
real server:server3(172.25.9.3) server4(172.25.9.4)
调度端(serevr1&server2)
关闭HA服务,清除arp规则
1 | [root@server1 ~]# /etc/init.d/heartbeat stop |
安装keepalived服务
1 | [root@server1 ha.d]# yum install keepalived -y |
修改keepalived配置文件
1 | [root@server1 ~]# vim /etc/keepalived/keepalived.conf |
将修改好的配置文件发送给server2
1 | [root@server1 ~]# scp /etc/keepalived/keepalived.conf 172.25.9.2:/etc/keepalived/ |
RS端
1.配置文件
1 | [root@server3 html]# tail -n 2 /etc/sysctl.conf |
2.开启httpd服务
1 | [root@server3 ~]# /etc/init.d/httpd start |
开启两端服务
1 | [root@server1 ~]# /etc/init.d/keepalived start |
实验结果
1.查看服务启动之后的日志:可以看到进入主备状态:
1 | [root@server1 ~]# tail /var/log/messages |
[root@server1 ~]# ip addr show
2: eth1:
link/ether 52:54:00:9a:d3:95 brd ff:ff:ff:ff:ff:ff
inet 172.25.9.1/24 brd 172.25.9.255 scope global eth1
inet 172.25.9.100/32 scope global eth11
2
3.自动生成arp规则
[root@server1 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.25.9.100:80 rr
-> 172.25.9.3:80 Route 1 0 0
-> 172.25.9.4:80 Route 1 0 01
2
3
4
5
6
7
## keepalived+lvs+ftp
只是将上面管理的服务修改为ftp服务
### RS端(server3&server4)
1.安装vsftpd服务,并创建测试文件
[root@server3 ~]# yum install vsftpd -y
[root@server3 ~]# cd /var/ftp/pub/
[root@server3 pub]# touch server3
[root@server3 pub]# /etc/init.d/vsftpd start1
2### 调度端(server1&server2)
1.修改配置文件(server1)
[root@server1 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@server1.example.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
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 {
172.25.9.100
}
}
virtual_server 172.25.9.100 21 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50 #
protocol TCP
real_server 172.25.9.3 21 {
weight 1
TCP_CHECK {
connect_timeout 3
}
}
real_server 172.25.9.4 21 {
weight 1
TCP_CHECK {
connect_timeout 3
}
}
}
1 |
|
[root@server1 ~]# scp /etc/keepalived/keepalived.conf 172.25.9.2:/etc/keepalived/
做如下改动:
notification_email_from keepalived@server2.example.com
state BACKUP1
2
3.重启keepalived服务
[root@server1 ~]# /etc/init.d/keepalived restart1
2
3
4.实验结果
vip在master上:
[root@server1 ~]# ip addr show1
2
3
调度端的arp规则:
server1:
[root@server1 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.25.9.100:21 rr
-> 172.25.9.3:21 Route 1 0 0
-> 172.25.9.4:21 Route 1 0 01
server2:
[root@server1 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.25.9.100:21 rr persistent 50
-> 172.25.9.3:21 Route 1 0 0
-> 172.25.9.4:21 Route 1 1 8
1 |
|
[root@foundation187 ~]# lftp 172.25.9.100
lftp 172.25.9.100:~> ls /pub/
-rw-r–r– 1 0 0 0 Feb 28 15:17 server41
2
过50秒后:
[root@foundation187 ~]# lftp 172.25.9.100
lftp 172.25.9.100:~> ls /pub/
-rw-r–r– 1 0 0 0 Feb 28 15:17 server3
```