Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Server \ Nginx Load Balancing (standby) + Keepalived     - PCM audio under Linux (Linux)

- Use py2exe to generate exe files Python script (Programming)

- Oracle 12C with multi-column index (Database)

- Android Action Compendium (Programming)

- GNU Linux use diff to generate a patch with the patch (Linux)

- How to publish projects to the Jcenter repository using Gradle in Android Studio (Programming)

- Linux under DB2SQL1024N A database connection does not exist. SQLS (Database)

- Construction Spark source and application development environment (Server)

- Modify MySQL character encoding under Linux (Database)

- Linux environmental performance data acquisition system (Linux)

- Oracle first Automated Installation Packages (Database)

- Four IDS intrusion detection tool under Linux environment (Linux)

- Oracle Client + PL SQL Developer enables remote access to the Oracle database (Database)

- Git you do not know about some of the things (Linux)

- Linux Timing task Crontab command Detailed (Linux)

- Ubuntu 13.04 configure MyEclipse 10.7 Environment (Linux)

- grep regular expression (Linux)

- Installation and deployment of Hadoop 2.7.1 on Ubuntu 14.04 LTS (Server)

- Linux upgrade GCC 4.8.1 clear and concise tutorials (Ubuntu 12.04 64-bit version as an example) (Linux)

- CentOS 6.0 system security level (Linux)

 
         
  Nginx Load Balancing (standby) + Keepalived
     
  Add Date : 2018-11-21      
         
         
         
  Nginx advantage load balancer:

Look architecture to achieve flexible operation, the pressure increases when you can temporarily add a back-end Web server;
upstream with load-balancing capability (default polling), it can automatically determine the following machine and automatically kicked out of the machine can not provide normal services;
Keepalvied monitoring scripts can be added Nginx nginx ensure the effectiveness of a single load balancer to avoid single points of failure
system

Two Nginx:

CentOS6.7 x86_64

Two Web:

Ubuntu 15.04 desktop

Topology

IP address

nginx (main LB): 192.168.15.132

nginx (prepared LB): 192.168.15.133

VIP Address: 192.168.15.135

Real1 the IP: 192.168.15.128

Real2 the IP: 192.168.15.130

Deployment of the entire environment for the software used:

nginx-1.6.3.tar.gz
prce-8.38.tar.gz

zlib-1.2.8.tar.gz

Deploy Nginx + PHP-FPM + MySQL a.2 on one Web host (Ubuntu), omitted here.

b. Installing Nginx Nginx respectively on the two sets of load balancer configured

Install GCC compiler and other tools:

yum install -y gcc gcc-c ++ autoconf automake libtool make openssl openssl-devel

Install Nginx:

wget http://exim.mirror.fr/pcre/pcre-8.38.tar.gz

tar -zxvf pcre-8.38.tar.gz

cd pcre-8.38

./configure

make && make install

wget http://zlib.net/zlib-1.2.8.tar.gz

tar -zxvf zlib-1.2.8.tar.gz

cd zlib-1.2.8

./configure

make && make install

wget http://nginx.org/download/nginx-1.6.3.tar.gz

tar -zxvf nginx-1.6.3.tar.gz
cd nginx-1.6.3 /

./configure --prefix = / usr / local / nginx

--sbin-path = / usr / local / nginx / sbin / nginx

--conf-path = / usr / local / nginx / conf / nginx.conf

 

--pid-path = / usr / local / nginx / logs / nginx.pid \

--with-http_ssl_module \

--with-http_stub_status_module \

--with-http_gzip_static_module \

make && make install

Note: Consult "./configure --help" related modules, according to needs specified to enable


Nginx.conf profile, two nginx load balancer same document

user www-data www-data;
worker_processes 1;
error_log /usr/local/nginx/logs/error.log notice;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events {
    use epoll;
    worker_connections 51200;
}
http {
    include mime.types;
    default_type application / octet-stream;
    log_format main '$ remote_addr - $ remote_user [$ time_local] "$ request"'
                      '$ Status $ body_bytes_sent "$ http_referer"'
                      ' "$ Http_user_agent" "$ http_x_forwarded_for"';
    access_log logs / access.log main;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 8m;
    sendfile on;
    tcp_nopush on;
    server_tokens off;
    keepalive_timeout 60;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
    gzip on;
    upstream backend
    {
    server 192.168.15.128;
    server 192.168.15.130;
    }
    server {
        listen 80;
        server_name 192.168.15.135;
        location / {
            root html;
            index index.php index.html index.htm;
            proxy_redirect off;
            proxy_set_header Host $ host;
            proxy_set_header X-Real-IP $ remote_addr;
            # Back-end Web server can obtain the user's real IP by X-Forwarded-For
            proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
            proxy_pass http: // backend;
        }
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root html;
        }
        
        location / nginx_status {
            stub_status on;
            auth_basic "NginxStatus";
            auth_basic_user_file / usr / local / nginx / htpasswd;
            #allow 127.0.0.1;
            #deny all;
        }
        location ~ * \. (ini | docx | txt | doc | pdf) $ {
        # Disable access to documents documents
        root / usr / share / nginx / html;
        deny all;
        }
        location ~ * \.. (gif | jpg | jpeg | png | bmp | swf | js | html | htm | css) $ {
        root / home / image;
        proxy_store on;
        proxy_store_access user: rw group: rw all: rw;
        proxy_temp_path / home / image;
        if (! -e $ request_filename) {
          proxy_pass http: // backend;
        }
    }
}
}

. C installation and configuration keepalived on Taiwan Nginx:

wget http://www.keepalived.org/software/keepalived-1.2.15.tar.gz

tar -zxvf keepalived-1.2.15.tar.gz

cd keepalived-1.2.15

./configure --sysconf = / etc / --with-kernel-dir = / usr / src / kernels / 2.6.32-573.8.1.el6.x86_64

make && make install

ln -s / usr / local / sbin / keepalived / sbin /

# This step is very important, do not execute ln -s will complain "Starting keepalived: / bin / bash: keepalived: command not found"

service keepalived start

keepalived.conf profile follows the two sets of Nginx, respectively service keepalived start start after configuration is complete. Verify that the configuration was successful keepalived

the Lord:

global_defs {
  notification_email {
    test@163.com
  }
  notification_email_from keepalived @ localhost
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  router_id LVS_MASTER
}
vrrp_script chk_http_port {
script "/usr/local/src/check_nginx_pid.sh"
interval 2 # (detection script execution interval)
weight 2
}
vrrp_instance VI_1 {
    state MASTER
    interface bond0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
}
track_script {
chk_http_port # (call detection script)
}
    virtual_ipaddress {
        192.168.15.135
    }
}

Preparation:

global_defs {
  notification_email {
    test@163.com
  }
  notification_email_from keepalived @ localhost
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  router_id LVS_BACKUP
}
vrrp_script chk_http_port {
script "/usr/local/src/check_nginx_pid.sh"
interval 2 # (detection script execution interval)
weight 2
}
vrrp_instance VI_1 {
    state BACKUP
    interface bond0
    virtual_router_id 51
    priority 66
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
}
track_script {
chk_http_port # (call detection script)
}
    virtual_ipaddress {
        192.168.15.135
    }
}
 

The following are performed for nginx state detection script, the first to die when nginx service, will restart the service if Nginx does not start properly, then kill the process keepalived

vim /usr/local/src/check_nginx_pid.sh

#! / Bin / bash
A = `ps -C nginx --no-header | wc -l`
if [$ A -eq 0]; then
      / Usr / local / nginx / sbin / nginx
      if [ `ps -C nginx --no-header | wc -l` -eq 0]; then
              killall keepalived
      fi
fi

Ok, start nginx load balancing test, turning off any service a station does not affect operation of the entire system.

NOTE: Two LBServer may be separately added a VIPab (Keepalived heartbeat monitoring service is unavailable or down, VIPa LBServer be prepared to take over), using external intelligent DNS round robin two VIPab, improve the utilization of hardware resources.
     
         
         
         
  More:      
 
- Ubuntu Linux use MAC binding against ARP attacks (Linux)
- Java objects to garbage collection (Programming)
- Under Ubuntu 15.04 installation JDK8 (Linux)
- Linux based exercises, interview questions (Linux)
- Ubuntu 14.04 Fixed update information is outdated error (Linux)
- How to write a new Git protocol (Linux)
- How to install Eclipse Luna IDE on CentOS 7 / RHEL 7 (Linux)
- Laravel 4 Expansion Pack (Server)
- Android components series Activity (Programming)
- CentOS 7 RHEL 7 to reset the root password (Linux)
- Some of the bibliographic management tools to good use on linux (Linux)
- Linux Network Programming - raw socket can do (Programming)
- CentOS 6.5 Telnet SecureCRT use management tools (Linux)
- Ubuntu UFW firewall settings Introduction (Linux)
- Use mysqldump MySQL database backup - Linux Shell Scripting (Database)
- CentOS RedHat YUM Source Extensions Supplement (including 32-bit, 64-bit) (Linux)
- How to run Kali Linux 2.0 in Docker container (Linux)
- Oracle Execute to Parse perform analytical Ratio Analysis (Database)
- Reported too many open files Linux solutions (Server)
- Quagga use authentication on strengthening BGP session security (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.