Ubuntu 编译安装haproxy

  1. 整体完整安装安装
root@youyou:/apps# apt install  gcc make libreadline-dev libsystemd-dev zlib1g-dev libpcre3 libpcre3-dev libssl-dev
root@youyou:/apps#  wget http://www.lua.org/ftp/lua-5.3.5.tar.gz
root@youyou:/apps# tar xvf lua-5.3.5.tar.gz
root@youyou:/apps# cd /apps/lua-5.3.5/
root@youyou:/apps/lua-5.3.5# make linux test
root@youyou:/apps# cd /apps
root@youyou:/apps# tar xvf haproxy-2.0.12.tar.gz
root@youyou:/apps# cd haproxy-2.0.12/
root@youyou:/apps# 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=/apps/lua-5.3.5/src/ LUA_LIB=/apps/lua-5.3.5/src/ PREFIX=/apps/haproxy
root@youyou:/apps# make install PREFIX=/apps/haproxy
root@youyou:/apps# cp /apps/haproxy/sbin/haproxy /usr/sbin/


## 启动脚本可以从yum安装的文件拷贝一个,也可以自己写
root@youyou:~# 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@youyou:~#  useradd haproxy -s /sbin/nologin
## 基础配置文件
root@youyou:~# cat /etc/haproxy/haproxy.cfg 
global
	maxconn 100000
	chroot /run/haproxy
	stats socket /run/haproxy.sock mode 600 level admin
	user haproxy
	group haproxy
	daemon
	#nbproc 4
	#cpu-map 1 0
	#cpu-map 2 1
	#cpu-map 3 2
	#cpu-map 4 3
	pidfile /run/haproxy.pid
defaults
	option http-keep-alive
	option forwardfor
	maxconn 100000
	mode http
	timeout connect 300000ms
	timeout client 300000ms
	timeout server 300000ms
root@youyou:~# 

  1. 编译安装lua报错问题
    需要安装三个包 gcc,make,libreadline-dev
root@youyou:/apps#  wget http://www.lua.org/ftp/lua-5.3.5.tar.gz
root@youyou:/apps# tar xvf lua-5.3.5.tar.gz
root@youyou:/apps/lua-5.3.5# make linux test

Command 'make' not found, but can be installed with:

apt install make      
apt install make-guile

root@youyou:/apps/lua-5.3.5# 
root@youyou:/apps/lua-5.3.5# 
root@youyou:/apps/lua-5.3.5# apt install make
root@youyou:/apps/lua-5.3.5# make linux test
cd src && make linux
make[1]: Entering directory '/apps/lua-5.3.5/src'
make all SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline"
make[2]: Entering directory '/apps/lua-5.3.5/src'
gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_USE_LINUX    -c -o lapi.o lapi.c
make[2]: gcc: Command not found
<builtin>: recipe for target 'lapi.o' failed
make[2]: *** [lapi.o] Error 127
make[2]: Leaving directory '/apps/lua-5.3.5/src'
Makefile:110: recipe for target 'linux' failed
make[1]: *** [linux] Error 2
make[1]: Leaving directory '/apps/lua-5.3.5/src'
Makefile:55: recipe for target 'linux' failed
make: *** [linux] Error 2
root@youyou:/apps/lua-5.3.5# apt install gcc
root@youyou:/apps/lua-5.3.5# make linux test
lua.c:82:10: fatal error: readline/readline.h: No such file or directory
 #include 
          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
<builtin>: recipe for target 'lua.o' failed
make[2]: *** [lua.o] Error 1
make[2]: Leaving directory '/apps/lua-5.3.5/src'
Makefile:110: recipe for target 'linux' failed
make[1]: *** [linux] Error 2
make[1]: Leaving directory '/apps/lua-5.3.5/src'
Makefile:55: recipe for target 'linux' failed
make: *** [linux] Error 2
root@youyou:/apps/lua-5.3.5# apt  install libreadline-dev
root@youyou:/apps/lua-5.3.5# make linux test
cd src && make linux
make[1]: Entering directory '/apps/lua-5.3.5/src'
make all SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline"
make[2]: Entering directory '/apps/lua-5.3.5/src'
gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_USE_LINUX    -c -o lua.o lua.c
gcc -std=gnu99 -o lua   lua.o liblua.a -lm -Wl,-E -ldl -lreadline 
gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_USE_LINUX    -c -o luac.o luac.c
gcc -std=gnu99 -o luac   luac.o liblua.a -lm -Wl,-E -ldl -lreadline 
make[2]: Leaving directory '/apps/lua-5.3.5/src'
make[1]: Leaving directory '/apps/lua-5.3.5/src'
src/lua -v
Lua 5.3.5  Copyright (C) 1994-2018 Lua.org, PUC-Rio
  1. 编译安装haproxy报错问题
root@youyou:/apps/haproxy-2.0.12# 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=/apps/lua-5.3.5/src/ LUA_LIB=/apps/lua-5.3.5/src/ PREFIX=/apps/haproxy
  CC      src/ev_poll.o
In file included from include/types/listener.h:29:0,
                 from include/types/global.h:32,
                 from src/ev_poll.c:26:
include/common/openssl-compat.h:5:10: fatal error: openssl/bn.h: No such file or directory
 #include 
          ^~~~~~~~~~~~~~
compilation terminated.
Makefile:834: recipe for target 'src/ev_poll.o' failed
make: *** [src/ev_poll.o] Error 1
root@youyou:/apps/haproxy-2.0.12# apt install libssl-dev
root@youyou:/apps/haproxy-2.0.12# 



root@youyou:/apps/haproxy-2.0.12# 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=/apps/lua-5.3.5/src/ LUA_LIB=/apps/lua-5.3.5/src/ PREFIX=/apps/haproxy
  CC      src/ev_poll.o
In file included from include/types/proxy.h:34:0,
                 from include/types/global.h:33,
                 from src/ev_poll.c:26:
include/common/regex.h:31:10: fatal error: pcre.h: No such file or directory
 #include 
          ^~~~~~~~
compilation terminated.
Makefile:834: recipe for target 'src/ev_poll.o' failed
make: *** [src/ev_poll.o] Error 1
root@youyou:/apps/haproxy-2.0.12#
root@youyou:/apps/haproxy-2.0.12# apt install libpcre3 libpcre3-dev



root@youyou:/apps/haproxy-2.0.12# 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=/apps/lua-5.3.5/src/ LUA_LIB=/apps/lua-5.3.5/src/ PREFIX=/apps/haproxy
  CC      src/ev_poll.o
  CC      src/ev_epoll.o
  CC      src/ssl_sock.o
  CC      src/hlua.o
  CC      src/hlua_fcn.o
  CC      src/namespace.o
  CC      src/proto_http.o
In file included from include/proto/compression.h:26:0,
                 from src/proto_http.c:55:
include/types/compression.h:32:10: fatal error: zlib.h: No such file or directory
 #include 
          ^~~~~~~~
compilation terminated.
Makefile:834: recipe for target 'src/proto_http.o' failed
make: *** [src/proto_http.o] Error 1
root@youyou:/apps/haproxy-2.0.12# 
root@youyou:/apps/haproxy-2.0.12# apt  install zlib1g-dev




root@youyou:/apps/haproxy-2.0.12# 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=/apps/lua-5.3.5/src/ LUA_LIB=/apps/lua-5.3.5/src/ PREFIX=/apps/haproxy
  CC      src/proto_http.o
  CC      src/cfgparse-listen.o
  CC      src/proto_htx.o
  CC      src/stream.o
  CC      src/mux_h2.o
  CC      src/stats.o
  CC      src/flt_spoe.o
  CC      src/server.o
  CC      src/checks.o
  CC      src/haproxy.o
src/haproxy.c:72:10: fatal error: systemd/sd-daemon.h: No such file or directory
 #include 
          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Makefile:843: recipe for target 'src/haproxy.o' failed
make: *** [src/haproxy.o] Error 1
root@youyou:/apps/haproxy-2.0.12# 
root@youyou:/apps/haproxy-2.0.12# apt install libsystemd-dev 
root@youyou:/apps/haproxy-2.0.12# make install PREFIX=/apps/haproxy
root@youyou:/apps/haproxy/sbin# cp /apps/haproxy/sbin/haproxy /usr/sbin/

你可能感兴趣的:(linux,Ubuntu)