[root@server1 haproxy]# cd /etc/haproxy/
[root@server1 haproxy]# vim haproxy.cfg
*******************************************************************************
global
maxconn 10000
stats socket /var/run/haproxy.stat mode 600 level admin
log 127.0.0.1 local0
uid 200
gid 200
chroot /var/empty
daemon
defaults ##可以把私有(frontend public.backend static)写到全局中(defaults)
mode http
log global
option httplog
option dontlognull
monitor-uri /monitoruri
maxconn 8000
timeout client 30s
option prefer-last-server
retries 2
option redispatch
timeout connect 5s
timeout server 5s
stats uri /admin/stats
stats auth admin:westos ##添加认证
# The public 'www' address in the DMZ
frontend public
bind 172.25.18.1:80
#bind 192.168.1.10:443 ssl crt /etc/haproxy/haproxy.pem
#use_backend static if { hdr_beg(host) -i img }
#use_backend static if { path_beg /img /css }
default_backend static
# The static backend backend for 'Host: img', /img and /css.
backend static
balance roundrobin
server statsrv1 172.25.18.2:80 check inter 1000
server statsrv2 172.25.18.3:80 check inter 1000
******************************************************************************
[root@server1 haproxy]# vim /etc/rsyslog.conf
13 $ModLoad imudp ##(13.14打开UDP)
14 $UDPServerRun 514
42 *.info;mail.none;authpriv.none;cron.none;local0.none /var/log /messages ##message中不记录haporxy
63 local0.* /var/log/haproxy.log ##定义haproxy日至目录
[root@server1 haproxy]# /etc/init.d/haproxy restart
[root@server1 haproxy]# /etc/init.d/rsyslog restart
测试:
curl 172.25.18.1
[root@server1 haproxy]# cat /var/log/haproxy.log
[root@server1 haproxy]# cat /var/log/message
haproxy日志
最新推荐文章于 2021-07-06 16:32:00 发布