haproxy 笔记

CentOS7 下安装

yum install haproxy
cat >> /etc/sysctl.conf <<-END
net.ipv4.ip_forward=1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 8
END
sysctl -p
sed -i '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config
reboot

全局配置

global
    log         127.0.0.1 local3 info
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     102400
    user        haproxy
    group       haproxy
    daemon
    stats socket /var/lib/haproxy/stats

默认配置

defaults
    log global
    option dontlognull
    option redispatch
    option abortonclose
    timeout check 8s

tcp 连接多个 ceph-radosgw

frontend  ceph-radosgw *:7480
    timeout client 8s
    default_backend ceph-radosgw
backend ceph-radosgw
    mode tcp
    balance roundrobin
    timeout connect 8s
    timeout server 8s
    retries 2
    server cpeh240 10.9.10.234:7480 check
    server ceph241 10.9.10.235:7480 check
    server ceph243 10.9.10.236:7480 check

tcp 连接 mysql galera cluster

frontend mysql *:3306
    timeout client 1800s
    default_backend mysql
backend mysql
    balance source
    option tcpka
    timeout connect    8s
    timeout server     1800s
    retries 2
    server  mysql231   10.9.10.231:3306 check inter 4s
    server  mysql232   10.9.10.232:3306 check inter 4s
    server  mysql233   10.9.10.233:3306 check inter 4s

tcp 连接 redis 主库

frontend redis *:6379
    timeout client 1800s
    default_backend redis
backend redis
    balance roundrobin
    timeout connect 8s
    timeout server 1800s
    retries 2
    option tcp-check
    tcp-check connect
    tcp-check send PING\r\n
    tcp-check expect string +PONG
    tcp-check send info\ replication\r\n
    tcp-check expect string role:master
    tcp-check send QUIT\r\n
    tcp-check expect string +OK
    server redis87 10.1.14.87:6379 check inter 4s
    server redis88 10.1.14.88:6379 check inter 4s
    server redis89 10.1.14.89:6379 check inter 4s

状态页面

listen admin_stats
    bind 0.0.0.0:10080
    mode http
    maxconn 100
    timeout client 1m
    timeout connect 4s
    timeout server 4s
    stats refresh 30s
    stats uri /
    stats auth username:password
    stats realm haproxy for private user, enter username/password
    stats hide-version

生成日志文件 haproxy.log

touch /var/log/haproxy.log
chown haproxy.haproxy /var/log/haproxy.log
sed -i -e '/ModLoad imudp/s/^#//' \
    -e '/UDPServerRun 514/s/^#//' /etc/rsyslog.conf
echo 'local3.* /var/log/haproxy.log' >> /etc/rsyslog.conf
systemctl restart rsyslog
systemctl restart haproxy

参考

转载于:https://my.oschina.net/colben/blog/1782831

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值