生产环境Tomat部署之一

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了生产环境Tomat部署之一相关的知识,希望对你有一定的参考价值。

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

  • [[email protected] ~]# hostname
    www
    [[email protected] ~]# cat /etc/hosts
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 www
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    • 创建应用程序安装目录

    [[email protected] ~]# mkdir -pv /usr/local/application
    mkdir: created directory `/usr/local/application'
    • 新建Tomcat运行普通用户

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

    [[email protected] ~]$ w
     16:29:13 up 8 days,  3:15,  2 users,  load average: 0.03, 0.01, 0.00
    USER     TTY      FROM              [email protected]   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并解压

    [[email protected] ~]$ ll jdk-7u80-linux-x64.tar.gz 
    -rw-r--r-- 1 tomcat tomcat 153530841 Dec 27 16:34 jdk-7u80-linux-x64.tar.gz
    [[email protected] ~]$ tar xf jdk-7u80-linux-x64.tar.gz
    • 配置环境变量

    [[email protected] ~]$ vim .bash_profile
    [[email protected] ~]$ 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
    [[email protected] ~]$ source .bash_profile
    [[email protected] ~]$ 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

    [[email protected] ~]$ wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.82/bin/apache-tomcat-7.0.82.tar.gz
    [[email protected] ~]$ 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
    [[email protected] ~]$ tar xf apache-tomcat-7.0.82.tar.gz 
    [[email protected] ~]$ 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
    [[email protected] ~]$ mv apache-tomcat-7.0.82 tomcat7
    [[email protected] ~]$ 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服务

    [[email protected] ~]$ 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.
    [[email protected] ~]$ 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
    • 访问

    [[email protected] ~]$ 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部署之一的主要内容,如果未能解决你的问题,请参考以下文章

    Spring Boot 最佳实践集成Jsp与生产环境部署

    基于公有云的准生产环境的搭建

    如何先使用实体​​框架代码部署到生产环境

    tomat(16)关闭钩子

    jenkins git maven tomat 项目拉取编译自动部署(操作详细)

    jenkins git maven tomat 项目拉取编译自动部署(操作详细)