使用nginx负载tomcat集群实现redis存贮session共享
2017-04-27 00:00
921 查看
本人测试环境:
JDK版本:JDK8Tomcat版本:apache-tomcat-8.0.33
Redis版本:redis-3.0.4
Nginx版本:nginx-1.12.0
第一步:. 下载
下载nginx。地址:http://nginx.org/en/download.html 本人将文件保存在/opt/下。下载redis。地址:http://www.redis.cn/download.html。
下载tomcat。地址:http://tomcat.apache.org/download-80.cgi。
第二步: 安装配置
1. 安装nginxtar -zxvf nginx-1.12.0.tar.gz cd /opt/nginx/ ./configure --prefix=/usr/local/java/nginx make make install
.注意:执行第三步的时候可能会报错:
./configure: error: the HTTP rewrite module requires the PCRE library.
安装pcre-devel解决问题
yum -y install pcre-devel
./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library.
安装openssl-devel
yum -y install openssl openssl-devel
./configure: error: the HTTP gzip module requires the zlib library.
安装zlib-devel
yum install -y zlib-devel
如果出现其他类似问题,按照上述操作执行就可。
1.4. 进入/usr/local/java/nginx/sbin/ 执行 ./nginx -t 查看安装是否成功。
1.5. 进入nginx 的conf下修改nginx.conf
#user nobody; worker_processes 1; error_log logs/error.log; pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; upstream localhost { server localhost:18080 weight=1; server localhost:28080 weight=2; server localhost:38080 weight=3; } server { listen 80; server_name localhost; location / { root html; index index.html index.htm; proxy_pass http://localhost; proxy_set_header X-Real-IP $remote_addr; client_max_body_size 100m; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }
2. 安装配置tomcat
cd /usr/local/java/cluster/ tar -zxvf tomcat-8.0.33.tar.gz
2.1 修改conf下contex.xml,在context节点内添加如下:
<Valve className="com.radiadesign.catalina.session.RedisSessionHandlerValve" /> <Manager className="com.radiadesign.catalina.session.RedisSessionManager" host="localhost" port="6379" password="root" database="0" maxInactiveInterval="60" />
这是tomcat集群将session存在redis中的配置,如果不使用redis,可以省略这一步。
tomcat结合redis需要相应的jar包支持。jar包地址:http://pan.baidu.com/s/1qY6nMaS。下载完后将下载的jar包放入tomcat的lib下。
修改conf内server.xml:修改三个port,端口依次为 18080/28080/38080。
分别启动三台tomcat。
3.此处省略redis安装配置,可以看https://my.oschina.net/gentlelions/blog/877880。
第三步:打开防火墙:
firewall-cmd --permanet --zone=public --add-port=18080/tcp firewall-cmd --permanet --zone=public --add-port=28080/tcp firewall-cmd --permanet --zone=public --add-port=38080/tcp firewall-cmd --reload 重启防火墙。 firewall-cmd --list-all 查看添加的端口
第四步:
依次启动redis、tomcat、nginx;打开浏览器访问 xxxIP:18080 ,如果出现ngin画面,说明配置成功。解决80端口被占用:(临时方案)
系统自带路径:/etc/init.d/httpd stop根据报错路径:/usr/sbin/httpd -k stop
相关文章推荐
- Linux+Nginx+Tomcat+Redis实现负载均衡,应用集群及session共享
- 使用nginx搭建集群tomcat8,redis实现session共享,文件共享问题
- 使用nginx搭建集群tomcat8,redis实现session共享,文件共享问题
- Nginx+Tomcat+Memcached 集群Session共享[memcached服务安装、tomcat使用memcache存储session、nginx安装配置实现tomcat负载均衡]
- 使用nginx搭建集群tomcat8,redis实现session共享,文件共享问题
- CentOS7 Nginx+Redis+Tomcat集群实现session保持和共享
- tomcat+nginx+redis实现均衡负载、session共享(一)
- 使用Tomcat+Redis来实现集群部署中的Session共享问题
- 负载均衡之Nginx+tomcat+redis实现session共享的负载均衡
- 使用Tomcat+Redis来实现集群部署中的Session共享问题
- tomcat+nginx+redis实现均衡负载、session共享(一)
- tomcat+nginx+redis实现均衡负载、session共享(一)
- tomcat+nginx+redis实现均衡负载、session共享(二)
- tomcat+nginx+redis实现均衡负载、session共享(二)
- tomcat+nginx+redis实现均衡负载、session共享---(推荐)
- Windows环境下Nginx+Tomcat+Redis实现应用服务器集群负载均衡和Session共享
- nginx+tomcat+redis实现负载均衡、动静分离、session共享
- Redis学习笔记(六)Nginx+Tomcat+Redis实现负载均衡、资源分离、session共享
- 使用Nginx实现多个tomcat的负载运行及Session共享的教程
- Nginx+Redis+Tomcat实现session共享的集群