Centos x64 6.2配置JSP環境

weixin_34115824發表於2017-11-23
Centos x64 6.2配置JSP環境
1、最小化安裝伺服器
2、yum install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel cURL cURL-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel lsof
3、(1)下載完成jdk-7u17-linux-x64.tar.gz
  (2)解壓tar zxvf  jdk-7u17-linux-x64.tar.gz
  (3)解壓後將其移動到mv jdk-7u17-linux-x64 /usr/local/jdk
 (4)配置 vi /etc/profile 環境變數,增加以下內容:
JAVA_HOME="/usr/local/jdk"
CLASS_PATH="$JAVA_HOME/lib:$JAVA_HOME/jre/lib"
PATH=".:$PATH:$JAVA_HOME/bin"
CATALINA_HOME="/usr/local/tomcat"
export JAVA_HOME CATALINA_HOME
4、解壓apache-tomcat-7.0.37.tar.gz
]# mv apache-tomcat-7.0.37 /usr/local/tomcat
將tomcat相關配置複製到網站目錄中去   
]# mkdir -p /webdata/htdocs/www/shop/ROOT
]# cp -Rf  /usr/local/tomcat/webapps  /webdata/htdocs/www   (備註:此部暫不用操作)

編輯tomcat的server.xml
Vi /usr/local/tomcat/conf/server.xml
<Host name="localhost"  appBase="/webdata/htdocs/www/shop/ROOT"
            unpackWARs="true" autoDeploy="true">
      (目錄中必須有ROOT,否則tomcat找不到)
啟動tomcat    /usr/local/tomcat/bin/startup.sh
使用lsof –i :8080
測試服務是否啟動
[root@localhost bin]# lsof -i :8080
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
java    3065 root   40u  IPv6  36361      0t0  TCP *:webcache (LISTEN)
5、安裝pcre,,通過 yum install pcre  pcre-devel
6、安裝nginx 
  [root@localhost bin]# useradd www
[root@localhost bin]# mkdir -p /webdata/logs   #日誌目錄
                  mkdir -p /webdata/htdocs/www/shop/ROOT #網頁目錄
 [root@localhost bin]# chown -R www:www /webdata
開始配置nginx原始碼檔案
 [root@localhost nginx-1.2.7]# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module 

出錯:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

需要安裝pcre
下載新版pcre-8.32.tar.gz  解壓安裝
./configure 
Make 
Make install
繼續nginx
[root@localhost nginx-1.2.7]# ./configure --user=www --group=www --prefix=/usr/l
ocal/nginx --with-http_stub_status_module --with-http_ssl_module
Make 
Make install
-------------------------------------------------------------------------------------------
安裝Nginx時報錯
./configure: error: the HTTP rewrite module requires the PCRE library.
安裝pcre-devel解決問題
yum -y install pcre-devel

錯誤提示:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library.   You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.
解決辦法:
yum -y install openssl openssl-devel

總結:
yum -y install pcre-devel openssl openssl-devel
./configure --prefix=/usr/local/nginx
make
make install

7、配置nginx.conf  在/usr/local/tomcat/conf/nginx.conf
配置內容如下:

user www www;
worker_processes  1;
error_log   /webdata/logs/error.log crit;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
pid  /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 65535;

events {
    use epoll;
    worker_connections  65535;
}


http {
  include       mime.types; 
  default_type  application/octet-stream; 
  #charset  gb2312; 
  server_names_hash_bucket_size 128; 
  client_header_buffer_size 32k; 
  large_client_header_buffers 4 32k; 
  client_max_body_size 300m; 
       
  sendfile on; 
  tcp_nopush     on; 
  keepalive_timeout 60; 
  tcp_nodelay on; 
  server_tokens off;
 client_body_buffer_size 512k;
 proxy_connect_timeout 5;
 proxy_send_timeout    60;
proxy_read_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.0; 
  gzip_comp_level 2; 
  gzip_types       text/plain application/x-javascript text/css application/xml; 
  gzip_vary on; 
  #access_log  logs/host.access.log  main;
     log_format wwwlog '$remote_addr -$remote_user[$time_local]"$request"' 
      '$status $body_bytes_sent "$http_referer"'
      '"$http_user_agent" $http_x_forwarded_for';
        access_log  /webdata/logs/web.log wwwlog;
   
 server {
        listen       80;
        server_name  localhost;
        index  index.html index.htm index.jsp index.do;
        root /webdata/htdocs/www/shop/ROOT; 
       
       if ( -d $request_filename)
      {
     #    rewrite  ^(/download/.*)/media/(.*)\..*$  $1/mp3/$2.mp3  break;

          rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent; 
         }

  
       location ~ .*\.(jsp|jspx|do)?$ {
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
       proxy_pass http://127.0.0.1:8080;  #תÏòtomcat´¦Àí

        }
     #charset koi8-r;
       location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ {
     expires 30d;
       }
      location ~ .*\.(js|css)?$ 

  expires 1h;
}
      


      
}
}

 
8、啟動nginx
/usr/local/nginx/sbin/nginx
檢視nginx
#ps –ef | grep nginx
這時,輸入以下命令檢視Nginx主程式號:

    ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'
螢幕顯示的即為Nginx主程式號,例如:
  6302
  這時,執行以下命令即可使修改過的Nginx配置檔案生效:

    kill -HUP 6302

  
或者無需這麼麻煩,找到Nginx的Pid檔案:
平滑重啟:
    kill -HUP `cat /usr/local/nginx/nginx.pid`

或者lsof –i:80
9、停止nginx的命令
#/usr/local/nginx/sbin/nginx -s stop
                   









本文轉自 lcpljc 51CTO部落格,原文連結:http://blog.51cto.com/lcpljc/1170928,如需轉載請自行聯絡原作者

相關文章