root@ubuntu:~# tar xvf lua-5.4.2.tar.gz -C /usr/local/src
root@ubuntu:~# cd /usr/local/src/lua-5.4.2/
root@ubuntu:/usr/local/src/lua-5.4.2#
root@ubuntu:/usr/local/src/lua-5.4.2# make linux test
root@ubuntu:/usr/local/src/lua-5.4.2# cd src/
root@ubuntu:/usr/local/src/lua-5.4.2/src# ./lua -v
Lua 5.4.2 Copyright (C) 1994-2020 Lua.org, PUC-Rio
root@ubuntu:/usr/local/src/lua-5.4.2/src#
- 编译安装haproxy报错,缺少某个systemd的库
root@ubuntu:~# tar xvf haproxy-2.2.6.tar.gz -C /usr/local/src/
root@ubuntu:~# cd /usr/local/src/haproxy-2.2.6/
root@ubuntu:/usr/local/src/haproxy-2.2.6#
root@ubuntu:/usr/local/src/haproxy-2.2.6# 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.4.2/src/ LUA_LIB=/usr/local/src/lua-5.4.2/src/ PREFIX=/apps/haproxy
CC src/haproxy.o
src/haproxy.c:78:10: fatal error: systemd/sd-daemon.h: No such file or directory
#include <systemd/sd-daemon.h>
^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Makefile:880: recipe for target 'src/haproxy.o' failed
make: *** [src/haproxy.o] Error 1
root@ubuntu:/usr/local/src/haproxy-2.2.6# apt search systemd-dev
Sorting... Done
Full Text Search... Done
golang-blitiri-go-systemd-dev/bionic,bionic 0.0+git20170821.0.aec3508-1 all
Utilities to interact with systemd sockets in Go
golang-github-coreos-go-systemd-dev/bionic,bionic 14-1 all
Go client bindings for systemd socket activation, journal and D-Bus
libsystemd-dev/bionic-updates 237-3ubuntu10.43 amd64
systemd utility library - development files
lua-systemd-dev/bionic 0~git20160517-1 amd64
Development files for lua-systemd library
root@ubuntu:/usr/local/src/haproxy-2.2.6# apt install libsystemd-dev
root@ubuntu:/usr/local/src/haproxy-2.2.6# 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.4.2/src/ LUA_LIB=/usr/local/src/lua-5.4.2/src/ PREFIX=/apps/haproxy
root@ubuntu:/usr/local/src/haproxy-2.2.6# make install PREFIX=/apps/haproxy
root@ubuntu:/usr/local/src/haproxy-2.2.6# cp haproxy /usr/sbin/
root@ubuntu:/usr/local/src/haproxy-2.2.6# haproxy -v
HA-Proxy version 2.2.6-3709bd4 2020/11/30 - 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.6.html
Running on: Linux 4.15.0-55-generic #60-Ubuntu SMP Tue Jul 2 18:22:20 UTC 2019 x86_64
- 创建systemd开机自启动管理haproxy.service文件
root@ubuntu:~# cat /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@ubuntu:~# cat /etc/haproxy/haproxy.cfg
global
maxconn 100000
chroot /var/lib/haproxy
stats socket /var/lib/haproxy/haproxy.sock1 mode 600 level admin process 1
stats socket /var/lib/haproxy/haproxy.sock2 mode 600 level admin process 2
user haproxy
group haproxy
daemon
nbproc 2
cpu-map 1 0
cpu-map 2 1
pidfile /var/lib/haproxy/haproxy.pid
defaults
option http-keep-alive
option forwardfor
maxconn 100000
mode http
timeout connect 120s
timeout client 120s
timeout server 120s
listen stats
mode http
bind :9999
stats enable
log global
stats uri /haproxy-status
stats auth haadmin:123456
listen web
bind :80
mode http
log global
server web1 127.0.0.1:8080 check inter 3 fall 2 rise 5
server web2 127.0.0.1:9090 check inter 3 fall 2 rise 5
root@ubuntu:~# useradd -r -s /sbin/nologin haproxy
root@ubuntu:~# mkdir /var/lib/haproxy
root@ubuntu:~# chown -R haproxy.haproxy /var/lib/haproxy
root@ubuntu:~#
root@ubuntu:~# systemctl enable --now haproxy
root@ubuntu:~# ps aux |grep haproxy
root 30251 0.2 0.5 150996 22728 ? Ss 23:37 0:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /var/lib/haproxy/haproxy.pid
haproxy 30253 0.8 0.3 150996 15816 ? S 23:37 0:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /var/lib/haproxy/haproxy.pid
haproxy 30254 0.8 0.3 150996 15768 ? S 23:37 0:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /var/lib/haproxy/haproxy.pid
root 30256 0.0 0.0 13144 1016 pts/0 S+ 23:37 0:00 grep --color=auto haproxy
root@ubuntu:~#