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)LB02
Hostname:lb02.example.com
VIP:192.168.3.33(eth0:0)
IP:192.168.3.25(eth0)
OS:Centos 7
3)WEB1
Hostname:web1.example.com
RIP:192.168.3.16(eth0)
OS:Centos 7
4)WEB2
Hostname:web2.example.com
RIP:192.168.3.17(eth0)
OS:Centos 7
5)USER
Hostname:user
UIP:192.168.3.34
安装配置
环境准备(略)
1)主机名配置
2)hosts文件解析
3)时间同步
WEB1
[root@web1 ~]# yum install -y nginx &>/dev/null && echo "web1.example.com" >/usr/share/nginx/html/index.html && systemctl start nginx && systemctl enable nginx
[root@web1 ~]# curl 127.0.0.1
web1.example.com
WEB2
[root@web2 ~]# yum install -y nginx &>/dev/null && echo "web2.example.com" >/usr/share/nginx/html/index.html && systemctl start nginx && systemctl enable nginx
[root@web2 ~]# curl 127.0.0.1
web2.example.com
LB01
[root@lb01 ~]# yum install -y nginx keepalived
[root@lb01 ~]# vim /etc/nginx/nginx.conf
http {
upstream backend {
server 192.168.3.16;
server 192.168.3.17;
}
server {
listen 80 default_server;
server_name www.example.com;
root /usr/share/nginx/html;
location / {
proxy_pass http://backend;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
[root@lb01 ~]# systemctl start nginx && systemctl enable nginx
[root@lb01 ~]# for i in {1..4};do curl 127.0.0.1;done
web1.example.com
web2.example.com
web1.example.com
web2.example.com
[root@lb01 ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
admin@example.com
}
notification_email_from root@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LB01
}
vrrp_script check_lb {
script "/usr/bin/killall -0 nginx" # killall -0 PROCESS 用于判断进程存在与否,存在返回0,不存在返回1
interval 1
}
vrrp_instance LB01 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.3.33/32 brd 192.168.3.33 dev eth0 label eth0:0
}
track_script {
check_lb
}
}
[root@lb01 ~]# systemctl start keepalived && systemctl enable keepalived
[root@lb01 ~]# ifconfig|grep 192.168.3.33|wc -l
1
[root@lb01 ~]# for i in {1..4};do curl 192.168.3.33;done
web1.example.com
web2.example.com
web1.example.com
web2.example.com
LB02
[root@lb02 ~]# yum install -y nginx keepalived
[root@lb02 ~]# vim /etc/nginx/nginx.conf
http {
upstream backend {
server 192.168.3.16;
server 192.168.3.17;
}
server {
listen 80 default_server;
server_name www.example.com;
root /usr/share/nginx/html;
location / {
proxy_pass http://backend;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
[root@lb02 ~]# systemctl start nginx && systemctl enable nginx
[root@lb02 ~]# for i in {1..4};do curl 127.0.0.1;done
web1.example.com
web2.example.com
web1.example.com
web2.example.com
[root@lb02 ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
admin@example.com
}
notification_email_from root@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LB02
}
vrrp_script check_lb {
script "/usr/bin/killall -0 nginx"
interval 1
}
vrrp_instance LB02 {
state BACKUP
interface eth0
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.3.33/32 brd 192.168.3.33 dev eth0 label eth0:0
}
track_script {
check_lb
}
}
[root@lb02 ~]# systemctl start keepalived.service && systemctl enable keepalived.service
[root@lb02 ~]# ifconfig|grep 192.168.3.33|wc -l
0
[root@lb02 ~]# tail /var/log/messages
Jul 3 17:23:35 lvs02 Keepalived_vrrp[5652]: SECURITY VIOLATION - scripts are being executed but script_security not enabled.
Jul 3 17:23:35 lvs02 Keepalived_vrrp[5652]: Using LinkWatch kernel netlink reflector...
Jul 3 17:23:35 lvs02 Keepalived_vrrp[5652]: VRRP_Instance(LB02) Entering BACKUP STATE
Jul 3 17:23:35 lvs02 Keepalived_vrrp[5652]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
Jul 3 17:23:35 lvs02 Keepalived_vrrp[5652]: VRRP_Script(check_lb) succeeded
USER
[root@user ~]# for i in {1..4};do curl www.example.com;done
web1.example.com
web2.example.com
web1.example.com
web2.example.com
[root@lb01 ~]# systemctl stop nginx
[root@lb01 ~]# tail /var/log/messages
Jul 3 17:27:31 lvs01 Keepalived_vrrp[54945]: /usr/bin/killall -0 nginx exited with status 1
[root@lb01 ~]# ifconfig|grep 192.168.3.33|wc -l
0
[root@lb02 ~]# ifconfig|grep 192.168.3.33|wc -l
1
[root@user ~]# for i in {1..4};do curl www.example.com;done
web1.example.com
web2.example.com
web1.example.com
web2.example.com
[root@lb01 ~]# systemctl start nginx
[root@lb01 ~]# ifconfig|grep 192.168.3.33|wc -l
1
Nginx+Keepalived部署流程的更多相关文章
- Tomcat+nginx+Keepalived部署实现集群
Tomcat+nginx+Keepalived部署实现集群 环境说明: 系统:Centos-7 主机:Centos-7 x3 IP地址: 服务器1(192.168.10.102/24) 服务器2(19 ...
- Nginx+Keepalived部署
-----------ReProxy-------------------------Client-----------192.168.56.200 nginx+keepalived 192.168. ...
- 使用Ansible实现nginx+keepalived高可用负载均衡自动化部署
本篇文章记录通过Ansible自动化部署nginx的负载均衡高可用,前端代理使用nginx+keepalived,端web server使用3台nginx用于负载效果的体现,结构图如下: 部署前准备工 ...
- docker 部署nginx 使用keepalived 部署高可用
一.体系架构 在Keepalived + Nginx高可用负载均衡架构中,keepalived负责实现High-availability (HA) 功能控制前端机VIP(虚拟网络地址),当有设备发生故 ...
- nginx+uwsgi+django部署流程
当我们在用django开发的web项目时,开发测试过程中用到的是django自带的测试服务器,由于其安全及稳定等性能方面的局限性,django官方并不建议将测试服务器用在实际生产. nginx+uws ...
- Nginx服务器部署 负载均衡 反向代理
Nginx服务器部署负载均衡反向代理 LVS Nginx HAProxy的优缺点 三种负载均衡器的优缺点说明如下: LVS的优点: 1.抗负载能力强.工作在第4层仅作分发之用,没有流量的产生,这个特点 ...
- Nginx知多少系列之(十四)Linux下.NET Core项目Nginx+Keepalived高可用(主从模式)
目录 1.前言 2.安装 3.配置文件详解 4.工作原理 5.Linux下托管.NET Core项目 6.Linux下.NET Core项目负载均衡 7.负载均衡策略 8.加权轮询(round rob ...
- Nginx+keepalived双机热备(主从模式)
负载均衡技术对于一个网站尤其是大型网站的web服务器集群来说是至关重要的!做好负载均衡架构,可以实现故障转移和高可用环境,避免单点故障,保证网站健康持续运行.关于负载均衡介绍,可以参考:linux负载 ...
- OpenStack Swift集群部署流程与简单使用
之前介绍了<OpenStack Swift All In One安装部署流程与简单使用>,那么接下来就说一说Swift集群部署吧. 1. 简介 本文档详细描述了使用两台PC部署一个小型Sw ...
随机推荐
- Troubleshooting routing topology based on a reference topology
In one embodiment, a computing device (e.g., border router or network management server) transmits a ...
- C#步骤控件
C#开发step步骤条控件 现在很多的javascript控件,非常的不错,其中step就是一个,如下图所示: 那么如何用C#来实现一个step控件呢? 先定义一个StepEntity类来存储步骤 ...
- go-wingui 2018 全新 v2.0 版本发布,包含重大更新!
go-wingui 2018 全新 v2.0 版本发布,包含重大更新!使用新版CEF内核Chromium 63.0.3239.109,页面可以使用最新的css3,html5技术.使用delphi7重写 ...
- IT 达人
1. 手机与电脑多屏互动 [教程]华为多屏互动功能与PC win7的连接 要求手机和电脑必须在同一局域网内,且手机必须支持多屏互动功能. 操作步骤如下: PC 端: services.msc,启动下面 ...
- virtualbox--在xp设置ubuntu虚拟机网络 主宿机能互通,宿机能通过主机上网Host-Only + Bridged
由于最近要写一个简单的C/S模式的程序,刚好虚拟机装了个ubuntu12.04TLS,正好拿来当服务器测试,但是发现无法ping通.刚学习ubuntu,实在不熟,苦苦弄了2小时,才弄明白,在此记录一下 ...
- STL优先级队列
priority_queue 这是一个优先级队列的所有权值概念单向队列queue.在这个队列中.全部元素是按优先级排列的(也能够觉得queue是个按进入队列的先后做为优先级的优先级队列--先进入队列的 ...
- QSplitter实现自由伸缩滑动窗口部件(要在m_pSplitter中加入frame_4之前,给frame_4设置样式;之后设置无效)
实现代码如下: #include <QSplitter> QSplitter *m_pSplitter; m_pSplitter = new QSplitter(ui->frame_ ...
- 动态加载Dll时,通过Type生成类对象
原文:动态加载Dll时,通过Type生成类对象 转:http://www.cnblogs.com/zfanlong1314/p/4197383.html "反射"其实就是利用程序集 ...
- Fiddler教程(Web调试工具)
转载地址:写得很不错的fildder教程 http://kb.cnblogs.com/page/130367/ Fiddler的基本介绍 Fiddler的官方网站: www.fiddler2.c ...
- .net core响应缓存
按照官网资料操作无效,这里使用https://github.com/speige/AspNetCore.ResponseCaching.Extensions的扩展包 安装AspNetCore.Resp ...