haproxy监听多配置文件

您所在的位置:网站首页 haproxy重新加载配置文件 haproxy监听多配置文件

haproxy监听多配置文件

2024-07-10 02:54| 来源: 网络整理| 查看: 265

haproxy是常用的负载均衡软件,在业务比较多的时候需要在主配置文件/etc/haproxy/haproxy.cfg配置较多的VIP和配置,时间一长多达数百行,后期进行更改会比较麻烦,而haproxy有没有Nginx的include功能可以直接导入其他目录的配置文件,因此通过自带参数-f实现配置文件导入功能,可以安装业务配置不同的 XX.cfg文件,然后在haproxy服务启动脚本里面进行配置即可,具体如下:

[root@haproxy~]# cat /usr/lib/systemd/system/haproxy.service [Unit] Description=HAProxy Load Balancer After=syslog.target network.target [Service] EnvironmentFile=/etc/sysconfig/haproxy ExecStart=/usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/pubcfg -p /run/haproxy.pid $OPTIONS ExecReload=/bin/kill -USR2 $MAINPID [Install] WantedBy=multi-user.target

创建配置文件目录

[root@haproxy~]# mkdir /etc/haproxy/pubcfg [root@haproxy~]#cat /etc/haproxy/pubcfg/haproxy1.cfg frontend test_web1 bind 172.20.0.1:80 mode http default_backend test_web_node1 backend test_web_node1 mode http balance source server 127.0.0.1 127.0.0.1:80 check inter 2000 fall 3 rise 5 server 127.0.0.1 127.0.0.1:80 check inter 2000 fall 3 rise 5 server 127.0.0.1 127.0.0.1:80 check inter 2000 fall 3 rise 5

重新加载配置文件:

[root@haproxy~]#systemctl reload haproxy


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3