关于Haproxy安装和配置:负载配置【haproxy.cfg】问题记录

1.  存放地址:
more /etc/haproxy/haproxy.cfg
ps -ef | grep haproxy
看看有没有haproxy的进程就是了
或者看看服务器的23306的端口有没有打开
netstat -an | grep 23306

2. 问一个问题,安装了haproxy,自己默认就会产生/etc/haproxy.cfg
这个文件吗? 还是安装好了之后要拷过去呢?
都不是
要自己创建!一般放在/etc/haproxy.cfg!
这个文件和里面的内容都自己手工创建?  -- 对头

另外,我自己创建的haproxy.cfg文件,haproxy怎么知道我这个文件在哪里呢?
 你启动haproxy的时候要加参数去指定配置文件的位置!
 也就是说我创建N个配置都可以,只要启动时告诉他加载哪一个就OK了?
对头 

我们启动haproxy命令
/usr/local/haproxy/sbin/haproxy -f /etc/haproxy.cfg




启动HA
 启动就是
/usr/local/haproxy/sbin/haproxy -f /etc/haproxy.cfg



3. 启动、停止HA
haproxy没得停止的命令
直接kill掉进程
Last login: Wed Mar 5 18:04:33 2014 from 172.16.3.218
[root@gsidc-4q-saas16 ~]# ps -ef | grep haproxy
root 11687 1 0 Mar05 ? 00:00:00 /usr/local/haproxy/sbin/haproxy -f /etc/haproxy.cfg
root 14188 14159 0 15:00 pts/1 00:00:00 grep haproxy
[root@gsidc-4q-saas16 ~]# kill -9 11687
[root@gsidc-4q-saas16 ~]# ps -ef | grep haproxy
root 14197 14159 0 15:01 pts/1 00:00:00 grep haproxy
[root@gsidc-4q-saas16 ~]# /usr/local/haproxy/sbin/haproxy -f /etc/haproxy.cfg
[root@gsidc-4q-saas16 ~]# ps -ef | grep haproxy
root 14199 1 0 15:01 ? 00:00:00 /usr/local/haproxy/sbin/haproxy -f /etc/haproxy.cfg
root 14201 14159 0 15:01 pts/1 00:00:00 grep haproxy
[root@gsidc-4q-saas16 ~]# 

4. 实际配置文件

 haproxy.cfg

global
        log     127.0.0.1   local0
        maxconn 4096
        stats socket /tmp/haproxy.socket uid haproxy mode 770 level admin
        # nbproc  2
        pidfile /tmp/haproxy.pid
        daemon

defaults
        log     global
        log     127.0.0.1   local0
        mode    tcp
        option  tcplog
        option  dontlognull
        retries 3
        option  redispatch
        maxconn 2000
        timeout connect 5s
        timeout client  120s
        timeout server  120s

listen mysql_proxy :23306
        mode    tcp
        balance roundrobin
        server  mysql_65 172.16.12.65:3306 check inter 5000 rise 2 fall 3
        server  mysql_67 172.16.12.67:3306 check inter 5000 rise 2 fall 3

listen private_monitoring :8101
        mode    http
        option  httplog
        stats   enable
        stats   uri       /stats
        stats   refresh   5s


5. 关键设置 

【添加负载均衡,只需要设置这里】

 

希望对安装的你有所帮助,喜欢请赞一下!

Meet so Meet. C plusplus I-PLUS....
原文地址:https://www.cnblogs.com/iplus/p/4464711.html