小言_互联网的博客

MySQL集群解决方案(4):负载均衡

203人阅读  评论(0)

在前面架构中,虽然对mycat做了集群,保障了mycat的可靠性,但是,应用程序需要连接到多个mycat,显然不是很友好的,也就是说缺少负载均衡的组件,接下来我们来了解下HAProxy。

1 简介

官网:HAProxy - The Reliable, High Performance TCP/HTTP Load Balancer

关于并发性能,haproxy可以做到千万级的并发。(当然了,运行环境不同,测试结果也不相同的)  

2 架构

3 部署安装HAProxy

3.1 下载haproxy

 官网:HAProxy - The Reliable, High Performance TCP/HTTP Load Balancer

3.2 解压安装包

tar -zxvf haproxy-2.2.26.tar.gz

3.3 查看linux内核版本

uname -r

 centos6.X需要使用TARGET=linux26,  centos7.x使用linux31 

3.4 安装haproxy

进入haproxy-2.2.26目录,执行安装命令


  
  1. make TARGET=linux31
  2. make install PREFIX= /usr/local/haproxy- 2.2 .26

3.5 创建配置文件

mkdir /usr/local/haproxy-2.2.26/conf

3.6 将解压后目录下的文件拷贝到程序运行目录的配置文件目录下

cp examples/option-http_proxy.cfg  /usr/local/haproxy-2.2.26/conf/haproxy.cfg

3.7 编辑haproxy.cfg


  
  1. #输入如下内容
  2. global
  3. log 127.0.0.1 local2
  4. maxconn 4000
  5. daemon
  6. defaults
  7. mode http
  8. log global
  9. option httplog
  10. option dontlognull
  11. option http-server-close
  12. option forwardfor except 127.0.0.0/8
  13. option redispatch
  14. retries 3
  15. timeout http-request 10s
  16. timeout queue 1m
  17. timeout connect 10s
  18. timeout client 1m
  19. timeout server 1m
  20. timeout http-keep-alive 10s
  21. timeout check 10s
  22. maxconn 3000
  23. listen admin_stats
  24. bind 0.0.0.0:4001
  25. mode http
  26. stats uri /dbs
  27. stats realm Global\ statistics
  28. stats auth admin:admin123
  29. listen proxy-mysql
  30. bind 0.0.0.0:4002
  31. mode tcp
  32. balance roundrobin
  33. option tcplog
  34. #代理mycat服务 配置mycat的地址
  35. server mycat_1 192.168.222.130:8066 check port 8066 maxconn 2000
  36. server mycat_2 192.168.222.131:8066 check port 8066 maxconn 2000

3.8 启动haproxy

/usr/local/haproxy-2.2.26/sbin/haproxy -f /usr/local/haproxy-2.2.26/conf/haproxy.cfg

安装成功后,通过浏览器访问

查看到节点的运行状态

使用客户端测试连接

 

 


转载:https://blog.csdn.net/u013938578/article/details/128391797
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场