操作步骤:
105php
在web安装apache
yum -y install httpd
[root@kvm122105 ~]# echo 122105 > /var/www/html/index.html
[root@kvm122105 ~]# echo 122105php > /var/www/html/index.php
systemctl start httpd
106php
在web安装apache
yum -y install httpd
[root@kvm122106 ~]# echo 122106 > /var/www/html/index.html
[root@kvm122106 ~]# echo 122106php > /var/www/html/index.php
systemctl start httpd
[root@kvm122101 haproxy-1.7]# tar xf haproxy-1.7.5.tar.gz
[root@kvm122101 haproxy-1.7]# cd haproxy-1.7.5/
[root@kvm122101 haproxy-1.7.5]# make TARGET=linux2628 PREFIX=/usr/local/haproxy/
[root@kvm122101 haproxy-1.7.5]# make TARGET=linux2628 PREFIX=/usr/local/haproxy/ install
[root@kvm122101 haproxy-1.7.5]# cd /usr/local/haproxy/
[root@kvm122101 haproxy]# vim haproxy.cfg
global #参数是进程级的,通常是和操作系统相关
log 127.0.0.1 local3
maxconn 4096
user nobody
group nobody
daemon
pidfile /usr/local/haproxy/haproxy.pid
defaults #配置默认参数,这些参数可以被用用到frontend,backend,Listen组件
log global
mode http
maxconn 2048
timeout connect 10s
timeout client 1m
timeout server 1m
retries 3
option redispatch
listen haproxy-monitor #Fronted和backend的组合体
bind *:8080
mode http
option forwardfor
option httpclose
stats enable
stats show-legends
stats refresh 5s
stats uri /stats
stats auth admin:admin
frontend main
#接收请求的前端虚拟节点,Frontend指定具体使用用后端的backend
bind *:8008
log global
option forwardfor
option httpclose
default_backend html-server
backend html-server
#后端服务集群的配置,真实服务器器,一一个Backend对应一一个或者多个实体服务器器
balance roundrobin
option httpchk GET /index.html
server html-A 192.168.122.105:80 check
server html-B 192.168.122.106:80 check
php操作
global
#参数是进程级的,通常是和操作系统相关
log 127.0.0.1 local3
maxconn 4096
user nobody
group nobody
daemon
pidfile /usr/local/haproxy/haproxy.pid
defaults
#配置默认参数,这些参数可以被用用到frontend,backend,Listen组件
log global
mode http
maxconn 2048
timeout connect 10s
timeout client 1m
timeout server 1m
retries 3
option redispatch
listen haproxy-monitor
#Fronted和backend的组合体
bind *:8080
mode http
option forwardfor
option httpclose
stats enable
stats show-legends
stats refresh 5s
stats uri /stats
stats auth admin:admin
frontend main
#接收请求的前端虚拟节点,Frontend指定具体使用用后端的backend
bind *:80
log global
option forwardfor
option httpclose
acl html url_reg -i .html$
acl php url_reg -i .php$
use_backend html-server if html
use_backend php-server if php
default_backend html-server
backend html-server
#后端服务集群的配置,真实服务器器,一一个Backend对应一一个或者多个实体服务器器
balance roundrobin
option httpchk GET /index.html
retries 3
option redispatch
cookie SERVERID insert indirect nocache
server html-A 192.168.122.105:80 cookie A check weight 1 inter 2000 rise 2 fall 5
server html-B 192.168.122.106:80 cookie B check weight 1 inter 2000 rise 2 fall 5
backend php-server
#后端服务集群的配置,真实服务器器,一一个Backend对应一一个或者多个实体服务器器
balance roundrobin
option httpchk GET /index.php
retries 3
option redispatch
cookie SERVERID insert indirect nocache
server html-A 192.168.122.105:80 cookie A check weight 1 inter 2000 rise 2 fall 5
server html-B 192.168.122.106:80 cookie B check weight 1 inter 2000 rise 2 fall 5
[root@kvm122101 haproxy]# ./sbin/haproxy -f haproxy.cfg