Home > System Tutorial > LINUX > Detailed explanation of haproxy

Detailed explanation of haproxy

PHPz
Release: 2024-06-10 11:43:58
Original
527 people have browsed it

Detailed explanation of haproxy

1.安装haproxy

CentOS自带了haproxy,但可能版本比较老。可以在IUS源上找到最新稳定版的haproxy。

cat /yum.repos.d/ius.repo
[ius]
name=iusrepo
baseurl=https://mirrors.tuna.tsinghua.edu.cn/ius/stable/CentOS/$releasever/\$basearch
gpgcheck=0
enable=1
eof

yum -y install haproxy17u
Copy after login

以下是编译安装haproxy-1.7.10的过程。

编译安装haproxy时,可以借助于pcre环境,该环境下编译时借助正则表达式分析编译速度会快很多,但是没有该环境也可以安装。

yum -y install pcre pcre-devel
tar xf haproxy-1.7.10.tar.gz
cd haproxy-1.7.10
make TARGET=linux2628 ARCH=x86_64 PREFIX=/usr/local/haproxy USE_PCRE=1
make install PREFIX=/usr/local/haproxy
Copy after login

make时需要使用TARGET指定内核及版本,版本如下:

- linux22 for Linux 2.2
- linux24 for Linux 2.4 and above (default)
- linux24e for Linux 2.4 with support for a working epoll (> 0.21)
- linux26 for Linux 2.6 and above
- linux2628 for Linux 2.6.28, 3.x, and above (enables splice and tproxy)
- solaris for Solaris 8 or 10 (others untested)
- freebsd for FreeBSD 5 to 10 (others untested)
- netbsd for NetBSD
- osx for Mac OS/X
- openbsd for OpenBSD 5.7 and above
- aix51 for AIX 5.1
- aix52 for AIX 5.2
- cygwin for Cygwin
- haiku for Haiku
- generic for any other OS or version.
- custom to manually adjust every setting
Copy after login

使用ARCH指定架构,不过ARCH选项可省。使用USE_PCRE=1表示使用PCRE环境编译,加快编译速度。

编译安装完成后,只有3个目录:doc、share和sbin,sbin里面只有一个haproxy的主程序haproxy。为了方便管理haproxy服务,可以从yum安装的haproxy中复制/etc/init.d/haproxy。

2.haproxy命令

常用的几个:

# 检查配置文件语法
haproxy -c -f /etc/haproxy/haproxy.cfg

# 以daemon模式启动,以systemd管理的daemon模式启动
haproxy -D -f /etc/haproxy/haproxy.cfg [-p /var/run/haproxy.pid]
haproxy -Ds -f /etc/haproxy/haproxy.cfg [-p /var/run/haproxy.pid]

# 启动调试功能,将显示所有连接和处理信息在屏幕
haproxy -d -f /etc/haproxy/haproxy.cfg

# restart。需要使用st选项指定pid列表
haproxy -f /etc/haproxy.cfg [-p /var/run/haproxy.pid] -st `cat /var/run/haproxy.pid`

# graceful restart,即reload。需要使用sf选项指定pid列表
haproxy -f /etc/haproxy.cfg [-p /var/run/haproxy.pid] -sf `cat /var/run/haproxy.pid`

# 显示haproxy编译和启动信息
haproxy -vv
Copy after login

The above is the detailed content of Detailed explanation of haproxy. For more information, please follow other related articles on the PHP Chinese website!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template