lvs-dr 模式-piranha

Posted derrickrose

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lvs-dr 模式-piranha相关的知识,希望对你有一定的参考价值。

系统: redhat 6.5 mini

机器名

 ip

   vip

 lvs01(主lvs)

192.168.20.10

 

192.168.20.254

 lvs02(备lvs)

192.168.20.20

 rs01 (web)

192.168.20.100

 rs02 (web) 

192.168.20.200

 

 

1、  在各个机器上配置ip地址,机器名,关闭selinux,同步时间

[[email protected] ~]# hostname

lvs01

[[email protected] ~]# getenforce

Disabled

[[email protected] ~]# hostname

lvs02

[[email protected] ~]# getenforce

Disabled

[[email protected] ~]# hostname

rs01

[[email protected] ~]# getenforce

Disabled

[[email protected] ~]# hostname

rs02

[[email protected] ~]# getenforce

Disabled

[[email protected] yum.repos.d]# cat /etc/hosts

192.168.20.10 lvs01

192.168.20.20 lvs02

192.168.20.100 rs01

192.168.20.200 rs02

[[email protected] yum.repos.d]# ntpdate 0.rhel.pool.ntp.org

[[email protected] yum.repos.d]# ntpdate 0.rhel.pool.ntp.org

[[email protected] yum.repos.d]# ntpdate 0.rhel.pool.ntp.org

[[email protected] yum.repos.d]# ntpdate 0.rhel.pool.ntp.org

 

2、  在各个机器关闭防火墙,配置yum源

[[email protected] yum.repos.d]# service iptables stop

[[email protected] yum.repos.d]# chkconfig iptables off

[[email protected] ~]# service iptables stop

[[email protected] ~]# chkconfig iptables off

[[email protected] ~]# service iptables stop

[[email protected] ~]# chkconfig iptables off

[[email protected] ~]# service iptables stop

[[email protected] ~]# chkconfig iptables off

[[email protected] yum.repos.d]# service iptables stop

[[email protected] yum.repos.d]# chkconfig iptables off

[[email protected] yum.repos.d]# cat rhel-source.repo

[base]

name=base

baseurl=file:///mnt

enabled=1

gpgcheck=0

[LB]

name=LB

baseurl=file:///mnt/LoadBalancer

enabled=1

gpgcheck=0

[HA]

name=HA

baseurl=file:///mnt/HighAvailability

enabled=1

gpgcheck=0

[RS]

name=RS

baseurl=file:///mnt/ResilientStorage

enabled=1

gpgcheck=0

[[email protected] yum.repos.d]# scp rhel-source.repo lvs02:/etc/yum.repos.d/rhel-source.repo

 

3、  在rs01.rs02上部署web服务,设置arptables,添加vip

[[email protected] ~]#ip addr add 192.168.20.254/24 dev eth0

[[email protected] ~]# echo "ip addr add 192.168.20.254/24 dev eth0">>/etc/rc.d/rc.local

[[email protected] ~]# arptables -A IN -d 192.168.20.254 -j DROP

[[email protected] ~]# arptables -A OUT -s 192.168.20.254 -j mangle --mangle-ip-s 192.168.20.100

[[email protected] ~]# service arptables_jf save

将当前规则保存到 /etc/sysconfig/arptables:                [确定]

[[email protected] ~]# chkconfig arptables_jf on

[[email protected] ~]# yum install -y httpd

[[email protected] ~]# echo "rs01">/var/www/html/index.html

[[email protected] ~]# service httpd restart

[[email protected] ~]# chkconfig httpd on

[[email protected] ~]# arptables -A IN -d 192.168.20.254 -j DROP

[[email protected] ~]# arptables -A OUT -s 192.168.20.254 -j mangle --mangle-ip-s 192.168.20.100

[[email protected] ~]# service arptables_jf save

将当前规则保存到 /etc/sysconfig/arptables:                [确定]

[[email protected] ~]# chkconfig arptables_jf on

[[email protected] ~]#ip addr add 192.168.20.254/24 dev eth0

[[email protected] ~]# echo "ip addr add 192.168.20.254/24 dev eth0">>/etc/rc.d/rc.local

[[email protected] ~]# yum install -y httpd

[[email protected] ~]# echo "rs02">/var/www/html/index.html

[[email protected] ~]# service httpd restart

[[email protected] ~]# chkconfig httpd on

 

4、  在lvs01,lvs02安装LB,在lvs01上配置lvs集群登录用户和密码

[[email protected] yum.repos.d]# yum groupinstall "Load Balancer"

[[email protected] yum.repos.d]# yum groupinstall "Load Balancer"

 [[email protected] yum.repos.d]# piranha-passwd

New Password:

Verify:

Adding password for user piranha

[[email protected] yum.repos.d]# /etc/init.d/piranha-gui start

[[email protected] yum.repos.d]# chkconfig piranha-gui on

 

5、通过浏览器配置lvs集群

5.1 在浏览器输入http://192.168.20.10:3636 输入用户名和密码

 技术分享图片

5.2 配置lvs01,ip地址,选direct

 技术分享图片

5.3 配置lvs02

 技术分享图片

5.4  配置对外服务和真实服务器

 技术分享图片

技术分享图片 

5.5  将在lvs01 上的配置文件复制到lvs02 上,在lvs01,lvs02 上启动负载均衡的监控进程

[[email protected] ~]# scp /etc/sysconfig/ha/lvs.cf lvs02:/etc/sysconfig/ha/lvs.cf

[email protected]‘s password:

lvs.cf                              100%  865     0.8KB/s   00:00

[[email protected] ~]# /etc/init.d/pulse restart

Shutting down pulse:                                       [失败]

Starting pulse:                                            [确定]

[[email protected] ~]# chkconfig pulse on

[[email protected] ~]# /etc/init.d/pulse restart

Shutting down pulse:                                       [失败]

Starting pulse:                                            [确定]

[[email protected] ~]# chkconfig pulse on

 

5.6  lvs 正常运行的状态

技术分享图片 

1、  测试

3.1 正常访问

 技术分享图片

 

3.2 lvs01 宕机了,可以正常访问

 技术分享图片

3.3 rs01 宕机了,也可正常访问

 技术分享图片

 

以上是关于lvs-dr 模式-piranha的主要内容,如果未能解决你的问题,请参考以下文章

LVS负载均衡群集部署——DR模式的介绍及搭建步骤

LVS-DR模式 搭建过程详解

LVS - linux 搭建LVS-DR模式

负载均衡LVS-DR模式群集部署实操

负载均衡LVS-DR模式群集部署实操

LVS-DR模式集群构建