金沙澳门官网网址:tomcat实现动静态分离

作者: 金沙澳门官网网址  发布:2019-12-18

  ===============Tomcat 概述:
    Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的三个主题项目,由Apache、Sun 和别的一些商号及民用协同开荒而成。由于有了Sun 的插手和支撑,最新的Servlet 和JSP 标准总是能在汤姆cat 中获得展现,Tomcat 5扶植新型的Servlet 2.4 和JSP 2.0 标准。因为汤姆cat 本当先进、品质稳固,並且免费,由此十分受Java 爱好者的友爱并获取了意气风发部分软件开荒商的承认,成为当下比较流行的Web 应用服务器。如今最新版本是8.0。

===tomcat服务器中:
1》安装jdk并安插情况变量:
  tar -xvf jdk-8u5-linux-x64.tar.gz
  mv jdk1.8.0_05/ /usr/local/src/java

       金沙澳门官网网址 1

  2》安装tomcat:
    tar -xvf apache-tomcat-7.0.54.tar.gz
    mv apache-tomcat-7.0.54 /usr/local/src/tomcat

3》配置tomcat:
  #vim /usr/local/src/tomcat/conf/server.xml
  <Connector port="80" protocol="HTTP/1.1"
    connectionTimeout="20000"
    redirectPort="8443" />
   纠正端口为私下认可WEB端口80;

  <Host name="localhost" appBase="che"
    unpackWARs="true" autoDeploy="true">
  <Context path="" docBase="/opt/che">
  新添最终朝气蓬勃行改进为WEB的家目录,要是要做代办,则name为localhost;      

  4》启动tomcat:

    金沙澳门官网网址 2

5》tomcat运营测量试验:

   金沙澳门官网网址 3

 

=============Nginx的安装与配置:
1》安装信赖库:
  yum -y install gcc gcc-c openssl-devel zlib-devel pcre-devel
2》安装pcre库:
  tar -xvf pcre-8.36.tar.gz
  cd pcre-8.36
  ./configure && make && make install cd pcre-8.36
3》安装libmd5:
  tar xf libmd5-0.8.2b.tar.gz
4》安装nginx:

           ar -xvf nginx-1.9.8.tar.gz
      cd nginx-1.9.8

CONFOPTS="
--user=user_00
--group=users
--with-http_realip_module
--with-http_stub_status_module
--with-http_gzip_static_module
--with-md5=/soft/md5/
--with-pcre=/usr/local/src/pcre-8.01
--without-select_module
--without-poll_module
--without-http_ssi_module
--without-http_userid_module
--without-http_geo_module
--without-http_map_module
--without-http_memcached_module
--without-mail_pop3_module
--without-mail_imap_module
--without-mail_smtp_module
--prefix=/usr/local/services/nginx-1.9.8
"
./configure $CONFOPTS && make && make install

 

  编译参数详明:
金沙澳门官网网址 ,--with-http_realip_module
此模块扶植显得真实来源IP地址,首要用来NGINX做前端负载均衡服务器使用。

-with-http_stub_status_module
其一模块能够获取一些nginx的运市价况,

--with-http_gzip_static_module
其一模块在三个预压缩文件传送到展开Gzip压缩的客商端在此以前检查是否业已存在以“.gz”结尾的压缩文件,那样能够幸免文件被另行压缩。

--with-md5=/soft/md5/
设定md5库文件路线

--with-sha1=auto/lib/sha1
设定sha1库文件路线
--with-pcre=/soft/pcre-8.01
设定PCRE库路径

--without-select_module
正式连接格局。暗许情形下活动编写翻译格局。您能够启用或剥夺通过行使-select_module和不带- select_module配置参数那些模块

--without-poll_module
不使用poll模块

--without-http_ssi_module
不使用ngx_http_ssi_module模块,此模块管理服务器端包蕴文件(ssi卡塔尔国的管理.

--without-http_userid_module
不使用ngx_http_userid_module模块

--without-http_geo_module
其一模块基于顾客端的IP地址成立一些ngx_http_geoip_module变量,并与马克斯MindGeoIP文件进行相配,该模块仅用于 0.7.63和0.8.6本子之后。但成效不太称心遂意,对于城市的IP记录而不是特地确切,可是对此网址的起点访问区域的剖析差没多少有必然参照他事他说加以考察性

--without-http_map_module
不使用ngx_http_map_module模块

--without-http_memcached_module
不使用ngx_http_memcached_module模块

--without-mail_pop3_module
不允许ngx_mail_pop3_module模块

--without-mail_imap_module
不允许ngx_mail_imap_module模块

--without-mail_smtp_module
不允许ngx_mail_smtp_module模块   

4》配置表达:
  配置文件地点:/usr/local/nginx/conf/nginx.conf
  1. Nginx配置文件分为4个部分
  2. main(全局设置)
  3. server(主机设置卡塔尔国
  4. upstream(负载均衡设置卡塔尔(قطر‎
  5. localtion(UXC90L匹配特定岗位的装置卡塔尔
  那多少个 server世襲main location世袭server,upstream即不会三番一遍,别的设置也不会被世袭.

   

====nginx文件配置内容:

user user_00;
worker_processes 8;
error_log logs/error.log;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 100000;
}
worker_rlimit_nofile 100000;
http {
include mime.types;
default_type application/octet-stream;
server_tokens off;
server_names_hash_bucket_size 128k;
client_header_buffer_size 32k;
large_client_header_buffers 432k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 60;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 254k;
fastcgi_buffers 16 256k;
fastcgi_busy_buffers_size 512k;
fastcgi_temp_file_write_size 512k;
gzip on;
gzip_min_length 1k;
gzip_buffers 416k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml text/javascript;
gzip_vary on;
charset utf-8;
access_log off;
log_not_found off;
error_page 400 403 405 408 /40x.html;
error_page 500 502 503 504 /50x.html;

server {
listen 80;
server_name www.test.com;
location / {
root html/cheche;
index index.html index.htm;
}
}

include   vhost/vhost.localhost.com;
}    

 

设想主机文件内容:

upstream webcount {

      server  10.0.0.202:8080 weight=1 max_fails=3 fail_timeout=20s;

#     server  10.0.0.203:8080 weight=1 max_fails=3 fail_timeout=20s;

 

}

server { 

        listen       80; 

        server_name  www.aatest.com; 

        charset utf-8; 

            location ~ (.jsp)|(.do)$ {  #jsp和do的付出tomcat管理完成情状分离

            index  index.html index.htm index.jsp index.do; 

            proxy_pass        ; 

            proxy_set_header  X-Real-IP  $remote_addr; 

            client_max_body_size  100m; 

            }

         location ~ .*.(gif|jpg|jpeg|png|bmp|swf|html|htm)$#html和图表的和其余的静态内容存路线html

    { 

       root   /opt/che;   #可随机钦命

        expires      30d; 

    } 

}~ 

 

5》开发银行与平滑重启

  # cd /usr/local/services/nginx-0.8.55/sbin/

  # ./nginx –t 检查实验配置文件是否有不当

  # ./nginx 启动nginx

  # ./nginx -s reload

6》动静分离测量检验

       1>在tomcat上

        在WEB目录创立

    # cd /opt/che

    # echo “this is jsp” >index.jsp

    # echo “this is do” >index.do

      http://10.0.0.202:8080/index.jsp

      

      

  2>在Nginx上

    在Nginx的/opt/che目录下

    # cd /opt/che

    # echo “this is index ” >index.html

    # echo “this is index a” >aa.html

      3>在浏览器里面

      

                金沙澳门官网网址 4

         http://www.aatest.com/aa.html

          金沙澳门官网网址 5

        http:// www.aatest.com /index.jsp

       金沙澳门官网网址 6

        

           

                     金沙澳门官网网址 7

 

==========================

能够完结调整tomcat开启与关闭的剧本:

#!/bin/bash
# Title:tomcat.sh
# Decription:Tomcat manager
# system:Use Linux
# Author:Alvin_zeng
# Version:1.0
# Date:2016-08-22
# Copyright:   2016 (c) alvin
# License:     GPL
TomcatDir="/usr/local/tomcat"
#====================================
# Function-->Men_CD()
#====================================
Men_CD()
{
clear
echo
echo "========TomcatManagerTool======"
echo
tput bold
echo "1: 启动tomcat服务"
tput sgr0
echo "    [*] start tomcat service"
echo
tput bold
echo "2: 关闭tomcat服务"
tput sgr0
echo "    [*] stop tomcat service"
echo
tput bold
echo "3: 重启tomcat服务"
tput sgr0
echo "    [*] restart tomcat service"
echo
tput bold
echo "4: 查看tomcat日志"
tput sgr0
echo "    [*] check tomcat logs"
echo
tput bold
echo "5:退出"
tput sgr0
echo "    [*]exit"
echo
echo "========TomcatManagerTool======="
echo
}
#====================================
# Function-->Acation_Manager
#====================================
Acation_Manager()
{
Men_CD
echo -n "Please enter you number:"
 read Myenter 
case $Myenter in 
1)
checktomcat=`ps -ef | grep java | grep "$TomcatDir" | wc -l`
if [ ${checktomcat} -eq 1 ]
then
    echo
             tput bold
    echo  " [Error]:The service is already running. Please stop the service at startup."
                                   
             tput sgr0
    echo
else
    $TomcatDir/bin/startup.sh start
    checktomcat1=`ps -ef | grep java | grep "$TomcatDir" | wc -l`
    if [ ${checktomcat1} -eq 1 ]
    then
              tput bold
              echo "Start Tomcat.....................[OK]"
              echo "Start Tomcat.....................[OK]"
              echo "Start Tomcat.....................[OK]"
              tput sgr0
    else
              tput bold
              echo "Start tomcat.....................[Fail]"
              echo "Start tomcat.....................[Fail]"
              echo "Start tomcat.....................[Fail]"
              tput sgr0
              return 1
    fi

fi
;;

2)
checktomcat1=`ps -ef | grep java | grep "$TomcatDir" | wc -l`
if [ ${checktomcat1}  -eq 1 ]
then
   
        /bin/ps -ef | grep java | grep "$TomcatDir"  | awk '{print $2}' | xargs kill -9 >>/dev/null 2>&1
    if [ $? -eq 0 ]
    then
       echo
       tput bold
       echo  "Tomcat Stop..............[OK]"
       echo  "Tomcat Stop..............[OK]"
       echo  "Tomcat Stop..............[OK]"
       tput sgr0
       echo
   else
       echo
       tput bold
       echo "Tomcat Stop...............[Fail]"
       echo "Tomcat Stop...............[Fail]"
       echo "Tomcat Stop...............[Fail]"
       tput sgr0
       echo
       return 1
    fi
else
   echo
   tput bold
   echo "Tomcat The service is already close."
   echo "Tomcat The service is already close."
   echo "Tomcat The service is already close."
   tput sgr0
   echo
fi
;;

3)
    ps -ef | grep java | grep "$TomcatDir"  | awk '{print $2}' | xargs kill -9 >>/dev/null 2>&1
        $TomcatDir/bin/startup.sh start
        checktomcat1=`ps -ef | grep java | grep "$TomcatDir" | wc -l`
        if [ ${checktomcat1} -eq 1 ]
        then
              echo
              tput bold
              echo "Restart Tomcat.....................[OK]"
              echo "Restart Tomcat.....................[OK]"
              echo "Restart Tomcat.....................[OK]"
              tput sgr0
              echo
        else
              tput bold
              echo "Restart Tomcat.....................[Fail]"
              echo "Restart Tomcat.....................[Fail]"
              echo "Restart Tomcat.....................[Fail]"
              tput sgr0
              return 1
        fi
;;

4)
 tail -f $TomcatDir/logs/catalina.out 
;;

5)
  clear
   exit 2
;;

*)
  echo "Please enter |1|2|3|4|5"
;;
esac
}

#====================================
# Function-->Main
#====================================
Main()
{
Acation_Manager
   if [ $? -eq 1 ]
   then
      exit 1
   fi
}

Main;

vhost.www.fanhougame.com 文件内容(原始内容,依照要求改善)

server {
        listen       80 ;
        server_name  www.fanhougame.com fanhougame.com  www.fanhouapp.com www.fanhougame.net fanhougame.net;
#        server_name  www.fanhougame.net fanhougame.net  www.fanhouapp.net;
        root         /data/www/oa.com/www.fanhougame.com ;

        location / {
            index index.php index.html index.htm;
            if (!-e $request_filename) {
                return 444;
            }
        }

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

        location ~ .php$ {
            fastcgi_pass   unix:/tmp/php-cgi-5313-web.sock;
            fastcgi_index  index.php;
            include        fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param SERVER_NAME $http_host;
            fastcgi_ignore_client_abort on;
        }

        location ~ .(swf|js|css|xml|gif|jpg|jpeg|png|bmp)$ {
            error_log    off;
            access_log   off;
            expires      max;
        }
    }

 

本文由金沙澳门官网发布于金沙澳门官网网址,转载请注明出处:金沙澳门官网网址:tomcat实现动静态分离

关键词: 金沙澳门官网

上一篇:Linux环境下安装NodeJS和mongoDB
下一篇:没有了