tengine+tomcat 安裝配置筆記

之前一直用glassfish, 從3到4, 省事卻是省事,就是過重了,圖形界面配置過程當中對cpu和內存的消耗較大,常遇到卡死的狀況,雖然配置完成後,運行穩定,但仍是決定放棄,改用tengine+tomcat。javascript

下載地址:http://tengine.taobao.org/ css

tengine-1.5.2算是最新的穩定版java


tomcat的設置可參見:http://my.oschina.net/u/221951/blog/372406node

在安裝tengine以前,確認centos環境中有無gcc、pcre、openssl,若是沒有按如下命令進行安裝nginx

#yum install gcc
#yum -y install pcre-devel
安裝最新版本:pcre-devel-7.8-6.el6.i686
#yum install openssl-devel
安裝最新版本:openssl-devel-1.0.1e-30.el6_6.5.i686

開始安裝tengine,注意確認有無nginx用戶和app用戶組,或者根據自身狀況更改web

#tar -vxzf tengine-1.5.2.tar.gz
#cd tengine-1.5.2
#./configure  --prefix=/usr/local/nginx  --user=nginx --group=app --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_concat_module --with-http_upstream_check_module --with-http_sub_module --with-http_realip_module
#make && make install

tengine自啓動腳本算法

#vi /etc/rc.d/init.d/nginx

編輯腳本以下,注意配置目錄的對應:shell

#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
}
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;

status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL

接下來保存退出,變動文件權限,centos

#:wq
#chmod a+x /etc/rc.d/init.d/nginx
#chkconfig --add nginx
#service nginx restart

編輯/user/local/nginx/conf/nginx.conf

# 根據你服務器的cpu核數來肯定此值
worker_processes 4;
	
error_log logs/error.log crit;
#error_log logs/error.log notice;
#error_log logs/error.log info;
	
#pid logs/nginx.pid;
 	
worker_rlimit_nofile 65535;
 	
# events事件主要用來肯定Nginx使用哪一種算法
 	events {
 	    use epoll;
 	    worker_connections 65535;
 	}
 	
 	http {
 	 include mime.types;
 	 default_type application/octet-stream;
 	 
 	 #關閉http header 中關於服務器的版本號
 	 server_tokens  off;
 	
 	 #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
 	 # '$status $body_bytes_sent "$http_referer" '
 	 # '"$http_user_agent" "$http_x_forwarded_for"';
 	
 	 # 因爲Nginx用於代理Tomcat,因此記錄訪問日誌的事情交給Tomcat來作好了,註釋掉
 	 #access_log logs/access.log main;
 	
 	 sendfile on;
 	 tcp_nopush on;
 	 tcp_nodelay on;
 	
 	#keepalive_timeout 0;
 	 keepalive_timeout 65;
 	
 	 server_names_hash_bucket_size 128;
 	 client_header_buffer_size 32k;
 	 large_client_header_buffers 4 32k;
 	 client_max_body_size 3m;
 	 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壓縮,提升用戶訪問速度
 	 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;
 	
 	# 配置須要代理的tomcat
 	upstream tomcat_proxy{
	   ip_hash;
           session_sticky;
 	   server 192.168.1.114:8080;
 	}
 	
 	# 虛擬主機:www.abc.com
 	server {
 	   listen 80;
 	   server_name www.abc.com;
 	   index index.html index.htm index.jsp;
 	   root /home/webapp/www/app1;
 	
 	   if (-d $request_filename){
 	     rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
 	   }
 	
 	   # 動態頁面,交給tomcat處理
 	   location ~ \.(jsp|jspx|do|action)?$ {
 	     proxy_set_header Host $host;
 	     proxy_set_header X-Forwarded-For $remote_addr;
 	     proxy_pass http://tomcat_proxy;
 	   }
	   
	    location /training/ { 
            proxy_pass        http://tomcat_proxy;
            proxy_set_header  Host             $host; 
            proxy_set_header  X-Real-IP        $remote_addr; 
            proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for; 
            #sub_filter        /training/          /; 
        } 
 	
 	    # 用戶瀏覽器端的緩存設置
 	    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
 	      expires 10d;
 	    }
 	    
 	    location ~ .*\.(js|css)?$ {
 	      expires 1h;
 	    }
 	    
 	     access_log off;
 	     #charset koi8-r;
 	     #access_log logs/host.access.log main;
 	}
}

設置確認沒有問題,保存退出,可重啓: service nginx restart

相關文章
相關標籤/搜索