LVS:实现real server的负载均衡
Keepalived:实现两节点的高可用,并监控Real server,屏蔽故障节点,将出现故障的节点从策略中移除
实验配置环境
1.sever1
1、安装ipvsadm
修改yum源
cd /etc/yum.repo/rhel.dvd.repo
[rhel-source]
name=Red Hat Enterprise Linux $releasever - $basearch - Source
baseurl=http://172.25.12.250/rhel6.5
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[LoadBalancer]
name=LoadBalancer
gpgcheck=0
baseurl=http://172.25.12.250/rhel6.5/LoadBalancer
[HighAvailability]
name=HighAvailability
gpgcheck=0
baseurl=http://172.25.12.250/rhel6.5/HighAvailability
[ResilientStorage]
name=ResilientStorage
gpgcheck=0
baseurl=http://172.25.12.250/rhel6.5/ResilientStorage
[ScalableFileSystem]
name=ScalableFileSystem
gpgcheck=0
baseurl=http://172.25.12.250/rhel6.5/ScalableFileSystem
注意:rhel6:需要对yum源配置;rhel7:不需要
1.2、配置虚拟IP(vip)sever1
[root@server1 ~]# ip addr add 172.25.254.151/24 dev eth4
[root@server1 ~]# ipvsadm -A -t 172.25.254.151:80 -s rr
[root@server1 ~]# ipvsadm -a -t 172.25.254.151:80 -r 172.25.254.2:80 -g
[root@server1 ~]# ipvsadm -a -t 172.25.254.151:80 -r 172.25.254.3:80 -g
[root@server1 ~]# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.25.254.100:http rr
-> server2:http Route 1 0 0
-> server3:http Route 1 0 0
[root@server1 ~]# /etc/init.d/ipvsadm save
ipvsadm: Saving IPVS table to /etc/sysconfig/ipvsadm: [ OK ]
2.sever2主机
下载 httpd iptables_jf -y 后配置
[root@server2 ~]# yum install httpd -y
[root@server2 ~]# /etc/init.d/httpd start
[root@server2 ~]# curl 172.25.51.2
<h1>server3</h1>
[root@server2 ~]# ip addr add 172.25.51.100/32 dev eth4
[root@server2 ~]# arptables -A IN -d 172.25.51.100 -j DROP
[root@server2 ~]# arptables -A OUT -s 172.25.51.100 -j mangle --mangle-ip-s 172.25.51.2
[root@server2 ~]# /etc/init.d/arptables_jf save
Saving current rules to /etc/sysconfig/arptables: [ OK ]
sever3主机
下载 httpd iptables_jf -y 后配置
[root@server3: ~]# yum install httpd arptables_jf -y
[root@server3: ~]# /etc/init.d/httpd start
[root@server3: html]# curl localhost
<h1>server3</h1>
[root@server3: ~]# ip addr add 172.25.51.100/32 dev eth4
[root@server3: ~]# arptables -A IN -d 172.25.51.100 -j DROP
[root@server3: ~]# arptables -A OUT -s 172.25.51.100 -j mangle --mangle-ip-s 172.25.51.3
[root@server3: ~]# /etc/init.d/arptables_jf save
Saving current rules to /etc/sysconfig/arptables: [ OK ]
试验:
物理主机
1、访问 172.25.51.100 实现负载均衡
[kiosk@foundation12 rhel6.5]$ curl 172.25.51.100
<h1>server3</h1>
[kiosk@foundation12 rhel6.5]$ curl 172.25.51.100
<h1>server2</h1>
[kiosk@foundation12 rhel6.5]$ curl 172.25.51.100
<h1>server3</h1>
[kiosk@foundation12 rhel6.5]$ curl 172.25.51.100
<h1>server2</h1>