场景:测试HAproxy服务的TCP代理服务,与nginx的TCP代理做性能对比
部署过程:
1、下载haproxy-1.8.0.zip,下载页面https://github.com/haproxy/haproxy/tree/v1.8.0
2、安装部署haproxy
unzip haproxy-1.8.0.zip
cdhaproxy-1.8.0
make TARGET=linux26 ARCH=X86_64 PREFIX=/home/homework/haproxy
make install PREFIX=/home/homework/haproxy
cd /home/homework/haproxy
mkdir etc logs
cd etc
vim haproxy.cfg
----------配置文件---------------
global
log 127.0.0.1 local3
pidfile /home/homework/haproxy/haproxy.pid
maxconn 4000
user homework
daemon
defaults
mode tcp
log global
log 127.0.0.1 local3
option tcplog
option dontlognull
option redispatch
option abortonclose
retries 3
timeout http-request 300s
timeout queue 1m
timeout connect 300s
timeout client 1m
timeout server 1m
timeout http-keep-alive 300s
timeout check 300s
maxconn 4000
listen stats
bind *:8090
balance roundrobin
mode tcp
server s1 192.168.8.63:8887 weight 1
-------------------------------------------------------------------
chown homework.homework -R /home/homework/haproxy/
3、开启日志接收
vim /etc/rsyslog.conf
下面两行注释去掉
$ModLoad imudp
$UDPServerRun 514
添加配置
local3.* /home/homework/haproxy/logs/access.log
vim /etc/sysconfig/rsyslog
SYSLOGD_OPTIONS="-c 5"修改为下面配置
SYSLOGD_OPTIONS="-r -m 0 -c 2"
/etc/init.d/rsyslog restart
4、启动haproxy
/home/homework/haproxy/sbin/haproxy -f /home/homework/haproxy/etc/haproxy.cfg
5、检查haproxy日志是否有输出
tail /home/homework/haproxy/logs/access.log
Dec 4 10:38:50 localhost haproxy[96612]: Proxy stats started.
Dec 4 10:38:50 localhost haproxy[96612]: Proxy stats started.
至此服务部署完成、重启服务的脚本自行创建,这里就不贴出来了。