haproxy 是常用的代理软件,本文重点介绍如何制作 haproxy rpm 安装包
说明
由于 haproxy 1.7.8 依赖于 lua 5.3 以上的版本,但 Centos 7.2 当前 lua 的版本是 5.1.4,且由于rpm-*.rpm 包依赖 5.1.4,故lua无法升级。
为将 haproxy 1.7.8 安装到 Centos 7.2,特将lua 5.3 作为静态链接库打包到 haproxy rpm 包中。
准备及编译 lua
下载 lua
下载最新版本lua并解压:
cd ~
wget https://www.lua.org/ftp/lua-5.3.4.tar.gz
tar -zxvf lua-5.3.4.tar.gz
编译lua
cd ~/lua-5.3.4/
make generic LIBS="-lm -ldl"
make generic LIBS="-lm -ldl" luac_LDADD="liblua.la -lm -ldl"
由于 haproxy 编译环境依赖于 lua 5.3,因此需在编译环境安装lua 5.3的包(可采用源码安装),本操作采用自己制作的 lua 5.3.4 (含liblua-5.1.3.so)包。
编译 haproxy
准备 rpm-build 环境
yum install -y rpm-build rpmdevtools readline-devel ncurses-devel gdbm-devel tcl-devel openssl-devel db4-devel byacc libyaml-devel libffi-devel make
下载 haproxy 源码包
wget https://copr-be.cloud.fedoraproject.org/results/bitshaka/openssl-lts/epel-7-x86_64/00577601-haproxy/haproxy-1.7.8-1.el7.centos.src.rpm
rpm -ivh haproxy-1.7.8-1.el7.centos.src.rpm
之后,我们可以在 ~/rpmbuild 目录下看到对应的文件。
替换 haproxy 源码 tar 包为官方发布包
cd ~/rpmbuild/SOURCES
wget -O ~/rpmbuild/SOURCES/haproxy-1.7.8.tar.gz http://www.haproxy.org/download/1.7/src/haproxy-1.7.8.tar.gz
修改 haproxy lua 依赖
修改 ~/rpmbuild/SPECS/haproxy.spec
第64行,使其支持采用采用指定 lua 版本:
{% highlight html %}
{% raw %}
64 %{__make} %{?_smp_mflags} CPU=“generic” TARGET=“linux2628” USE_OPENSSL=1 USE_PCRE=1 USE_ZLIB=1 USE_LUA=1 ${regparm_opts} ADDINC="%{optflags}" USE_LINUX_TPROXY=1 ADDLIB="%{__global_ldflags}"
{% endraw %}
{% endhighlight %}
添加以下内容:
cd ~/rpmbuild/BUILD/haproxy-1.7.8
gcc -g -o haproxy src/haproxy.o src/base64.o src/protocol.o src/uri_auth.o src/standard.o src/buffer.o src/log.o src/task.o src/chunk.o src/channel.o src/listener.o src/lru.o src/xxhash.o src/time.o src/fd.o src/pipe.o src/regex.o src/cfgparse.o src/server.o src/checks.o src/queue.o src/frontend.o src/proxy.o src/peers.o src/arg.o src/stick_table.o src/proto_uxst.o src/connection.o src/proto_http.o src/raw_sock.o src/backend.o src/tcp_rules.o src/lb_chash.o src/lb_fwlc.o src/lb_fwrr.o src/lb_map.o src/lb_fas.o src/stream_interface.o src/stats.o src/proto_tcp.o src/applet.o src/session.o src/stream.o src/hdr_idx.o src/ev_select.o src/signal.o src/acl.o src/sample.o src/memory.o src/freq_ctr.o src/auth.o src/proto_udp.o src/compression.o src/payload.o src/hash.o src/pattern.o src/map.o src/namespace.o src/mailers.o src/dns.o src/vars.o src/filters.o src/flt_http_comp.o src/flt_trace.o src/flt_spoe.o src/cli.o src/ev_poll.o src/ev_epoll.o src/ssl_sock.o src/shctx.o src/hlua.o src/hlua_fcn.o ebtree/ebtree.o ebtree/eb32tree.o ebtree/eb64tree.o ebtree/ebmbtree.o ebtree/ebsttree.o ebtree/ebimtree.o ebtree/ebistree.o -lcrypt -lz -ldl -lssl -lcrypto -ldl -L/root/lua-5.3.4/src -llua -lm -ldl -L/usr/lib -lpcreposix -lpcre
gcc -g -o haproxy-systemd-wrapper src/haproxy-systemd-wrapper.o -lcrypt -lz -ldl -lssl -lcrypto -ldl -L/root/lua-5.3.4/src -llua -lm -ldl -L/usr/lib -lpcreposix -lpcre
cd -
haproxy 的编译命令:
make CPU="generic" TARGET="linux2628" USE_OPENSSL=1 USE_PCRE=1 USE_ZLIB=1 USE_LUA=1 USE_LINUX_TPROXY=1
判断上述命令是否成功的标识(运行打包后产生):
cd ~/rpmbuild/BUILD/haproxy-1.7.8/
默认情况下,新编译的 haproxy/haproxy-systemd-wrapper 包含 liblua-5.3.so 依赖包含:
[root@xiexianbin_cn haproxy-1.7.8]# ldd haproxy-systemd-wrapper
...
liblua-5.3.so => /lib64/liblua-5.3.so (0x00007fdefcef2000)
...
采用我们的方式,不包含 liblua-5.3.4.so 的依赖:
[root@xiexianbin_cn haproxy-1.7.8]# ldd haproxy-systemd-wrapper
linux-vdso.so.1 => (0x00007ffda4dd5000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f918d45f000)
libz.so.1 => /lib64/libz.so.1 (0x00007f918d249000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f918d044000)
libssl.so.10 => /lib64/libssl.so.10 (0x00007f918cdd2000)
libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007f918c971000)
libm.so.6 => /lib64/libm.so.6 (0x00007f918c66e000)
libpcreposix.so.0 => /lib64/libpcreposix.so.0 (0x00007f918c46b000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f918c20a000)
libc.so.6 => /lib64/libc.so.6 (0x00007f918be48000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007f918bc45000)
/lib64/ld-linux-x86-64.so.2 (0x00007f918d69e000)
libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f918b9f7000)
libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f918b70f000)
libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f918b50b000)
libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f918b2d9000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f918b0bc000)
libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f918aead000)
libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f918aca9000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f918aa8e000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f918a867000)
[root@xiexianbin_cn haproxy-1.7.8]#
运行打包命令
rpmbuild -bb ~/rpmbuild/SPECS/haproxy.spec --define="dist .el7"
md5sum
制作好的 rpm 在目录 ~/rpmbuild/RPMS/x86_64 下,md5 如下:
[root@xiexianbin_cn x86_64]# md5sum *
b359add96085f60272703ff680e33145 haproxy-1.7.8-1.el7.x86_64.rpm
41983f4247d182808c5e20b2d27c6220 haproxy-debuginfo-1.7.8-1.el7.x86_64.rpm
附件
haproxy.spec