系统: redhat 6.5 mini
机器名 |
ip |
vip |
gw |
lvs01(主lvs) |
192.168.10.10(外网) 192.168.20.10(内网) |
192.168.10.254 |
|
lvs02(备lvs) |
192.168.20.10(外网) 192.168.20.20(内网) |
192.168.10.254 |
|
rs01 (web) |
192.168.20.100 |
192.168.20.254 |
192.168.20.254 |
rs02 (web) |
192.168.20.200 |
192.168.20.254 |
192.168.20.254 |
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服务
[[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] ~]# 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]# vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
[[email protected] yum.repos.d]# sysctl –p
[[email protected] yum.repos.d]# vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
[[email protected] yum.repos.d]# sysctl –p
[[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.10.10:3636,点击login,输入用户名和密码
5.2 配置lvs01,选择nat 模式,最后点击accept
5.3 配置lvs02的ip,先点击ENABLE,配置ip 后,最后点击accept确定
5.4 配置对外的服务,点击add->edit->accept
5.5 配置真实服务器(rs01和rs02)步骤add->edit->accept->active
5.6 up对外服务的vip
5.7 将在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] ~]# cat /etc/sysconfig/ha/lvs.cf
serial_no = 17
primary = 192.168.10.10
primary_private = 192.168.20.10
service = lvs
backup_active = 1
backup = 192.168.10.20
backup_private = 192.168.20.20
heartbeat = 1
heartbeat_port = 539
keepalive = 6
deadtime = 18
network = nat
nat_router = 192.168.20.254 eth1:0
nat_nmask = 255.255.255.0
debug_level = NONE
monitor_links = 0
syncdaemon = 0
virtual http {
active = 1
address = 192.168.10.254 eth0:1
vip_nmask = 255.255.255.0
port = 80
send = "GET / HTTP/1.0\\r\\n\\r\\n"
expect = "HTTP"
use_regex = 0
load_monitor = none
scheduler = rr
protocol = tcp
timeout = 6
reentry = 15
quiesce_server = 0
server rs01 {
address = 192.168.20.100
active = 1
weight = 1
}
server rs02 {
address = 192.168.20.200
active = 1
weight = 2
}
}
5.8 在lvs01,lvs02 上启动负载均衡的监控进程
[[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.9 查看lvs的正常运行状态
6、 测试
6.1 访问vip,web的内容是后台两台真实服务器网页内容,轮替提供服务
6.2 lvs01失效的情况下服务依然可用(我直接把lvs01关机了)
[[email protected] ~]# elinks -dump http://192.168.10.254
rs01