当前位置:网站首页>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 .

  1. 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 .

HAProxy The compilation, installation and global configuration section of _ The configuration file

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 .

HAProxy The compilation, installation and global configuration section of _lua_02

HAProxy The compilation, installation and global configuration section of _ Compilation and installation _03

     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 .

HAProxy The compilation, installation and global configuration section of _ The configuration file _04


  1. 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.

HAProxy The compilation, installation and global configuration section of _lua_05

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 .

HAProxy The compilation, installation and global configuration section of _lua_06

HAProxy The compilation, installation and global configuration section of _ Compilation and installation _07

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 .

HAProxy The compilation, installation and global configuration section of _ Compilation and installation _08

     Installation can be specified HAProxy Installation path of the program .

HAProxy The compilation, installation and global configuration section of _ The configuration file _09

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 .

HAProxy The compilation, installation and global configuration section of _ Compilation and installation _10

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 .

HAProxy The compilation, installation and global configuration section of _ The configuration file _11

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 .

HAProxy The compilation, installation and global configuration section of _ The configuration file _12

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 .

HAProxy The compilation, installation and global configuration section of _ The configuration file _13

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 .

HAProxy The compilation, installation and global configuration section of _ Compilation and installation _14

原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230332327399.html