目录
一、作用
(一)使用keepalived解决lvs的单点故障
(二)高可用集群
二、搭建过程
(一)调度器上的配置
1、安装ipvsadm
yum install -y ipvsadm
modprobe ip_vs #加载模块
ipvsadm -ln #查看lvs节点状态
创建文件 touch /etc/sysconfig/ipvsadm
启动ipvsadm服务 systemctl start ipvsadm
2、安装keepalived
yum install -y keepalived
3、配置keepalived(/etc/keepalived/keepalived.conf)
①master
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL1
vrrp_skip_check_adv_addr
#vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.115.200
}
}
virtual_server 192.168.115.200 80 {
delay_loop 6
lb_algo rr
lb_kind DR
#persistence_timeout 50
protocol TCP
real_server 192.168.115.131 80 {
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.115.132 80 {
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
②backup
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL2
vrrp_skip_check_adv_addr
#vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.115.200
}
}
virtual_server 192.168.115.200 80 {
delay_loop 6
lb_algo rr
lb_kind DR
# persistence_timeout 50
protocol TCP
real_server 192.168.115.131 80 {
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.115.132 80 {
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
(二)web节点配置
1、调整ARP参数
①vim /etc/sysctl.conf
②添加内容
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
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce=2
③sysctl -p
2、配置虚拟IP地址
①cd /etc/sysconfig/network-scripts/
②cp ifcfg-lo ifcfg-lo:0
③vim ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.115.200
NETMASK=255.255.255.255
ONBOOT=yes
NAME=loopback:0
3、添加回环路由
route add -host 192.168.115.200/32 dev lo:0
4、安装httpd
yum -y install httpd
5、启动服务
systemctl start httpd