Linux学习-keepalived+nginx+Tomcat+redis实现高可用和Session共享
Posted 丢爸
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux学习-keepalived+nginx+Tomcat+redis实现高可用和Session共享相关的知识,希望对你有一定的参考价值。
通过keepalived实现系统的高可用,nginx反射代理实现负载均衡,Tomcat+Redis实现session的共享
环境准备
#---两台Centos主机
tomcat1:192.168.115.160
tomcat2:192.168.115.161
#---两台Centos主机
#在centos主机上分别安装keepalived,nginx,tomcat
keepalived配置
#------------------------keepalived配置----------------------
#keepalived配置(/etc/keepalived/keepalived.conf)--tomcat1
! Configuration File for keepalived
global_defs
notification_email
xuwenpeng3@163.com
notification_email_from xuwenpeng3@163.com
smtp_server smtp.163.com
smtp_connect_timeout 30
router_id tye_master
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
vrrp_instance TYE
state MASTER
interface ens33
virtual_router_id 10
priority 240
advert_int 1
authentication
auth_type PASS
auth_pass 123456
virtual_ipaddress
192.168.115.200/24 dev ens33
#keepalived配置(/etc/keepalived/keepalived.conf)--tomcat2
! Configuration File for keepalived
global_defs
notification_email
xuwenpeng3@163.com
notification_email_from xuwenpeng3@163.com
smtp_server smtp.163.com
smtp_connect_timeout 30
router_id tye_backup
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
vrrp_instance TYE
state BACKUP
interface ens33
virtual_router_id 10
priority 100
advert_int 1
authentication
auth_type PASS
auth_pass 123456
virtual_ipaddress
192.168.115.200/24 dev ens33
#------------------------keepalived配置----------------------
Nginx配置
worker_processes 1;
pid logs/nginx.pid;
events
worker_connections 1024;
http
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream tomcatserver
server 192.168.115.160:8080 weight=2;
server 192.168.115.161:8080 weight=1;
server
listen 80;
server_name localhost;
location /
proxy_pass http://tomcatserver/tye;
root html;
index index.html index.htm;
error_page 500 502 503 504 /50x.html;
location = /50x.html
root html;
Tomcat配置
#配置tomcat共享session需要下载对应的jar包[tomcat+redis]()
<Valve className="com.s.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.s.tomcat.redissessions.RedisSessionManager"
host="192.168.115.160" #redis服务器地址
port="6379" #redis服务器端口
database="0" #数据库名称
password="tye0000" #redis密码(远程连接需要给数据库设置密码)
maxInactiveInterval="60" />
将war包放入tomcat的webapps目录,通过web浏览器访问,获得sessionID
以上是关于Linux学习-keepalived+nginx+Tomcat+redis实现高可用和Session共享的主要内容,如果未能解决你的问题,请参考以下文章
linux 负载均衡配置 keepalive lvs 使用nginx转发 CentOS7 搭建LVS+keepalived负载均衡