首页 > 代码库 > 29 lvs
29 lvs
LVS-NAT
Director
添加一块网卡,并调整为VMnet2
1)复制eth0配置文件至eth1
2)修改eth1配置文件,主要包括
A、修改IP地址、NAME、DEVICE
B、删除网关、DNS、UUID行
3)挂载本地光盘,安装ipvs
rpm -ivh ipvsadm-1.27-7.el7.x86_64.rpm
4)打开网络转发功能
vim /etc/sysctl.conf
添加
net.ipv4.ip_forward = 1
[root@localhost Packages]# sysctl -p
net.ipv4.ip_forward = 1
RS1、2
调整RS1、RS2的网卡类型为VMnet2
修改RS1、RS2的IP地址为20.7、20.8,网关为20.1
配置集群
1)配置集群
ipvsadm -A -t 192.168.1.72:80 -s rr
2)添加RealServer
ipvsadm -a -t 192.168.1.72:80 -r 192.168.20.7 -m
ipvsadm -a -t 192.168.1.72:80 -r 192.168.20.8 -m
3)查看集群
ipvsadm -L -n -c
4)保存配置信息
ipvsadm -S > /etc/sysconfig/ipvsadm
5)清除配置信息
ipvsadm -C
6)还原配置信息
ipvsadm -R < /etc/sysconfig/ipvsadm
7)删除RealServer
ipvsadm -d -t 192.168.1.72:80 -r 192.168.20.8
8)删除集群服务
ipvsadm -D -t 192.168.1.72:80
常见问题:
1、无默认路由
添加一条默认路由或在/etc/sysconfig/network中添加网关地址
LVS-DR
配置环境:
director (CentOS7.x)
DIP: eth0:192.168.1.72
VIP: lo:0 192.168.1.80
RS1 (CentOS6.x)
eth0:192.168.1.61
VIP: lo:0 192.168.1.80
RS2 (CentOS6.x)
eth0:192.168.1.62
VIP: lo:0 192.168.1.80
配置director
ifconfig eno16777736:0 192.168.1.80/32 broadcast 192.168.1.80 up
route add -host 192.168.1.80 dev eno16777736:0
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.254 0.0.0.0 UG 100 0 0 eno16777736
192.168.1.0 0.0.0.0 255.255.255.0 U 100 0 0 eno16777736
192.168.1.80 0.0.0.0 255.255.255.255 UH 0 0 0 eno16777736
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
配置RS1、RS2
配置内核参数
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce
配置VIP
ifconfig lo:0 192.168.1.80/32 broadcast 192.168.1.80 up
route add -host 192.168.1.80 dev lo:0
配置集群
ipvsadm -A -t 192.168.1.80:80 -s rr
ipvsadm -a -t 192.168.1.80:80 -r 192.168.1.61 -g
ipvsadm -a -t 192.168.1.80:80 -r 192.168.1.62 -g
本文出自 “追梦” 博客,请务必保留此出处http://sihua.blog.51cto.com/377227/1842966
29 lvs