目录
HAProxy 安装与配置
https://cloudinfrastructureservices.co.uk/haproxy-vs-nginx-whats-the-difference/
ha-proxy概述: ha-proxy是一款高性能的负载均衡软件。因为其专注于负载均衡这一些事情,因此与nginx比起来在负载均衡这件事情上做更好,更专业。
ha-proxy的特点: ha-proxy 作为目前流行的负载均衡软件,必须有其出色的一面。下面介绍一下ha-proxy相对LVS,Nginx等负载均衡软件的优点。
支持tcp / http 两种协议层的负载均衡,使得其负载均衡功能非常丰富。 支持8种左右的负载均衡算法,尤其是在http模式时,有许多非常实在的负载均衡算法,适用各种需求。 性能非常优秀,基于单进程处理模式(和Nginx类似)让其性能卓越。 拥有一个功能出色的监控页面,实时了解系统的当前状况。 功能强大的ACL支持,给用户极大的方便
官网地址:https://www.haproxy.org/#tact
注:以haproxy-ss-LATEST.tar.gz为例
$>wget https://www.haproxy.org/download/2.8/src/snapshot/haproxy-ss-LATEST.tar.gz
$>tar -zxvf haproxy-ss-LATEST.tar.gz
$>mv haproxy-ss-2023*** haproxy2.7
$>cd haproxy2.7
TARGET参数查看
$> uname -r
3.10.0-1160.el7.x86_64
$>make TARGET=linux31
注意:TARGET必须大写,如果缺少gcc则需安装gcc
$> yum -y install gcc automake autoconf libtool make
$>make install PREFIX=/usr/local/haproxy
注意:PREFIX必须大写
$>cd /usr/local/haproxy/
$> mkdir conf
$> cd conf/
$> cp /home/haproxy/haproxy-2.7.3/examples/option-http_proxy.cfg haproxy.cfg
haproxy.cfg 编辑(本机地址:192.168.106.101)
| global maxconn 4000 ulimit-n 16384 log 127.0.0.1 local0 user root group root chroot /usr/local/haproxy pidfile /usr/local/haproxy/conf/haproxy.pid daemon stats socket /usr/local/haproxy/stats defaults mode tcp log global option tcplog option dontlognull option http-server-close option redispatch retries 3 timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout http-keep-alive 10s timeout check 10s maxconn 3000 frontend mysql bind 0.0.0.0:63306 # mysql绑定端口 mode tcp log global default_backend mysql_server #balance roundrobin #server mysql1 192.168.106.102:33062 #server mysql2 192.168.108.133:33063 backend mysql_server balance leastconn server mysql1 192.168.106.102:33062 check inter 5s rise 2 fall 3 server mysql2 192.168.106.103:33063 check inter 5s rise 2 fall 3 #rise 2是2次正确认为服务器可用,fall 3是3次失败认为服务器不可用 listen haproxy_stats bind 0.0.0.0:8089 #控制台访问端口 option httplog log global stats enable mode http maxconn 100 stats refresh 30s stats uri /admin-status #控制台访问地址 stats realm Haproxy\ Statistics stats auth admin:admin #用这个账号登录,可以自己设置 stats hide-version |
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg

地址:192.168.106.101:63306 用户名密码与代理的192.168.106.102/103相同
连接报错:遇到reading initial communication packet问题
查找MYSQL配置文件:
检查my.cnf,设置过小innodb_buffer_pool_size = 18M ,调整为innodb_buffer_pool_size = 1024M
如果还不能连接则采用下面方法;
1、修改mysql配置文件
vi /etc/my.cnf(跳过域名解析)
[mysqld]段加skip-name-resolve
2、修改hosts.allow
vi /etc/hosts.allow加上:
mysqld : ALL : ALLOW
mysqld-max : ALL :ALLOW
$> cd /usr/local/java/haproxy2.7/examples
$> cp haproxy.init /etc/init.d/haproxy
$> vim /etc/init.d/haproxy
修改两个位置:
haproxy命令所在的位置:BIN=/usr/local/haproxy/sbin/haproxy


940

被折叠的 条评论
为什么被折叠?



