haproxy编译安装

本文档详细介绍了在CentOS系统中如何编译安装haproxy并添加lua库支持的过程,包括安装依赖、下载源码、编译参数设置、配置haproxy服务脚本以及主配置文件等步骤。但在安装完成后,服务无法启动且`reboot`命令失效,寻求解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#cnetos系统编译安装haproxy
#需要依赖lua库,官网:http://www.lua.org
#harpoxy 官网下载:http://www.haproxy.org/download/

DIR=pwd
file_lua=“lua-5.4.3”
file_haproxy=“haproxy-2.2.11”
suffix=".tar.gz"
lua_install_dir=/usr/local/src
haproxy_install_dir=/apps/haproxy
tar_dir=/usr/local/src
local_ip=ifconfig | grep 'netmask' | head -n1 |awk '{print $2}' #主机的ip地址
port=9999 #定义状态页监听端口

check(){
echo “正在安装环境包,请勿退出!”
yum install -y make vim wget libtermcap-devel ncurses-devel libevent-devel readline-devel gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel net-tools iotop zip unzip zlib-devel lrzsz tree lsof tcpdump systemd-devel
[ -f DIR/{DIR}/DIR/{file_lua}KaTeX parse error: Expected '}', got 'EOF' at end of input: …} ] || { echo "{lua_file}${suffix} is not find" ; exit 1; }
[ -f DIR/{DIR}/DIR/{file_haproxy}KaTeX parse error: Expected '}', got 'EOF' at end of input: …} ] || { echo "{lua_haproxy}${suffix} is not find" ; exit 1; }
if ! id haproxy &>/dev/null ;then
useradd -s /sbin/nologin -r haproxy
else
echo “haproxy用户已存在,略过用户创建!”
fi
[ -d ${lua_install_dir} ] || mkdir -p ${lua_install_dir}
}
install_lua(){
tar xf DIR/{DIR}/DIR/{file_lua}${suffix} -C ${lua_install_dir}
cd luainstalldir/{lua_install_dir}/luainstalldir/{file_lua}
make all test
if [ $? -eq 0 ];then
luainstalldir/{lua_install_dir}/luainstalldir/{file_lua}/src/lua -v
echo “lua install success!”
fi
}

install_haproxy(){
tar xf DIR/{DIR}/DIR/{file_haproxy}${suffix} -C ${tar_dir}
cd tardir/{tar_dir}/tardir/{file_haproxy}
make PREFIX=/apps/haproxy ARCH=x86_64 TARGET=linux-glibc USE_OPENSSL=1 USE_ZLIB=1 USE_LUA=1 USE_PCRE=1 USE_SYSTEMD=1 USE_CPU_AFFINITY=1 LUA_INC=luainstalldir/{lua_install_dir}/luainstalldir/{file_lua}/src LUA_LIB=luainstalldir/{lua_install_dir}/luainstalldir/{file_lua}/src
[ KaTeX parse error: Expected 'EOF', got '&' at position 11: ? -eq 0 ] &̲& make install …{haproxy_install_dir} || echo “haproxy make is error!”
#cp tardir/{tar_dir}/tardir/{file_haproxy}/haproxy /usr/sbin/
#配置haproxy启动服务脚本
cat > /usr/lib/systemd/system/haproxy.service << END
[Unit]
Description=HAProxy Load Balancer
After=syslog.target network.target
[Service]
ExecStartPre=haproxyinstalldir/sbin/haproxy−f/etc/haproxy/haproxy.cfg−c−qExecStart={haproxy_install_dir}/sbin/haproxy -f /etc/haproxy/haproxy.cfg -c -q ExecStart=haproxyinstalldir/sbin/haproxyf/etc/haproxy/haproxy.cfgcqExecStart={haproxy_install_dir}/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /var/lib/haproxy/haproxy.pid
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
END
mkdir /etc/haproxy
#配置haproxy主配置文件
cat > /etc/haproxy/haproxy.cfg << EOF
global
maxconn 100000
chroot ${haproxy_install_dir}
stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin
user haproxy
group haproxy
#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 admin:123456
EOF
mkdir /var/lib/haproxy
chown -R haproxy.haproxy /var/lib/haproxy
systemctl daemon-reload haproxy
systemctl enable --now haproxy
if [ ?−eq0];thenecho"haproxyinstallsuccess!"echo"可以访问状态页面http://? -eq 0 ];then echo "haproxy install success!" echo "可以访问状态页面http://?eq0];thenecho"haproxyinstallsuccess!"echo"访http://{local_ip}😒{port}/haproxy-status"
echo “账户/密码:admin/123456”
${haproxy_install_dir}/sbin/haproxy -v
fi

}
check
install_lua
install_haproxy
在这里插入图片描述

脚本执行完毕后 服务启动不起来,而且就连重启的reboot命令都不能执行! 希望老铁们指教!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值