1.安裝keepalived在兩台調度伺服器上安裝)
vim /etc/yum.repo.d/rhel.repo
[local-cdrom]
name=local from cdrom
baseurl=file:///mnt/
enable=1
gpgcheck=0
yum -y install kernel-devel openssl-devel popt-devel
rpm -ivh /mnt/Packgets/ipvsadm-1.25-9.el6.i686.rpm
tar zxvf keepalived-1.2.2.tar.gz -C /usr/src/
cd /usr/src/keepalived-1.2.2/
./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-131.0.15.el6.i686
make &&make install
chkconfig --add keepalived
chkconfig keepalived on
2.配置調度器主:192.168.13.95,備:192.168.13.96,漂移ip:192.168.13.100)web伺服器集區節點1:192.168.13.41、節點2:192.168.13.47)
1)、配置主HA調度伺服器
cd /etc/keepalived/
cp keepalived.conf keepalived.conf.bak
vi /etc/keepalived/keepalived.conf
#################全域配置#################33
global_defs {
router_id LVS_HA_R1
}
##################高可用HA的設定##############
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_route_id 1
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 123123
}
virtual_ipaddress {
192.168.13.100
}
}
###################伺服器集區的配置######################
virtual_server 192.168.13.100 80 {
delay_loop 15
lb_algo rr
lb_kind DR
protocol TCP
real_server 192.168.13.41 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
real_server 192.168.13.41 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
}
modprobe ip_vs
lsmod |grep ip_vs
echo "modprobe ip_vs" >>/etc/rc.local
/etc/init.d/keepalived restart
chkconfig ipvsadm off
ip addr show dev eth0
2)、配置HA從調度伺服器
cd /etc/keepalived/
cp keepalived.conf keepalived.conf.bak
vi /etc/keepalived/keepalived.conf
#################全域配置#################33
global_defs {
router_id LVS_HA_R2
}
##################高可用HA的設定##############
vrrp_instance VI_1 {
state SLAVE
interface eth0
virtual_route_id 1
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 123123
}
virtual_ipaddress {
192.168.13.100
}
}
###################伺服器集區的配置######################
virtual_server 192.168.13.100 80 {
delay_loop 15
lb_algo rr
lb_kind DR
protocol TCP
real_server 192.168.13.41 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
real_server 192.168.13.47 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
}
modprobe ip_vs
lsmod |grep ip_vs
echo "modprobe ip_vs" >>/etc/rc.local
/etc/init.d/keepalived restart
chkconfig ipvsadm off
ip addr show dev eth0
######設定防火牆和selinux此處為測試)#########
iptables -F
setenforce 0
3.配置Web節點伺服器DR工作模式的配置,分別在節點伺服器上做如下設定)
cd /etc/sysconfig/network-script/
cp ifcfg-lo ifcfg-lo:0
vi ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.13.100
NETMASK=255.255.255.255
ONBOOT=yes
echo "route add -host 192.168.13.100 dev lo:0" >>/etc/rc.local
route add -host 192.168.13.100 dev lo:0
ip addr show dev lo
vi /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
sysctl -p
yum install -y httpd
vi /var/www/html/index.html
test page!!!!
/etc/init.d/httpd start
chkconfig httpd on
iptables -F
setenforce 0
4.測試lvs+Keepalived高可用叢集
在客戶機瀏覽器訪問192.168.13.100,調度伺服器可用壞一個,節點伺服器至少要有一個是好的。
通過/var/log/message記錄檔,跟蹤故障切換過程。使用ipvsadm -Ln查看LVS。