1、服务器A安装ng,服务器B、C安装tomcat;

2、服务器A建立/data/www目录,用于发布静态文件;

3、ng无动静分离配置;

user root root;
worker_processes 8;
pid /usr/local/nginx/nginx.pid;
worker_rlimit_nofile 102400;
events
{
use epoll;
worker_connections 102400;
}
http
{
include mime.types;
default_type application/octet-stream;
fastcgi_intercept_errors on;
charset utf-8;
server_names_hash_bucket_size 128;
client_header_buffer_size 4k;
large_client_header_buffers 4 32k;
client_max_body_size 300m;
sendfile on;
tcp_nopush on; keepalive_timeout 60; tcp_nodelay on;
client_body_buffer_size 512k; proxy_connect_timeout 5;
proxy_read_timeout 60;
proxy_send_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k; gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on; ###2012-12-19 change nginx logs
log_format main '$http_x_forwarded_for - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $request_time $remote_addr'; upstream web_app {
server 192.168.203.130:10086 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.203.131:10087 weight=1 max_fails=2 fail_timeout=30s;
} ####chinaapp.sinaapp.com
server {
listen 80;
server_name chinaapp.sinaapp.com;
index index.jsp index.html index.htm;
# 发布目录:/data/www
root /data/www; location /
{
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://web_app;
expires 3d;
} } }

4、ng动静分离配置;

user root root;
worker_processes 8;
pid /usr/local/nginx/nginx.pid;
worker_rlimit_nofile 102400;
events
{
use epoll;
worker_connections 102400;
}
http
{
include mime.types;
default_type application/octet-stream;
fastcgi_intercept_errors on;
charset utf-8;
server_names_hash_bucket_size 128;
client_header_buffer_size 4k;
large_client_header_buffers 4 32k;
client_max_body_size 300m;
sendfile on;
tcp_nopush on; keepalive_timeout 60; tcp_nodelay on;
client_body_buffer_size 512k; proxy_connect_timeout 5;
proxy_read_timeout 60;
proxy_send_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k; gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on; ###2012-12-19 change nginx logs
log_format main '$http_x_forwarded_for - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $request_time $remote_addr'; upstream web_app {
server 192.168.203.130:10086 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.203.131:10087 weight=1 max_fails=2 fail_timeout=30s;
} ####chinaapp.sinaapp.com
server {
listen 80;
server_name chinaapp.sinaapp.com;
index index.jsp index.html index.htm;
# 发布目录:/data/www
root /data/www; location /
{
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://web_app;
expires 3d;
}
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
{
root /data/www;
#expires定义用户浏览器缓存的时间为3天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力
expires 3d; } } }

5、安装ng的时候不用指定编译参数,直接./configure --prefix=/usr/local/nginx & make & make install就行;

6、这里直接访问域名依然会请求tomcat,没搞清楚为什么,只有域名后面带有具体静态文件才会从ng请求;

7、下载https://github.com/jcoleman/tomcat-redis-session-manager,修改相关参数,编译,将下面的9个文件放到tomcat的lib目录下;

gradle.build修改成为:

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'signing' group = 'com.orangefunction'
version = '2.0.0' repositories {
mavenCentral()
} compileJava {
sourceCompatibility = 1.7
targetCompatibility = 1.7
} dependencies {
compile group: 'org.apache.tomcat', name: 'tomcat-catalina', version: '7.0.67'
compile group: 'redis.clients', name: 'jedis', version: '2.5.2'
compile group: 'org.apache.commons', name: 'commons-pool2', version: '2.2'
//compile group: 'commons-codec', name: 'commons-codec', version: '1.9' testCompile group: 'junit', name: 'junit', version: '4.+'
testCompile 'org.hamcrest:hamcrest-core:1.3'
testCompile 'org.hamcrest:hamcrest-library:1.3'
testCompile 'org.mockito:mockito-all:1.9.5'
testCompile group: 'org.apache.tomcat', name: 'tomcat-coyote', version: '7.0.67'
} task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from 'build/docs/javadoc'
} task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
} artifacts {
archives jar archives javadocJar
archives sourcesJar
} //signing {
// sign configurations.archives
//} task copyJars(type: Copy) {
from configurations.runtime
into 'dist'
} uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } //repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
// authentication(userName: sonatypeUsername, password: sonatypePassword)
//}
//repository(url: "https://oss.sonatype.org/content/repositories/snapshots") {
// authentication(userName: sonatypeUsername, password: sonatypePassword)
//} pom.project {
name 'tomcat-redis-session-manager'
packaging 'jar'
description 'Tomcat Redis Session Manager is a Tomcat extension to store sessions in Redis'
url 'https://github.com/jcoleman/tomcat-redis-session-manager' issueManagement {
url 'https://github.com:jcoleman/tomcat-redis-session-manager/issues'
system 'GitHub Issues'
} scm {
url 'https://github.com:jcoleman/tomcat-redis-session-manager'
connection 'scm:git:git://github.com/jcoleman/tomcat-redis-session-manager.git'
developerConnection 'scm:git:git@github.com:jcoleman/tomcat-redis-session-manager.git'
} licenses {
license {
name 'MIT'
url 'http://opensource.org/licenses/MIT'
distribution 'repo'
}
} developers {
developer {
id 'jcoleman'
name 'James Coleman'
email 'jtc331@gmail.com'
url 'https://github.com/jcoleman'
}
}
}
}
}
}

8、编译完之后,上面的倒数第三那个是在build目录下面;

9、修改tomcat配置文件:

<Context>
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
host="redis主机ip地址"
port="6379"
database="0"
maxInactiveInterval="60" />
</Context>

10、上面的host是redis的地址,如果tomcat和redis没有在同一台机器上,那么tomcat的启动是比较慢的,需要耐心等候,不是报错;

11、一般来说,session中我们记录用户的信息,如果记录单个属性,那么没什么说得 ,如果session的属性是用户对象,那么该对象需要实现Serializable接口;

12、异常记录:由于我的数据库装载笔记本实体机上面,而ng,tomcat1,tomcat2分别装在vm的3个不同的机器里面的,所以导致vm里面的机器连接实体机的数据库时报错,无法连接,我们需要为数据库增加访问权限:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '' WITH GRANT OPTION;
FLUSH PRIVILEGES;

13、另外:tomcat启动真的很慢,需要1分钟,搞不懂为什么,我这里把文件做了动静分离的,把静态文件放在ng的/data/www目录下面,而ajax请求会被做负载均衡。

nginx+tomcat负载均衡+动静分离+redis集中管理session的更多相关文章

  1. Nginx+Tomcat负载均衡、动静分离群集

    Nginx+Tomcat负载均衡.动静分离群集 目录 Nginx+Tomcat负载均衡.动静分离群集 一.Tomcat 1. Tomcat简介 2. Tomcat重要目录 二.Nginx负载均衡原理 ...

  2. nginx+tomcat负载均衡

    最近练习nginx+tomcat负载均衡.根据一些资料整理了大体思路,最终实现了1个nginx+2个tomcat负载均衡. 安装JDK 1>进入安装目录,给所有用户添加可执行的权限 #chmod ...

  3. linux+nginx+tomcat负载均衡,实现session同步

    linux+nginx+tomcat负载均衡,实现session同步 花了一个上午的时间研究nginx+tomcat的负载均衡测试,集群环境搭建比较顺利,但是session同步的问题折腾了几个小时才搞 ...

  4. Nginx + Tomcat 负载均衡配置详解

    Nginx常用操作指南一.Nginx 与 Tomcat 安装.配置及优化1. 检查和安装依赖项 yum -y install gcc pcre pcre-devel zlib zlib-devel o ...

  5. nginx+tomcat实现集群,redis实现session共享,软连接实现文件共享:http://blog.csdn.net/hua1586981/article/details/78132710

    转载 2017年02月08日 16:52:41 730 相信很多人都听过nginx,这个小巧的东西慢慢地在吞食apache和IIS的份额.那究竟它有什么作用呢?可能很多人未必了解. 说到反向代理,可能 ...

  6. Linux下Nginx+Tomcat负载均衡和动静分离配置要点

    本文使用的Linux发行版:CentOS6.7 下载地址:https://wiki.centos.org/Download 一.安装Nginx 下载源:wget http://nginx.org/pa ...

  7. Nginx+Tomcat+Keepalived+Memcache 负载均衡动静分离技术

    一.概述 Nginx 作负载均衡器的优点许多,简单概括为: ①实现了可弹性化的架构,在压力增大的时候可以临时添加Tomcat服务器添加到这个架构里面去; ②upstream具有负载均衡能力,可以自动判 ...

  8. 使用Redis存储Nginx+Tomcat负载均衡集群的Session

    配置Tomcat的session共享可以有三种解决方案: 第一种是以负载均衡服务器本身提供的session共享策略,每种服务期的配置是不一样的并且nginx本身是没有的. 第二种是利用web容器本身的 ...

  9. Nginx+tomcat负载均衡时静态页面报404

    百度到的问题解决BLOG http://os.51cto.com/art/201204/326843.htm nginx+2台tomcat负载均衡,应用程序已部署,单独访问tomcat时,可以访问到所 ...

随机推荐

  1. CentOS6.5Minimal安装Gitlab7.5

    文章出处:http://www.restran.net/2015/04/09/gilab-centos-installation-note/ 在 CentOS 6.5 Minimal 系统环境下,用源 ...

  2. Linux绑定双网卡

    Linux绑定双网卡 1. 配置参数文件 版本在centos6以下在/etc/modproe.conf文件中配置,版本是centos6.x或以上在/etc/modproe.d/目录下配置. 2.    ...

  3. Android ExpandableListView的下拉刷新实现

    该控件的修改时根据PullToRefreshList的机制修改 下面是对ExpandableListView的扩展 package com.up91.gwy.view.componet; import ...

  4. 添加gogs服务后 web丢失样式问题

    暂时的解决办法

  5. Centos php项目发布问题

    LAMP环境,项目运行错误日志路径:/var/log/httpd 错误日志例如: [Sat Jul :: ] [error] [client , referer: http://192.168.100 ...

  6. C# Main函数的 args参数

    网上参考 博客,使用如下代码: using System; using System.Collections.Generic; using System.Linq; using System.Text ...

  7. Linux 创建用户和工作组

    创建用户 useradd user1                            #创建user1用户,创建user1用户同时会创建一个同名的工作组user1 passwd user1   ...

  8. [GeoServer]重拾GeoServer之安装篇

    GeoServer的项目是一个完整的Java(J2EE)系统,现实了OpenGIS联盟的网络功能服务器规范和网络覆盖服务器规范,并且集成了Web地图服务器. 在大三的时候WebGIS课程中老师讲解过一 ...

  9. 淘宝付邮试用Chrome桌面提醒插件(含源码)

    淘宝付邮试用每天都会推出10元邮费试用的商品,有些对自己还是有用的.试用一下还不错,关键是便宜.不过,有些商家也抓住了买家贪便宜的特点,推出廉价垃圾商品.这里,大家还是慧眼识别了.每天浏览这些商品会很 ...

  10. 使用UDEV绑定ASM多路径磁盘

    OS版本:RHEL6.4 1) 找出目标磁盘的分区别名 # dmsetup ls |grep data data01 (253:9) data04 (253:4) data03 (253:3) dat ...