系统: 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,同步时间
[root@lvs01 ~]# hostname
lvs01
[root@lvs01 ~]# getenforce
Disabled
[root@lvs02 ~]# hostname
lvs02
[root@lvs02 ~]# getenforce
Disabled
[root@rs01 ~]# hostname
rs01
[root@rs01 ~]# getenforce
Disabled
[root@rs02 ~]# hostname
rs02
[root@rs02 ~]# getenforce
Disabled
[root@lvs01 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
[root@lvs01 yum.repos.d]# ntpdate 0.rhel.pool.ntp.org
[root@lvs02 yum.repos.d]# ntpdate 0.rhel.pool.ntp.org
[root@rs01 yum.repos.d]# ntpdate 0.rhel.pool.ntp.org
[root@rs02 yum.repos.d]# ntpdate 0.rhel.pool.ntp.org
2、 在各个机器关闭防火墙,配置yum源
[root@lvs01 yum.repos.d]# service iptables stop
[root@lvs01 yum.repos.d]# chkconfig iptables off
[root@lvs02 ~]# service iptables stop
[root@lvs02 ~]# chkconfig iptables off
[root@rs01 ~]# service iptables stop
[root@rs01 ~]# chkconfig iptables off
[root@rs02 ~]# service iptables stop
[root@rs02 ~]# chkconfig iptables off
[root@lvs01 yum.repos.d]# service iptables stop
[root@lvs01 yum.repos.d]# chkconfig iptables off
[root@lvs01 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
[root@lvs01 yum.repos.d]# scp rhel-source.repo lvs02:/etc/yum.repos.d/rhel-source.repo
3、 在rs01.rs02上部署web服务,设置arptables,添加vip
[root@rs01 ~]#ip addr add 192.168.20.254/24 dev eth0
[root@rs01 ~]# echo "ip addr add 192.168.20.254/24 dev eth0">>/etc/rc.d/rc.local
[root@rs01 ~]# arptables -A IN -d 192.168.20.254 -j DROP
[root@rs01 ~]# arptables -A OUT -s 192.168.20.254 -j mangle --mangle-ip-s 192.168.20.100
[root@rs01 ~]# service arptables_jf save
将当前规则保存到 /etc/sysconfig/arptables: [确定]
[root@rs01 ~]# chkconfig arptables_jf on
[root@rs01 ~]# yum install -y httpd
[root@rs01 ~]# echo "rs01">/var/www/html/index.html
[root@rs01 ~]# service httpd restart
[root@rs01 ~]# chkconfig httpd on
[root@rs02 ~]# arptables -A IN -d 192.168.20.254 -j DROP
[root@rs02 ~]# arptables -A OUT -s 192.168.20.254 -j mangle --mangle-ip-s 192.168.20.100
[root@rs02 ~]# service arptables_jf save
将当前规则保存到 /etc/sysconfig/arptables: [确定]
[root@rs02 ~]# chkconfig arptables_jf on
[root@rs02 ~]#ip addr add 192.168.20.254/24 dev eth0
[root@rs02 ~]# echo "ip addr add 192.168.20.254/24 dev eth0">>/etc/rc.d/rc.local
[root@rs02 ~]# yum install -y httpd
[root@rs02 ~]# echo "rs02">/var/www/html/index.html
[root@rs02 ~]# service httpd restart
[root@rs02 ~]# chkconfig httpd on
4、 在lvs01,lvs02安装LB,在lvs01上配置lvs集群登录用户和密码
[root@lvs01 yum.repos.d]# yum groupinstall "Load Balancer"
[root@lvs02 yum.repos.d]# yum groupinstall "Load Balancer"
[root@lvs01 yum.repos.d]# piranha-passwd
New Password:
Verify:
Adding password for user piranha
[root@lvs01 yum.repos.d]# /etc/init.d/piranha-gui start
[root@lvs01 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 上启动负载均衡的监控进程
[root@lvs01 ~]# scp /etc/sysconfig/ha/lvs.cf lvs02:/etc/sysconfig/ha/lvs.cf
root@lvs02‘s password:
lvs.cf 100% 865 0.8KB/s 00:00
[root@lvs01 ~]# /etc/init.d/pulse restart
Shutting down pulse: [失败]
Starting pulse: [确定]
[root@lvs01 ~]# chkconfig pulse on
[root@lvs02 ~]# /etc/init.d/pulse restart
Shutting down pulse: [失败]
Starting pulse: [确定]
[root@lvs02 ~]# chkconfig pulse on
5.6 lvs 正常运行的状态
1、 测试
3.1 正常访问
3.2 lvs01 宕机了,可以正常访问
3.3 rs01 宕机了,也可正常访问