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. django项目模型字段

    一个模型(model)就是一个单独的.确定的数据的信息源,包含了数据的字段和操作方法.通常,每个模型映射为一张数据库中的表. 基本的原则如下: 每个模型在Django中的存在形式为一个Python类 ...

  2. PyTorch之DataLoader杂谈

    输入数据PipeLine pytorch 的数据加载到模型的操作顺序是这样的: ①创建一个 Dataset 对象②创建一个 DataLoader 对象③循环这个 DataLoader 对象,将img, ...

  3. [LeetCode] 350. Intersection of Two Arrays II 两个数组相交II

    Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1 ...

  4. STM32F405的内部ADC采集

    1. ADC的初始化部分基本一致,下面是引脚复用配置 void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) { GPIO_InitTypeDef GPIO_Ini ...

  5. Kubernetes StatefulSet

    StatefulSet 简介 在Kubernetes中,Pod的管理对象RC.Deployment.DaemonSet和Job都是面向无状态的服务.但现实中有很多服务是有状态的,特别是一些复杂的中间件 ...

  6. junit单元测试不通过报documentationPluginsBootstrapper相关异常

    这是因为Spring整合springfox-swagger2后导致的,错误信息如下: -- ::, [main] [WARN] [org.springframework.context.support ...

  7. Django文档阅读之聚合

    聚合 我们将引用以下模型.这些模型用来记录多个网上书店的库存. from django.db import models class Author(models.Model): name = mode ...

  8. 为Ubuntu笔记本电脑创建WiFi热点共享上网

    from: linux公社 http://www.linuxidc.com/Linux/2014-02/97139.htm   该文由土木坛子转译而来,说是转译,其实看截图就可以方便的设置,没有任何命 ...

  9. LeetCode 556. 下一个更大元素 III(Next Greater Element III)

    556. 下一个更大元素 III 556. Next Greater Element III 题目描述 给定一个 32 位正整数 n,你需要找到最小的 32 位整数,其与 n 中存在的位数完全相同,并 ...

  10. INV*账户别名接收发放

    DECLARE --p_old_new_flag OLD 为导出 NEW 为导入 l_iface_rec inv.mtl_transactions_interface%ROWTYPE; l_iface ...