Haproxy Centos7源码安装Haproxy 1.6.X
程序员文章站
2022-04-16 08:21:31
安装haproxy的方式有两种,一种是通过yum安装epel源,一种是通过源码编译的方式安装,下面是基于Centos7系列安装Haproxy 1.6安装前准备#安装编译时候需要的软件包[root@localhost ~]# yum install gcc openssl-devel readline-devel systemd-devel make pcre-devel psmisc -y#我的系统是centos7.4版本[root@localhost ~]# cat /etc/......
安装haproxy的方式有两种,一种是通过yum安装需要epel源(yum -y install haproxy 这么一句话搞定安装),一种是通过源码编译的方式安装,下面是基于Centos7系列安装Haproxy 1.6
安装前准备
#安装编译时候需要的软件包
[root@localhost ~]# yum install gcc openssl-devel readline-devel systemd-devel make pcre-devel psmisc -y
#我的系统是centos7.4版本
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@localhost ~]# ls
anaconda-ks.cfg haproxy-1.6.15.tar.gz
[root@localhost ~]# tar xf haproxy-1.6.15.tar.gz
[root@localhost ~]# mv haproxy-1.6.15 /usr/src/
[root@localhost src]# cd haproxy-1.6.15/
[root@localhost ~]# uname -r
3.10.0-693.el7.x86_64
#将haproxy安装到/usr/local/haproxy目录,注意:TARGET=Linux31 是通过uname -a 来查看Linux内核版本的
[root@localhost haproxy-1.6.15]# make TARGET=linux31 PREFIX=/usr/local/haproxy/
[root@localhost haproxy-1.6.15]# 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 cookie-options lua proxy-protocol linux-syn-cookies network-namespaces close-options intro; do \
install -m 644 doc/$x.txt "/usr/local/haproxy/doc/haproxy" ; \
done
#安装完成之后,默认安装目录是没有配置文件的,需要创建配置文件目录同时将源码包的配置文件拷贝到配置文件目录
[root@localhost haproxy]# mkdir /usr/local/haproxy/conf
[root@localhost haproxy]# cp /usr/src/haproxy-1.6.15/examples/option-http_proxy.cfg /usr/local/haproxy/conf/haproxy.cfg
[root@localhost haproxy]# cd conf/
[root@localhost conf]# ll
total 4
-rw-r--r--. 1 root root 1234 Jul 14 16:01 haproxy.cfg
上面过程没有报错整个haproxy安装过程就完成了
Haproxy安装好修改配置文件
#在你的配置文件修改这几行
[root@localhost ~]# vim /usr/local/haproxy/conf/haproxy.cfg
global
maxconn 200
ulimit-n 1000
nbproc 1
pidfile /usr/local/haproxy/haproxy.pid
frontend test-proxy
bind 192.168.179.102:8080
#bind 192.168.179.102:8080 这个IP写你主机的IP地址,不修改报错如下
[ALERT] 195/160502 (1864) : Starting frontend test-proxy: cannot bind socket [192.168.200.10:8080]
#将默认配置文件的值修改小,因为你没有配置系统的参数,不修改报错如下
[WARNING] 195/160555 (1889) : [/usr/local/haproxy/sbin/haproxy.main()] FD limit (16384) too low for maxconn=20000/maxsock=40011. Please raise 'ulimit-n' to 40011 or more to avoid any trouble.
maxconn 200
ulimit-n 1000
#修改为你的CPU总逻辑核数,我这逻辑核数为1
[root@localhost ~]# cat /proc/cpuinfo | grep 'model name'
model name : Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
[root@localhost ~]# cat /proc/cpuinfo | grep 'model name' | wc -l
1
nbproc 1
管理Haproxy服务
启动服务:
[root@localhost conf]# /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg
[root@localhost conf]# ps -ef | grep haproxy
200 1908 1 0 16:08 ? 00:00:00 /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg
重启服务:
[root@localhost conf]# /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg -st `cat /usr/local/haproxy/haproxy.pid`
停止服务:
[root@localhost ~]# ps -ef | grep haproxy
200 14796 1 0 16:16 ? 00:00:00 /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg -st 14550
root 15921 1278 0 16:39 pts/1 00:00:00 grep --color=auto haproxy
[root@localhost ~]# killall haproxy
[root@localhost ~]# ps -ef | grep haproxy
本文地址:https://blog.csdn.net/qq_34556414/article/details/107341014