linux运维学习笔记:集群系列之03:LVS_DR
作者:周少言
2018年 1月 ,于北京
声明:本博客是本人周少言在某培训机构学习期间所写,其中参考借鉴了他人的博客,本文将会选择性给出相关链接,如有侵权,恳请告知。本文如有错误,恳请告知,欢迎交流。
环境规划
director 192.168.22.32
web1 192.168.22.33
web2 192.168.22.34
虚拟IP 192.168.22.39
配置DIRECTOR
虚拟网卡的IP与真实网卡的IP需在同 一网段, 且子网掩码为255.255.255.255,且主机虚拟网卡与其他服务器虚拟网卡IP相同
启动虚拟接口, 必须关闭NetworkManager服务
如果报错:NetworkManager: 未被识别的服务 则是因为该服务未被安装,可先安装NetworkManager。
yum -y install NetworkManager
也可不安装直接略过NetworkManager的设置
service NetworkManager stop
chkconfig NetworkManager off
cd /etc/sysconfig/network-scripts/
cp -a ifcfg-eth0 ifcfg-eth0:0
vim ifcfg-eth0:0
DEVICE=eth0:0
IPADDR=虚拟IP
NETMASK=255.255.255.0
ifup eth0:0
修改内核参数。防止相同网络地址广播冲突,如果有多快网卡需要设置多行
net.ipv4.conf.eth0.send_redirects = 0
vim /etc/sysctl.conf
#LVS
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.eth0.send_redirects = 0
sysctl -p 刷新内核参数
modprobe ip_vs 查看内核是否加载, 无反应,则已经加载
cat /proc/net/ip_vs 参看版本, 确认是否正确加载
安装ipvsadm管理工具
yum -y install ipvsadm
ipvsadm -v
ipvsadm -A -t 虚拟IP:80 -s rr
ipvsadm -a -t 虚拟IP:80 -r 网站1:80 -g
ipvsadm -a -t 虚拟IP:80 -r 网站2:80 -g
ipvsadm -Ln
service ipvsadm save
chkconfig ipvsadm on
配置web1
配置网卡
service NetworkManager stop
cd /etc/sysconfig/network-scripts/
cp -a ifcfg-lo ifcfg-lo:0
vim ifcfg-lo:0
DEVICE=lo:0
IPADDR=虚拟IP
NETMASK=255.255.255.255
设置内核参数
vim /etc/sysctl.conf
#LVS
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
ifup lo:0
route add -host 虚拟IP dev lo:0
echo "this is web1" >> /var/www/html/index.html
service httpd restart
chkconfig httpd on
curl localhost
配置web2
service NetworkManager stop
chkconfig NetworkManager off
cd /etc/sysconfig/network-scripts/
cp ifcfg-lo ifcfg-lo:0
vim ifcfg-lo:0
DEVICE=lo:0
IPADDR=虚拟IP
NETMASK=255.255.255.255
vim /etc/sysctl.conf
#LVS
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
ifup lo:0
route add -host 虚拟IP dev lo:0
echo "this is web2" >> /var/www/html/index.html
service httpd restart
chkconfig httpd on
curl localhost
测试
在测试机上访问虚拟IP地址,并刷新。