• tomcat安装配置


    #tomcat安装配置

    #tomcat安装配置
    #centos6
    #参考http://blog.csdn.net/our_sky/article/details/51362676
    #参考http://blog.csdn.net/u012562943/article/details/51441157
    
    #-----------------------------------------------
    mkdir -p /it/app && cd /it/app
    #上传jdk、tomcat
    
    #安装JDK
    rpm -ivh jdk-8u112-linux-x64.rpm
    java -version
    #设置环境变量
    vim /etc/profile.d/java.sh
        #JDK
        JAVA_HOME=/usr/java/jdk1.8.0_112
        JRE_HOME=/usr/java/jdk1.8.0_112/jre
        PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
        CLASSPATH=:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
        export JAVA_HOME JRE_HOME PATH CLASSPATH 
    source /etc/profile.d/java.sh #使修改立即生效
    echo $PATH
    
    ### 安装tomcat
    #Tomcat8官网下载地址:http://tomcat.apache.org/download-80.cgi
    tar -zvxf apache-tomcat-8.5.13.tar.gz
    mv apache-tomcat-8.5.13 /usr/local/tomcat
    #-----------------------------------------------
    #——————防火墙
    #便于测试,可关闭 service iptables stop
    sudo iptables -I INPUT -p tcp -m tcp --dport 8080 -j ACCEPT   
    sudo /etc/rc.d/init.d/iptables save
    sudo service iptables restart
    #centos7设置方法
    firewall-cmd --zone=public --add-port=8080/tcp --permanent
    firewall-cmd --zone=public --add-port=80/tcp --permanent
    firewall-cmd --reload
    #-----------------------------------------------
    #编译tomcat daemon服务守候程序,以非root运行Java
    yum -y install gcc
    cd /usr/local/tomcat/bin
    tar -xvzf commons-daemon-native.tar.gz
    cd commons-daemon-1.0.15-native-src/unix
    ./configure
    make
    cp jsvc ../..
    cd ../..
    #配置
    cd /usr/local/tomcat/bin
    cp daemon.sh daemon.sh.bak
    vim daemon.sh #在#!/bin/sh行下增加如下内容
    # chkconfig: 2345 10 90
    # description: Tomcat service
    JAVA_HOME=/usr/java/jdk1.8.0_112
    CATALINA_HOME=/usr/local/tomcat
    #CATALINA_OPTS="-Xms128m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=256m"
    # 添加restart命令,在“version  )”行上添加如下
      restart   ) 
        # Restart Tomcat  
        if $0 stop  
        then  
            $0 start  
        else  
            echo "Failed to stop tomcat,  try to start."  
            $0 start
        fi  
        exit 0  
        ;; 
    #加入到服务
    ln -s /usr/local/tomcat/bin/daemon.sh /etc/init.d/tomcat
    #cp daemon.sh /etc/init.d/tomcat
    chmod 755 /etc/init.d/tomcat
    chkconfig --add tomcat
    #运行用户
    useradd tomcat -M -d / -s /usr/sbin/nologin
    chown -R tomcat:tomcat /usr/local/tomcat
    #chkconfig tomcat on #开机启动
    chkconfig --list tomcat
    service tomcat start
    #-----------------------------------------------
    #域名配置
    cd /usr/local/tomcat/conf
    cp server.xml server.xml.bak
    vim server.xml
        <!-- a.com实例 /usr/local/tomcat/webapps/a.com/ -->
        <Host name="a.com"   appBase="webapps"
        unpackWARs="true" autoDeploy="true">
        <Alias>www.a.com</Alias>
        <Context path="" docBase="a.com" debug="0" reloadable="true" crossContext="true" />
        </Host>
    mkdir /usr/local/tomcat/webapps/a.com
    chown -R tomcat:tomcat /usr/local/tomcat/webapps/a.com
    echo 'a.com'>/usr/local/tomcat/webapps/a.com/index.html
    echo '404'>/usr/local/tomcat/webapps/a.com/404.htm
    #IE浏览器只显示大于512字节的错误页面
    #配置404错误页面
    vim /usr/local/tomcat/conf/web.xml
        <error-page>  
          <error-code>401</error-code>    
          <location>/401.htm</location>    
        </error-page>    
        <error-page>    
          <error-code>404</error-code>    
          <location>/404.htm</location>    
        </error-page>    
        <error-page>    
          <error-code>500</error-code>    
          <location>/500.htm</location>    
        </error-page> 
    #-----------------------------------------------
    ##性能优化
    # JVM性能设置
    java -Xmx1400M -version #测试-Xmx1400M参数能否运行,正常显示JDK版本
    cd /usr/local/tomcat/bin
    cp daemon.sh daemon.sh.bak
    vim daemon.sh #还有 vim catalina.sh +60 ,jdk8 参数调整
    #export JAVA_OPTS="-server -Xms1400M -Xmx1400M -Xss512k -XX:+AggressiveOpts -XX:+UseBiasedLocking -XX:+DisableExplicitGC -XX:MaxTenuringThreshold=31 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC  -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m  -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -Djava.awt.headless=true "
    
    #Tomcat容器优化
    cp /usr/local/tomcat/conf/server.xml /usr/local/tomcat/conf/server.xml.bak
    vim /usr/local/tomcat/conf/server.xml
    <Connector port="8009" #注释8009端口,与其它http服务集成才需要
     <Server port="8005"   #关闭Tomcat指令,更改端口号如8008
    #连接池配置、JDK性能配置,参考配置
    #<Connector port="8080" protocol="HTTP/1.1" 更改如下
    <Connector port="8080" 
        protocol="org.apache.coyote.http11.Http11Nio2Protocol"  
        connectionTimeout="20000" 
        redirectPort="8443" 
        server="APP server"
        executor="tomcatThreadPool"
        enableLookups="false"
        acceptCount="100" 
        maxPostSize="10485760" 
        compression="on" 
        disableUploadTimeout="true" 
        compressionMinSize="2048" 
        noCompressionUserAgents="gozilla, traviata" 
        acceptorThreadCount="2" 
        compressableMimeType="text/html,text/xml,text/plain,text/css,text/javascript,application/javascript" 
        minSpareThreads="22" maxSpareThreads="66" 
        URIEncoding="utf-8"/>
    #其它优化
    #隐藏页版本号
    mkdir -p /usr/local/tomcat/lib/org/apache/catalina/util
    echo 'server.info=tomcat2017'>/usr/local/tomcat/lib/org/apache/catalina/util/ServerInfo.properties
    #生产环境,禁用Tomcat管理界面————删除webapps下默认目录,删除tomcat_user.xml
    
    #重启服务
    #/usr/local/tomcat/bin/shutdown.sh & /usr/local/tomcat/bin/startup.sh
    #  @说明tomcat/bin/startup.sh启动,使用catalina.sh配置,启动方式不同配置不同
    #如下重启使用daemon.sh配置
    service tomcat restart
    
    #-----------------------------------------------
    #manager-gui的管理页面,测试环境使用
    cd ../conf
    cp tomcat-users.xml tomcat-users.xml.bak
    vim tomcat-users.xml
        <role rolename="admin-gui"/>
        <role rolename="manager-gui"/>
        <user username="tomcat" password="tomcat" roles="admin-gui,manager-gui"/> 
    vim /usr/local/tomcat/webapps/manager/META-INF/context.xml
    vim /usr/local/tomcat/webapps/host-manager/META-INF/context.xml
        #allow="127.d+.d+.d+|::1|0:0:0:0:0:0:0:1" /> 改为如下,或者注释整段,或allow="192.168.18.*"
        allow="127.d+.d+.d+|::1|0:0:0:0:0:0:0:1|d+.d+.d+.d+" />
    #重启
    service tomcat restart
    #-----------------------------------------------
    netstat -antp|grep java
  • 相关阅读:
    MySQL慢查询日志总结
    SQL Server 关于列的权限控制
    Oracle global database name与db link的纠缠关系
    TCP Provider The semaphore timeout period has expired
    SQL SERVER 中如何用脚本管理作业
    Unable to determine if the owner (DomainUserName) of job JOB_NAME has server access
    TNS-12535: TNS:operation timed out案例解析
    ORA-12154 & TNS-03505 案例分享
    MS SQL巡检系列——检查数据库上一次DBCC CHECKDB的时间
    查看数据库表的数据量和SIZE大小的脚本修正
  • 原文地址:https://www.cnblogs.com/elvi/p/7718073.html
Copyright © 2020-2023  润新知