Analysis of Nginx Server Load balancer application cases

Source: Internet
Author: User
Tags install openssl

Analysis of Nginx Server Load balancer application cases

Lab environment 1
1. test hardware preparation
Three virtual machines, two for load balancing, and one for RS


2. test software preparation
System: Red Hat6.4 x86_64
Software: nginx-1.8.1.tar.gz
3. Install the basic environment package (some systems already have it) before installation)
Yum install openssl
Yum install libjpeg-devel libpng-devel freetype-devel-y
Yum install libxml2 libxml2-devel zlib-devel ncurses-devel curl-devel-y
Yum install gd gd2 gd-level gd2-devel-y
4. Install the pcre package
Wget https://ftp.pcre.org/pub/pcre/pcre-8.32.tar.gz -- no-check-certificate
Tar-zxf pcre-8.32.tar.gz
./Configure
Compilation configuration error
Problem description:
Checking for dirent. h... yes
Checking windows. h usability... no
Checking windows. h presence... no
Checking for windows. h... no
Configure: error: You need a C ++ compiler for C ++ support.
Solution: The system package lacks the package for the C ++ compiler to install gcc-c ++.
Then install yum.
Make
Make install
Cd ../to the parent directory
=============================== Pcre Installation Complete ======================== ====================
5. Install nginx
Wget http://nginx.org/download/nginx-1.8.1.tar.gz
Tar-zxvf nginx-1.8.1.tar.gz
Cd nginx-1.8.1
./Configure -- user = nginx -- group = nginx -- prefix =/application/nginx-1.8.1 -- with-http_stub_status_module -- with-http_ssl_module
Note: -- user = nginx specifies the user
-- Group = nginx: specified group
-- Prefix =/application/nginx-1.8.1 specifies the installation path
-- With-http_stub_status_module Status Module
-- With-http_ssl_module ssl module
Useradd nginx-s/sbin/nologin-M needs to be created by the user-M does not create home directory-s specifies non-Login shell
Make
Make install
========= Nginx Installation Complete ======================================== ====================
6. Configuration after installation
Ln-s/application/nginx-1.8.1/application/nginx
Echo "/usr/local/lib">/etc/ld. so. conf
Tail-1/etc/ld. so. conf''
Ldconfig
/Application/nginx/sbin/nginx
[Root @ lb01 application] # ps-ef | grep nginx | grep-v grep
Root 17057 1 0? 00:00:00 nginx: master process/application/nginx/sbin/nginx
Nginx 17058 17057 0? 00:00:00 nginx: worker process
[Root @ lb01 application] # lsof-I tcp: 80
Command pid user fd type device size/OFF NODE NAME
Nginx 17057 root 6u IPv4 82990 0t0 TCP
: Http (LISTEN)
Nginx 17058 nginx 6u IPv4 82990 0t0 TCP *: http (LISTEN)
7. Configure and debug the web server used for testing
Note: The operation is only performed on the following nginx web server nodes:

Configure and view web service configuration results
The two RS1 servers all follow the above steps for nginx service.
Run the following command:
RS1 (192.168.232.132)
Echo "www.etiantian132.org">/application/nginx/html/index.html
Cat/application/nginx/html/index.html
/Application/nginx/sbin/nginx-s reload
RS2 (192.168.232.133)
Echo "www.etiantian133.org">/application/nginx/html/index.html
Cat/application/nginx/html/index.html
/Application/nginx/sbin/nginx-s reload
Then you can view the display results under the Local curl.

Modify the master configuration file to achieve Load Balancing
Cd/application/nginx/conf
Mkdir extra create extra directory
Cd extra/
Vim ../nginx. conf

# User nobody; worker_processes 1; # error_log logs/error. log; # error_log logs/error. log notice; # error_log logs/error. log info; # pid logs/nginx. pid; events {worker_connections 1024;} http {include mime. types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; include extra/upstream01.conf ;} ####################################### Delete we do not need to add this line of content include extra/upstream01.conf; then we need to create upstream01.conf under the extra directory and edit it vim extra/upstream01.conf # blog lb by cyt at 20180107 upstream blog_real_server {server 192.168.232.132: 80 weight = 5; # upstream defines the name of a vserver blog_real_server server 192.168.232.133: 80 weight = 5;} server {listen 80; server_name blog.etiantian.org; location/{proxy_pass http://blog_real_server ; # Use proxy_pass to define that if blog.etiantian.org is accessed, it will be automatically transferred to the two realservers defined under blog_real_server }}

Check syntax

Save and exit
[Root @ lb01 conf] #/application/nginx/sbin/nginx-t
Nginx: the configuration file/application/nginx-1.8.1/conf/nginx. conf syntax is OK
Nginx: configuration file/application/nginx-1.8.1/conf/nginx. conf test is successful
You also need to perform a local domain name resolution operation on the local machine to resolve the local ip address to blog.etiantian.org

Restart nginx on three machines
/Application/nginx/sbin/nginx-s reload
Then run the curl command to test

We can see that multiple executions are evenly distributed to two machines, but load balancing is achieved.

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.