3.1.1 Keepalived概述及安装
[root@node1 ~]# yum -y install keepalived ipvsadm ##两台机器均需要安装
[root@node1 ~]# systemctl enable keepalived.service ##两台机器均需要安装
[root@node1 ~]# systemctl stop firewalld
[root@node1 ~]# cd /etc/keepalived/
[root@node1 keepalived]# cp keepalived.conf keepalived.conf.bak
[root@node1 keepalived]# vim keepalived.conf
global_defs {
router_id HA_TEST_R1
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 1
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.8.10
}
}
[root@node1 keepalived]# systemctl start keepalived.service
[root@node1 keepalived]# ip addr show dev ens33
2: ens33: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:6c:32:f2 brd ff:ff:ff:ff:ff:ff
inet 192.168.8.11/24 brd 192.168.8.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet 192.168.8.10/32 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::7457:78b3:7f51:9a01/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@node1 keepalived]#
global_defs {
router_id HA_TEST_R2
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 1
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.8.10
}
}
[root@node2 keepalived]# systemctl start keepalived.service
[root@node1 ~]# cd /etc/keepalived/
[root@node1 keepalived]# vim keepalived.conf
global_defs {
router_id HA_TEST_R1
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 1
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.8.10
}
}
vrrp_instance VI_2 {
state MASTER
interface ens36
virtual_router_id 2
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.10.10
}
}
[root@node1 keepalived]# systemctl restart keepalived.service
[root@node1 keepalived]# ip addr show dev ens36
3: ens36: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:6c:32:fc brd ff:ff:ff:ff:ff:ff
inet 192.168.10.11/24 brd 192.168.10.255 scope global noprefixroute ens36
valid_lft forever preferred_lft forever
inet 192.168.10.10/32 scope global ens36
valid_lft forever preferred_lft forever
inet6 fe80::f237:a7e7:aa9:c19f/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@node1 keepalived]#
[root@node2 keepalived]# vim keepalived.conf
global_defs {
router_id HA_TEST_R2
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 1
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.8.10
}
}
vrrp_instance VI_2 {
state BACKUP
interface ens36
virtual_router_id 2
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.10.10
}
}
[root@node2 keepalived]# systemctl restart keepalived.service
[root@node2 keepalived]# ip add show dev ens36
3: ens36: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:59:ba:e7 brd ff:ff:ff:ff:ff:ff
inet 192.168.10.12/24 brd 192.168.10.255 scope global noprefixroute ens36
valid_lft forever preferred_lft forever
inet6 fe80::78de:7a13:fd75:e51a/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@node2 keepalived]#
virtual_server 192.168.8.10 80 {
delay_loop 15
lb_algo rr
lb_kind DR
! persistence_timeout 50
protocol TCP
real_server 192.168.8.11 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
real_server 192.168.8.12 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
}
(3)主/从机器的参数配置
[root@node1 ~]# vim /etc/sysctl.conf
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
[root@node1 ~]# sysctl -p
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
[root@node1 ~]# systemctl restart keepalived.service
(4)Web服务站参数配置
[root@node4 network-scripts]# vim /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
[root@node4 network-scripts]# sysctl -p
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
[root@node4 ~]# cd /etc/sysconfig/network-scripts/
[root@node4 network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@node4 network-scripts]# vim ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.8.10
NETMASK=255.255.255.255
ONBOOT=yes
[root@node4 network-scripts]# ifup ifcfg-lo:0
[root@node4 network-scripts]# ifconfig