nginx+ keepalived+proxy_cache实现nginx高可用及高速缓存

环境:

master: 10.10.0.224

slave: 10.10.0.225

real server 1: 10.10.0.221

real server 2: 10.10.0.226

vip: 10.10.0.220

real server 事先安装好web服务

# yum install httpd -y

# cd /var/www/html

# touch test.html

# echo "10.10.0.221" > test.html    # real server1

# echo "10.10.0.226" > test.html    # real server2

Master/slave:

一、安装nginx

安装依赖

# yum install -y pcre pcre-devel gd gd-devel

# tar zcvf nginx-1.9.1.tar.gz

# cd nginx-1.9.1

# ./configure --prefix=/etc/nginx --with-http_ssl_module --with-http_spdy_module --with-http_stub_status_module --with-pcre

# make

# make install

二、配置文件修改

# cd /etc/nginx/conf

# vim nginx

#负载均衡

upstream webs {

server 10.10.0.221      weight=2;

server 10.10.0.226      weight=1 max_fails=2 fail_timeout=2;

}

#设置缓存

proxy_cache_path /data/cache levels=1:2 keys_zone=one:20m max_size=1g;

server {

listen  80;

server_name     www.a.com;

location / {

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_pass    http://webs;

add_header X-Via-IP $server_addr;

add_header X-Cache-Status $upstream_cache_status;

proxy_cache   one;

proxy_cache_valid 200 302 301 304 10m;

}

}

启动脚本

# vim /etc/init.d/nginx

#!/bin/bash

# it is nginx

# chkconfig: - 85 15

# discription: nginx is a high-performance web and proxy server

# date: 2015-6-2

nginxd=/etc/nginx/sbin/nginx

nginx_config=/etc/nginx/conf/nginx.conf

nginx_pid=/var/run/nginx.pid

RETVAL=0

prog="nginx"

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

. /etc/sysconfig/network

[ ${NETWORKING} = no ] && exit 0

[ -x $ngind ] || exit 0

start() {

if [ -e $nginx_pid ]

then

echo "nginx already running..."

exit 1

fi

echo -n $"staring $prog: "

daemon $nginxd -c ${nginx_config}

RETVAL=$?

echo

[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx

return $RETVAL

}

stop() {

echo -n $"stopping $prog: "

killproc $nginxd

RETVAL=$?

echo

[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid

}

reload() {

echo -n $"reloading $prog: "

killproc $nginxd -HUP

RETVAL=$?

echo

}

case "$1" in

start)

start;;

stop)

stop;;

reload)

reload;;

restart)

stop

start

;;

status)

status $prog

RETVAL=$?;;

*)

echo $"Usage:$prog{start|stop|status|reload|restart|help}"

exit 1;;

esac

exit $RETVAL

# chmod +x /etc/init.d/nginx

# service nginx restart

三、测试

四、安装配置keepalived(这里采用yum安装)

# yum install -y 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 127.0.0.1

smtp_connect_timeout 30

router_id LVS_DEVEL1    #全局唯一,slave上需修改

}

vrrp_instance VI_1 {

state MASTER

interface eth0

virtual_router_id 51

priority 100    #slave需修改

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

10.10.0.220/12 dev eth0 label eth0:0

}

}

五、开启服务,并开机启动

# service keepalived start

# chkconfig keepalived on

# chkconfig nginx on

六、测试

时间: 2024-11-05 04:45:28

nginx+ keepalived+proxy_cache实现nginx高可用及高速缓存的相关文章

公司nginx keepalived tomcat cxf 搭建高可用负载均衡实战系列1- keepalived安装配置

1,ip说明 vip 10.50.13.67 server1 10.50.13.68 server2 10.50.13.140 2,keepalived安装 keepalived通常与lvs或者nginx结合使用保证集群的高可用,keepalived的master会绑定一个vip用来对外服务并定期向backup发送消息,当backup接收不到消息时则会判定master已经挂掉,backup将升为master并且绑定vip继续对外提供服务,从而保证高可用.下面介绍keepalived的安装 安装依

公司nginx keepalived tomcat cxf 搭建高可用负载均衡实战系列1- keepalived的安装配置

1,ip说明 vip 10.50.13.67 server1 10.50.13.68 server2 10.50.13.140 2,keepalived安装 keepalived通常与lvs或者nginx结合使用保证集群的高可用,keepalived的master会绑定一个vip用来对外服务并定期向backup发送消息,当backup接收不到消息时则会判定master已经挂掉,backup将升为master并且绑定vip继续对外提供服务,从而保证高可用.下面介绍keepalived的安装 安装依

单主模型的IPVS高可用和nginx+keepalived的双主高可用模型

一.IPVS的单主高可用 (1)配置RS,我们使用两台服务器作为RS服务器配置过程我们可以使用脚本来配置,这样当我们完成试验后便于卸载,脚本如下: #!/bin/bash # vip=192.168.125.198 #你用的虚拟路由的IP地址 case $1 in start) echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore echo 1 > /p

Nginx +keepalived+varnish+lamp实现高可用、负载均衡集群

描述:1.前端两台NGINX,通过keepalived虚拟IP漂移,实现前端两台NGINX高可用:2.利用NGINX反向代理功能对后端varnish实现高可用集群, 3.再通过varnish实现动静分离 注:1.先装Nginx +keepalived2.装varnish3.装lamp需要6台虚拟机(100-101装Nginx +keepalived:100主,101备)需要联网(102-103装varnish)需要联网(104-105装lamp)需要联网 所有主机必做的步骤 systemctl

nginx+keepalived+tomcat实现的高可用

环境准备 172.16.119.100:nginx + keepalived   master 172.16.119.101:nginx + keepalived   backup 172.16.119.102:tomcat 172.16.119.103:tomcat 虚拟ip(VIP):172.16.119.200,对外提供服务的ip,也可称作浮动ip 各个组件之间的关系图如下: tomcat做应用服务器 将172.16.119.102.172.16.119.103上的tomcat启动起来 上

Nginx+Keepalived实现负载均衡高可用

一.环境 5台虚拟机,分别是: 1台测试机(192.168.2.83); 2台nginx/keepalived(192.168.2.235/192.168.2.236); 2台Web Servers(192.168.2.237/192.168.2.238); 注:VIP设置为 192.168.2.229: 二.安装配置Web Server 由于Web Server的安装与配置非常简单,根据自己喜好,安装一个即可:比如:apache.nginx.tomcat等等.在此就不再详述: 三.安装配置Ng

linux Nginx +keepalived+varnish+lamp实现高可用、负载均衡集群

环境 需要六台服务器:两台keepalived+nginx:192.168.80.100/192.168.80.101两台varnish:192.168.80.102/192.18.80.103两台lamp:192.168.80.104/192.168.80.105 安装epel-releases 需要释放yum源yum install epel-releases 安装epel源 需要联网 安装服务 yum install keepalived -y安装keepalived服务 配置主keepa

keepalived+nginx 双主模型实现高可用服务

一.keepalived的工作原理 keepalived是以VRRP协议为实现基础的,VRRP全称Virtual Router Redundancy Protocol,即虚拟路由冗协议. 虚拟路由冗余协议,可以认为是实现路由器高可用的协议,即将N台提供相同功能的路由器组成一个虚拟路由器组,这个组里面有一个master和多个backup,master上面有一个对外提供服务的vip(该路由器所在局域网内其他机器的默认路由为该vip),master会发组播,当backup收不到vrrp包时就认为mas

Nginx+Zuul集群实现高可用网关

代码参考:https://github.com/HCJ-shadow/Zuul-Gateway-Cluster-Nginx Zuul的路由转发功能 前期准备 搭建Eureka服务注册中心 服务提供者msc-provider-5001[提供一个hello请求做测试] 创建gateway-7001 pom依赖 <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-