2024-07-08
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
#主服务器keepalived的安装
[root@localhost ~]# systemctl stop NetworkManager #网络托管 网络管理
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# yum -y install keepalived ipvsadm
[root@localhost ~]# systemctl enable keepalived
#主服务器keepalived的配置
[root@localhost ~]# cd /etc/keepalived/
[root@localhost keepalived]# cp keepalived.conf keepalived.conf.bak
[root@localhost keepalived]# vi keepalived.conf
global_defs { :w#全局参数
notification_email {
[email protected]
[email protected]
[email protected]
}
notification_email_from [email protected]
#vrrp_strict #严格模式 禁用单播模式
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_01 #路由器名称
}
vrrp_instance VI_1 { #示例参数
state MASTER
interface ens33
virtual_router_id 51 #虚拟路由id在群集中需一致
priority 100 #优先级 0~255
advert_int 1 #通告发送间隔
authentication {
auth_type PASS #验证类型
auth_pass 1111 #验证密码
}
virtual_ipaddress {
192.168.10.172
}
}
virtual_server 192.168.10.172 80 { #群集ip
delay_loop 6 #健康检查间隔
lb_algo wrr #负载均衡算法
lb_kind DR #负载均衡类型
nat_mask 255.255.255.0 #非不许
! persistence_timeout 50
protocol TCP #虚拟服务器协议
real_server 192.168.10.103 80 { #真实服务器
weight 1 #权重
TCP_CHECK { #健康检查
connect_port 80
connect_timeout 3
nb_get_retry 3 #超时次数
delay_before_retry 3 #重连时间
}
}
real_server 192.168.10.104 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
#主服务器内核参数的配置
[root@localhost ~]# 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
[root@localhost ~]# sysctl -p
#开启主服务器的keepalived服务
[root@localhost keepalived]# systemctl start keepalived
[root@localhost keepalived]# ip add show dev ens33
2: ens33: