lvs + keepalived + nginx + tomcat高可用负载反向代理服务器配置(二) LVS+Keepalived
一、安装ipvs
sudo apt-get install ipvsadm
二、安装keepalived
sudo apt-get install keepalived
三、创建keepalived.conf文件
sudo gedit /etc/keepalived/keepalived.conf
四、配置keepalived.conf
说明:VIP: 192.168.2.68
real_server: 192.168.2.66(MASTER), 192.168.2.67(BACKUP)
# Global Configuration
global_defs {
lvs_id director1
} # VRRP Configuration
vrrp_instance LVS { #定义虚拟路由,LVS 为虚拟路由的标示符,自己定义名称
state MASTER #备份服务器上将MASTER改为BACKUP
interface eth0
virtual_router_id 51 #虚拟路由的ID,而且这个ID也是虚拟MAC最后一段的来源,这个ID号一般不能大于255,且这个ID一定不能有冲突
priority 150 #初始优先级
advert_int 1 #通告的个数
authentication { #认证机制
auth_type PASS #认证类型
auth_pass 123456 #密码,应该为随机的字符串
} virtual_ipaddress { #虚拟地址,即VIP
192.168.2.68
#(如果有多个VIP,继续换行填写.)
} # Virtual Server Configuration - for WWW service
virtual_server 192.168.2.68 {
delay_loop 1 #(每隔1秒查询realserver状态)
lb_algo rr #(lvs 算法)
lb_kind DR #(Direct Route)
persistence_timeout 60 #(同一IP的连接60秒内被分配到同一台realserver)
protocol TCP #(用TCP协议检查realserver状态) # Real Server configuration
real_server 192.168.2.67 {
weight 1 #权重
TCP_CHECK {
connection_timeout 10 #(10秒无响应超时)
nb_get_retry
delay_before_retry
}
} # Real Server configuration
real_server 192.168.2.66 {
weight
TCP_CHECK {
connection_timeout
nb_get_retry
delay_before_retry
}
}
}
}
1.配置vrrp ip为68(启动keepalived之后可使用ip addr可查看)
2.配置real_server 此处是67和66的一个集群
五、启动并查看keepalived
#service keepalived start
查看 keepalived状态
# ps -ef | grep keepalived
root : ? :: keepalived -D
root : ? :: keepalived -D
root : pts/ :: grep keepalived
如果未能启动,请使用sudo启动或者检查配置文件 # tail -f /var/log/syslog
Feb :: localhost Keepalived_vrrp: Registering gratutious ARP shared channel
Feb :: localhost Keepalived_vrrp: Opening file '/etc/keepalived/keepalived.conf'.
Feb :: localhost Keepalived_vrrp: Configuration is using : Bytes
Feb :: localhost Keepalived_vrrp: Using LinkWatch kernel netlink reflector...
Feb :: localhost Keepalived_vrrp: VRRP sockpool: [ifindex(), proto(), fd(,)]
Feb :: localhost Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Feb :: localhost Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Feb :: localhost Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
Feb :: localhost Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.2.68
Feb :: localhost avahi-daemon[]: Registering new address record for 192.168.2.68 on eth0. 可以看到VIP已经在主服务器上开启
到此lvs+keepalived就已经完成了,接下来就是nginx.
Append: 使用Keepalived管理nginx
! Configuration File for keepalived global_defs {
# notification_email {
# henryhe@starhubdev.com
# }
# notification_email_from happy@starhubdev.com
# smtp_server 127.0.0.1
# smtp_connect_timeout
router_id LVS_DEVEL
} vrrp_script chk_nginx {
script "/etc/keepalived/check_nginx.sh"
interval
weight
} vrrp_instance VI_1 {
state BACKUP
interface eno1
virtual_router_id
priority
advert_int
authentication {
auth_type PASS
auth_pass starhub
}
virtual_ipaddress {
172.31.34.92
}
track_script {
chk_nginx
}
} #virtual_server 172.31.34.92 {
# delay_loop
# lb_algo rr
# lb_kind DR
# nat_mask 255.255.255.248
# persistence_timeout
# protocol TCP
# sorry_server 172.31.34.94
# real_server 172.31.34.93 {
# weight
# notify_down /usr/local/bin/keepalived_notify.sh
# TCP_CHECK {
# connect_timeout
# nb_get_retry
# delay_before_retry
# connect_port
# }
# }
}
check_nginx.sh
!/bin/bash
status=$(ps -C nginx --no-heading|wc -l)
if [ "${status}" = "" ]; then
/bin/systemctl start nginx.service #redhat7
/etc/init.d/nginx start #centos
status2=$(ps -C nginx --no-heading|wc -l)
if [ "${status2}" = "" ]; then
/bin/systemctl stop keepalived.service #redhat7
/etc/init.d/keepalived start #centos
fi
fi
lvs + keepalived + nginx + tomcat高可用负载反向代理服务器配置(二) LVS+Keepalived的更多相关文章
- lvs + keepalived + nginx + tomcat高可用负载反向代理服务器配置(一) 简介
一. 为什么这样构架 1. 系统高可用性 2. 系统可扩展性 3. 负载均衡能力 LVS+keepalived能很好的实现以上的要求,keepalived提供健康检查,故障转移,提高系统的可用性!采用 ...
- lvs + keepalived + nginx + tomcat高可用负载反向代理服务器配置(三) Nginx
1. 安装 sudo apt-get install nginx 2. 配置nginx sudo gedit /etc/nginx/nginx.conf user www-data; worker_ ...
- [转]搭建Keepalived+Nginx+Tomcat高可用负载均衡架构
[原文]https://www.toutiao.com/i6591714650205716996/ 一.概述 初期的互联网企业由于业务量较小,所以一般单机部署,实现单点访问即可满足业务的需求,这也是最 ...
- Keepalived + Nginx + Tomcat 高可用负载均衡架构
环境: 1.centos7.3 2.虚拟ip:192.168.217.200 3.192.168.217.11.192.168.217.12上分别部署Nginx Keepalived Tomcat并进 ...
- LVS+Keepalived+Nginx+Tomcat高可用负载均衡集群配置(DR模式,一个VIP,多个端口)
一.概述 LVS作用:实现负载均衡 Keepalived作用:监控集群系统中各个服务节点的状态,HA cluster. 配置LVS有两种方式: 1. 通过ipvsadm命令行方式配置 2. 通过Red ...
- Keepalived+Nginx实现高可用负载均衡集群
一 环境介绍 1.操作系统CentOS Linux release 7.2.1511 (Core) 2.服务keepalived+nginx双主高可用负载均衡集群及LAMP应用keepalived-1 ...
- LVS+keeplived+nginx+tomcat高可用、高性能jsp集群
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://kerry.blog.51cto.com/172631/557749 #!/bin ...
- KeepAlived+Nginx实现高可用负载
一.环境及安装版本: centos6.5.Nginx1.4.7.keepalived1.3.2 虚拟IP 真是IP Nginx端口 主从分配 10.0.90.215 10.0.90.217 80 MA ...
- Linux巩固记录(9) keepalived+nginx搭建高可用负载分发环境
环境准备(继续服用hadoop节点) slave1 192.168.2.201(CentOs 7) slave2 192.168.2.202(CentOs 7) slave1 和 slave2 上 ...
随机推荐
- 如何使用Hive集成Solr?
(一)Hive+Solr简介 Hive作为Hadoop生态系统里面离线的数据仓库,可以非常方便的使用SQL的方式来离线分析海量的历史数据,并根据分析的结果,来干一些其他的事情,如报表统计查询等. So ...
- Balking Pattern不需要就不用做
word自动保存功能,如果文档被修改了,后台线程每隔一段时间会自动执行保存功能,但是如果用户在自动保存之前用Ctrl+S手动保存呢?自动保存还会执行吗?答案是不会,因为这个操作时不需要重复做的. pu ...
- JAVA API about HTTP 2
import java.io.IOException; import java.nio.charset.Charset; import java.security.KeyManagementExcep ...
- 当对象转换成JSON的时候处理时间格式
/// <summary> /// 格式化日期 /// </summary> /// <param name="foramt">格式化规则< ...
- 如何检测 Web 服务请求丢失问题
导读 『StabilityGuide』是阿里多位阿里技术工程师共同发起的稳定性领域的知识库开源项目,涵盖性能压测.故障演练.JVM.应用容器.服务框架.流量调度.监控.诊断等多个技术领域,以更结构化的 ...
- thinkphp action参数绑定
参数绑定是通过直接绑定URL地址中的变量作为操作方法的参数,可以简化方法的定义甚至路由的解析. 参数绑定功能默认是开启的,其原理是把URL中的参数(不包括模块.控制器和操作名)和操作方法中的参数进行绑 ...
- 莫比乌斯反演——hdu6390推公式
/*首先要把原始化简成 k/phi[k] 的格式,然后把有关k的sigma提出来,后面就是求gcd(i,j)==k的莫比乌斯反演这里要用整除分块加下速*/#include<bits/stdc++ ...
- kubernetes监控和性能分析工具:heapster+influxdb+grafana
1.部署heapster 下载 heapster 相关 yaml 文件 [root@master dashboard]# wget https://raw.githubusercontent.com/ ...
- csp-s模拟测试83(集训过半)
csp-s模拟测试83(集训过半) 一场信心赛.起初$OJ$爆了我就看见全场$A$了$T1$并且夹杂着$A$掉$T2$我就很难受. 这场比赛没有深入思考,很失败,一个多小时后就结束了我罪恶的一生. 0 ...
- IK分词器插件
(1)源码 https://github.com/medcl/elasticsearch-analysis-ik (2)releases https://github.com/medcl/elast ...