tomcat(3)- tomcat部署zrlog



1. Tomcat单独部署

部署场景为:

  • 客户端:192.168.20.1
  • tomcat:主机名:tomcat01,地址:192.168.20.22,版本:9.0.45
  • mariadb:主机名:mysql01,地址:192.168.20.50,版本:10.5.2
  • zrlog:版本:2.2.0

tomcat(3)- tomcat部署zrlog

  1. 在tomcat主配置文件server.xml中增加虚拟主机

    #新增加的虚拟主机的域名为zrlog.xuzhichao.com,虚拟主机的根目录为/data/tomcat/zrlog,开启自动部署。
    [root@tomcat01 zrlog]# vim /apps/tomcat/conf/server.xml
          <Host name="zrlog.xuzhichao.com"  appBase="/data/tomcat/zrlog"
                unpackWARs="true" autoDeploy="true">
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                   prefix="zrlog_access_log" suffix=".txt"
                   pattern="%h %l %u %t &quot;%r&quot; %s %b" />
          </Host>  
    
  2. 下载zrlog软件包,创建/data/tomcat/zrlog目录,将软件包解压到该目录

    [root@tomcat01 ~]# mkdir /data/tomcat/zrlog -pv
    [root@tomcat01 ~]# cd /data/tomcat/zrlog/
    
    #当使用的是war包进行部署时,需要将war包命名为ROOT.war,tomcat会自动部署该应用。
    #当使用的是zip包时,需要手动解压到/data/tomcat/zrlog/ROOT目录下。
    
    [root@tomcat01 zrlog]# ll
    -rw-r--r-- 1 root root 11110760 Jul  6 09:55 zrlog-2.2.0-5e8a51f-release.war
    [root@tomcat01 zrlog]# mv zrlog-2.2.0-5e8a51f-release.war ROOT.war
    
  3. 重新启动tomcat服务:

    [root@tomcat01 apps]# /apps/tomcat/bin/shutdown.sh && /apps/tomcat/bin/startup.sh 
    Using CATALINA_BASE:   /apps/tomcat
    Using CATALINA_HOME:   /apps/tomcat
    Using CATALINA_TMPDIR: /apps/tomcat/temp
    Using JRE_HOME:        /usr
    Using CLASSPATH:       /apps/tomcat/bin/bootstrap.jar:/apps/tomcat/bin/tomcat-juli.jar
    Using CATALINA_OPTS:   
    Using CATALINA_BASE:   /apps/tomcat
    Using CATALINA_HOME:   /apps/tomcat
    Using CATALINA_TMPDIR: /apps/tomcat/temp
    Using JRE_HOME:        /usr
    Using CLASSPATH:       /apps/tomcat/bin/bootstrap.jar:/apps/tomcat/bin/tomcat-juli.jar
    Using CATALINA_OPTS:   
    Tomcat started.
    
  4. 重新启动tomcat后,会对指定的目录中的war包进行自动解压部署

    [root@tomcat01 zrlog]# ll
    total 10852
    drwxr-x--- 9 root root      126 Jul  6 10:04 ROOT
    -rw-r--r-- 1 root root 11110760 Jul  6 09:55 ROOT.war
    
    #查看日志:
    [root@tomcat01 zrlog]# tail -f /apps/tomcat/logs/catalina.out 
    06-Jul-2021 15:39:47.643 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/data/tomcat/zrlog/ROOT.war] has finished in [1,287] ms
    06-Jul-2021 15:39:47.660 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
    06-Jul-2021 15:39:47.790 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [3235] milliseconds
    
  5. 在数据库上创建数据库和远程连接的用户

    [root@mysql01 ~]# mysql -uroot -p123456
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 375
    Server version: 10.5.2-MariaDB MariaDB Server
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
    
    MariaDB [(none)]> CREATE DATABASE zrlog;
    Query OK, 1 row affected (0.011 sec)
    
    MariaDB [(none)]> GRANT ALL PRIVILEGES ON zrlog.* TO "tomcat"@"192.168.20.%" IDENTIFIED BY "123456";
    Query OK, 0 rows affected (0.024 sec)
    
    MariaDB [(none)]> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.015 sec)
    
  6. 客户端访问http://zrlog.xuzhichao.com:8080

tomcat(3)- tomcat部署zrlog

  1. 点击“下一步”,创建zrlog的用户名密码

tomcat(3)- tomcat部署zrlog

tomcat(3)- tomcat部署zrlog

  1. 安装完成,登录后台页面:

tomcat(3)- tomcat部署zrlog

2. nginx+tomcat部署

可以在tomcat前端部署nginx,由nginx将请求方向代理到tomcat中进行处理,实验环境如下:

  • 客户端:192.168.20.1
  • nginx:主机名tomcat01,地址:192.168.20.22,版本:1.20.1
  • tomcat:和nginx共用一台主机,版本:9.0.45
  • mariadb:主机名:mysql01,地址:192.168.20.50,版本:10.5.2
  • zrlog:版本:2.2.0

tomcat(3)- tomcat部署zrlog

  1. 部署tomcat,

    #新增加的虚拟主机的域名为zrlog.xuzhichao.com,虚拟主机的根目录为/data/tomcat/zrlog,开启自动部署。
    [root@tomcat01 zrlog]# vim /apps/tomcat/conf/server.xml
          <Host name="zrlog.xuzhichao.com"  appBase="/data/tomcat/zrlog"
                unpackWARs="true" autoDeploy="true">
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                   prefix="zrlog_access_log" suffix=".txt"
                   pattern="%h %l %u %t &quot;%r&quot; %s %b" />
          </Host>
    
    [root@tomcat01 ~]# mkdir /data/tomcat/zrlog -pv
    [root@tomcat01 ~]# cd /data/tomcat/zrlog/
    
    [root@tomcat01 zrlog]# ll
    -rw-r--r-- 1 root root 11110760 Jul  6 09:55 zrlog-2.2.0-5e8a51f-release.war
    [root@tomcat01 zrlog]# mv zrlog-2.2.0-5e8a51f-release.war ROOT.war
    
    [root@tomcat01 apps]# /apps/tomcat/bin/shutdown.sh && /apps/tomcat/bin/startup.sh 
    
    [root@tomcat01 zrlog]# ll
    total 10852
    drwxr-x--- 9 root root      126 Jul  6 10:04 ROOT
    -rw-r--r-- 1 root root 11110760 Jul  6 09:55 ROOT.war
    
  2. 数据库创建库名和用户名:

    [root@mysql01 ~]# mysql -uroot -p123456
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 375
    Server version: 10.5.2-MariaDB MariaDB Server
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
    
    MariaDB [(none)]> CREATE DATABASE zrlog;
    Query OK, 1 row affected (0.011 sec)
    
    MariaDB [(none)]> GRANT ALL PRIVILEGES ON zrlog.* TO "tomcat"@"192.168.20.%" IDENTIFIED BY "123456";
    Query OK, 0 rows affected (0.024 sec)
    
    MariaDB [(none)]> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.015 sec)
    
  3. 部署nginx

    #1.nginx的配置文件:
    [root@tomcat01 apps]# cat /etc/nginx/conf.d/zrlog.xuzhichao.com 
    server {
    	listen 80;
    	server_name zrlog.xuzhichao.com;
    	access_log /var/log/nginx/access_zrlog.log access_json;
    	charset utf-8,gbk;
    
    	location / {
    		proxy_pass http://127.0.0.1:8080;
    		include proxy_params;
    	}
    }
    
    [root@tomcat01 apps]# cat /etc/nginx/proxy_params 
    proxy_set_header host $http_host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    
    proxy_connect_timeout 30;
    proxy_send_timeout 60;
    proxy_read_timeout 60;										        
    
    proxy_buffering on;
    proxy_buffer_size 64k;
    proxy_buffers 4 64k;
    
    #2.重启nginx服务:
    [root@tomcat01 apps]# systemctl reload nginx.service
    
  4. 客户端访问测试:http://zrlog.xuzhichao.com/

tomcat(3)- tomcat部署zrlog

tomcat(3)- tomcat部署zrlog

上一篇:RMAN完全备份


下一篇:[ARC117D] Miracle Tree