先解决lua环境,(因为centos自带的版本不符合haproxy要求的最低版本(5.3)先安装Lua依赖的包
[root@slave-master lua-5.3.5]# yum install vim iotop bc gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel zip unzip zlib-devel net-tools lrzsz tree ntpdate telnet lsof tcpdump wget libevent libevent-devel bc systemd-devel bash-completion traceroute -y
[root@slave-master lua-5.3.5]# yum install libtermcap-devel ncurses-devel libevent-devel readline-devel -y
下载lua并编译安装
[root@slave-master haproxy-2.0.4]# cd /usr/local/src/
[root@slave-master src]# tar xf lua-5.3.5.tar.gz
[root@slave-master src]# cd lua-5.3.5
[root@slave-master lua-5.3.5]# make linux test
[root@slave-master lua-5.3.5]# src/lua -v
Lua 5.3.5 Copyright (C) 1994-2018 Lua.org, PUC-Rio
下载haproxy并编译安装
[root@slave-master src]# tar xf haproxy-2.0.4.tar.gz -C /usr/local/
[root@slave-master src]# cd /usr/local/haproxy
[root@slave-master haproxy-2.0.4]# make ARCH=x86_64 TARGET=linux-glibc USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1 USE_CPU_AFFINITY=1 USE_LUA=1 LUA_INC=/usr/local/src/lua-5.3.5/src/ LUA_LIB=/usr/local/src/lua-5.3.5/src/ PREFIX=/usr/local/haproxy
[root@slave-master haproxy-2.0.4]# make install PREFIX=/usr/local/haproxy
[root@slave-master haproxy-2.0.4]# cp haproxy /usr/sbin/
准备启动脚本
[root@slave-master haproxy]# vim /usr/lib/systemd/system/haproxy.service
[Unit]
Description=HAProxy Load Balancer
After=syslog.target network.target
[Service]
ExecStartPre=/usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -c -q
ExecStart=/usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /var/lib/haproxy/haproxy.pid
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
准备配置文件
[root@slave-master haproxy]# mkdir /etc/haproxy/
[root@slave-master haproxy]# vim /etc/haproxy/haproxy.cfg
global
maxconn 100000
chroot /usr/local/haproxy
stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin
uid 99
gid 99
daemon
#nbproc 4
#cpu-map 1 0
#cpu-map 2 1
#cpu-map 3 2
#cpu-map 4 3
pidfile /var/lib/haproxy/haproxy.pid
log 127.0.0.1 local3 info
defaults
option http-keep-alive
option forwardfor
maxconn 100000
mode http
timeout connect 300000ms
timeout client 300000ms
timeout server 300000ms
listen stats
mode http
bind 0.0.0.0:9999
stats enable
log global
stats uri /haproxy-status
stats auth haadmin:q1w2e3r4ys
listen web_port
bind 192.168.37.33:80
mode http
log global
server web1 127.0.0.1:8080 check inter 3000 fall 2 rise 5
启动服务
[root@slave-master src]# mkdir /var/lib/haproxy
[root@slave-master src]# chown 99.99 /var/lib/haproxy/ -R
[root@slave-master haproxy]# systemctl start haproxy
手机扫一扫
移动阅读更方便
你可能感兴趣的文章