共计 3976 个字符,预计需要花费 10 分钟才能阅读完成。
Keepalived 是一个类似于 layer3, 4 & 7 交换机制的软件,也就是我们平时说的第 3 层、第 4 层和第 7 层交换。Keepalived 是自动完成,不需人工干涉。
调度服务器:
需要在 LVS 的基础上面做。
参考 https://www.linuxidc.com/Linux/2018-03/151514.htm
一块网卡:
Vmnet1:192.168.80.100
主与从调度器上都做下面的 3 步的:加载、安装 ipvsadm 包
下载地址:http://www.keepalived.org/download.html
[root@lss ~]# modprobe ip_vs
[root@lss ~]# rpm -ivh /mnt/Packages/ipvsadm-1.27-7.el7.x86_64.rpm
———keepalived 安装配置(主、从都要配置的)—-
[root@lss ~]# yum -y install popt-devel kernel-devel openssl-devel
WinSCP 上传 keepalived 到主从服务器
[root@lss ~]# tar fx keepalived-1.4.2.tar.gz -C /opt
[root@lss opt]# cd /opt/keepalived-1.4.2/
[root@lss keepalived-1.4.2]# yum -y install \
gcc \
gcc-c++ \
make
[root@lss keepalived-1.4.2]# ./configure –prefix=/
[root@lss keepalived-1.4.2]# make && make install
[root@lss keepalived]# cp -r /opt/keepalived-1.4.2/keepalived/etc/keepalived/ /etc/init.d
[root@lss keepalived]# systemctl enable keepalived
——————————– 修改配置文件(主调度器)————-
[root@lss keepalived]# vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {br/>acassen@firewall.loc
failover@firewall.locbr/>sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
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
priority 110
advert_int 1
authentication {
auth_type PASS
auth_pass 6666
}
virtual_ipaddress {
192.168.80.188
}
}
virtual_server 192.168.80.188 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.80.101 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.80.102 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
[root@lss keepalived]# service keepalived start
[root@lss keepalived]# ip addr show dev ens33 // 验证绑定了虚拟地址
inet 192.168.80.188/32 scope global ens33
[root@lss keepalived]# ipvsadm -L
[root@lss keepalived]# tail -f /var/log/messages // 对业务服务器和主调度器进行关闭验证热备及健康检查效果。
MASTER STATE 代表主服务器
BACKUP STATE 代表备用服务器
——————————— 修改配置文件(从调度器)—————–
[root@LSS03 ~]# modprobe ip_vs
[root@LSS03 ~]# rpm -ivh /mnt/Packages/ipvsadm-1.27-7.el7.x86_64.rpm
[root@LSS03 ~]# yum -y install \
gcc \
gcc-c++ \
make
[root@LSS03 ~]# tar fx keepalived-1.4.2.tar.gz -C /opt
[root@LSS03 ~]# cd /opt/keepalived-1.4.2/
[root@LSS03 keepalived-1.4.2]# ./configure –prefix=/
[root@LSS03 keepalived-1.4.2]# make && make install
[root@LSS03 keepalived-1.4.2]# cp -r keepalived/etc/init.d/keepalived /etc/init.d/
[root@LSS03 keepalived-1.4.2]# systemctl enable keepalived
[root@LSS03 keepalived-1.4.2]# vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost.localdomain
}
notification_email_from benet root@localhost.localdomain
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_02 // 主从要不相同
}
vrrp_instance VI_1 {
state BACKUP // 从调度器的热备状态
interface ens33
virtual_router_id 51 // 编号主与从的两边要一样的
priority 105 // 从调度器的优先级
advert_int 1
authentication {// 主、从热备认证信息
auth_type PASS
auth_pass 6666
}
virtual_ipaddress {// 指定群集 VIP 地址(虚拟服务器地址),可以指定多个的
192.168.80.188
}
}
virtual_server 192.168.80.188 80 {// 虚拟服务器地址(VIP)、端口
delay_loop 6 // 健康检查的间隔时间(秒)正常情况下。
lb_algo rr // 轮询(rr)调度算法
lb_kind DR // 直接路由(DR)群集工作模式
persistence_timeout 60 // 连接保持时间,(秒),若注释掉加个 ”!” 在这个时间内同一客户端的请求被同一服务器处理
protocol TCP // 应用服务采用的是 TCP 协议
real_server 192.168.80.101 80 {// 第一个 web 节点的地址、端口
weight 1 // 节点的权重
TCP_CHECK {// 健康检查方式
connect_port 80 // 检查的目标端口
connect_timeout 3 // 连接超时(秒)
nb_get_retry 3 // 重试次数
delay_before_retry 3 // 重试间隔(秒)
}
}
real_server 192.168.80.102 80 {// 第二个 web 节点的地址、端口
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
[root@LSS03 keepalived-1.4.2]# service keepalived start
[root@LSS03 keepalived-1.4.2]# ip addr show dev ens33
[root@LSS03 keepalived-1.4.2]# tail -f /var/log/messages
MASTER STATE 代表主服务器
BACKUP STATE 代表备用服务器
以下是 WEB 服务器:
192.168.80.101 服务器:
[root@lss01 ~]# yum install -y httpd
[root@lss01 ~]# vi /etc/httpd/conf/httpd.confServerName www.aa.com
[root@lss01 ~]# vi /var/www/html/index.html
<h1>Server aa </h1>
192.168.80.102 服务器:
[root@lss02 ~]# yum install -y httpd
[root@lss02 ~]# vi /etc/httpd/conf/httpd.conf
ServerName www.bb.com
[root@lss02 ~]# vi /var/www/html/index.html
<h1>Server bb </h1>
![post-qrcode](https://www.xgss.net/wp-content/uploads/2023/07/二维码-微信公众号256x256.jpg)