技能展示:
- 会构建双机热备系统
- 会构建 LVS+HA 高可用群集
3.1 Keepalived双机热备基础知识
3.1.1 Keepalived概述及安装
3.1.1 Keepalived概述及安装
1. Keepalived的热备方式
2. Keepalived的安装与服务控制
(1)安装 Keepalived
[root@node1 ~]# yum -y install keepalived ipvsadm ##两台机器均需要安装
(2)控制 Keepalived 服务
[root@node1 ~]# systemctl enable keepalived.service ##两台机器均需要安装
3.1.2 使用Keepalived实现双机热备
1. 主服务器的配置
[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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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]#
2. 备用服务器的配置
- 路由器名称(router_id):建议为每个参与热备的服务器指定不同的名称。
- 热备状态(state):至少应有一台主服务器,将状态设为 MASTER;可以有多台备用的服务器,将状态设为 BACKUP。
- 优先级(priority):数值越大则取得 VIP 控制权的优先级越高,因此主服务器的优先级应设为最高;其他备用服务器的优先级可依次递减,但不要相同,以免在争夺 VIP 控制权时发生冲突。
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
3. 测试双机热备功能
(1)连通性测试
(2)Web 访问测试
(3)查看日志记录
3.2 LVS+Keepalived高可用群集
1. 配置主调度器
(1)全局配置、热备配置
[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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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]#
(2)Web 服务器池配置
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服务站参数配置文章来源:https://www.toymoban.com/news/detail-797213.html
[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
文章来源地址https://www.toymoban.com/news/detail-797213.html
到了这里,关于第 3 章 Keepalived 双机热备的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!