Nginx+Keepalived部署
-----------ReProxy-------------------------Client-----------
192.168.56.200 nginx+keepalived 192.168.56.202 nginx
192.168.56.201 nginx+keepalived
1、编译安装Nginx
[root@localhost ~]# yum -y install pcre-devel zlib-devel
[root@localhost ~]# useradd -M -s /sbin/nologin nginx
[root@localhost ~]# tar -zxvf nginx-1.12.0.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/nginx-1.12.0/
[root@localhost nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
[root@localhost nginx-1.6.0]# make && make install
[root@localhost ~]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
[root@localhost ~]# nginx -t
[root@localhost ~]# nginx
[root@localhost ~]# netstat -anpt | grep 80
2、创建nginx服务启动脚本
[root@localhost ~]# vim /etc/init.d/nginx
添加:
#!/bin/bash
#### welcome to nginx ####
# chkconfig: - 99 20
# description: this is nginx server
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0
3、编译安装keepalived
[root@localhost keepalived-1.2.13]#./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/
[root@localhost keepalived-1.2.13]# make && make install
[root@localhost ~]#chkconfig --add keepalived
[root@localhost ~]#chkconfig keepalived on
[root@localhost ~]#cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
[root@localhost ~]#vim /etc/keepalived/keepalived.conf
[root@localhost conf]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email { //通知电子邮件
}
vrrp_instance VI_1 { //VRRP热备
state MASTER state BACKUP //热备状态master为主,backup为辅
interface eth0 //承载VIP的物理接口
virtual_router_id 51 //虚拟路由编号,每组一个
priority 100 priority 55 //优先级,越大越优先
advert_int 1 //心跳频率,单位秒
authentication { //认证信息,每组内一致
auth_type PASS //认证类型
auth_pass 1111 //认证字符串
}
virtual_ipaddress { //漂移地址VIP。可以有多个
192.168.56.10
}
notify_master "/etc/init.d/nginx start" //成为MASTER之后执行的动作
notify_backup "/etc/init.d/nginx stop" //成为BACKUP之后执行的动作
notify_fault "/etc/init.d/nginx stop" //FAULT之后执行的动作
}
[root@localhost ~]#/etc/init.d/keepalived start
[root@localhost ~]#ip addr show
inet 192.168.56.201/24 brd 192.168.56.255 scope global eth0
inet 192.168.56.10/32 scope global eth0
[root@localhost ~]#netstat -anput | grep 80
4、反向代理设置
vim /etc/nginx/conf.d/default.conf
----------------------------------------------
location / { //增加此段
proxy_pass http://192.168.56.202;
}
#location / { //将此段注释掉
# root /usr/share/nginx/html;
# index index.html index.htm;
# example
#ModSecurityEnabled on;
#ModSecurityConfig /etc/nginx/modsecurity.conf;
#}
----------------------------------------------
service nginx restart
service keepalived restart
5、日志查看
[root@localhost conf]# tailf /var/log/messages
Nginx+Keepalived部署的更多相关文章
- Tomcat+nginx+Keepalived部署实现集群
Tomcat+nginx+Keepalived部署实现集群 环境说明: 系统:Centos-7 主机:Centos-7 x3 IP地址: 服务器1(192.168.10.102/24) 服务器2(19 ...
- 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)L ...
- 使用Ansible实现nginx+keepalived高可用负载均衡自动化部署
本篇文章记录通过Ansible自动化部署nginx的负载均衡高可用,前端代理使用nginx+keepalived,端web server使用3台nginx用于负载效果的体现,结构图如下: 部署前准备工 ...
- docker 部署nginx 使用keepalived 部署高可用
一.体系架构 在Keepalived + Nginx高可用负载均衡架构中,keepalived负责实现High-availability (HA) 功能控制前端机VIP(虚拟网络地址),当有设备发生故 ...
- Nginx+keepalived双机热备(主从模式)
负载均衡技术对于一个网站尤其是大型网站的web服务器集群来说是至关重要的!做好负载均衡架构,可以实现故障转移和高可用环境,避免单点故障,保证网站健康持续运行.关于负载均衡介绍,可以参考:linux负载 ...
- Nginx+Keepalived主备切换(包含nginx服务停止)
原文地址:http://blog.sina.com.cn/s/blog_79ac6aa80101bmed.html Nginx+Keepalived主备切换(包含nginx服务停止) 环境: VM中4 ...
- Nginx+Keepalived 主备高可用 安装与配置
环境说明:操作系统:CentOS6.7 x86_64Nginx版本:nginx-1.9.7Keepalived版本:keepalived-1.2.24 主nginx + Keepalived :10. ...
- Centos7+nginx+keepalived集群及双主架构案例
目录简介 一.简介 二.部署nginx+keepalived 集群 三.部署nginx+keepalived双主架构 四.高可用之调用辅助脚本进行资源监控,并根据监控的结果状态实现动态调整 一.简介 ...
- nginx + keepalived 主从模式
转自:https://www.cnblogs.com/kevingrace/p/6138185.html 负载均衡技术对于一个网站尤其是大型网站的web服务器集群来说是至关重要的!做好负载均衡架构,可 ...
随机推荐
- 学习yii2.0——行为
学习yii框架的行为之前,需要先了解yii的事件,可以参考这篇博客: 怎么理解行为 yii框架的行为有点类似于trait,可以有个大体的概念: 1.有一个类A,包含一些属性和方法,很普通的一个类A. ...
- vue 短信验证
直接贴代码: HTML <div class="phone"> <div class="number"> <p class=&qu ...
- [转帖]OS/2 兴 衰 史
OS/2 兴 衰 史 https://zhidao.baidu.com/question/12076254.html 最近在看windows的版本 感觉自己接触电脑太晚 知道的也是很少 不明白 之前有 ...
- vue-axios的application/x-www-form-urlencod的post请求无法解析参数
vue-axios的post会先将对象转为json然后再根据headers的设置再转一次格式,可以将参数先用qs.stringify()转一次再传输
- idea 方便的设置代码段
使用快捷键(ctrl+alt+s)找到:从idea的菜单File->Settings->Editor->Live Templates 先添加Template Group,然后添加Li ...
- python raise
当程序出现错误,python会自动引发异常,也可以通过raise显示地引发异常.一旦执行了raise语句,raise后面的语句将不能执行. 演示raise用法 try: s = None if s ...
- 移动端Web界面滚动touch事件
解决办法一: elem.addEventListener( 'touchstart', fn, { passive: false } ); 解决办法二: * { touch-action: pan-y ...
- shit iview docs & i-radio bug
shit iview docs & i-radio bug https://github.com/iview/iview/issues/5627 <i-row> <i-col ...
- String、StringBuffer、StringBuilder三种类型的一点比较
简要记一点 以运行速度来说: StringBuilder>StringBuffer>String 以线程安全来说: StringBuilder线程不安全,而StringBuffer线程安全 ...
- pip 升级
pip install --upgrade qrcode pip install --upgrade qrcode==5.3