1.定义配置
[root@proxy01 haproxy]# cat /etc/haproxy/conf.d/app.oldxu.net.cfg
frontend app_web
bind *:8899
mode http
use_backend app_servers
backend app_servers
balance roundrobin
server web1 172.16.1.7:8888 check inter 3000 fall 2 rise 5
server web2 172.16.1.8:8888 check inter 3000 fall 2 rise 5
2.haproxy启动方式:
[root@proxy01 haproxy]# cat /usr/lib/systemd/system/haproxy.service
[Unit]
Description=HAProxy Load Balancer
After=network-online.target
Wants=network-online.target
[Service]
EnvironmentFile=-/etc/sysconfig/haproxy
Environment="CONFIG=/etc/haproxy/haproxy.cfg" "PIDFILE=/run/haproxy.pid"
Environment="CONFIG_D=/etc/haproxy/conf.d/"
ExecStartPre=/usr/sbin/haproxy -f $CONFIG -f $CONFIG_D -c -q $OPTIONS
ExecStart=/usr/sbin/haproxy -Ws -f $CONFIG -f $CONFIG_D -p $PIDFILE $OPTIONS
ExecReload=/usr/sbin/haproxy -f $CONFIG -f $CONFIG_D -c -q $OPTIONS
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=mixed
SuccessExitStatus=143
Type=notify
[Install]
WantedBy=multi-user.target
[root@proxy01 haproxy]# systemctl daemon-reload
[root@proxy01 haproxy]# systemctl restart haproxy
[root@proxy01 haproxy]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:8899 0.0.0.0:* LISTEN 112435/haproxy
PS: #创建子配置文件,注意:必须为cfg后缀非.开头的配置文件