编译安装haproxy

一、安装lua环境

1.1 安装依赖包

[root@centos7 ~]# yum install gcc readline-devel

1.2 下线lua源码包并解压

[root@centos7 ~]#wget http://www.lua.org/ftp/lua-5.3.5.tar.gz
[root@centos7 ~]# tar xvf lua-5.3.5.tar.gz  -C /usr/local/src

1.3 进行编译

[root@centos7 ~]# cd /usr/local/src/lua-5.3.5
[root@centos7 lua-5.3.5]# make linux test
#查看编译安装的版本
[root@centos7 lua-5.3.5]#src/lua -v
Lua 5.3.5 Copyright (C) 1994-2018 Lua.org, PUC-Rio

二、安装haproxy

2.1安装依赖包

[root@centos7 ~]#yum -y install gcc openssl-devel pcre-devel systemd-devel

2.2下载源码包

[root@centos7 ~]#wget https://www.haproxy.org/download/2.2/src/haproxy-2.2.20.tar.gz
[root@cetnos7 ~]#tar xvf haproxy-2.2.20.tar.gz
[root@cetnos7 ~]#cd haproxy-2.2.20/
[root@cetnos7 haproxy-2.2.20]#make ARCH=x86_64 TARGET=linux-glibc USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1 USE_LUA=1 LUA_INC=/usr/local/src/lua-5.3.5/src/ LUA_LIB=/usr/local/src/lua-5.3.5/src/
[root@cetnos7 haproxy-2.2.20]#make install PREFIX=/apps/haproxy
[root@cetnos7 haproxy-2.2.20]#ln -s /apps/haproxy/sbin/haproxy /usr/sbin/
[root@cetnos7 haproxy-2.2.20]#haproxy -v
HA-Proxy version 2.2.20-6e457a2 2022/01/12 - https://haproxy.org/
Status: long-term supported branch - will stop receiving fixes around Q2 2025.
Known bugs: http://www.haproxy.org/bugs/bugs-2.2.20.html
Running on: Linux 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64

2.3 准备service文件

[root@cetnos7 ~]#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
LimitNOFILE=100000

[Install]
WantedBy=multi-user.target

2.4 创建配置文件

[root@centos7 ~]# vim /etc/haproxy/haproxy.cfg
global
	maxconn 100000
	chroot /apps/haproxy
	stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin
	#uid 99
	#gid 99
	user haproxy
	group haproxy
	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 local2 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:123456  #状态页的登录账户和密码
	
listen web_port
	bind 10.0.0.7:80
	mode http
	log global
	server web1 127.0.0.1:8080 check inter 3000 fall 2 rise 5

2.5 启动haproxy

#准备socket文件目录
[root@centos7 ~]# mkdir /var/lib/haproxy
[root@centos7 ~]# useradd -r -s /sbin/nologin -d /var/lib/haproxy haproxy
[root@centos7 ~]# systemctl start haproxy

2.6 查看hapoxy的状态页面



到此,haproxy已安装完成

posted @ 2022-01-25 18:23  火火7412  阅读(161)  评论(0编辑  收藏  举报