Nginx + Keepalived (with Nginx monitoring script)

Source: Internet
Author: User

Nginx + Keepalived (with Nginx monitoring script)

Install and deploy Keepalived + nginx
 
HOST: IP-> 10.252.3.160 nginx has installed OK (omitted)
SLAVE: IP> 10.252.3.161 nginx has been installed with OK (omitted)
VIP: 10.252.3.162
 
Step 1: Install keepalived together with the master and slave nodes
Yum installkeepalived-y
Step 2: Configure/etc/keepalived. conf
The configuration of host 10.252.3.160 is as follows:
! Configuration File for keepalived
Global_defs {
Notification_email {
Acassen@firewall.loc # mail target address
Failover@firewall.loc
Sysadmin@firewall.loc
}
Notification_email_from root @ nginx2 # source email address
Smtp_server 127.0.0.1 # smtp Server
Smtp_connect_timeout 30
Router_id LVS_DEVEL
}
 
Vrrp_scriptchk_http_port {
Script "/data/script/nginx. sh" # Monitoring Service Progress
Interval 2 # detection interval (Execution interval)
Weight 2
}
 
Vrrp_instanceVI_1 {
State MASTER # What is the difference between the MASTER and slave databases?
Interface eth1 # corresponding Nic
Virtual_router_id 60
Priority 101 # priority, who is the master (the greater the value, the higher the priority)
Advert_int 2
Authentication {# authentication method, and the password must be the same as the Master/Slave Password
Auth_type PASS
Auth_pass 1234
}
 
Track_interface {# monitored Nic. If you only monitor the service, do not enter
Eth1
}
Track_script {# using the script as the monitor chk_http_port is previously filled in
Chk_http_port
}
Virtual_ipaddress {# Switch Mode. Switch virtual IP Address
10.252.3.165/24 dev eth1 label eth1: 1
}
}
========================================================== ==============
Backup Machine configuration: 10.252.3.161
! Configuration File for keepalived
Global_defs {
Notification_email {
Acassen@firewall.loc # mail target address
Failover@firewall.loc
Sysadmin@firewall.loc
}
Notification_email_from root @ nginx2 # source email address
Smtp_server 127.0.0.1 # smtp Server
Smtp_connect_timeout 30
Router_id LVS_DEVEL
}
 
Vrrp_scriptchk_http_port {
Script "/data/script/nginx. sh" # Monitoring Service Progress
Interval 2 # detection interval (Execution interval)
Weight 2
}
 
Vrrp_instanceVI_1 {
State BACKUP # What is the difference between the master and slave databases?
Interface eth1 # corresponding Nic
Virtual_router_id 60
Priority 100 # priority, who is the master (the greater the value, the higher the priority)
Advert_int 2
Authentication {# authentication method, and the password must be the same as the Master/Slave Password
Auth_type PASS
Auth_pass 1234
}
 
Track_interface {# monitored Nic. If you only monitor the service, do not enter
Eth1
}
Track_script {# using the script as the monitor chk_http_port is previously filled in
Chk_http_port
}
Virtual_ipaddress {# Switch Mode. Switch virtual IP Address
10.252.3.165/24 dev eth1 label eth1: 1
}
}
Step 3: Write/data/script/nginx. sh script content
#! /Bin/sh
NginxPidNum = 'ps-C nginx -- no-header | wc-l'
KeepalivedPidNum = 'ps-C keepalived -- no-header | wc-l'
If [$ nginxPidNum-eq 0]; then
Killall keepalived
Elif [$ keepalivedPidNum-eq 0]; then
Service keepalived start
Fi
 
Grant the script permission chmod + x/data/script/nginx. sh
Step 4: Start Master/Slave keepalived
Servicekeepalived start
Ifconfig: Check whether eth1: 1 is up. If it is up, you can test it. No self-debugging is performed.

For more Nginx tutorials, see the following:

Deployment of Nginx + MySQL + PHP in CentOS 6.2

Build a WEB server using Nginx

Build a Web server based on Linux6.3 + Nginx1.2 + PHP5 + MySQL5.5

Performance Tuning for Nginx in CentOS 6.3

Configure Nginx to load the ngx_pagespeed module in CentOS 6.3

Install and configure Nginx + Pcre + php-fpm in CentOS 6.4

Nginx installation and configuration instructions

Nginx log filtering using ngx_log_if does not record specific logs

Nginx details: click here
Nginx: click here

This article permanently updates the link address:

 

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.