概述:
使用keepalived解决lvs的单点故障,实现高可用集群
开始之前准备六台虚拟机,搭建环境
systemctl stop NetworkManager
systemctl disable NetworkManager
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
vim /etc/selinux/config
SELINUX=disabled
客户端 | ip:192.168.115.199 |
keepalived+lvs1 | ip:192.168.115.200 |
keepalived+lvs2 | ip:192.168.115.201 |
web1 | ip:192.168.115.202 |
web2 | ip:192.168.115.203 |
nfs共享存储 | ip:192.168.115.204 |
目录
一、调度器配置
1、安装keepalived、安装ipvsadm
yum install -y keepalived 安装
yum install -y ipvsadm 安装
modprobe ip_vs 加载模块
lsmod | grep ip_vs 查看模块
2、配置keepalived
主
global_defs {
router_id MASTER
}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.100
}
}virtual_server 192.168.115.100 80 {
delay_loop 6
lb_algo rr
lb_kind DR
#persistence_timeout 50
protocol TCPreal_server 192.168.115.202 80 {
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.115.203 80 {
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
从global_defs {
router_id BACKUP
}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.100
}
}virtual_server 192.168.115.100 80 {
delay_loop 6
lb_algo rr
lb_kind DR
# persistence_timeout 50
protocol TCPreal_server 192.168.115.202 80 {
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.115.203 80 {
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
3、查看lvs节点状态ipvsadm -ln
二、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=2sysctl -p
2、配置虚拟IP地址
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
wqroute add -host 192.168.115.100/32 dev lo:0
3、安装httpd
yum -y install httpd
systemctl start httpd
vim /var/www/html/index.html
web1
wq
nfs共享存储搭建好之后安装,创建共享目录挂载到两个web节点就好了
下次见