Linux-centos-7-64 bit: 5, Nginx proxy +sticky module for cookie-based load balancing

Source: Internet
Author: User
Tags openssl library sha1

Nginx can be installed using the default packages of each platform, this article is to introduce the use of source code compilation installation, including specific compilation parameters information.

Preparatory work:

1. Install the necessary tools:

Compilation environment GCC g++ Development Library and the like need to be installed in advance.

-y install gcc gcc-c++ autoconf automake

If an error occurs during installation:

Reason:
DNS server is not configured correctly
Workaround:
①, open the file/etc/resolv.conf in which you added:

nameserver8.8.8.88.8.4.4 search localdomain

②, and then restart the network card: Use the command:service network restart

If it is in a virtual machine configuration, set the route to be the same as the host

-y install zlib zlib-devel openssl openssl-devel pcre-devel

Description

Pcre: The function used for address rewriting.

Zlib:nginx's gzip module, which transmits data packaging, saves traffic (but consumes resources).

OpenSSL: Provides SSL encryption protocol.

You can also download it online first:

Pcre:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/

zlib:http://zlib.net/

openssl:http://www.openssl.org/source/

2. Create a new system-level user group and anonymous user, and use the following compile-time

-r-s-g-r nginx-user

View user groups and their members

groups nginx-user

Nginx Compiler installation:

1. Download nginx:http://nginx.org/en/download.html
2. Download sticky:http://download.csdn.net/detail/u014799292/9506315

Create an Nginx folder under the USR/LOCAL/SRC directory

mkdir nginx

Put the downloaded nginx-1.9.15.tar.gz into the/mnt/share resource directory and copy it to the/usr/local/src/nginx folder and unzip it and go to the extracted nginx-1.9.15 folder.
Nginx-sticky-module-1.1.tar.gz the same thing.

cp /mnt/share/nginx-1.9.15.tar.gz /usr/local/nginx/tar -zxvf nginx-1.9.15.tar.gzcd nginx-1.9.15/

./configure parameter configuration information details can be queried by help

$./configure \ #nginx启动--prefix=/usr/local/nginx \ # Sets the installation directory, which uses/usr by default/local/nginx. --sbin-path=/usr/local/nginx/nginx \ # Sets the path of the Nginx executable file, which defaults to Prefix/sbin/nginx. --conf-path=/etc/nginx/nginx.conf \ # Set the path in the nginx.conf configuration file. Nginx allows you to start with a different configuration file via the-C option on the command line. The default is prefix/conf/nginx.conf. --error-log-path=/var/log/nginx/error. log \ # Sets the name of the primary error, warning, and diagnostic file. After the installation is complete, you can change the file name at any time, using the Error_log directive in the nginx.conf configuration file. By default, the file name is Prefix/logs/error.log. --http-log-path=/var/log/nginx/access. log \ # Sets the name of the log file for the HTTP server for the primary request. After the installation is complete, you can change the file name at any time, using the Access_log directive in the nginx.conf configuration file. By default, the file name is Prefix/logs/access.log. --pid-path=/var/run/nginx.pid \ # Sets the Nginx.pid file that will store the process number of the main process. After the installation is complete, you can change the file name at any time by using the PID directive in the nginx.conf configuration file. By default, the file name is Prefix/logs/nginx.pid. --lock-path=/var/run/nginx.lock \ # Setting the lock file (nginx.lock) directory --http-client-body-temp-path=/var/cache/nginx/client_temp \ # Set client Request temp file path --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ # Set HTTP Proxy temp file path --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \ # set HTTP fastcgi temp file path --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ # set path store HTTP Uwsgi temp file path --http-scgi-temp-path=/var/cache/nginx/scgi_temp \ # set path store HTTP scgi temp file path --user=nginx \ # Sets the user for the Nginx worker process. After the installation is complete, you can change the name of the user directive that is used in the nginx.conf configuration file at any time. The default user name is nobody. --group=nginx \ # Sets the user group of the Nginx worker process. After the installation is complete, you can change the name of the user directive that is used in the nginx.conf configuration file at any time. The default is non-privileged users. --with-http_ssl_module \ # uses the HTTPS protocol module. By default, the module is not built. It is necessary to establish and run the OpenSSL library for this module. --with-http_realip_module \ # allow Ngx_http_realip_module module (MOD_RPAF) --with-http_addition_module \ #. Module (mod_layout) --with-http_sub_module \ #. Module --with-http_dav_module \ #. Module (MOD_DAV) --with-http_flv_module \ #. (MOD_FLVX) --with-http_mp4_module \ #. Module (mod_mp4) --with-http_gunzip_module \ #. Module (mod_gunzip) --with-http_gzip_static_module \ #. Module (mod_dflate) --with-http_random_index_module \ #. Module (mod_autoindex) --with-http_secure_link_module \ #. Module --with-http_stub_status_module \ #. Module (mod_status) to view the Web interface when Nginx needs to open the status module --with-http_auth_request_module \ # allow Ngx_http_auth_request_module module --with-http_xslt_module # allow Ngx_http_xslt_module module --with-mail \ # allow POP3/IMAP4/SMTP proxy module --with-mail_ssl_module \ # allow Ngx_mail_ssl_module module --with-file-aio \ # allow file Aio support --with-ipv6 \ # allow IP6 proxy support --with-http_spdy_module \ # allow Ngx_http_spdy_module module 1.9.5 start to switch--with-http_spdy_module to--with-http_v2_ module, or error --with-cc-opt='-o2-g-pipe-wp,-d_fortify_source=2-fexceptions-fstack-protector--param=ssp-buffer-size= 4-m64-mtune=generic '# setting C compiler parameters   --without-http_charset_module # do not use Ngx_http_charset_module module --without-http_gzip_module # do not use Ngx_. Module --without-http_ssi_module # do not use Ngx_. Module --without-http_userid_module # do not use Ngx_. Module --without-http_access_module # do not use Ngx_. Module --without-http_auth_basic_module # do not use Ngx_. Module --without-http_autoindex_module # do not use Ngx_. Module --without-http_geo_module # do not use Ngx_. Module --without-http_map_module # do not use Ngx_. Module --without-http_referer_module # do not use Ngx_. Module --without-http_rewrite_module # do not use Ngx_. Module --without-http_proxy_module # do not use Ngx_. Module --without-http_fastcgi_module # do not use Ngx_. Module --without-http_memcached_module # do not use Ngx_. Module --without-http_limit_zone_module # do not use Ngx_. Module --without-http_empty_gif_module # do not use Ngx_. Module --without-http_browser_module # do not use Ngx_. Module --without-http_upstream_ip_hash_module # do not use Ngx_. Module --with-http_perl_module # allows ngx_. Module --with-perl_modules_path=Path# set Perl module path    --with-perl=path# setting Perl library file Paths         --http-log-path=path# setting Access log file path     --without-http # do not use the HTTP Server feature --without-mail_pop3_module # ngx_ not allowed. Module --without-mail_imap_module # ngx_ not allowed. Module --without-mail_smtp_module # ngx_ not allowed. Module --with-google_perftools_module # allows ngx_. Module (for commissioning) --with-cpp_test_module # allows ngx_. Module --add-module=path# allows the use of external modules, as well as path         --with-cc=path# setting C compiler path           --with-cpp=path# setting C preprocessing path          --with-ld-opt=OPTIONS# Setting Connection file Parameters    --with-cpu-opt=CPU# for specified CPU optimizations, optional parameters are:       Pentium, Pentiumpro, Pentium3, Pentium4, Athlon, Opteron, Sparc32, SPARC64, ppc64--without-pcre # do not use Pcre library files --with-pcre=DIR# setting Pcre library path          --with-pcre-opt=OPTIONS # setting Pcre run parameters --with-md5=DIR# setting MD5 library file path           --with-md5-opt=OPTIONS# setting MD5 run parameters   --with-md5-asm # Compiling with MD5 source files --with-sha1=DIR# setting SHA1 library file path          --with-sha1-opt=OPTIONS # setting SHA1 run parameters --with-sha1-asm # Compiling with SHA1 source files --with-zlib=DIR# setting zlib library file path          --with-zlib-opt=OPTIONS # setting zlib run parameters --with-zlib-asm=CPU# enables zlib to optimize for specific CPUs, optional parameters:      Pentium, pentiumpro--with-openssl=DIR# Setting the OpenSSL library file path       --with-openssl-opt=OPTIONS# setting OpenSSL run parameters   --with-debug # allow debug Logs --builddir=dir# Setting Program compilation directory           --with-rtsig_module # allow Rtsig module --with-select_module # allows select module (a polling mode, not recommended for high-load environments) --without-select_module # Do not use the Select module --with-poll_module # allows poll module (a polling mode, not recommended for high-load environments) --without-poll_module # Do not use poll module 

Nginx compile time is not the more the more the better, should be as few as possible to compile the module, not the best not to join.
The compiled nginx can be/usr/local/nginx/sbin/nginx-v to view the parameters at compile time (the specific path is more practical)

Now add the following parameters #文件夹要自己创建

./configure--add-module=/usr/local/src/nginx/nginx-  Sticky-module-1.1 \ --with-http_ssl_module--with-http_stub_status_module--sbin-path=/usr/local/nginx/nginx \--conf-path=/usr/local/nginx/nginx. conf--pid-path=/usr/local/nginx/nginx. PID--with-openssl=/usr/local/src/openssl/openssl-1.0.1s/ \

Subsequent execution

makemake install

Start Nginx, run into the/usr/local/nginx/sbin directory and see if it starts

| grep nginx

Startup success

Re-start Nginx

cd-s reload

Determine if the configuration file is correct

cd  /usr/local/nginx/sbin.-t

Shut down

Query Nginx main process number

Ps-ef | grep nginx

Calmly stop Kill-quit master process number

Fast Stop Kill-term main process number

Force Stop kill-9 Nginx

If the PID file path is configured nginx.conf, if not, in the logs directory

Kill-Signal type '/usr/local/nginx/logs/nginx.pid '

Upgrade

1. Replace the old program file with the new program first

2, KILL-USR2 the old version of the program's main process number or process file name

At this point the old Nginx master process will rename its process file to. oldbin, then execute the new version of Nginx, at which time the old and the newer versions run simultaneously

3, Kill-winch old version main process number

4. Start new/old worker process without overloading configuration

Kill-hup old/New version main process number

Calmly close the old/new process

Kill-quit old/New process number

Close old/new processes quickly

Kill-term old/New process number

Linux-centos-7-64 bit: 5, Nginx proxy +sticky module for cookie-based load balancing

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.