一、安装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的更多相关文章

  1. lvs + keepalived + nginx + tomcat高可用负载反向代理服务器配置(一) 简介

    一. 为什么这样构架 1. 系统高可用性 2. 系统可扩展性 3. 负载均衡能力 LVS+keepalived能很好的实现以上的要求,keepalived提供健康检查,故障转移,提高系统的可用性!采用 ...

  2. lvs + keepalived + nginx + tomcat高可用负载反向代理服务器配置(三) Nginx

    1.  安装 sudo apt-get install nginx 2. 配置nginx sudo gedit /etc/nginx/nginx.conf user www-data; worker_ ...

  3. [转]搭建Keepalived+Nginx+Tomcat高可用负载均衡架构

    [原文]https://www.toutiao.com/i6591714650205716996/ 一.概述 初期的互联网企业由于业务量较小,所以一般单机部署,实现单点访问即可满足业务的需求,这也是最 ...

  4. Keepalived + Nginx + Tomcat 高可用负载均衡架构

    环境: 1.centos7.3 2.虚拟ip:192.168.217.200 3.192.168.217.11.192.168.217.12上分别部署Nginx Keepalived Tomcat并进 ...

  5. LVS+Keepalived+Nginx+Tomcat高可用负载均衡集群配置(DR模式,一个VIP,多个端口)

    一.概述 LVS作用:实现负载均衡 Keepalived作用:监控集群系统中各个服务节点的状态,HA cluster. 配置LVS有两种方式: 1. 通过ipvsadm命令行方式配置 2. 通过Red ...

  6. Keepalived+Nginx实现高可用负载均衡集群

    一 环境介绍 1.操作系统CentOS Linux release 7.2.1511 (Core) 2.服务keepalived+nginx双主高可用负载均衡集群及LAMP应用keepalived-1 ...

  7. LVS+keeplived+nginx+tomcat高可用、高性能jsp集群

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://kerry.blog.51cto.com/172631/557749 #!/bin ...

  8. KeepAlived+Nginx实现高可用负载

    一.环境及安装版本: centos6.5.Nginx1.4.7.keepalived1.3.2 虚拟IP 真是IP Nginx端口 主从分配 10.0.90.215 10.0.90.217 80 MA ...

  9. Linux巩固记录(9) keepalived+nginx搭建高可用负载分发环境

    环境准备(继续服用hadoop节点) slave1  192.168.2.201(CentOs 7) slave2  192.168.2.202(CentOs 7) slave1 和 slave2 上 ...

随机推荐

  1. JSON Web Token (JWT)生成Token及解密实战。

    昨天讲解了JWT的介绍.应用场景.优点及注意事项等,今天来个JWT具体的使用实践吧. 从JWT官网支持的类库来看,jjwt是Java支持的算法中最全的,推荐使用,网址如下. https://githu ...

  2. mysql8以上版本时区问题:The server time zone value乱码XXXX

    异常类似: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. ...

  3. Response案例1_重定向

    import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.serv ...

  4. Guarded Suspention 要等到我准备好

    线程在运行过程中需要停下来等待,然后再继续执行. 范例程序,一个线程(ClientThread)对另外一个线程(ServerThread)传递请求,实现一个模拟消息通道的功能. public clas ...

  5. 【第五周读书笔记】我是一只IT小小鸟

    读了第一个同学的自述,我印象最深的就是一些高分同学,只是机械性地背诵知识点,然后不停刷题,只是为了拿一个高分,然而他们对学科的一些基本概念都没有掌握牢靠.高分,并不代表学的就好.学得好不仅仅要牢靠掌握 ...

  6. HTML语法检测

    网络上收集到的资源: HTML在线编辑//////////////////////////////////////////http://tool.oschina.net/codeformat/ 文本框 ...

  7. Java 基础 - 原生类型

    更详细的说明,请参考: Java 原生类型与包装器类型深度剖析,https://blog.csdn.net/justloveyou_/article/details/52651211 一. 原生类型与 ...

  8. excel破解工作簿与工作表保护

    1.工作簿保护 1.1.使用压缩文件打开文件

  9. Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)F3 - Lightsabers (hard)

    题意:n个数字1-m,问取k个组成的set方案数 题解:假设某个数出现k次,那么生成函数为\(1+x+...+x^k\),那么假设第i个数出现ai次,结果就是\(\sum_{i=1}^m(1+x+.. ...

  10. Android Scroller简单用法 --View滚动

    转:http://ipjmc.iteye.com/blog/1615828 Android里Scroller类是为了实现View平滑滚动的一个Helper类.通常在自定义的View时使用,在View中 ...