Linux-haproxy动静分离
设备
centos7 10.0.0.27 client 客户端
centos7 10.0.017 haproxy服务器
centos8 10.0.0.8 httpd服务器
centos8 10.0.0.18 httpd服务器
设置启用子配置文件,haproxy服务器
[root@centos7-liyj ~]#mkdir /etc/haproxy/conf.d [root@centos7-liyj ~]#vim /lib/systemd/system/haproxy.service #编辑haproxy.service文件 [root@centos7-liyj ~]#cat /lib/systemd/system/haproxy.service [Unit] Description=HAProxy Load Balancer After=syslog.target network.target [Service] ExecStartPre=/usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/conf.d/ -c -q #添加子配置文件路径 ExecStart=/usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/conf.d/ -p /var/lib/haproxy/haproxy.pid ExecReload=/bin/kill -USR2 $MAINPID LimitNOFILE=100000 [Install] WantedBy=multi-user.target [root@centos7-liyj ~]#systemctl daemon-reload [root@centos7-liyj ~]#systemctl restart haproxy
haproxy服务器子配置文件
[root@centos7-liyj ~]#vim /etc/haproxy/conf.d/test.cfg frontend N65_web_https bind 10.0.0.17:80 ###########################acl setting###################### acl acl_static path_beg -i /static /images /javascript #定义acl acl acl_static path_end -i .jpg .jpeg .png .gif .css .js .html .htm acl acl_app path_beg -i /api ###########################acl hosts###################### #use_backend N65_webserver use_backend static_hosts if acl_static #判断acl匹配为静态资源,调用 static_hosts服务器组 default_backend app_hosts #所有acl不匹配,则使用默认的backend backend static_hosts server 10.0.0.8 10.0.0.8:80 check backend app_hosts server 10.0.0.18 10.0.0.18:80 check #backend N65_webserver # server 10.0.0.8 10.0.0.8:80 # server 10.0.0.18 10.0.0.18:80
测试调度
[root@centos7-liyj ~]#curl www.lyj.org #纯域名,直接调度到18 10.0.0.18 [root@centos7-liyj ~]#curl www.lyj.org 10.0.0.18[root@centos7-liyj ~]#curl www.lyj.org/index.html #域名后加了 .html文件,调度到8 10.0.0.8 [root@centos7-liyj ~]#curl www.lyj.org/index.html 10.0.0.8
浙公网安备 33010602011771号