***LVS的相关内容在我之前博客已经说明,这里就不多说了,直接开干吧!***
Keepalive+lvs(Master): 192.168.1.6
Keepalive+lvs(Slave): 192.168.1.7
node1: 192.168.1.14
node2: 192.168.1.11
vip:192.168.1.166
安装Keepalive和LVS:(Master、Slave)
yum -y install ipvsadm keepalived
配置 KeepAlive
单独配置lvs的时候调度算法需要用ipvsadm命令来配置,与keepalive一起使用时可以直接通过keepalive配置文件来配置调度算法,不需要ipvsadm命令配置。
cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak //做好配置模板的备份!
[root@master keepalived]# cat keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 101
advert_int 1
authentication {
auth_type PASS
auth_pass zxq666
}
virtual_ipaddress {
192.168.1.166/24 dev ens33 label ens33:1
}
}
virtual_server 192.168.1.166 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 0
protocol TCP
real_server 192.168.1.14 80 {
weight 1
SSL_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.1.11 80 {
weight 1
SSL_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
state MASTER //定义主备
priority 101 //为keepalive优先级,主要比备优先级高
persistence_timeout 0 //在一定时间内对于同一个ip的请求调度到统一server上
lb_algo rr //调度算法为轮询
lb_kind DR //调度模式为DR模式
notification_email {
root@localhost
} //接受通知邮件的用户邮箱
notification_email_from keepalived@localhost //发送通知的用户
SSL_GET {
url {
path /
status_code 200
} //设置状态码回显
weight 1 //权重
connect_timeout 3 //探测超时
nb_get_retry 3 //重试次数
delay_before_retry 3 //重试间隔时间
[root@slave /]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass zxq666
}
virtual_ipaddress {
192.168.1.166/24 dev ens33 label ens33:1
}
}
virtual_server 192.168.1.166 80 {
delay_loop 6
lb_algo rr
lb_kind DR
net_mask 255.255.255.0
persistence_timeout 0
protocol TCP
real_server 192.168.1.14 80 {
weight 1
SSL_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.1.11 80 {
weight 1
SSL_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
开启keepalive服务
systemctl start keepalived
Master:
Slave: