搭建环境:
两台centos。
主机一:192.168.1.6 安装haproxy以及apche
主机二:192.168.1.7 安装apache
主机一配置:
使用本地yum源。
安装haproxy、apache:
[[email protected] ~]# yum -y install haproxy httpd
[[email protected] conf.d]# vim /etc/httpd/conf.d/web.conf
[[email protected] ~]# vim /etc/httpd/conf/httpd.conf
去掉 listen 80
写一个访问页面:
[[email protected] ~]# echo "<h1>我是主机一(haproxy)。</h1>" > /var/www/html/index.html
[email protected] ~]# systemctl restart httpd.service
访问:
[[email protected] ~]# curl 192.168.1.6:8181
<h1>我是主机一(haproxy)。</h1>
配置haproxy:
[[email protected] ~]# vim /etc/haproxy/haproxy.cfg #最后一行、默认使用轮询
[[email protected] ~]# systemctl restart haproxy
主机二配置:
[[email protected] ~]# yum -y install httpd
[[email protected] ~]# vim /etc/httpd/conf.d/web.conf
[[email protected] ~]# vim /etc/httpd/conf/httpd.conf
去掉 listen 80
[[email protected] ~]# systemctl restart httpd
[[email protected] ~]# echo "<h1>我是主机二。(haproxy)</h1>" > /var/www/html/index.html
测试:
[[email protected] ~]# curl 192.168.1.7:8181
<h1>我是主机二。(haproxy)</h1>
测试:
刷新:
原文地址:https://www.cnblogs.com/meml/p/12443398.html