Nginx+keepalive 搭建负载均衡
准备两台服务器
NginXkeepalived:
yum -y install gcc pcre-devel zlib-devel openssl-devel
yum -y install popt-devel
wget http://nginx.org/download/nginx-1.2.4.tar.gz
wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz
NginX
keepalive
tar zxvf keepalived-1.2.7.tar.gz
cd keepalived-1.2.7
3
NginX
NginX,/usr/local/nginx/conf/nginx.confhttphttpserverserverlocationhttpupstream,serverlocationproxypasshttp
http {
}
IPurl
/
keepalived
keepalived/etc/keepalived/keepalived.conf
Master:
! Configuration File for keepalived
global_defs {
}
vrrp_instance VI_1 {
}
Backup:
! Configuration File for keepalived
global_defs {
}
vrrp_instance VI_1 {
}
keepalived: /etc/init.d/keepalived start
IPip addr
keepalived: /etc/init.d/keepalived stop IP
keepalivedIP
keepalivedNginX
keepalivedVIPkeepalivedVIPNginX
keepalivedNginXNginXkeepalived
NginX
NginXNginXurl
NginX3
nmapnginxnginxnmap:
#!/bin/bash
# check nginx server status
NGINX=/usr/local/nginx/sbin/nginx
PORT=8080
nmap localhost -p $PORT | grep "$PORT/tcp open"
#echo $?
if [ $? -ne 0 ];then
fi
/opt/chk_nginx.shkeepalived.conf
主keepalived
vrrp_script chk_http_port {
}
track_script {
}
例子:
! Configuration File for keepalived
global_defs {
}
vrrp_script chk_http_port {
}
vrrp_instance VI_1 {
}
keepalivednginx , /etc/init.d/keepalivedstartnginx:
start() {
}