server1:
cd /etc/haproxy/
vim haproxy.cfg
注释
93 #listen westos *:80 #监听的实例名称,地址和端口
94 # balance roundrobin #负载均衡算法
95 # server web1 172.25.1.2:80 check
96 # server web2 172.25.1.3:80 check
写:
63 frontend westos *:80
64 acl url_static path_beg -i /images
65 acl url_static path_end -i .jpg .gif .png
66
67 use_backend static if url_static
68 default_backend app
73 backend static
74 #balance roundrobin
75 server static 172.25.1.3:80 check
80 backend app
81 balance roundrobin
82 server web1 172.25.1.2:80 check
83 server web2 172.25.1.1:8000 check
84 # server app3 127.0.0.1:5003 check
85 # server app4 127.0.0.1:5004 check
server1
yum install httpd -y
cd /var/www/html/
vim index.html
server1
cd /etc/httpd/conf
vim httpd.conf
42 Listen 8000
systemctl start httpd
3. 配置server2和server3
server3
cd /var/www/html/
mkdir images
cd images/ #在目录下放一张照片
systemctl start httpd
server2
systemctl start httpd
4. 测试
打开游览器:
http://172.25.1.1/
把server1做为backup:
cd /etc/haproxy/
vim haproxy.cfg
80 backend app
81 # balance roundrobin
82 server web1 172.25.1.2:80 check
83 server web2 172.25.1.1:8000 check backup
84 # server app3 127.0.0.1:5003 check
85 # server app4 127.0.0.1:5004 check
server2
systemctl stop httpd
打开游览器:
http://172.25.1.1/
动态:
打开游览器:
http://172.25.1.1/images/