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 ...
随机推荐
- R 语言的学习(一)
1. 基本 "hello world!" > "hello world!" [1] "hello world!" 这在 R 中并不是一 ...
- 我眼中的robot framework
由于近期公司需要,需要一个测试框架对于公司的服务做自动化测试. 由于服务的复杂性,人工测试的方式越来越复杂,体现在以下方面: 1.人工测试步骤复杂,容易出错.服务的复杂性会使人工测试的准备工作,测试条 ...
- 罚函数(penalty function)的设计
1. encourage sparsity ℓ0 范数: non-differentiable and difficult to optimize in general ℓ1 范数: 对数约束,log ...
- qt线程(转)----这篇很专业!
本文档是自己所整理的一份文档,部分是原创,还转贴了网上的一此资料(已经标明了),(难点是多线程的编写),是有源代码的,大家可以作为参考,用到的知识是视频采集,压缩解压(xvid),实时传输(jrtp) ...
- C++ 异常机制分析(C++标准库定义了12种异常,很多大公司的C++编码规范也是明确禁止使用异常的,如google、Qt)
阅读目录 C++异常机制概述 throw 关键字 异常对象 catch 关键字 栈展开.RAII 异常机制与构造函数 异常机制与析构函数 noexcept修饰符与noexcept操作符 异常处理的性能 ...
- Jenkins build失败条件
在Jenkins 项目写了很多剧本.有时候,我发现脚本失败,但Jenkins运行成功. Jenkins无论是通过退出代码0比量build成功. 因此,newLISP在.您可以使用(exit)对于成功. ...
- C++异常机制的实现方式和开销分析 (大图,编译器会为每个函数增加EHDL结构,组成一个单向链表,非常著名的“内存访问违例”出错对话框就是该机制的一种体现)
白杨 http://baiy.cn 在我几年前开始写<C++编码规范与指导>一文时,就已经规划着要加入这样一篇讨论 C++ 异常机制的文章了.没想到时隔几年以后才有机会把这个尾巴补完 :- ...
- debian 下py2.7 安装mysql模块
先安装pip 然后用pip安装 setuptools 安装模块的时候会报错 python setup.py install sh: mysql_config: command not found Tr ...
- CSharp获取图形文件的读写
C#是微软发布了一个面向对象.开展对.NET Framework上述高级编程语言.并定于占领在微软开发者论坛(PDC)在首演. C#这是微软研究员Anders Hejlsberg最新成就.C#容貌Ja ...
- postgresql 自带函数
替换函数 SELECT replace('abcdefabcdef', 'cd', 'XX') 得到 abXXefabXXef ------------------------------------ ...