技术支持 云市场镜像产品 其它镜像环境 Web 负载均衡解决方案 HAproxy

Web 负载均衡解决方案 HAproxy

操作系统:centos 6.5

软件明细:haproxy - nginx

注:各个软件版本以云市场镜像中产品介绍为准。

在镜像环境中,/root/sh-haproxy.tar.gz 是安装镜像环境的脚本,您可以在 centos 6.5 统中自行采用此脚本安装,安装后的环境跟镜像里初始化的环境一致。值得注意的是,如果采用此脚本安装镜像环境,需要 chmod +x install.sh 即可执行。

在镜像环境中,/alidata/haproxy 是安装环境的主目录,镜像中的环境是在此目录下编译安装的。

软件的主目录:/alidata haproxy主目录: /alidata/haproxy nginx主目录:/alidata/nginx haproxy配置文件:/alidata/haproxy/haproxy.cfg nginx配置文件:/alidata/nginx/conf/vhosts 网站存放目录:/alidata/www

haproxy: /etc/init.d/haproxy start/stop/restart Nginx: /etc/init.d/nginx start/stop/restart

如何卸载镜像环境中安装的软件,可以参考如下命令完成卸载:

cd  ~
chmod +x uninstall.sh
./uninstall.sh

备注:执行以上卸载,会清理镜像环境的 /alidata 目录,请卸载前自行备份好相应数据。

1.在使用镜像安装系统后,默认开启了 haproxy 监控页面,网址为:http://IP:8888/stats ,该网页的配置在配置文件 /alidata/haproxy/haproxy.cfg 中:

listen admin_stats bind 0.0.0.0:8888 #8888端口可以自行修改,请注意不要导致端口冲突 option httplog stats refresh 30s stats uri /stats stats realm Haproxy Manager stats auth admin:admin #stats hide-version 2.访问网址 http://IP:8888/stats ,如下图所示,使用用户名:admin,密码:admin 登录:

1.实验条件: 114.215.173.93:haproxy 镜像

114.215.173.93,端口:81,web01,网站应用

114.215.173.93,端口:82,web02,网站应用

使用netstat -tpln 查看端口

注:实际情况中,web01 和 web02 上必须部署相同的应用,该实验为了区分通过 haproxy 转发到的后台服务器,部署的网站内容不一致,下面2图分别是 web01 、 web02 的网站

Haproxy 的7层负载配置 在114.215.173.93上的配置文件 /alidata/haproxy/haproxy.cfg 中进行下面一段配置

方法一:

listen test2 :80 option httpclose option forwardfor server s1 127.0.0.1:81 check weight 1 minconn 1 maxconn 3 check inter 40000 server s2 127.0.0.1:82 check weight 1 minconn 1 maxconn 3 check inter 40000 3.在步骤1的前提下,在114.215.173.93上配置了7层负载均衡,访问 http://114.215.173.93 时,可以访问到 http://114.215.173.93:81http://114.215.173.93:82 访问的页面