keepalived的概念
keepalived的工作原理
基于vrrp实现的调度器高可用方案
keepalived的配置实验
先在调度服务器上安装keepalived和ipvsadm
apt -y install keepalived ipvsadm
复制keepalived的配置文件到/etc/keepalived/目录下
cp /usr/share/doc/keepalived/samples/keepalived.conf.sample /etc/keepalived/keepalived.conf
配置keepalived的配置
1! Configuration File for keepalived
2
3 global_defs {
4 notification_email {
5 acassen
6 }
7 notification_email_from Alexandre.Cassen@firewall.loc
8 smtp_server 127.0.0.1
#本地邮件服务,可以删除不要
9 smtp_connect_timeout 30
#本地邮件服务,可以删除不要
10 router_id LVS_01
#确定主备服务器的id号,必须不同
11 vrrp_iptables
配置了之后keepalived重启之后不会添加iptables的策略。
12 }
13
14 vrrp_instance VI_1 {
15 state MASTER
确定服务器的身份 主
16 interface ens33
指定网卡设备
17 virtual_router_id 50
虚拟路由的id,主备保持一致
18 priority 100
优先级。谁数字大就是主
19 advert_int 1
主备之间检查的心跳率
20 virtual_ipaddress {
21 192.168.233.100
集群的vip地址
22 }
23 }
24
25 virtual_server 192.168.233.100 80 {
26 delay_loop 6
健康检查的间隔时间
27 lb_algo rr
负载均衡的算法
28 lb_kind DR
lvs的模式
29 persistence_timeout 50
连接保持的时间
30 protocol TCP
服务采用的协议
31 #指定的后台真实的服务器
32 real_server 192.168.233.61 80 {
33 weight 1
负载算法的圈子
34 TCP_CHECK {
tcp的健康
35 connect_port 80
检查的目标端口是80
36 connect_timeout 3
连接检查的超时时间3秒
37 retry 3
重试的次数
38 delay_before_retry 3
重试的间隔时间
39 }
40 }
41 }
42 }
调度器2更改如下配置,其余和调度器1一样
检查主备配置是否正常
修改主备的内核
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens37.send_redirects = 0
sysctl -p
给后端服务器添加网卡或者虚拟网卡
修改后端服务器网卡配置
修改内核配置
net.ipv4.conf.ens37.arp_ignore = 1
net.ipv4.conf.ens37.arp_announce = 2
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
sysctl -p
启动nginx服务
systemctl restart nginx.service