当前位置:网站首页>Compilation, installation and global configuration section description of haproxy
Compilation, installation and global configuration section description of haproxy
2022-06-23 04:03:00 【51CTO】
HAProxy It's French developer willitaro (Willy Tarreau) stay 2000 Annual use C Language development of an open source software , It's a product with high concurrency ( More than 10000 )、 High performance TCP and HTTP Load Balancer , Support based on cookie The durability of 、 Automatic failover 、 Support regular expressions and web State Statistics .
HAProxy You need to use... When compiling and installing lua, also lua The minimum version requirement for is 5.3. at present CentOS8 perhaps Rocky8 Series through yum install lua It meets the version requirements , and CentOS7 And previous versions of Linux The system cannot meet this requirement , So use CentOS7 Or previous versions of Linux Compile and install the system HAProxy, You must first compile and install a newer version of lua Environmental Science , The author of this experiment will pass CentOS7 To demonstrate the operation .
- Get ready lua Environmental Science
1.1 Install dependency packages
lua The compilation and installation of requires gcc and readline-devel These two bags , Need to be installed in advance .

1.2 Compilation and installation lua
lua The source code package of can be obtained through the official website ( Official website address : http://www.lua.org/download.html), It has been updated to 5.4.4 edition , And the time is nearly half a year , The author will install the latest version directly .lua The compilation and installation of is relatively simple , And the official website also explains how to operate , The author will directly follow the operation of the official website .


After installation , Take the author's path as an example , A new generation of lua It's on the /usr/local/src/lua-5.4.4/src In the catalog , You need to remember this position , Back HAProxy You need to use... When compiling and installing .

- Compilation and installation HAProxy
2.1 Install dependency packages
HAProxy The compilation and installation of requires openssl-devel、pcre-devel and systemd-devel These three bags , If lua It's directly through yum Installed by , Additional installation is required gcc.

2.2 Get the source code and unzip it
HAProxy The source code of the open source version can be obtained through the official website ( Official website : https://www.haproxy.org/), It has been updated to 2.6 Main version ,2.7 Version is still under development , In the choice HAProxy Select an even number of versions , Such as 2.2、2.4、2.6 And so on LTS Long term support , in consideration of 2.6 edition 5 It will be updated at the end of the month , What the author downloaded is 2.4.17 edition .


2.3 Compilation and installation
Enter the unzipped directory , You can see HAProxy Has been automatically generated Makefile file , So you can compile directly , When compiling, you need to add the above compiled and installed lua Storage path , Some options to be used during compilation can be found in Makefile View in , And add or delete according to the actual needs of the enterprise .

Installation can be specified HAProxy Installation path of the program .

2.4 Generate soft links
For ease of use HAProxy service , You can generate PATH Variables or soft links , Because there is only one service , The author directly creates soft links .

2.5 establish service file
HAProxy Of service The document may refer to yum What to install , Modify according to your own path or other settings .

2.6 create profile
2.6.1 HAProxy The configuration file
according to service Settings in file ,HAProxy Configuration files are placed in /etc/haproxy/ Under the table of contents , But the directory does not yet exist , So you need to create . The contents of the configuration file are shown in the following figure , It should be noted that ,HAProxy The configuration file for must be in cfg It's a suffix .

2.6.2 Configuration segment description
In the above configuration file ,global The statement block configures the segment for the global configuration ,default The statement block is the default configuration segment .
①global Global configuration segment description :
maxconn Represent each HAProxy The maximum number of connections for a process ;
chroot Indicates that the running directory will be locked ;
stats socket Set the permissions of the socket file and the corresponding process ;
uid、gid perhaps user、group Indicates that you can run HAProxy The identity of the , One pair is enough for two pairs ;
daemon Express HAProxy Run in the background as a daemon ;
nbproc You can set HAProxy The number of processes , The default is a ;
cpu-map Can be HAProxy Is bound to the specified CPU At the core , Number of processes from 1 Start calculating ,CPU The core number is from 0 Start calculating ;
pidfile You can specify pid File path ;
log Partially defines the global syslog The server , The log server needs to be turned on udp agreement , You can define up to two ;
In addition to the above , Common global configuration segment parameters also include nbthread、maxsslconn、maxconnrate and spread-checks.nbthread You can specify each HAProxy Number of threads in the process , Default to a , But this parameter will be associated with nbproc Mutually exclusive (CentOS8 Medium HAProxy1.8 There is no problem with this version );maxsslconn Represent each HAProxy process ssl Is the maximum number of connections , be used for HAProxy The certificate is configured ;maxconnrate Indicates the maximum number of connections per second created by each process ;spread-checks You can set the backend server Random lead or delay percentage time of status check , The default is 0, It is recommended to set 2-5, namely 20%-50%.
②default Description of the default configuration segment :
default Configure the segment for the default , in the light of frontend、backend and listen take effect , There can be multiple name, There can be no name.
option http-keep-alive Indicates to open a session with the client ;
option forwardfor The client's ip Through to the back end server ;
maxconn Indicates the maximum number of process connections in the default configuration segment ;
mode You can set the default work type , Yes tcp and http Two options , Use tcp Can reduce server pressure , Performance will be better ;
timeout Some units are milliseconds ,timeout connect You can set the client request process HAProxy Server to back end server The longest waiting time of ;timeout client You can set HAProxy Maximum server and client inactivity ;timeout server You can set the client request from HAProxy Server to back end server Processing timeout length of (tcp After the connection ), The recommended value is the same as timeout client Partially consistent , At the same time, in order to avoid 502 error , You can increase the value a little .
2.7 Other preparation items
according to HAProxy Configuration files and service Settings in file ,socket Document and pid The storage path of the file is /var/lib/haproxy/, But the directory does not exist , It needs to be created in advance . Actually HAProxy Services are generally used for reverse proxy , As long as the user is a non login user of the system , But for ease of Management , You can also create a service specific user .

2.8 Load and start HAProxy service
After reloading the service , You can use systemd Mode start HAProxy service , Because no proxy forwarding settings have been made , Therefore, no port is opened .

边栏推荐
- The tax software exits when it detects that it is a virtual machine. How to solve this problem?
- Select sort method
- 【owt】owt-client-native-p2p-e2e-test vs2017构建 4 : 第三方库的构建及链接p2pmfc.exe
- An implementation of warning bombing
- 折半查找法
- [advanced Android] kotlin delegate attribute
- [OWT] OWT client native P2P E2E test vs2017 build 2: test unit construction and operation
- Flutter怎么实现不同缩放动画效果
- 数据加密技术之源代码加密
- 【机器学习】 吴恩达机器学习作业 ex2逻辑回归 Matlab实现
猜你喜欢
随机推荐
Differences between MyISAM and InnoDB of MySQL storage engine
What is the difference between the poll () method and the remove () method?
[machine learning] wuenda's machine learning assignment ex2 logistic regression matlab implementation
选择排序法
Google Earth Engine(GEE)——长时间序列逐月VCI数据提取分析和面积计算(墨西哥为例)
How can I realize video call and interactive live broadcast in a small program?
【LeetCode】23. 合并K个升序链表
Gx3001q UI instructions for upgrading 8-bit color to 16 bit color
How to implement collection sorting?
What if the self incrementing IDs of online MySQL are exhausted?
粒子动画背景登录页面particles.js
怎么用好MySQL索引
[leetcode] flip linked list II
冒泡排序法
页面导出excel的三种方式
New configuration of Alipay
[tcapulusdb knowledge base] [list table] delete all data sample codes in the list
Learning summary of spanquery source code
redis 精讲系列介绍八 - 淘汰策略
数据交易怎样实现








