LVS-DR模式+NFS

构建DR模式的LVS群集

LVS-DR模式+NFS_第1张图片
dr.png

一、配置LVS调度器

1、配置IP和VIP

1)配置IP

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:82:1E:D4
TYPE=Ethernet
UUID=1c2fa852-aea2-4c4a-a2c1-c0990f073ea5
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=1.1.1.10
NETMASK=255.0.0.0

2)配置VIP

[root@localhost ~]#cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network- scripts/ifcfg-eth0:0
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0:0
添加:
DEVICE=eth0:0
NBOOT=yes 
IPADDR=1.1.1.1
NETMASK=255.0.0.0
[root@localhost ~]# service network restart

2、调整响应参数

对于DR群集模式来说,由于LVS负载调度器和各个节点需要共用VIP地址,所以关闭Linux内核的重定向参数响应

[root@localhost ~]# vim /etc/sysctl.conf
添加:
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.eth0.send_redirects = 0
[root@localhost ~]# sysctl -p 立即生效

3、安装并配置ipvsadm

[root@localhost ~]# rpm -ihv /mnt/Packages/ipvsadm-1.26-2.el6.x86_64.rpm
[root@localhost ~]# service ipvsadm stop 清除原有策略
[root@localhost ~]# ipvsadm -A -t 1.1.1.1:80 -s rr 
[root@localhost ~]# ipvsadm -a -t 1.1.1.1:80 -r 192.168.1.2 -g -w 1
[root@localhost ~]# ipvsadm -a -t 1.1.1.1:80 -r 192.168.1.3 -g -w 1
[root@localhost ~]# service ipvsadm save 保存策略
[root@localhost ~]# chkconfig --add ipvsadm 添加为系统服务 
[root@localhost ~]# chkconfig ipvsadm on

二、配置WEB节点服务器

在使用DR模式时,节点服务器也需要配置VIP地址,并调整内核的ARP响应参数以阻止更新VIP的MAC地址,避免发生冲突,剩下的web配置和NAT方式类似。

web1

1、配置IP地址

1)设置IP(eth0:192.168.1.2 eth1:1.1.1.101)

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 

2)设置VIP

[root@localhost ~]# cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network- scripts/ifcfg-lo:0
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-lo:0
修改:
DEVICE=lo:0
IPADDR=1.1.1.1 
NETMASK=255.255.255.255
ONBOOT=yes

3)添加路由

[root@localhost ~]# route add -host 1.1.1.1 dev lo:0添加到群集IP地址的本地路由记录
[root@localhost ~]# echo "route add -host 1.1.1.1 dev lo:0" >> /etc/rc.local 避免重新丢失,写到配置文件

2、调整响应参数

[root@localhost ~]# 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
[root@localhost ~]# sysctl -p

mount 192.168.1.200:/www /var/www/html(做完nfs共享存储再挂载)

开启web服务
service httpd restart

web2

1、配置IP地址

1)设置IP(eth0:192.168.1.3 eth1:1.1.1.102)

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 

2)设置VIP

[root@localhost ~]# cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network- scripts/ifcfg-lo:0
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-lo:0
修改:
DEVICE=lo:0
IPADDR=1.1.1.1 
NETMASK=255.255.255.255
ONBOOT=yes

3)添加路由

[root@localhost ~]# route add -host 1.1.1.1 dev lo:0添加到群集IP地址的本地路由记录
[root@localhost ~]# echo "route add -host 1.1.1.1 dev lo:0" >> /etc/rc.local 避免重新丢失,写到配置文件

2、调整响应参数

[root@localhost ~]# 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
[root@localhost ~]# sysctl -p

echo "a11111111" > /var/www/html/index.html

开启web服务
service httpd restart

3、设置NFS共享存储器

1)配置ip(192.168.1.200)
2)
[root@localhost ~]# mkdir /www
[root@localhost ~]#echo "b1111111111111" >/www/index.html
[root@localhost ~]#vim /etc/exports
添加:#格式为“目录位置  客户机地址(权限选项)”
/www 192.168.1.0/24(rw,sync)
[root@localhost ~]#chkconfig --add nfs
[root@localhost ~]#chkconfig  nfs on
[root@localhost ~]#service nfs start

三、验证:

1、客户端访问:
[root@localhost ~]# http://1.1.1.1/ 
2、在LVS上查看:
[root@localhost ~]# ipvsadm -Lnc

你可能感兴趣的:(LVS-DR模式+NFS)