编译安装HAProxy1.8.20

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了编译安装HAProxy1.8.20相关的知识,希望对你有一定的参考价值。

一、安装前准备

官网下载安装包:http://www.haproxy.org/download/1.8/src/haproxy-1.8.20.tar.gz

[[email protected] src]$cd /usr/local/src/
[[email protected] src]$ls
haproxy-1.8.20.tar.gz
[[email protected] src]$yum install -y gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel net-tools vim iotop bc zip unzip zlib-devel lrzsz tree screen lsof tcpdump wget ntpdate 

二、开始安装

[[email protected] src]$tar xvf haproxy-1.8.20.tar.gz
[[email protected] src]$cd haproxy-1.8.20/
[[email protected] haproxy-1.8.20]$make ARCH=x86_64 TARGET=linux2628 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1 USE_CPU_AFFINITY=1 PREFIX=/usr/local/haproxy
[[email protected] haproxy-1.8.20]$ make install PREFIX=/usr/local/haproxy
install -d "/usr/local/haproxy/sbin"
install haproxy  "/usr/local/haproxy/sbin"
install -d "/usr/local/haproxy/share/man"/man1
install -m 644 doc/haproxy.1 "/usr/local/haproxy/share/man"/man1
install -d "/usr/local/haproxy/doc/haproxy"
for x in configuration management architecture peers-v2.0 cookie-options lua WURFL-device-detection proxy-protocol linux-syn-cookies network-namespaces DeviceAtlas-device-detection 51Degrees-device-detection netscaler-client-ip-insertion-protocol peers close-options SPOE intro; do     install -m 644 doc/$x.txt "/usr/local/haproxy/doc/haproxy" ; done
[[email protected] haproxy-1.8.20]$cp haproxy /usr/sbin/

三、创建启动脚本

[[email protected] ~]$vim /usr/lib/systemd/system/haproxy.service
[Unit]
Description=HAProxy Load Balancer
After=syslog.target network.target
[Service] #支持多配置文件读取,类似于配置文件的include功能
ExecStartPre=/usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -c -q
ExecStart=/usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target

四、创建目录和用户

[[email protected] ~]$mkdir /etc/haproxy
[[email protected] ~]$useradd -r -s /sbin/nologin haproxy
[[email protected] ~]$mkdir /var/lib/haproxy
[[email protected] ~]$chown -R haproxy.haproxy /var/lib/haproxy/
[[email protected] ~]$cat /etc/haproxy/haproxy.cfg 
global
    log         127.0.0.1 local2

    chroot      /usr/local/haproxy
    pidfile       /run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats mode 600 level admin

defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue             1m
    timeout connect         10s
    timeout client               1m
    timeout server             1m
    timeout http-keep-alive 10s
    timeout check               10s
    maxconn                       3000
# haproxy.cfg文件中定义了chroot、pidfile、user、group等参数,如果系统没有相应的资源会导致haproxy无法启动,具体参考日志文件/var/log/messages

五、启动haproxy

[[email protected] ~]$systemctl start haproxy
[[email protected] ~]$systemctl enable haproxy
Created symlink from /etc/systemd/system/multi-user.target.wants/haproxy.service to /usr/lib/systemd/system/haproxy.service.
[[email protected] ~]$ps -ef | grep haproxy
root       8492      1  0 20:48 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
haproxy    8495   8492  0 20:48 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
root       8606   7171  0 20:53 pts/0    00:00:00 grep --color=auto haproxy

以上是关于编译安装HAProxy1.8.20的主要内容,如果未能解决你的问题,请参考以下文章

centos7 编译安装 haproxy1.8.20

haproxy 配置文件详解 之 配置文件示例

Android 逆向Android 逆向通用工具开发 ( Android 平台运行的 cmd 程序类型 | Android 平台运行的 cmd 程序编译选项 | 编译 cmd 可执行程序 )(代码片段

是否可以动态编译和执行 C# 代码片段?

Notepad++编辑器——Verilog代码片段直接编译

导致资产预编译在heroku部署上失败的代码片段