赞
踩
目录
虚拟机 | 操作系统 | ip地址 | 软件安装 |
---|---|---|---|
HAproxy | centOS7 | 192.168.115.130 | haproxy-1.7.2 |
web1 | centOS7 | 192.168.115.131 | httpd-2.4.6 |
web2 | centOS7 | 192.168.115.150 | httpd-2.4.6 |
- wget https://www.haproxy.org/download/1.7/src/haproxy-1.7.2.tar.gz
-
- #网上下载
-
- tar xf haproxy-1.7.2.tar.gz
-
- #解压
-
- make PREFIX=/usr/local/haproxy TARGET=linux2628
-
- #可能会报失败错误,查询是否安装gcc
-
- make install PREFIX=/usr/local/haproxy
-
- #安装haproxy
- mkdir /etc/haproxy
-
-
- touch /etc/haproxy/haproxy.cfg
- vim /etc/haproxy/haproxy.cfg
-
- global
- daemon
- maxconn 256
- pidfile /var/run/haproxy.pid
-
-
- defaults
- mode tcp
- timeout connect 5000ms
- timeout client 50000ms
- timeout server 50000ms
-
-
- frontend http-in
- bind *:80
- default_backend servers
-
-
- backend servers
- server server1 192.168.115.131:80 maxconn 32
- server server2 192.168.115.150:80 maxconn 32
-
-
- balance roundrobin #轮询
- #web1
- echo web1 > /var/www/html/index.html
-
- #web2
- echo web2 > /var/www/html/index.html
- #haproxy虚拟机启动haproxy服务
- systemctl daemon-reload
-
- systemctl start haproxy
-
- #web1、2启动apache服务
-
- systemctl start httpd
- global
- daemon
- maxconn 256
- pidfile /var/run/haproxy.pid
-
-
- defaults
- mode http
- timeout connect 5000ms
- timeout client 50000ms
- timeout server 50000ms
-
-
- frontend http-in
- bind *:80
- default_backend servers
-
-
- backend servers
- server server1 192.168.115.131:80 maxconn 32
- server server2 192.168.115.150:80 maxconn 32
-
- #在haproxy配置文件中写入
-
- listen stats #定义监控页面
- bind *:1080 #绑定端口1080
- stats refresh 30s #每30秒更新监控数据
- stats uri /stats #访问监控页面的uri
- stats realm HAProxy\ Stats #监控页面的认证提示
- stats auth test:123 #监控页面的用户名和密码
- systemctl daemon-reload
-
-
-
- systemctl restart haproxy
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。