keekalived+nginx 高可用
高可用环境准备
后端服务器主配置文件
[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;
}
后端服务器站点目录文件
[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;
}
}
后端服务器网页文件
[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
2台lb 前端配置
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;
}
}
}
keepailved配置双主配置
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
}
}
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
}
}
让内核识别网卡ip
[root@lb01 ~]# echo 'net.ipv4.ip_nonlocal_bind = 1' >>/etc/sysctl.conf
[root@lb01 ~]# sysctl -p
前端解析
[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 高可用的更多相关文章
- keepalived对nginx高可用演练脚本
keepalived对nginx高可用演练脚本 参考文章:http://deidara.blog.51cto.com/400447/302402/ .安装nginx.keepalived.epel-r ...
- Keepalived保证Nginx高可用配置
Keepalived保证Nginx高可用配置部署环境 keepalived-1.2.18 nginx-1.6.2 VM虚拟机redhat6.5-x64:192.168.1.201.192.168.1. ...
- linux中keepalived实现nginx高可用配置
linux中keepalived实现nginx高可用配置 安装keepalived 运行如下命令即可 tar -zxvf keepalived-2.0.8.tar.gz -C /usr/src cd ...
- 配置keepalived支持nginx高可用
实验环境 序号 主机名 IP地址 1 nginx1 192.168.204.11 2 nginx2 192.168.204.12 安装nginx 安装nginx yum install -y epel ...
- 面试中的nginx高可用高并发!
本文转自:91博客:原文地址:http://www.9191boke.com/439923471.html 面试题: nginx高可用?nginx 是如何实现并发的?为什么nginx不使用多线程?ng ...
- 001/Nginx高可用模式下的负载均衡与动静分离(笔记)
Nginx高可用模式下的负载均衡与动静分离 Nginx(engine x)是一个高性能的HTTP和反向代理服务器,具有内存少,并发能力强特点. 1.处理静态文件.索引文件以及自动索引:打开文件描述符缓 ...
- Nginx(四):Keepalived+Nginx 高可用集群
Keepalived+Nginx 高可用集群 (主从模式) 集群架构图 安装keepalived [root@localhost ~]# yum install -y keepalived 查看状态 ...
- Docker下配置KeepAlive支持nginx高可用
案例子任务一.安装配置keepalived 步骤1:使用nginx镜像生成nginx-keep镜像 1) 启动nginx容器并进入 docker run -d --privileged nginx / ...
- 3.keepalived+脚本实现nginx高可用
标题 : 3.keepalived+脚本实现nginx高可用 目录 : Nginx 序号 : 3 else exit 0 fi else exit 0 fi - 需要保证脚本有执行权限,可以使用chm ...
随机推荐
- 转:laydate只显示时分,不显示秒
@转载地址 原文全文: 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/weixin_40 ...
- python自动化测试之连接几组测试包实例
python自动化测试之连接几组测试包实例 本文实例讲述了python自动化测试之连接几组测试包的方法,分享给大家供大家参考.具体方法如下: 具体代码如下: class RomanNumera ...
- LeetCode_405. Convert a Number to Hexadecimal
405. Convert a Number to Hexadecimal Easy Given an integer, write an algorithm to convert it to hexa ...
- [LeetCode] 146. LRU Cache 近期最少使用缓存
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...
- WARNING:Your password has expired --linux 用户密码过期
今天在ssh 提示 WARNING:Your password has expired 设置用户到期时间 chage -M 36000 用户名 chage -l 用户名 #查看用户信息
- linux下RAR和ZIP安装和使用
服务器没装rar,对于上传是压缩的文件来说,是个很大的问题. 源码安装rar: 1. 下载: wget http://www.rarlab.com/rar/rarlinux-x64-4.2.0.tar ...
- idea右下角显示使用内存情况
效果 设置
- Connection: close和Connection: keep-alive有什么区别
转自:https://www.cnblogs.com/TinyMing/p/4597136.html 看到有人问Connection: close和Connection: keep-alive有什么区 ...
- 【LeetCode】盛最多水的容器【双指针+贪心 寻找最大面积】
给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线, ...
- C++多态性----运算符重载与虚函数
一.多态性 ①概述:多态是指同样的消息被不同类型的对象接收时导致的不同行为. ②类型: 可以分为四类:重载多态.强制多态.包含多态.参数多态. ------------------------ --- ...