linux12企业实战 -- 32haproxy2.0.12
Posted FikL-09-19
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux12企业实战 -- 32haproxy2.0.12相关的知识,希望对你有一定的参考价值。
一、部署haproxy
官网: https://www.haproxy.org/download/2.0/src/
[root@test ~]# wget https://www.haproxy.org/download/2.0/src/haproxy-2.0.12.tar.gz
二、解压并查看
[root@test ~]# tar xf haproxy-2.0.12.tar.gz -C /opt/
[root@test /opt]# cd /opt/haproxy-2.0.12/
[root@test /opt/haproxy-2.0.12]# ls
BRANCHES contrib doc examples INSTALL MAINTAINERS README ROADMAP src tests VERSION
CHANGELOG CONTRIBUTING ebtree include LICENSE Makefile reg-tests scripts SUBVERS VERDATE
三、编译安装
# 1、安装依赖
[root@test /opt/haproxy-2.0.12]# yum install gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel vim iotop bc zip unzip zlib-devel lrzsz tree screen lsof tcpdump wget ntpdate -y
# 2、编译
[root@test /opt]# mkdir haproxy
[root@test /opt/haproxy-2.0.12]# pwd
/opt/haproxy-2.0.12
[root@test /opt/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 PREFIX=/opt/haproxy
[root@test /opt/haproxy-2.0.12]# make install PREFIX=/opt/haproxy
[root@test /opt/haproxy-2.0.12]# cp haproxy /usr/sbin/
# 3、查看版本
[root@test /opt/haproxy-2.0.12]# haproxy -v
HA-Proxy version 2.0.12 2019/12/21 - https://haproxy.org/
四、配置文件
[root@test /opt/haproxy-2.0.12]# vim /usr/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 -f /etc/haproxy/conf -c -q
ExecStart=/usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/conf -p /run/haproxy.pid
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
五、创建haproxy的所需目录
[root@test /opt/haproxy-2.0.12]# mkdir -p /etc/haproxy && mkdir -p /etc/haproxy/con
六、创建haproxy启动配置文件
[root@test /opt/haproxy-2.0.12]# vim /etc/haproxy/haproxy.cfg
global
maxconn 100000
chroot /opt/haproxy
#stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin
uid 99
gid 99
daemon
# 绑定CPU核心数
nbproc 2
cpu-map 1 0
cpu-map 2 1
pidfile /opt/haproxy/run/haproxy.pid
log 127.0.0.1 local3 info
defaults
option http-keep-alive
option forwardfor
maxconn 100000
mode http
timeout connect 300000ms
timeout client 300000ms
timeout server 300000ms
listen stats
mode http
bind 0.0.0.0:9999
stats enable
log global
stats uri /haproxy-status
stats auth admin:admin
listen web_port
bind 0.0.0.0:80
mode http
log global
server web1 127.0.0.1:8080 check inter 3000 fall 2 rise 5
七、启动haproxy服务
# 由于在/usr/lib/systemd/system/下新加了haproxy.service启动文件需要reload
[root@test /opt/haproxy-2.0.12]# systemctl daemon-reload
[root@test /opt/haproxy-2.0.12]# systemctl start haproxy
八、查看服务是否启动
[root@test /opt/haproxy-2.0.12]# ps -ef | grep haproxy
root 1978 1 0 12:00 ? 00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/conf -p /run/haproxy.pid
nobody 1980 1978 0 12:00 ? 00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/conf -p /run/haproxy.pid
nobody 1981 1978 0 12:00 ? 00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/conf -p /run/haproxy.pid
root 1983 1067 0 12:00 pts/0 00:00:00 grep --color=auto haproxy
九、知识补充
# 上传过程就省略掉了
[root@test ~]# tar xf haproxy-2.0.12.tar.gz -C /opt/
[root@test /opt]# cd /opt/haproxy-2.0.12/
# USE_CPU_AFFINITY=1 为开启haproxy进程与CPU核心绑定,USE_SYSTEMD=1为支持使用 -Ws参数(systemd-aware master-worker 模式)启动Haproxy,从而实现单主进程多子进程运行模式。在2.0后TARGET=linux2628 被剔除掉了如果继续用的话就会报错
[root@test haproxy-2.0.13]# 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
Target 'linux2628' was removed from HAProxy 2.0 due to being irrelevant and
often wrong. Please use 'linux-glibc' instead or define your custom target
by checking available options using 'make help TARGET=<your-target>'.
make: *** [all] Error 1
# 解决方法是把TARGET=linux2628替换成TARGET=linux-glibc
[root@test haproxy-2.0.13]# make ARCH=x86_64 TARGET=linux-glibc USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1 USE_CPU_AFFINITY=1 PREFIX=/usr/local/haproxy
[root@test haproxy-2.0.13]# make install PREFIX=/opt/haproxy
# 编译完成之后会在当前目录中生成一个可执行程序复制到/usr/sbin下
[root@test haproxy-2.0.13]# cp haproxy /usr/sbin/
以上是关于linux12企业实战 -- 32haproxy2.0.12的主要内容,如果未能解决你的问题,请参考以下文章