基于centos7,所以有的命令和centos6.x及以下有所区别
首先安装
yum install haproxy -y cd /usr/local/haproxy/ 或 /etc/haproxy/ vim haproxy.cfg
下面编辑配置文件
global
ulimit-n 51200
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
user haproxy
group haproxy
daemon
defaults
log global
mode tcp
option dontlognull
timeout connect 600
timeout client 5m
timeout server 5m
frontend 51-in
bind *:3422
default_backend 51-out
backend 51-out
server server1 192.168.122.51:22 maxconn 20480
frontend 101-in
bind *:8888
default_backend 101-out
backend 101-out
server server1 192.168.122.101:8080 maxconn 20480
如果要添加多个就复制后面5行代码分别增加。
51-out只是用来区别转发端口的标签,可以根据自己爱好命名。
frontend 101-in
bind *:8888 //表示所有访问公网ip的8888端口的将转发到小鸡8080端口
default_backend 101-out
backend 101-out
server server1 192.168.122.101:8080 maxconn 20480 //设置小鸡的ip和需转发的端口
启动服务
haproxy -f /etc/haproxy/haproxy.cfg
设置开机启动
systemctl enable haproxy.service
查看运行状态
systemctl status haproxy.service
重启服务
service haproxy restart
追梦人博客
评论前必须登录!
注册