#配置文件
# cat /usr/local/haproxy/2.7.0/conf/haproxy.cfg
# 如何解决该问题呢。在服务器资源(内存、CPU)还未满负荷情况下,增加Haproxy代理该服务的连接数限制即可。最常用的连接数配置为maxconn
#
# 该配置中,在global、defaults、listen、server四个位置均有maxconn参数信息,其中:
#
# global段中的maxconn: 设置整个haproxy进程的最大连接数
#
# default段中的maxconn: 设置所有代理段的默认最大连接数
#
# listen段中的maxconn: 设置该代理段的最大连接数
#
# server中的maxconn: 设置该后台服务的最大连接数
global
daemon
#log 127.0.0.1 local3 err
#log 127.0.0.1 local0
#log 127.0.0.1 local3 info
log 127.0.0.1 local0 info
# log local2.* /tmp/haproxy.log
# 设定每个haproxy进程所能接受的最大并发连接数;
maxconn 65536
# 每个进程每秒种所能创建的最大连接数量
maxconnrate 25600
# 每个进程每秒钟所能创建的最大数量
#maxsessrate 12500
ulimit-n 65536
#nbproc 1
pidfile /tmp/haproxy.pid
#
defaults
mode tcp # 协议,支持http、tcp、health三种
retries 3
option abortonclose
# 设置最大可支持的并发连接数
maxconn 65536
# 每个进程每秒种所能创建的最大连接数量
maxconnrate 25600
# 每个进程每秒钟所能创建的最大数量
#maxsessrate 12500
ulimit-n 65536
#nbproc 1
pidfile /tmp/haproxy.pid
#
defaults
mode tcp # 协议,支持http、tcp、health三种
retries 3
option abortonclose
maxconn 65536 # 设置最大可支持的并发连接数
timeout connect 300000ms
timeout client 300000ms
timeout server 300000ms
#---------------------------------------------------------------------
# HAPROXY状态页面
#---------------------------------------------------------------------
listen admin_stats
stats enable
# 监听端口
bind *:12345
mode http
option httplog
log global
maxconn 10
# 刷新间隔
stats refresh 30s
# 页面路径
stats uri /
stats realm haproxy
# 访问认证
stats auth admin:qwert123
stats hide-version
stats admin if TRUE
#---------------------------------------------------------------------
# 游戏应用数据转发配置
#---------------------------------------------------------------------
# 游戏网关服务
listen game-gate
bind :5051
mode tcp
fullconn 65536
server backend-gate 10.8.0.8
# tomcat 监听
listen game-chat
bind :7001
mode tcp
fullconn 65536
server backend-chat-server 10.8.0.8
#斗地主比赛场 401-450
listen game-ddz-bs
bind :6401-6450
mode tcp
fullconn 65536
server backend-ddz-bs 10.8.0.8
#四人斗地主普通场 61 -65
listen game-ddz4-pt
bind :6061-6165
mode tcp
fullconn 65536
server backend-ddz4-pt 10.8.0.8
#四人斗地主不洗牌场 127 - 182
listen game-ddz4-bxp
bind :6127-6182
mode tcp
fullconn 65536
server backend-ddz4-bxp 10.8.0.8
#四人斗地主红包场68
listen game-ddz4-hb
bind :6068
mode tcp
fullconn 65536
server backend-ddz4-hb 10.8.0.8
#三人斗地主普通场 71-74
listen game-ddz3-pt
bind :6071-6074
mode tcp
fullconn 65536
server backend-ddz3-pt 10.8.0.8
#三人斗地主不洗牌 124-126
listen game-ddz3-bxp
bind :6124-6126
mode tcp
fullconn 65536
server backend-ddz3-bxp 10.8.0.8
#三人斗地主红包场 76
listen game-ddz3-hb
bind :6076
mode tcp
fullconn 65536
server backend-ddz3-hb 10.8.0.8
#二人斗地主普通场 81-84
listen game-ddz2-pt
bind :6081-6084
mode tcp
fullconn 65536
server backend-ddz2-pt 10.8.0.8
#二人斗地主娱乐场 69
listen game-ddz2-yl
bind :6069
mode tcp
fullconn 65536
server backend-ddz2-yl 10.8.0.8
#二人斗地主话费场 118
listen game-ddz2-hf
bind :6118
mode tcp
fullconn 65536
server backend-ddz2-hf 10.8.0.8
#大赢家(拼三张)77-80
listen game-dyj-pt
bind :6077-6080
mode tcp
fullconn 65536
server backend-dyj-pt 10.8.0.8
#极品飞车(奔驰宝马)100-106
listen game-jpfc-pt
bind :6100-6106
mode tcp
fullconn 65536
server backend-jpfc-pt 10.8.0.8
#百人斗牌(牛牛)90-91
listen game-brdp-pt
bind :6090-6091
mode tcp
fullconn 65536
server backend-brdp-pt 10.8.0.8
#水果机 107
listen game-sgj-pt
bind :6107
mode tcp
fullconn 65536
server backend-sgj-pt 10.8.0.8
#摇摇乐 105
listen game-yyl-pt
bind :6105
mode tcp
fullconn 65536
server backend-yyl-pt 10.8.0.8
#杰克捕鱼 109 | 112 | 113 | 120 TODO
listen game-jkby-pt
bind :6109
bind :6112
bind :6113
bind :6120
mode tcp
fullconn 65536
server backend-jkby-pt 10.8.0.8
#水浒传 121-123
listen game-shz-pt
bind :6121-6123
mode tcp
fullconn 65536
server backend-shz-pt 10.8.0.8
#二人麻将 130-133
listen game-ermj-pt
bind :6130-6133
mode tcp
fullconn 65536
server backend-ermj-pt 10.8.0.8
#血流麻将 139-142
listen game-xlmj-pt
bind :6139-6142
mode tcp
fullconn 65536
server backend-xlmj-pt 10.8.0.8
#掼蛋 143-147
listen game-guandan-pt
bind :6143-6147
mode tcp
fullconn 65536
server backend-guandan-pt 10.8.0.8
#消灭病毒 160
listen game-xmbd-pt
bind :6160
mode tcp
fullconn 65536
server backend-xmbd-pt 10.8.0.8
#病毒战场170
listen game-bdzc-pt
bind :6170
mode tcp
fullconn 65536
server backend-bdzc-pt 10.8.0.8
#首领对决 175
listen game-sldj-pt
bind :6175
mode tcp
fullconn 65536
server backend-sldj-pt 10.8.0.8
#四人连炸地主普通场 51-54
listen game-lzddz4-pt
bind :6051-6054
mode tcp
fullconn 65536
server backend-lzddz4-pt 10.8.0.8
为了方便管理,写个脚本
# cat /usr/local/haproxy/2.7.0/haproxy.sh
#!/bin/bash
haproxy_home=/usr/local/haproxy/2.7.0
haproxy_cfg=$haproxy_home/conf/haproxy.cfg
haproxy_pid=/tmp/haproxy.pid
function start(){
echo "load config path: $haproxy_cfg"
if [ -f "$haproxy_cfg" ];then
echo "starting haproxy service"
$haproxy_home/sbin/haproxy -Ws -f $haproxy_cfg &
fi
}
function reload(){
if [ -f "$haproxy_cfg" ];then
$haproxy_home/sbin/haproxy -f $haproxy_cfg -sf `cat $haproxy_pid`
fi
}
function restart(){
if [ -f "$haproxy_cfg" ];then
$haproxy_home/sbin/haproxy -f $haproxy_cfg -st `cat $haproxy_pid`
fi
}
function stop(){
if [ -f $haproxy_pid ];then
kill -9 `cat $haproxy_pid`
fi
}
function init_log(){
mkdir -p /etc/rsyslog.d
$log_file=/etc/rsyslog.d/haproxy.conf
if [ ! -f $log_file ];then
cat > $log_file <<EOF
local0.* /tmp/haproxy.log
EOF
systemctl restart rsyslog
fi
}
function info(){
echo "[INFO]: haproxy home: $haproxy_home"
echo "[INFO]: haproxy config file: $haproxy_cfg"
}
function status(){
if ps -ef | grep haproxy | grep -v grep > /dev/null
then
echo "[success] haproxy is running"
else
echo "[warn] haproxy is stop!"
fi
}
usage="Usage: `basename $0` (start|kill|reload|init|info|status|restart|stop) parameter1 parameter2"
command=$1
case $command in
(start)
start
;;
(kill)
pkill haproxy
;;
(stop)
stop
;;
(restart)
restart
;;
(reload)
reload
;;
(init)
init_log
;;
(info)
info
;;
(status)
status
;;
(*)
echo "Error command"
echo "$usage"
;;
esac
正文完