centos7 编译安装 haproxy1.8.20

Posted yyxianren

tags:

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

当前系统信息:

[[email protected] ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

 

当前内核版本

[[email protected] ~]# uname -r
3.10.0-957.10.1.el7.x86_64

 

解压haproxy包:

[[email protected] ~]# tar zxvf haproxy-1.8.20.tar.gz 

 

安装依赖包:

[[email protected] ~]# yum install -y gcc
或者
[[email protected] ~]# yum install 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

  #编译需要GCC来编译,下边一条安装了众多常用的工具。

 

编译安装:

[[email protected] ~]# cd haproxy-1.8.20

[[email protected] ~]# make TARGET=linux2628 PREFIX=/usr/local/haproxy #haproxy编译需要指定对应的内核版本,此参数可以查看README文件中有对应的值linux2628
[[email protected] ~]# make install PREFIX=/usr/local/haproxy

 

将haproxy拷贝到/usr/sbin/目录下:

[[email protected] ~]# cp -rf /usr/local/haproxy/sbin/haproxy /usr/sbin/

 

查看当前版本:

[[email protected] ~]# haproxy -v
HA-Proxy version 1.8.20 2019/04/25
Copyright 2000-2019 Willy Tarreau <[email protected]>

 

添加配置文件:

[[email protected] ~]# mkdir /usr/local/haproxy/conf
[[email protected] ~]# vim /usr/local/haproxy/conf/haproxy.conf

配置文件内容如下(精简配置):

    global
        daemon
        maxconn 256

    defaults
        mode http
        timeout connect 5000ms
        timeout client 50000ms
        timeout server 50000ms

    frontend http-in
        bind *:80
        default_backend web_servers

    backend web_servers
        server server1 127.0.0.1:8000 maxconn 32

 

启动haproxy

[[email protected] ~ ] haproxy -f /usr/local/haproxy/conf/haproxy.conf 

 

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

CentOS7.3编译安装python3.6

Centos7 编译安装Nginx 教程

Centos7.2 编译安装方式搭建 phpMyAdmin

CentOS7编译安装OpenSSL1.1.1f

三台主机CentOS7 编译安装lamp

Centos7 编译安装Swoole