NginX+keepalived实现高可用

yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel

安装缺少组件后编辑成功。

执行 make && make install

编译安装成功:

默认编译安装目录 :

编辑脚本:vim /etc/init.d/nginx

内容如下:

#!/bin/sh

#

# nginx - this script starts and stops the nginx daemin

#

# chkconfig: - 85 15

# description: Nginx is an HTTP(S) server, HTTP(S) reverse \

# proxy and IMAP/POP3 proxy server

# processname: nginx

# config: /usr/local/nginx/conf/nginx.conf

# pidfile: /usr/local/nginx/logs/nginx.pid

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

lockfile=/var/lock/subsys/nginx start() {

[ -x $nginx ] || exit 5

[ -f $NGINX_CONF_FILE ] || exit 6

echo -n $"Starting $prog: "

daemon $nginx -c $NGINX_CONF_FILE

retval=$?

echo

[ $retval -eq 0 ] && touch $lockfile return $retval

}

stop() {

echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$?

echo

[ $retval -eq 0 ] && rm -f $lockfile return $retval

}

restart() {

configtest || return $?

stop start

}

reload() {

configtest || return $?

echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$?

echo

}

force_reload() {

restart

}

configtest() {

$nginx -t -c $NGINX_CONF_FILE

}

rh_status() {

status $prog

}

rh_status_q() {

rh_status >/dev/null 2>&1

}

case "$1" in start)

rh_status_q && exit 0

$1

;;

stop)

rh_status_q || exit 0

$1

;;

restart|configtest)

$1

;;

reload)

rh_status_q || exit 7

$1

;;

force-reload)

force_reload

;;

status)

rh_status

;;

condrestart|try-restart)

rh_status_q || exit 0

;;

*)

echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

exit 2

esac

保存退出添加执行权限

chmod +x /etc/init.d/nginx

启动脚本观察监听端口是否有80

编辑一个测试页:

vim /usr/local/nginx/html/index.html

保存退出测试能否访问

同样26.210也测试下

26.210 keepalived 配置文件:vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {

notification_email {

[email protected]

[email protected]

}

notification_email_from [email protected]

smtp_server smtp.hysec.com smtp_connect_timeout 30 router_id nginx

}

vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111

}

virtual_ipaddress {

192.168.27.210

}

}

virtual_server 192.168.27.210 80 {

delay_loop 2 lb_algo rr lb_kind DR

persistence_timeout 60

protocol TCP

real_server 192.168.26.210 80 {

weight 1

notify_down /etc/keepalived/chk_nginx.sh

TCP_CHECK { connect_port 80 connect_timeout 3 nb_get_retry 2 delay_before_retry 1

}

}

}

chk_nginx.sh脚本:vim /etc/keepalived/chk_nginx.sh

#!/bin/bash

A=`ps -C nginx --no-header |wc -l`

if [ $A -eq 0 ];then

echo ‘nginx server is died‘

/etc/init.d/keepalived stop

fi

别忘记加执行权限:chmod +x /etc/keepalived/chk_nginx.sh

26.211 keepalived 配置文件:vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {

notification_email {

[email protected]

[email protected]

}

notification_email_from [email protected]

smtp_server smtp.hysec.com smtp_connect_timeout 30 router_id nginx

}

vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 51 priority 99 advert_int 1 authentication { auth_type PASS auth_pass 1111

}

virtual_ipaddress {

192.168.27.210

}

}

virtual_server 192.168.27.210 80 {

delay_loop 2 lb_algo rr lb_kind DR

persistence_timeout 60

protocol TCP

real_server 192.168.26.211 80 {

weight 1

notify_down /etc/keepalived/chk_nginx.sh

TCP_CHECK { connect_port 80 connect_timeout 3 nb_get_retry 2 delay_before_retry 1

}

}

}

chk_nginx.sh脚本:vim /etc/keepalived/chk_nginx.sh

#!/bin/bash

A=`ps -C nginx --no-header |wc -l`

if [ $A -eq 0 ];then

echo ‘nginx server is died‘

/etc/init.d/keepalived stop

fi

时间: 2024-11-10 01:22:57

NginX+keepalived实现高可用的相关文章

Nginx+Keepalived搭建高可用负载均衡集群

Nginx+Keepalived搭建高可用负载均衡集群   一. 环境说明 前端双Nginx+keepalived,nginx反向代理到后端的tomcat集群实现负载均衡,Keepalived实现集群高可用. 操作系统: Centos 6.6_X64 Nginx版本: nginx-1.9.5 Keepalived版本:keepalived-1.2.13 结构: Keepalived+nginx-MASTER:10.6.1.210         Keepalived+nginx-BACKUP:

Nginx+Keepalived搭建高可用负载平衡WEB 集群

Nginx+Keepalived搭建高可用负载平衡WEB 集群 1.1环境规划: Nginx_master:192.168.5.129 Nginx_backup:192.168.5.131 Tomcat:192.168.5.132 端口:8080,9080 操作系统:CentOS6.5 x86_64 内核版本:2.6.32-696.el6.x86_64 Nginx版本:nginx/1.12.0 nginx-1.12.0 Keepalived版本:Keepalived v1.2.13 前端双Ngi

nginx+keepalived的高可用负载均衡集群构建

实验架构图: 实验环境 Nginx和Keepalived原理介绍 参考博客:http://467754239.blog.51cto.com/4878013/1541421 1.nginx Nginx进程基于于Master+Slave(worker)多进程模型,自身具有非常稳定的子进程管理功能.在Master进程分配模式下,Master进程永远不进行业务处理,只是进行任务分发, 从而达到Master进程的存活高可靠性,Slave(worker)进程所有的业务信号都 由主进程发出,Slave(wor

架构设计:负载均衡层设计方案(6)——Nginx + Keepalived构建高可用的负载层

1.概述 前两遍文章中,我们一直在说后文要介绍Nginx + Keepalived的搭建方式.这篇文章开始,我们就来兑现前文的承诺,后续的两篇文章我们将介绍Nginx + Keepalived和 LVS + Keepalived搭建高可用的负载层系统.如果你还不了解Nginx和LVS的相关知识,请参见我之前的两篇文章<架构设计:负载均衡层设计方案(2)--Nginx安装>(http://blog.csdn.net/yinwenjie/article/details/46620711).<

使用Nginx+Keepalived组建高可用负载平衡Web server集群

一,首先说明一下网络拓扑结构: 1,Nginx 反向代理Server(HA):      ①Nginx master:192.168.1.157      ②Nginx backup:192.168.1.158         虚拟IP统一为:192.168.1.110   2,web服务器:      192.168.1.160 ,192.168.1.161,192.168.1.162     即web服务器,已配置好 Tomcat(Jboss等皆可)和java程序 3,mysql 数据库Se

Centos 7部署docker+nginx+keepalived实现高可用web集群

一.体系架构 在Keepalived + Nginx高可用负载均衡架构中,keepalived负责实现High-availability (HA) 功能控制前端机VIP(虚拟网络地址),当有设备发生故障时,热备服务器可以瞬间将VIP自动切换过来,实际运行中体验只有2秒钟切换时间,DNS服务可以负责前端VIP的负载均衡.nginx负责控制后端web服务器的负载均衡,将客户端的请求按照一定的算法转发给后端Real Server处理,而Real Server将响应直接返回给客户端. 二.简单原理 NG

nginx+keepalived做高可用

nginx进程基于于Master+Slave(worker)多进程模型,自 身具有非常稳定的子进程管理功能.在Master进程分配模式下,Master进程永远不进行业务处理,只是进行任务分发,从而达到Master进程的存 活高可靠性,Slave(worker)进程所有的业务信号都由主进程发出,Slave(worker)进程所有的超时任务都会被Master中止,属于 非阻塞式任务模型. Keepalived是Linux下面实现VRRP 备份路由的高可靠性运行件.基于Keepalived设计的服务模

Centos6下nginx+keepalived构建高可用web集群

1)拓扑描述: 2) nginx的安装准备 pcre:兼容的正则表达式,nginx也要支持伪静态 # yum -y install pcre pcre-devel # yum -y install openssl* # mkdir -p /application/nginx1.6.2 # ln -s /application/nginx1.6.2 /application/nginx 3) 安装nginx # cd /usr/local/src # tar xf nginx-1.6.2.tar.

nginx+keepalived实现高可用负载均衡

环境: centos7.3虚拟机A 10.0.3.46 centos7.3虚拟机B 10.0.3.110 虚拟机A和B都需要安装nginx和keepalived(过程省略,其中keepalived为yum安装模式) 为了区别虚拟机AB,修改nginx的默认页面 分别开启nginx 分别修改keepalived的配置文件keepalived.conf 虚拟机A的keepalived配置文件为 vrrp_instance VI_1 { state MASTER interface ens33 #这里