Resin+Nginx动静分离和负载均衡

案例:目前很多人喜欢Nginx+tomcat动静分离,或者反代后端tomcat集群,不过很多人也喜欢用Resin。

本人花了些功夫总结了Resin和tomcat区别:


特性\容器


resin


tomcat


公司


CAUCHO


Apache


是否收费


不完全免费(pro版本收费)


完全免费


Eclipse下调试开发


适中


复杂


性能


轻量级,pro版本支持负载均衡,以及缓存功能


轻量级(NIO模式性能高些),支持负载均衡


多实例


略麻烦


比较简单


集群部署


支持


支持


是否支持php


新版本支持(但很少用)


默认不支持(可配置)


用户喜好


略少


略多


常用组合


Nginx+Resin or+其它


Nginx+tomcat+or其它


报错机制


简单


复杂


标准|开发|行为喜好


两者在标准支持,开发使用,用户喜好有很大关系

常用JavaEE容器有很多:Tomcat、Resin、JBoss、Glassfish ,注意weblogic属于应用服务器。

1、安装配置Resin:

1.1)jdk目录创建:

[[email protected] ~]# tar zxvfjdk-7u75-linux-x64.tar.gz
[[email protected] ~]# mkdir/usr/local/jdk1.7
[[email protected] ~]# mvjdk1.7.0_75/* /usr/local/jdk1.7/
[[email protected] ~]# cat/etc/profile.d/jdk.sh 
export JAVA_HOME=/usr/local/jdk1.7/
exportCLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
exportPATH=$PATH:$JAVA_HOME/bin
export JAVA_HOMECLASSPATH PATH
[[email protected] ~]#

1.2)Resin安装配置:

[[email protected] ~]# yum install ntpdate -y
[[email protected]~]# ntpdate time.windows.com安装resin
[[email protected]~]# tar xf resin-4.0.50.tar.gz -C /usr/local/
[[email protected]~]# cd /usr/local
[[email protected]~]# #./configure --prefix=/usr/local/resin
[[email protected]~]# #make
[[email protected] ~]# #make install
[[email protected] local]# ln -s resin-4.0.50 resin
[[email protected] local]#cat / etc/profile.d/resin.sh 
exportRESIN_HOME=/usr/local/resin
[[email protected] local]#
[[email protected] local]#cp /usr/local/resin/bin/resin.sh /etc/init.d/resin
[[email protected] local]#chmod +x /etc/init.d/resin
[[email protected] local]#/etc/init.d/resin start

1.3)首页访问:

1.4)配置多个项目:

[[email protected] ~]# cd /usr/local/resin/conf
[[email protected] conf]# vim resin.xml
#配置多个项目:
<clusterid="app1">
<!-- define the servers in the cluster -->
<server-multiid-prefix="app1"address-list="${app1_servers}"port="6800"/>  //端口1
<!-- the default host, matching any host name -->
<hostid=""root-directory=".">
<web-appid="/"root-directory="/usr/local/resin/webapps/app1"/>   //项目1
</host>
</cluster>
<clusterid="app2">
<!-- define the servers in the cluster -->
<server-multiid-prefix="app2"address-list="${app2_servers}"port="6801"/> //端口2
<!-- the default host, matching any host name -->
<hostid=""root-directory=".">
<web-appid="/"root-directory="/usr/local/resin/webapps/app2"/> //项目2
</host>
</cluster>

1.4.1)定义端口:

# app-tier Triad servers: app-0 app-1 app-2 
app1_servers      : 127.0.0.1:6800 
app2_servers      : 127.0.0.1:6801 
app1.http          : 8080 
app2.http          : 8081

1.5)JDBC配置:

<database>
<jndi-name>jdbc/test</jndi-name>
<driver type="com.microsoft.jdbc.sqlserver.SQLServerDriver">
<url>jdbc:microsoft:sqlserver://localhost:3306;databasename=Northwind</url>  //后端数据库
<user>sa</user>
<password>password</password>  //密码
</driver>
<prepared-statement-cache-size>8</prepared-statement-cache-size>
<max-connections>20</max-connections>
<max-idle-time>30s</max-idle-time>
</database>

注意:jdbc文件可自己定义,需要导入相应的驱动包。

2、安装配置Nginx:

useradd nginx -M -s /sbin/nologin
tar xf nginx-1.9.2.tar.gz
cd nginx-1.9.2
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx  --with-http_stub_status_module--with-http_ssl_module --with-http_realip_module  --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module&&make &&make install

2.1)nginx.conf配置负载均衡:

user  nginx; 

worker_processes  8;

#worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

error_log  logs/error.log  info;

pid        /var/run/nginx.pid;

events {
use epoll;
worker_connections  1024;
}

http {
include       mime.types;

default_type  application/octet-stream;

charset UTF-8;

server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

large_client_header_buffers 4 32k;

client_max_body_size 8m;

#limit_conn_zone $binary_remote_addr zone=one:32k;
#limit_conn_zone $binary_remote_addr zone=permitip:10m;

error_page   404 =  http://www.jb51.net/404.html;

#error_page   404  = /40x.html;
#location = /40x.html{
#root   html;
#}

#error_page   500 502 503 504  /50x.html;
#location = /50x.html {
#root   html;
#}

open_file_cache max=102400 inactive=20s;

sendfile        on;

#autoindex on;

tcp_nopush  on;
tcp_nodelay on;

keepalive_timeout  60;

gzip  on;
gzip_min_length  1k;
gzip_buffers     4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
#gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;

fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;

#如果要启用负载均衡
#upstream www.xxx.com {    
#zone myapp1 64k; 
#server 192.168.1.220:80 weight=1 max_fails=2 fail_timeout=30s slow_start=30s; 
#server 192.168.1.221:80 weight=1 max_fails=2 fail_timeout=30s;   
#} 
  
#upstream www.xxx.org {   
#zone myapp1 64k; 
#server 192.168.1.220:80 weight=1 max_fails=2 fail_timeout=30s slow_start=30s; 
#server 192.168.1.221:80 weight=1 max_fails=2 fail_timeout=30s;   
#}   
log_format  access ‘$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 access;

include vhost/*.conf;
}

2.2)renzhiyuan.conf配置动静分离:

server {
        listen       80;
        server_name  
        #路径根据 Resin定义路径配置,这里根据默认
        root   /usr/local/resin/webapps/ROOT;  
        index  index.html index.php index.jsp index.html;

#location ~ \.php$ {
#            root           html;
#            fastcgi_pass   127.0.0.1:9000;
#            fastcgi_index  index.php;
#            include        fastcgi.conf;
#        }

location ~ .(jsp|jspx|do)?$ {
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
client_max_body_size 10m; 
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}

location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ {
expires      30d;
}

location ~ .*\.(js|css)?$ {
expires      12h;
}
}
时间: 2024-08-05 07:08:09

Resin+Nginx动静分离和负载均衡的相关文章

Nginx反向代理、动静分离、负载均衡及rewrite隐藏路径详解(Nginx Apache MySQL Redis)–第三部分

Nginx反向代理.动静分离.负载均衡及rewrite隐藏路径详解 (Nginx Apache MySQL Redis) 楓城浪子原创,转载请标明出处! 更多技术博文请见个人博客:https://fengchenglangzi.000webhostapp.com 微信bh19890922 QQ445718526.490425557 三.Nginx动静分离及负载均衡 3.1 Nginx安装 请参考:https://fengchenglangzi.000webhostapp.com/?p=511 亦

nginx反向代理tomacat+keepalived实现动静分离、负载均衡、高可用

本文的动静分离主要是通过nginx+tomcat来实现,其中nginx处理图片.html.JS.CSS等静态文件,tomcat处理jsp.servlet等动态请求 服务器名称                                 系统版本                           预装软件                     IP地址 Nginx服务器                             CentOS 7 最小安装              Nginx

varnish的缓存加速,以及动静分离,负载均衡

一个简单的拓扑如上,varnish1 上还同时开了nginx,用来做静态的http,app1和app2 是nginx+fastcgi,这个拓扑主要做的是Discuz!论坛的动静分离,以及app的负载均衡,varnish起到个反向代理和缓存加速的功能. varnish1:192.168.1.151,172.16.0.51 app1:172.16.0.52 app3:172.16.0.54 varnish 简介 varnish的缓存方式: 1.malloc,通过malloc获取内存,简单,速度. 2

LNMT/LAMT实现动静分离、负载均衡和会话保持

1.本次试验主要是通过nginx代理到tomcat处理动态响应: 2.通过httpd代理到tomcat做动态请求的处理: 3.通过httpd和tomcat实现session会话的绑定: 4.通过httpd和tomcat实现session会话的保持: 5.通过httpd实现tomcat负载均衡效果: 一.LNMT的试验配置 LNMT: 主机 IP haproxy 192.168.0.111    node1.soul.com varnish 192.168.0.112    node2.soul.

实验:部署实现nginx在http上的动静分离和负载均衡

首先复习一下LB Cluster负载均衡集群 四层: LVS Nginx(stream) Haproxy(mode_tcp) 七层 Http protocol Nginx(http,upstream) Haproxy(mode http) Httpd/ats/perlbal/pound/- 接下来如何实现nginx在http的负载均衡 ngx_stream_proxy_module模块能为http服务做调度,其中stream模块中有 专门的server子命令,不同于其他server,其他serv

Nginx+Tomcat实现动静分离和负载均衡

一.动静分离 Nginx动静分离简单来说就是把动态和静态请求分开,不能理解成只是单纯的把动态页面和静态页面物理分离.严格意义上说应该是将动态请求和静态请求分开,可以理解成使用Nginx处理静态页面,Tomcat处理动态页面.动静分离从目前实现角度来讲大致分为两种,一种是纯粹的把静态文件放在独立的服务器上,独立出来用域名访问,也是目前主流推崇的方案:另外一种方法就是动态跟静态文件混合在一起部署,通过Nginx来分开. 为什么要动静分离? Tomcat是一个比较全面的web容器,对静态网页的处理,应

Ngigx+Tomcat配置动静分离,负载均衡

由于公司使用过Ngnix,对于刚接触Nginx来说,感觉有些好奇,于是研究了下. 本人在windows下使用的版本是nginx-1.8.1: 1. 启动Ngnix 双击nginx-1.8.1文件夹中nginx.exe,当任务管理器中存在两个nginx进程时,则说明启动成功! 2. Ngnix常用命令 nginx -s stop 强制关闭      nginx -s quit 安全关闭      nginx -s reload 改变配置文件的时候,重启nginx工作进程,来时配置文件生效     

Nginx + Tomcat 动静分离实现负载均衡

0.前期准备 使用Debian环境.安装Nginx(默认安装),一个web项目,安装tomcat(默认安装)等. 1.一份Nginx.conf配置文件 # 定义Nginx运行的用户 和 用户组 如果对应服务器暴露在外面的话建议使用权限较小的用户 防止被入侵 # user www www; #Nginx进程数, 建议设置为等于CPU总核心数 worker_processes 8; #开启全局错误日志类型 error_log /var/log/nginx/error.log info; #进程文件

Nginx(七层)动静分离的负载均衡群集

环境:(全部为公网IP,可以直接和客户端通信) 分发器:192.168.200.101 静态文件服务器:192.168.200.102 192.168.200.103 动态文件服务器:192.168.200.104 192.168.200.105 图片服务器:       192.168.200.106 192.168.200.107 nginx常用的三种模式: 轮询   默认模式,后端服务器挂了自动踢出 weight   指定权重 ip_hash   每个请求按访问IP的hash结果分配,每个