1. 程式人生 > >生產環境Tomat部署之一

生產環境Tomat部署之一

centos tomcat

  • 查看主機名、做本地解析

  • [root@www ~]# hostname
    www
    [root@www ~]# cat /etc/hosts
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 www
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    • 創建應用程序安裝目錄

    [root@www ~]# mkdir -pv /usr/local/application
    mkdir: created directory `/usr/local/application'
    • 新建Tomcat運行普通用戶

    [root@www ~]# useradd -d /usr/local/application/tomcat -m tomcat
    [root@www ~]# echo "tomcat" | passwd --stdin tomcat
    Changing password for user tomcat.
    passwd: all authentication tokens updated successfully.
    [root@www ~]# id tomcat
    uid=503(tomcat) gid=503(tomcat) groups=503(tomcat)
    • 使用新建的普通用戶登錄服務器

    [tomcat@www ~]$ w
     16:29:13 up 8 days,  3:15,  2 users,  load average: 0.03, 0.01, 0.00
    USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
    root     pts/1    172.19.5.142     16:14    2:23   0.02s  0.02s bash
    tomcat   pts/2    172.19.10.155    16:28    0.00s  0.00s  0.00s w
    • 部署java運行環境

    JDK下載地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html

    Tomcat下載地址:http://tomcat.apache.org/

    • 下載JDK並解壓

    [tomcat@www ~]$ ll jdk-7u80-linux-x64.tar.gz 
    -rw-r--r-- 1 tomcat tomcat 153530841 Dec 27 16:34 jdk-7u80-linux-x64.tar.gz
    [tomcat@www ~]$ tar xf jdk-7u80-linux-x64.tar.gz
    • 配置環境變量

    [tomcat@www ~]$ vim .bash_profile
    [tomcat@www ~]$ tail -3 .bash_profile 
    export JAVA_HOME=/usr/local/application/tomcat/jdk1.7.0_80
    export PATH=$JAVA_HOME/bin:$PATH:$JAVA_HOME/jre/bin
    export CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib
    [tomcat@www ~]$ source .bash_profile
    [tomcat@www ~]$ java -version
    java version "1.7.0_80"
    Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
    Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
    • 下載Tomcat

    [tomcat@www ~]$ wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.82/bin/apache-tomcat-7.0.82.tar.gz
    [tomcat@www ~]$ ll -d apache-tomcat-7.0.82.tar.gz 
    -rw-rw-r-- 1 tomcat tomcat 8997403 Sep 29 21:11 apache-tomcat-7.0.82.tar.gz
    [tomcat@www ~]$ tar xf apache-tomcat-7.0.82.tar.gz 
    [tomcat@www ~]$ ll 
    total 158736
    drwxrwxr-x 9 tomcat tomcat      4096 Dec 27 16:41 apache-tomcat-7.0.82
    -rw-rw-r-- 1 tomcat tomcat   8997403 Sep 29 21:11 apache-tomcat-7.0.82.tar.gz
    drwxr-xr-x 8 tomcat tomcat      4096 Apr 11  2015 jdk1.7.0_80
    -rw-r--r-- 1 tomcat tomcat 153530841 Dec 27 16:34 jdk-7u80-linux-x64.tar.gz
    [tomcat@www ~]$ mv apache-tomcat-7.0.82 tomcat7
    [tomcat@www ~]$ ll tomcat7/
    total 116
    drwxr-xr-x 2 tomcat tomcat  4096 Dec 27 16:41 bin
    drwxr-xr-x 2 tomcat tomcat  4096 Sep 29 20:27 conf
    drwxr-xr-x 2 tomcat tomcat  4096 Dec 27 16:41 lib
    -rw-r--r-- 1 tomcat tomcat 56846 Sep 29 20:27 LICENSE
    drwxr-xr-x 2 tomcat tomcat  4096 Sep 29 20:23 logs
    -rw-r--r-- 1 tomcat tomcat  1239 Sep 29 20:27 NOTICE
    -rw-r--r-- 1 tomcat tomcat  8965 Sep 29 20:27 RELEASE-NOTES
    -rw-r--r-- 1 tomcat tomcat 16195 Sep 29 20:27 RUNNING.txt
    drwxr-xr-x 2 tomcat tomcat  4096 Dec 27 16:41 temp
    drwxr-xr-x 7 tomcat tomcat  4096 Sep 29 20:26 webapps
    drwxr-xr-x 2 tomcat tomcat  4096 Sep 29 20:23 work
    • 啟動Tomcat服務

    [tomcat@www ~]$ tomcat7/bin/startup.sh 
    Using CATALINA_BASE:   /usr/local/application/tomcat/tomcat7
    Using CATALINA_HOME:   /usr/local/application/tomcat/tomcat7
    Using CATALINA_TMPDIR: /usr/local/application/tomcat/tomcat7/temp
    Using JRE_HOME:        /usr/local/application/tomcat/jdk1.7.0_80
    Using CLASSPATH:       /usr/local/application/tomcat/tomcat7/bin/bootstrap.jar:/usr/local/application/tomcat/tomcat7/bin/tomcat-juli.jar
    Tomcat started.
    [tomcat@www ~]$ tailf tomcat7/logs/catalina.out 
    Dec 27, 2017 4:43:55 PM org.apache.catalina.startup.HostConfig deployDirectory
    INFO: Deployment of web application directory /usr/local/application/tomcat/tomcat7/webapps/host-manager has finished in 81 ms
    Dec 27, 2017 4:43:55 PM org.apache.catalina.startup.HostConfig deployDirectory
    INFO: Deploying web application directory /usr/local/application/tomcat/tomcat7/webapps/examples
    Dec 27, 2017 4:43:56 PM org.apache.catalina.startup.HostConfig deployDirectory
    INFO: Deployment of web application directory /usr/local/application/tomcat/tomcat7/webapps/examples has finished in 622 ms
    Dec 27, 2017 4:43:56 PM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler ["ajp-bio-8009"]
    Dec 27, 2017 4:43:56 PM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 2295 ms
    • 訪問

    [tomcat@www ~]$ curl -I http://localhost:8080/
    HTTP/1.1 200 OK
    Server: Apache-Coyote/1.1
    Content-Type: text/html;charset=ISO-8859-1
    Transfer-Encoding: chunked
    Date: Wed, 27 Dec 2017 09:03:50 GMT

    生產環境Tomat部署之一