Resin+Nginx实现动静分离和负载均衡(2)

[root@resin ~]# cd /usr/local/resin/conf
[root@resin 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 =  ;
 
#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 {   
#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 { 
#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配置动静分离:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/4aafc063d6f57083d48407ac7ba1cdea.html