配置haproxy
添加haproxy用户
添加一个 haproxy 用户,并赋权
代码语言:javascript复制[root@h101 haproxy]# grep proxy /etc/passwd
[root@h101 haproxy]# useradd haproxy
[root@h101 haproxy]# grep proxy /etc/passwd
haproxy:x:505:506::/home/haproxy:/bin/bash
[root@h101 haproxy]# chown -R haproxy.haproxy /usr/local/haproxy/
[root@h101 haproxy]# ll /usr/local/haproxy/
total 16
drwxr-xr-x 3 haproxy haproxy 4096 Mar 2 16:23 doc
drwxr-xr-x 2 haproxy haproxy 4096 Mar 2 16:23 sbin
drwxr-xr-x 3 haproxy haproxy 4096 Mar 2 16:23 share
[root@h101 haproxy]#
配置haproxy
代码语言:javascript复制[root@h101 ~]# cd /usr/local/haproxy/
[root@h101 haproxy]# vim haproxy.cfg
[root@h101 haproxy]# grep -v "^#" haproxy.cfg
global
log 127.0.0.1 local0
maxconn 512
chroot /usr/local/haproxy
user haproxy
group haproxy
daemon
defaults
log global
option dontlognull
retries 3
option redispatch
maxconn 512
timeout connect 5000
timeout client 50000
timeout server 50000
listen admin_status
bind *:1234
stats uri /admin
stats auth admin:admin
mode http
option httplog
listen all_mycat
bind *:8888
mode tcp
option tcplog
balance roundrobin
server mycat_101 192.168.100.101:8066 check port 8066 inter 5s rise 2 fall 3
server mycat_102 192.168.100.102:8066 check port 8066 inter 5s rise 2 fall 3
timeout server 20000
listen all_mycat_admin
bind *:9999
mode tcp
option tcplog
balance roundrobin
server mycat_101 192.168.100.101:9066 check port 9066 inter 5s rise 2 fall 3
server mycat_102 192.168.100.102:9066 check port 9066 inter 5s rise 2 fall 3
timeout server 20000
[root@h101 haproxy]#