-----------ReProxy-------------------------Client-----------
192.168.56.200 nginx+keepalived 192.168.56.202 nginx
192.168.56.201 nginx+keepalived

1、编译安装Nginx
[root@localhost ~]# yum -y install pcre-devel zlib-devel
[root@localhost ~]# useradd -M -s /sbin/nologin nginx
[root@localhost ~]# tar -zxvf nginx-1.12.0.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/nginx-1.12.0/
[root@localhost nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
[root@localhost nginx-1.6.0]# make && make install
[root@localhost ~]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
[root@localhost ~]# nginx -t
[root@localhost ~]# nginx
[root@localhost ~]# netstat -anpt | grep 80

2、创建nginx服务启动脚本
[root@localhost ~]# vim /etc/init.d/nginx
添加:
#!/bin/bash
#### welcome to nginx ####
# chkconfig: - 99 20
# description: this is nginx server
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0

3、编译安装keepalived
[root@localhost keepalived-1.2.13]#./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/
[root@localhost keepalived-1.2.13]# make && make install
[root@localhost ~]#chkconfig --add keepalived
[root@localhost ~]#chkconfig keepalived on
[root@localhost ~]#cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
[root@localhost ~]#vim /etc/keepalived/keepalived.conf
[root@localhost conf]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email { //通知电子邮件
}
vrrp_instance VI_1 { //VRRP热备
state MASTER state BACKUP //热备状态master为主,backup为辅
interface eth0 //承载VIP的物理接口
virtual_router_id 51 //虚拟路由编号,每组一个
priority 100 priority 55 //优先级,越大越优先
advert_int 1 //心跳频率,单位秒
authentication { //认证信息,每组内一致
auth_type PASS //认证类型
auth_pass 1111 //认证字符串
}
virtual_ipaddress { //漂移地址VIP。可以有多个
192.168.56.10
}
notify_master "/etc/init.d/nginx start" //成为MASTER之后执行的动作
notify_backup "/etc/init.d/nginx stop" //成为BACKUP之后执行的动作
notify_fault "/etc/init.d/nginx stop" //FAULT之后执行的动作
}
[root@localhost ~]#/etc/init.d/keepalived start
[root@localhost ~]#ip addr show
inet 192.168.56.201/24 brd 192.168.56.255 scope global eth0
inet 192.168.56.10/32 scope global eth0
[root@localhost ~]#netstat -anput | grep 80

4、反向代理设置
vim /etc/nginx/conf.d/default.conf
----------------------------------------------
location / { //增加此段
proxy_pass http://192.168.56.202;
}
#location / { //将此段注释掉
# root /usr/share/nginx/html;
# index index.html index.htm;
# example
#ModSecurityEnabled on;
#ModSecurityConfig /etc/nginx/modsecurity.conf;
#}
----------------------------------------------
service nginx restart
service keepalived restart
5、日志查看
[root@localhost conf]# tailf /var/log/messages

Nginx+Keepalived部署的更多相关文章

  1. Tomcat+nginx+Keepalived部署实现集群

    Tomcat+nginx+Keepalived部署实现集群 环境说明: 系统:Centos-7 主机:Centos-7 x3 IP地址: 服务器1(192.168.10.102/24) 服务器2(19 ...

  2. Nginx+Keepalived部署流程

    环境介绍 1)LB01 Hostname:lb01.example.com VIP:192.168.3.33(eth0:0) IP:192.168.3.31(eth0) OS:Centos 7 2)L ...

  3. 使用Ansible实现nginx+keepalived高可用负载均衡自动化部署

    本篇文章记录通过Ansible自动化部署nginx的负载均衡高可用,前端代理使用nginx+keepalived,端web server使用3台nginx用于负载效果的体现,结构图如下: 部署前准备工 ...

  4. docker 部署nginx 使用keepalived 部署高可用

    一.体系架构 在Keepalived + Nginx高可用负载均衡架构中,keepalived负责实现High-availability (HA) 功能控制前端机VIP(虚拟网络地址),当有设备发生故 ...

  5. Nginx+keepalived双机热备(主从模式)

    负载均衡技术对于一个网站尤其是大型网站的web服务器集群来说是至关重要的!做好负载均衡架构,可以实现故障转移和高可用环境,避免单点故障,保证网站健康持续运行.关于负载均衡介绍,可以参考:linux负载 ...

  6. Nginx+Keepalived主备切换(包含nginx服务停止)

    原文地址:http://blog.sina.com.cn/s/blog_79ac6aa80101bmed.html Nginx+Keepalived主备切换(包含nginx服务停止) 环境: VM中4 ...

  7. Nginx+Keepalived 主备高可用 安装与配置

    环境说明:操作系统:CentOS6.7 x86_64Nginx版本:nginx-1.9.7Keepalived版本:keepalived-1.2.24 主nginx + Keepalived :10. ...

  8. Centos7+nginx+keepalived集群及双主架构案例

    目录简介 一.简介 二.部署nginx+keepalived 集群 三.部署nginx+keepalived双主架构 四.高可用之调用辅助脚本进行资源监控,并根据监控的结果状态实现动态调整 一.简介 ...

  9. nginx + keepalived 主从模式

    转自:https://www.cnblogs.com/kevingrace/p/6138185.html 负载均衡技术对于一个网站尤其是大型网站的web服务器集群来说是至关重要的!做好负载均衡架构,可 ...

随机推荐

  1. Azure系列2.1.9 —— CloudBlob

    (小弟自学Azure,文中有不正确之处,请路过各位大神指正.) 网上azure的资料较少,尤其是API,全是英文的,中文资料更是少之又少.这次由于公司项目需要使用Azure,所以对Azure的一些学习 ...

  2. [转帖]漫画趣解Linux内核

    漫画趣解Linux内核 https://blog.csdn.net/juS3Ve/article/details/84207142 Linux 内核漫画 今天,我来为大家解读一幅来自 TurnOff. ...

  3. 【Java基础】switch语句实现根据数字输出对应星期

    代码: import java.util.Scanner; /* * switch语句格式: * switch(表达式) { * case 值1: * 语句体1; * break; * case 值2 ...

  4. k8s HPA自动收缩

    HPA自动收缩 autoscale 自动调整一个 Deployment, ReplicaSet, 或者 ReplicationController 的副本数量 #创建一个replicaset测试 [r ...

  5. docker学习笔记二

    知识点: 1)手动构建镜像 2)Dockerfile快速构建镜像 阿里云yum源https://opsx.alibaba.com/mirror 镜像制作nginx镜像实例 创建并运行centos容器 ...

  6. centos无网络问题

  7. C#使用MemoryStream类读写内存

    MemoryStream和BufferedStream都派生自基类Stream,因此它们有很多共同的属性和方法,但是每一个类都有自己独特的用法.这两个类都是实现对内存进行数据读写的功能,而不是对持久性 ...

  8. yolo算法解析

  9. 打包一个UWP APP

    Before packaging your app Test your app. Before you package your app for store submission, make sure ...

  10. hdu-2072(字典树)

    字典树模板题 代码 #include<iostream> #include<algorithm> #include<cstdio> #include<cstr ...