"My technology is my Master" shell script: Create a function and specify the directory to download

Source: Internet
Author: User

Using Nginx as a load balancer, proxy Web server, the user requested data points to the Nginx load balancer, Nginx is responsible for scheduling the backend Web server to provide services.


Environment Construction and Description:

Nginx Load Balancer LNMP environment or only nginx service, two NICs, 192.168.11.30 (Analog public IP), 192.168.20.30 (intranet)

Web server lamp Environment 1:ip address is intranet 192.168.20.10 Apache is version 2.4

Web server lamp Environment 2:ip address is intranet 192.168.20.11

Web server lamp Environment 3:ip address is intranet 192.168.20.12

Three Web server Web site directories, the program remains consistent. The intranet IP is maintained in the same network segment as the Nginx load balancer.


1, only one site configuration:

Operation on Web1, WEB2, WEB3:

HTTPD profile join, allow Site Directory access, open vhost virtual configuration file.

# vi/etc/httpd/httpd.confinclude/etc/httpd/extra/httpd-vhosts.conf<directory/data/www> Options FollowSymLinks allowoverride None Require all granted</directory>

Virtual Host Configuration

# vi/etc/httpd/extra/httpd-vhosts.conf<virtualhost *:80> documentroot "/data/www" ServerName www.yong.com< ;/virtualhost>

Create directories, write index.html file distinctions.

Mkdir/data/www

Write the index.html in each Web directory, respectively: This islamp 1!;this are lamp 2!;this is lamp 3!

# Curl 192.168.20.10This is lamp 1!# curl 192.168.20.11This are lamp 2!# curl 192.168.20.12This is lamp 3!

Nginx Proxy Server Operation:

Write an agent configuration file:

# Cat/usr/local/nginx/conf/vhosts/nginxproxy.confupstream Backend {server 192.168.20.10:80 weight=1 max_fails=3 fail_   timeout=30s;   Server 192.168.20.11:80 weight=1 max_fails=3 fail_timeout=30s; Server 192.168.20.12:80 weight=1 max_fails=3 fail_timeout=30s;}   server {Listen 80;   server_name www.yong.com;   Index index.html;  Location/{Proxy_pass http://backend; }}


Hosts add local IP address resolution, analog public IP corresponding domain name, Windows Local hosts also to increase the resolution;

# cat/etc/hosts192.168.11.30 Www.yong.com

Use Curl test, default RR polling, Access once web1, once web2, once web3

Use for loop execution to view access results:

# for N in ' seq ';d o curl www.yong.com;sleep 2;donethis is LAMP 2! This is LAMP 1! This is LAMP 3! This is LAMP 2! This is LAMP 1! This is LAMP 3! This is LAMP 2! This is LAMP 1! This is LAMP 3! This is LAMP 2!


2, the configuration of multiple sites:

In Web1,web2,web3, add a 2nd site bbs.yong.com

httpd configuration file to allow Site Directory access;

<Directory/data/bbs> Options followsymlinks allowoverride none Require all granted</directory>

Increased Virtual Host Configuration

# vi/etc/httpd/extra/httpd-vhosts.conf<virtualhost *:80> documentroot "/data/bbs" ServerName bbs.yong.com< /virtualhost>

Create directories, write index.html file distinctions.

Mkdir/data/bbs

In each Web directory write index.html, the contents are: This is BBS.yong.com 1!;this are BBS.yong.com 2!;this is BBS.yong.com 3!


Nginx Load balancer Server, virtual host Add server:

server {Listen 80;    server_name bbs.yong.com;    Index index.html;        Location/{Proxy_pass http://backend;        Proxy_set_header Host $host;    Proxy_set_header x-forwarded-for $remote _addr; }}

Hosts add local IP address resolution, analog public IP corresponding domain name, Windows Local hosts also to increase the resolution;

# cat/etc/hosts192.168.11.30 Www.yong.com bbs.yong.com


Use for loop execution to view access results:

# for N in ' seq ';d o curl bbs.yong.com;sleep 2;donethis is BBS.yong.com 1! This is BBS.yong.com 2! This is BBS.yong.com 3! This is BBS.yong.com 1! This is BBS.yong.com 2! This is BBS.yong.com 3! This is BBS.yong.com 1! This is BBS.yong.com 2! This is BBS.yong.com 3! This is BBS.yong.com 1!


3, upstream the following increase Ip_hash;

The test results are as follows: Keeping the user connected will also result in uneven distribution.

# for N in ' seq ';d o curl bbs.yong.com;sleep 2;donethis is BBS.yong.com 3! This is BBS.yong.com 3! This is BBS.yong.com 3! This is BBS.yong.com 3! This is BBS.yong.com 3! This is BBS.yong.com 3! This is BBS.yong.com 3! This is BBS.yong.com 3! This is BBS.yong.com 3! This is BBS.yong.com 3!


4, add a upstream, separate for the request of the BBS load balancing, and set weights, configuration file as follows:

upstream backend {    server 192.168.20.10:80 weight=2 max_fails= 3 fail_timeout=30s;    server 192.168.20.11:80 weight=1 max_fails=3  fail_timeout=30s;} Upstream bbs {    server 192.168.20.11:80 weight=1 max_fails=3  fail_timeout=30s;    server 192.168.20.12:80 weight=2 max_fails=3  fail_timeout=30s;} server {    listen 80;    server_name www.yong.com;     index index.html;    location / {         proxy_pass http://backend;    }}server {     listen 80;    server_name bbs.yong.com;     index index.html;    location / {   &nbSp;    proxy_pass http://bbs;        proxy_ set_header host  $host;        proxy_set_header  x-forwarded-for  $remote _addr;    }}

The experimental results are as follows

# for N in ' seq ';d o curl bbs.yong.com;sleep 2;donethis is BBS.yong.com 2! This is BBS.yong.com 3! This is BBS.yong.com 3! This is BBS.yong.com 2! This is BBS.yong.com 3! This is BBS.yong.com 3! This is BBS.yong.com 2! This is BBS.yong.com 3! This is BBS.yong.com 3! This is BBS.yong.com 2!
# for N in ' seq ';d o curl www.yong.com;sleep 2;donethis is LAMP 2! This is LAMP 1! This is LAMP 1! This is LAMP 2! This is LAMP 1! This is LAMP 1! This is LAMP 2! This is LAMP 1! This is LAMP 1! This is LAMP 2!

Similarly, if there are multiple servers, multiple sites can be assigned, associated with each other.


"51cto 10 Anniversary Blog Activity " > You're on it. ~ 

Event Address :http://51ctoblog.blog.51cto.com/26414/1679643



This article is from the "Model Student's Learning blog" blog, please be sure to keep this source http://mofansheng.blog.51cto.com/8792265/1681807

"My technology is my Master" shell script: Create a function and specify the directory to download

Related Article

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.