个人整理,如有疑问,评论留言!
- 一,Keepalived
-
- 介绍
- 二,搭建LVS+Keepalived
-
- 主调度器配置:
- 备调度器配置:
- 三,超链接(搭建web,nfs的)
- 四,验证LVS+Keepalived
一,Keepalived
解决单台服务器承担应用存在的单点故障的危险
介绍
专为LVS和HA设计的一款健康的健康检查工具
- 支持故障自动切换
- 支持节点健康状态检查
- 官方网站:http://www.keepalived.org/
二,搭建LVS+Keepalived
- VRRP (虚拟路由冗余协议)针对对路由器的一种备份解决方案
- Keepalived可实现多机热备,没个热备组可有多台服务器
- 咱们是双机热备,双机热备的故障切换是由虚拟ip地址的漂移来实现的,适用于各种应用服务器
准备环境:
依赖于LVS-DR的操作基础上,添加了备调度器,和更改了一下配置,
主调度器: | 192.168.100.25 vip地址:ens33:0 192.168.100.100 |
备调度器: | 192.168.100.29 |
web1: | 192.168.100.26 vip地址:lo:0 192.168.100.100 |
web2: | 192.168.100.27 vip地址:lo:0 192.168.100.100 |
nfs存储: | 192.168.100.28 |
主调度器配置:
1.安装Keepalived ipvsadm
root@localhost ~]# yum -y install keepalived ipvsadm
2.配置keepalived.conf 配置文件
[root@localhost ~]# cd /etc/keepalived/
[root@localhost keepalived]# cp keepalived.conf keepalived.conf.bakup
[root@localhost keepalived]# vi 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.100.100
}
}
virtual_server 192.168.100.100 80 {
delay_loop 15
lb_algo rr
lb_kind DR
persistence 60
protocol TCP
real_server 192.168.100.26 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
real_server 192.168.100.27 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
区域配置模块解释:
global_defs { :定义本路由器的服务器router_id
vrrp_instance VI_1 { :定义VRRP热备实列
virtual_ipaddress { :定义漂移地址(VIP),可以是多个
virtual_server 192.168.100.10 80 { :定义虚拟服务器地址(VIP)、端口
real_server 192.168.100.26 80 { :定义WEB站点的地址,端口
3.启动keepalived和开机自启,ipvsadm
systemctl start keepalived
systemctl enable keepalived
systemctl enable ipvsadm
4.配置vip地址192.168.100.100
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@localhost network-scripts]# vi ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.100.100
NETMASK=255.255.255.255
ONBOOT=yes
ifup lo:0 #开启lo:0
ifconfig
5.查看配置下负载策略
[root@localhost ]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.100.100:80 rr
-> 192.168.100.26:80 Route 1 0 0
-> 192.168.100.27:80 Route 1 0 0
6.查看vip信息
ip addr show
ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:da:8c:3c brd ff:ff:ff:ff:ff:ff
inet 《192.168.100.25/24》 brd 192.168.100.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet 《192.168.100.100/32》scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::a33e:6402:8d1:c2aa/64 scope link noprefixroute
valid_lft forever preferred_lft forever
7.调整/proc响应参数(内核参数优化)
vi /etc/sysctl.conf
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
sysctl -p
备调度器配置:
咱们只需要配置keepalive 配置文件设置优先升级,router_id,bakup(备)
LVS的调度规则咱们也在keepalived.conf配置文件里,可直接生成
1.安装Keepalived ipvsadm
root@localhost ~]# yum -y install keepalived ipvsadm
2.配置keepalived.conf 配置文件
[root@localhost ~]# cd /etc/keepalived/
[root@localhost keepalived]# cp keepalived.conf keepalived.conf.bakup
[root@localhost keepalived]# vi 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.100.100
}
}
virtual_server 192.168.100.100 80 {
delay_loop 15
lb_algo rr
lb_kind DR
persistence 60
protocol TCP
real_server 192.168.100.26 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
real_server 192.168.100.27 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
}
3.启动keepalived和开机自启,ipvsadm
systemctl start keepalived
systemctl enable keepalived
systemctl enable ipvsadm
4.查看配置下负载策略
[root@localhost ]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.100.100:80 rr
-> 192.168.100.26:80 Route 1 0 0
-> 192.168.100.27:80 Route 1 0 0
三,超链接(搭建web,nfs的)
还有三台服务器未配置(web1,web2, nfs存储)
web服务器和nfs存储服务,见博主分类负载群集的LVS-DR模式部署
参考web和nfs部分步骤就行 下面是超链接:
链接:参看web,nfs存储搭建步骤…
四,验证LVS+Keepalived
通过cmd验证下,是否做故障切换,vip地址转移!!
1.先验证正常的:
2.一直ping vip地址;让主调度器断开,看看mac地址是否变化,vip地址是否漂移
3.查看vip地址是否漂移到备调度器
ip addr show
ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:9e:cf:4e brd ff:ff:ff:ff:ff:ff
inet <192.168.100.29/24> brd 192.168.100.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet <192.168.100.100/32> scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::f50a:6f87:cda8:5a2d/64 scope link noprefixroute
valid_lft forever preferred_lft forever