若依项目利用nginx实现负载均衡及保持会话
记录一下若依项目利用nginx实现负载均衡及保持会话的步骤。
此次作为试验性的测试,为了方便在本地window的环境上实现。
具体步骤:
1、安装两个tomcat8,可以下载一个后,另一个复制即可,下载地址:
https://tomcat.apache.org/download-80.cgi
注意为了避免端口冲突的问题,需要进入D:\tomcat-9080\conf\目录,打开server.xml文件,修改下面两个地方:
(1)<Server port="8006" shutdown="SHUTDOWN">
修改这个port=”8006”,使得它的关闭端口和另一个关闭端口不发生冲突。
(2)<Connector port="9080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
修改port=”9080”,使得它的连接端口和另一个不冲突。
(3)<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
修改这个port=”8010”,使得它的AJP端口和另一个不冲突。
2、安装nginx,我下载的是稳定版本,地址:http://nginx.org/download/nginx-1.12.2.zip。
解压即可使用,在启动前,必须要对nginx进行一下配置才可实现负载均衡的功能,打开conf文件夹,下面有一个nginx.conf文件,配置如下:
#user nobody;
worker_processes 1; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #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; #以下四行是新添加的,两个IP是两个tomcat的访问地址,weight表示分给该服务器的请求比重,两个都是1,则按照1:1来分配,
upstream netitcast.com{
server 127.0.0.1:8080 weight=1;
server 127.0.0.1:9080 weight=1;
} server {
listen 80;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #一下两行是进行修改的,http://netitcast.com和上面添加的要保持一致
location / {
proxy_pass http://netitcast.com; proxy_connect_timeout 1; #表示是1秒后超时会连接到另外一台服务器
proxy_read_timeout 1;
proxy_send_timeout 1;
} #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;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }
3、安装redis,redis官方没有64位的Windows下的可执行程序,目前有个开源的托管在github上, 地址:https://github.com/ServiceStack/redis-windows,
下载文件并解压到自己的电脑目录下,我这边选择的是redis-64.3.0.503版本。
4、选择若依项目,此处选择RuoYi-duzunwu512,该版本集成了Redis实现Session共享多模块(支持Cacheable缓存),地址:https://gitee.com/duzunwu512/RuoYi。
将该版本的若依在本地环境中搭建起来,修改数据库配置,将ruoyi-admin项目的pom.xml中改成<packaging>war</packaging>,即将其打成war包。
5、将war包复制到对应两个tomcat的webapp目录下,分别启动两个tomcat,在cmd中cd到对应tomcat的bin目录下,运行startup.bat即可。
此处分别修改一下ruoyi-admin\WEB-INF\classes\templates下的login.html文件,更改此处,主要目的是为了区分后续的访问到底访问到了那个tomcat。
<h4>欢迎使用 <strong>若依 后台管理系统【Master】</strong></h4>
6、启动nginx,运行start nginx即可。详细可参考
https://www.cnblogs.com/qianzf/p/6809427.html
启动redis,运行redis-server redis.windows.conf,详细可参考
https://blog.csdn.net/qq_33450681/article/details/78250664
7、本地访问http://localhost/ruoyi-admin/index,不断刷新,可看到会不断切换至不同的tomcat项目中,登录后,故意停止一个tomcat,仍然可以正常访问,自此基本搭建成功。
若依项目利用nginx实现负载均衡及保持会话的更多相关文章
- liunx 利用nginx 实现负载均衡
一般采用软件实现负载均衡的有Nginx.apache.nginx 近年来使用频繁,其官网上面显示可以承载5万并发访问量,太牛了. nginx 相比 apache优势明显:Nginx 服务程序比较稳定, ...
- Linux下利用nginx实现负载均衡
linux下利用nginx实现负载均衡 前提条件: 1,安装好jdk 2,安装好tomcat和nginx(可以参考我前两篇文章) 满足前提条件后,要用nginx实现负载均衡,主要是靠配置nginx的配 ...
- [转帖]利用nginx实现负载均衡 | 哈希算法,sticky模块实现session粘滞
利用nginx实现负载均衡 | 哈希算法,sticky模块实现session粘滞 2018年08月02日 10:06:03 Minza 阅读数 483 https://blog.csdn.net/ha ...
- 如何利用nginx实现负载均衡(总结)
如何利用nginx实现负载均衡(总结) 一.总结 一句话总结: 推荐使用nginx七层(应用层)负载均衡的实现:配置那是相当的简单 1.nginx配置实例? |||-begin #这里的域名要和下面p ...
- 利用nginx实现负载均衡和动静分离
1.Nginx介绍 Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器 . Nginx 是由 ...
- 利用Nginx构建负载均衡server
大家都知道.一个域名相应一个IP地址,而一个WebSite则相应一个IP地址上相应port服务的应用程序(或位置).而大型站点的并发訪问量很大,这些站点是怎样在一台Webserver上实现负载均衡的呢 ...
- 利用nginx实现负载均衡
1.安装nginx和tomcat 我这里是使用docker安装的.安装流程可参照 dockerfile 这里安装了两个tomcat,端口分别是42000和42001.第二个tomcat的首页随便加了些 ...
- 利用nginx做负载均衡
round-robin:轮询.以轮询方式将请求分配到不同服务器上,默认 least-connected:最少连接数.将下一个请求分配到连接数最少的那台服务器上 ip-hash :基于客户端的IP地址. ...
- windows平台下利用Nginx做负载均衡
1.下载nginx(http://nginx.org/en/download.html)安装包,解压,并使用cmd命令转到nginx.exe所在的目录 2.执行cmd命令start nginx启动ng ...
随机推荐
- python之requests模块快速上手
安装 pip3 install requests 使用 发送请求 import requests r = requests.get('http://www.baidu.com') 还可以如下方式发送不 ...
- [js]js栈内存的全局/私有作用域,代码预解释
js代码如何执行的 浏览器提供执行环境: 全局作用域(提供js执行环境, 栈内存) --> 执行js需要预解释 - 带var : 提前声明 - 带function关键字的: 提前声明+定义 js ...
- sql 存储过程参数为空则不作为条件
/****** Object: StoredProcedure [dbo].[GetCommonGroupByRegion] Script Date: 03/23/2017 17:31:18 **** ...
- Java基础(basis)-----关键字final和static的作用
1.关键字final final修饰类:这个类就不能被继承 final修饰方法:不能被重写 final修饰属性:此属性就是一个常量,一旦初始化后,不可再被赋值.习惯 ...
- scrapy流程图
refer:https://blog.yongli1992.com/2015/02/08/python-scrapy-module/ 这里是一张Scrapy架构图的展示.Scrapy Engine负责 ...
- 艾妮记账本Web开发(开发版)
因为没有办法制作微信小程序版的艾妮记账本所以只能选择做Web开发版,但因为是花时间赶出来到的(但用了我已学的所有Web知识)所以就没有办法按老师的要求写七天的制作过程. 其实真正说起来我的这个Web开 ...
- mybites
[mybatis-spring] http://www.mybatis.org/spring/zh/index.html 使用spring mybatis 中间件 方便使用 mybatis [myba ...
- DataTables页面列点击排序
<!-- DataTables --> <script type="text/javascript" charset="utf8" src=& ...
- Missing library: xdoclet-1.2.1.jar.如何解决?
去这里下载xdoclet-bin-1.2.1.zip http://sourceforge.net/projects/xdoclet/files/xdoclet/1.2.1/ 解压出来,比如解压到C: ...
- JavaScript case 条件语句
JavaScript case 条件语句 示例 switch(name){ case '1': age = 123; break; case '2' age = 456; break; default ...