haproxy安装及配置

安装

操作系统:Centos7.4

yum install haproxy


配置


[root@wsjy-proxy01 haproxy]# cat haproxy.cfg
global
    log /dev/log    local0
    log /dev/log    local1 notice
    chroot /var/lib/haproxy
    stats socket /var/run/haproxy-admin.sock mode 660 level admin
    stats timeout 30s
    user haproxy
    group haproxy
    daemon
    nbproc 1

defaults
    log     global
    timeout connect 5000
    timeout client  10m
    timeout server  10m

listen  admin_stats
    bind 0.0.0.0:10080
    mode http
    log 127.0.0.1 local0 err
    stats refresh 30s
    stats uri /status
    stats realm welcome login\ Haproxy
    stats auth admin:123456
    stats hide-version
    stats admin if TRUE

listen wsjy_proxy
    bind 0.0.0.0:80
    mode tcp
    option tcplog
    balance source
    server 10.101.75.121 10.101.75.121:30080 check inter 2000 fall 2 rise 2 weight 1
    server 10.101.75.122 10.101.75.122:30080 check inter 2000 fall 2 rise 2 weight 1
    server 10.101.75.123 10.101.75.123:30080 check inter 2000 fall 2 rise 2 weight 1


systemctl restart haproxy

日志配置

/etc/rsyslog.conf 添加:

# /dev/log to chroot'ed HAProxy processes
$AddUnixListenSocket /dev/log
if $programname startswith 'haproxy' then /var/log/haproxy/haproxy.log

[root@wsjy-proxy01 haproxy]# systemctl restart rsyslog


日志查看


[root@wsjy-proxy01 haproxy]# tailf /var/log/haproxy/haproxy.log 
May 17 14:43:53 wsjy-proxy01 haproxy-systemd-wrapper: haproxy-systemd-wrapper: executing /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
May 17 14:43:53 wsjy-proxy01 haproxy[1985]: Proxy admin_stats started.
May 17 14:43:53 wsjy-proxy01 haproxy[1985]: Proxy admin_stats started.
May 17 14:43:53 wsjy-proxy01 haproxy[1985]: Proxy wsjy_proxy started.
May 17 14:43:53 wsjy-proxy01 haproxy[1985]: Proxy wsjy_proxy started.
May 17 14:43:53 wsjy-proxy01 haproxy[1985]: Proxy wsjy_public_proxy started.
May 17 14:43:53 wsjy-proxy01 haproxy[1985]: Proxy wsjy_public_proxy started.


参考

https://unix.stackexchange.com/questions/260940/does-haproxy-support-logging-to-a-file

posted @ 2019-05-17 14:50  bugbeta  阅读(210)  评论(0编辑  收藏  举报