1. 高可用环境准备

  2. 后端服务器主配置文件

[192.168.2.7-root@web01~]#cat /etc/nginx/nginx.conf

user www;

worker_processes 1;

error_log /var/log/nginx/error.log warn;

pid /var/run/nginx.pid;

events {

worker_connections 1024;

}

http {

include /etc/nginx/mime.types;

default_type application/octet-stream;

 

log_format main '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for"';

 

access_log /var/log/nginx/access.log main;

sendfile on;

#tcp_nopush on;

keepalive_timeout 65;

gzip on;

include /etc/nginx/conf.d/www.conf;

include /etc/nginx/conf.d/bbs.conf;

}

 

  1. 后端服务器站点目录文件

[192.168.2.7-root@web01~]#cat /etc/nginx/conf.d/bbs.conf

server {

    listen 80;

    index index.html;

    server_name bbs.etiantian.org;

location / {

    root html/bbs;

    index index.html;

}    

}

 

 

 

[192.168.2.7-root@web01~]#cat /etc/nginx/conf.d/www.conf

server {

    listen 80;

    index index.html;

    server_name www.etiantian.org;

location / {

    root html/www;

    index index.html;

}    

}

 

  1. 后端服务器网页文件

[192.168.2.7-root@web01~]#cat /etc/nginx/html/www/bingbing.html

www web01

[192.168.2.7-root@web01~]#cat /etc/nginx/html/bbs/bingbing.html

bbs web01

 

  1. 2台lb 前端配置

  2. nginx负载均衡配置

[root@lb01 ~]# cat /etc/nginx/nginx.conf

worker_processes 1;

events {

worker_connections 1024;

}

http {

include mime.types;

gzip on;

default_type application/octet-stream;

sendfile on;

keepalive_timeout 65;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for"';

 

access_log /var/log/nginx/access.log main;

upstream spool {

server 192.168.2.7:80 weight=1 max_conns=2999 max_fails=1 fail_timeout=3s;

server 192.168.2.8:80 weight=1 max_conns=4000 max_fails=2 fail_timeout=3s;

}

server {

listen 192.168.2.3:80;

server_name www.eitantian.org;

location / {

proxy_pass http://spool;

     include proxy.conf;

}

}

server {

listen 192.168.2.4:80;

server_name bbs.etiantian.org;

location / {

proxy_pass http://spool;

     include proxy.conf;

}

}

}

 

  1. keepailved配置双主配置

    1. lb01 keepalived配置

[root@lb01 ~]# cat /etc/keepalived/keepalived.conf

[root@lb01 ~]# cat /etc/keepalived/keepalived.conf

global_defs {

router_id lb01

}

vrrp_instance VI_1 {

state MASTER

interface eth0

virtual_router_id 51

priority 150

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.2.3/24 dev eth0 label eth0:3

}

}

 

vrrp_script chk_nginx_proxy {

script "/server/scripts/chk_nginx_proxy.sh"

interval 2

weight 2

}

vrrp_instance VI_2 {

state BACKUP

interface eth0

virtual_router_id 52

priority 100

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.2.4/24 dev eth0 label eth0:4

}

track_script {

chk_nginx_proxy

}

}

  1. lb 02 keepalived 配置

[root@lb02 scripts]# cat /etc/keepalived/keepalived.conf

global_defs {

router_id lb02

}

 

vrrp_instance VI_1 {

state BACKUP

interface eth0

virtual_router_id 51

priority 100

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.2.3/24 dev eth0 label eth0:3

}

}

vrrp_script chk_nginx_proxy {

script "/server/scripts/chk_nginx_proxy.sh"

interval 2

weight 2

}

 

vrrp_instance VI_2 {

state MASTER

interface eth0

virtual_router_id 52

priority 150

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.2.4/24 dev eth0 label eth0:4

}

track_script {

chk_nginx_proxy

}

}

  1. 让内核识别网卡ip

[root@lb01 ~]# echo 'net.ipv4.ip_nonlocal_bind = 1' >>/etc/sysctl.conf

[root@lb01 ~]# sysctl -p

  1. 前端解析

[root@lb01 ~]# cat /etc/hosts

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.2.3 www.eitantian.org

192.168.2.4 bbs.eitantian.org

 

windows本地解析

192.168.2.3 www.etiantian.org

192.168.2.4 bbs.etiantian.org

 

测试:因为是高可用

[root@nfs ~]# curl -H Host:www.etiantian.org 192.168.2.3/bingbing.html

www web01

[root@nfs ~]# curl -H Host:www.etiantian.org 192.168.2.3/bingbing.html

www web01

[root@nfs ~]# curl -H Host:bbs.etiantian.org 192.168.2.4/bingbing.html

bbs web01

[root@nfs ~]# curl -H Host:bbs.etiantian.org 192.168.2.4/bingbing.html

bbs web01

keekalived+nginx 高可用的更多相关文章

  1. keepalived对nginx高可用演练脚本

    keepalived对nginx高可用演练脚本 参考文章:http://deidara.blog.51cto.com/400447/302402/ .安装nginx.keepalived.epel-r ...

  2. Keepalived保证Nginx高可用配置

    Keepalived保证Nginx高可用配置部署环境 keepalived-1.2.18 nginx-1.6.2 VM虚拟机redhat6.5-x64:192.168.1.201.192.168.1. ...

  3. linux中keepalived实现nginx高可用配置

    linux中keepalived实现nginx高可用配置 安装keepalived 运行如下命令即可 tar -zxvf keepalived-2.0.8.tar.gz -C /usr/src cd ...

  4. 配置keepalived支持nginx高可用

    实验环境 序号 主机名 IP地址 1 nginx1 192.168.204.11 2 nginx2 192.168.204.12 安装nginx 安装nginx yum install -y epel ...

  5. 面试中的nginx高可用高并发!

    本文转自:91博客:原文地址:http://www.9191boke.com/439923471.html 面试题: nginx高可用?nginx 是如何实现并发的?为什么nginx不使用多线程?ng ...

  6. 001/Nginx高可用模式下的负载均衡与动静分离(笔记)

    Nginx高可用模式下的负载均衡与动静分离 Nginx(engine x)是一个高性能的HTTP和反向代理服务器,具有内存少,并发能力强特点. 1.处理静态文件.索引文件以及自动索引:打开文件描述符缓 ...

  7. Nginx(四):Keepalived+Nginx 高可用集群

    Keepalived+Nginx 高可用集群 (主从模式) 集群架构图 安装keepalived [root@localhost ~]# yum install -y keepalived 查看状态 ...

  8. Docker下配置KeepAlive支持nginx高可用

    案例子任务一.安装配置keepalived 步骤1:使用nginx镜像生成nginx-keep镜像 1) 启动nginx容器并进入 docker run -d --privileged nginx / ...

  9. 3.keepalived+脚本实现nginx高可用

    标题 : 3.keepalived+脚本实现nginx高可用 目录 : Nginx 序号 : 3 else exit 0 fi else exit 0 fi - 需要保证脚本有执行权限,可以使用chm ...

随机推荐

  1. hibernate的load和get有什么作用

    ① load方法认为该数据在数据库中一定存在,可以放心的使用代理来延迟加载,如果在使用过程中发现了问题,只能抛异常(ObjectNotFoundException)load方法加载实体对象的时候,根据 ...

  2. matlab学习笔记8 基本绘图命令-特殊图形绘制

    一起来学matlab-matlab学习笔记8 基本绘图命令_3 特殊图形绘制 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考书籍 <matlab 程序设计与综合应用>张德丰等 ...

  3. Swift编码总结8

    1.判断当前控制器是否在显示: // 判断当前控制器是否在显示 func isCurrentViewControllerVisible() -> Bool { return (self.isVi ...

  4. jQuery hashchange监听浏览器url变化

    $(window).bind('hashchange', function() { // });

  5. [LeetCode] 20. Valid Parentheses 合法括号

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...

  6. java面试 (六)

    1 String.split(String regex), 传入的参数是正则表达式,有一些特殊字符(比如.[]()\| 等)需要转义. 2  关于枚举类型,一般用作常量,理想情况下,枚举中的属性字段是 ...

  7. grok语法定义

    grok默认表达式 Logstash 内置了120种默认表达式,可以查看patterns,里面对表达式做了分组,每个文件为一组,文件内部有对应的表达式模式.下面只是部分常用的. 常用表达式 表达式标识 ...

  8. PHP设计模式 - 合成模式

    组合模式(Composite Pattern)有时候又叫做部分-整体模式,用于将对象组合成树形结构以表示“部分-整体”的层次关系.组合模式使得用户对单个对象和组合对象的使用具有一致性. 常见使用场景: ...

  9. PHP_MySQL高并发加锁事务处理

    1.背景: 现在有这样的需求,插入数据时,判断test表有无username为‘mraz’的数据,无则插入,有则提示“已插入”,目的就是想只插入一条username为‘mraz’的记录. 2.一般程序 ...

  10. vue封装一个简单的div框选时间的组件

    记录一下我前段时间封装的一个vue组件吧.技术需要积累,有时间我把我之前写的还不错的组件都开源出来.并尝试vue和react 两种方式的组件封装.今天简单写下鼠标框选div选中效果的封装吧. div框 ...