一、作用
二、环境简介
三、操作步骤
部署web服务器
调整web1与web2的ARP参数
web1与web2安装 http
web1与web2创建虚拟ip
web1与web2添加回环路由
部署LVS主备调度器
调整master和backup的ARP参数(一致)
编辑master和backup安装 keepalived ipvsadm(一致)
配置keepalived master(红色字体master和backup不一致的地方)
配置keepalived backup
启动master和backup的keepalived与ipvsadm
master和backup加载ip_vs模块
查看lvs节点状态
测试(下图可以看到测试成功,自动切换web1与web2)
部署NFS共享服务器
存储配置文件
web1和web2挂载共享存储
测试(下图可以看到可以正常访问共享存储里面的内容了
使用keepalived解决lvs的单点故障
高可用集群
1.准备6台虚拟机,2台做LVS主备调度器,2台做web服务器,1台做存储,1台客户机验证
2.LVS主备调度器 master(192.168.1.17)backup(192.168.1.18)
3.web1(192.168.1.88)web2(192.168.1.89)
4.存储(192.168.1.20)
5.客户机(192.168.1.21)
6.虚拟ip(192.168.1.46)
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
yum -y install httpd
web1与web2分别写一个index.html用于测试(/var/www/html/ )httpd的网站根目录
echo "web1" >/var/www/html/index.html
echo "web2" >/var/www/html/index.html
cd /etc/sysconfig/network-scripts/
cp ifcfg-lo ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.1.46
NETMASK=255.255.255.255
ONBOOT=yes
NAME=loopback:0
重启网卡(可以看到下图已经创建成功)
route add -host 192.168.1.46/32 dev lo:0
启用httpd
systemctl start httpd
vim /etc/sysctl.conf
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects=0
net.ipv4.conf.ens33.send_redirects = 0
sysctl -p
yum install -y keepalived ipvsadm
global_defs {
router_id LVS_DEVEL1
}
vrrp_instance master {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.46 #虚拟IP回环地址
}
}
virtual_server 192.168.1.46 80 { #虚拟IP回环地址
delay_loop 6
lb_algo rr
lb_kind DR
#persistence_timeout 50
protocol TCP
real_server 192.168.1.17 80 { #master主IP
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.1.18 80 { #backup从IP
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
global_defs {
router_id LVS_DEVEL2
}
vrrp_instance backup {
state BACKUP
interface ens33
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.46 #虚拟IP回环地址
}
}
virtual_server 192.168.1.46 80 { #虚拟IP回环地址
delay_loop 6
lb_algo rr
lb_kind DR
#persistence_timeout 50
protocol TCP
real_server 192.168.1.17 80 { #master主IP
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.1.18 80 { #backup从IP
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
touch /etc/sysconfig/ipvsadm #两台机都输入该命令
systemctl start keepalived
systemctl start ipvsadm
modprobe ip_vs
ipvsadm -ln
NFS安装
yum -y install nfs-utils rpcbind
(rw:指定共享目录具备可读写权限)
(no_all_squash: 所有用户操作文件是什么用户就保留什么用户权限,不转换用户身份)
vim /etc/exports
/data/www/html/ 192.168.1.0/24(rw,no_all_squash)
mkdir -p /data/www/html
echo "web 1 2" >/data/www/html/index.html
systemctl start nfs
showmount -e
mount 192.168.115.133:/data/www/html /var/www/html/
将web1中httpd服务停掉
web1宕机挂掉之后web2会代替web1工作