ubuntu下使用haproxy做tcp 层的负载均衡
来源:互联网 发布:卷皮网源码7.0 编辑:程序博客网 时间:2024/05/16 18:58
首先下载haproxy包:
wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.13.tar.gz
安装:
tar zxvf haproxy-1.4.13.tar.gz
make TARGET=linux26 PREFIX=/usr/local/haproxy ##我的系统内核为2.6,所以target=linux26
make install PREFIX=/usr/local/haproxy
然后进行配置:
vi /etc/haproxy/haproxy.cfg
##写入以下内容:
###########全局配置#########global daemon nbproc 1 pidfile /var/run/haproxy.pid########默认配置############defaults mode http #默认的模式mode { tcp|http|health },tcp是4层,http是7层,health只会返回OK retries 2 #两次连接失败就认为是服务器不可用,也可以通过后面设置 option redispatch #当serverId对应的服务器挂掉后,强制定向到其他健康的服务器 option abortonclose #当服务器负载很高的时候,自动结束掉当前队列处理比较久的链接 maxconn 4096 #默认的最大连接数 timeout connect 5000ms #连接超时 timeout client 30000ms #客户端超时 timeout server 30000ms #服务器超时 #timeout check 2000 #=心跳检测超时 log 127.0.0.1 local0 err #[err warning info debug]########统计页面配置########listen admin_stats bind 0.0.0.0:1080 #监听端口 mode http #http的7层模式 option httplog #采用http日志格式 #log 127.0.0.1 local0 err maxconn 10 stats refresh 30s #统计页面自动刷新时间 stats uri /stats #统计页面url stats realm XingCloud\ Haproxy #统计页面密码框上提示文本 stats auth admin:admin #统计页面用户名和密码设置 stats hide-version #隐藏统计页面上HAProxy的版本信息########test1配置#################listen test1 bind 0.0.0.0:90 mode tcp #maxconn 4086 #log 127.0.0.1 local0 debug server s1 10.18.138.201:80 server s2 10.18.102.190:80 server s3 10.18.102.189:80 server s4 10.18.102.188:80 server s5 10.18.102.187:80########frontend配置######################test2配置#################listen test2 bind 0.0.0.0:91 mode tcp #maxconn 4086 #log 127.0.0.1 local0 debug server s1 10.18.138.130:80 weight 1 server s2 10.18.138.201:8080 weight 6########frontend配置##############
ok. 启动haproxy.
haproxy /etc/haproxy/haproxy.cfg
马上试试, 发现负载已经成功了。
但是有一个问题, 不能看到log. 是因为我没有启动syslog.
在ubuntu下, 需要启动的是rsyslogd.
我的机器上没有安装,先安装rsyslogd.
apt-get install rsyslog
安装完成之后,配置rsyslog
vi /etc/rsyslog.d/haproxy.conf
加入以下内容:
$ModLoad imudp
$UDPServerRun 514
local0.* /var/log/haproxy.log
保存, 重启rsyslogd.
restart rsyslogd
ok.现在你就可以看到日志了。
试试看。
tail -f /var/log/haproxy.log
最后,再加一个平滑重启的命令:
haproxy -f /etc/haproxy/haproxy.cfg -sf `cat /var/run/haproxy.pid`
- ubuntu下使用haproxy做tcp 层的负载均衡
- ubuntu下使用haproxy做tcp 层的负载均衡
- haproxy做TCP层的负载均衡
- 使用haproxy做tcp 层的负载均衡
- Haproxy+keepalived TCP 层的负载均衡
- Ubuntu 16.04 下安装HAProxy 1.5.11 做tcp负载均衡
- ubuntu下使用nginx做负载均衡
- 使用Haproxy对Sphinx做负载均衡
- HAproxy七层负载均衡
- windows下 Haproxy 负载均衡(HTTP+TCP)--- 建议
- 在Linux 下 用HAProxy给MySQL做负载均衡
- 使用haproxy给mail server做负载均衡
- 使用balancer_by_lua_block做应用层负载均衡
- 使用balancer_by_lua_block做应用层负载均衡
- Haproxy安装、tcp/ip & http的负载均衡
- Haproxy安装、tcp/ip & http的负载均衡
- nginx haproxy两者做负载均衡的优缺点
- 用Haproxy来做RabbitMQ集群的负载均衡
- c语言—指针高级和宏定义
- Linux内存管理之一:基本概念篇 .
- HDU-1828-Picture(线段树)
- MyEclipse快捷键大全
- 环境变量中administrator的用户变量和系统变量
- ubuntu下使用haproxy做tcp 层的负载均衡
- spintf用法
- CSS样式中"大于号"
- Swift编程语言学习1.7——断言
- 陇南做流产哪里好
- 为什么要用Linux做开发
- 横竖屏转换(onConfigurationChanged)
- 简单的几种光照模型
- mips编译日志