tomcat(3)- tomcat部署zrlog
阿新 • • 發佈:2021-07-07
目錄
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主配置檔案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 "%r" %s %b" /> </Host>
-
下載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
-
重新啟動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.
-
重新啟動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
-
在資料庫上建立資料庫和遠端連線的使用者
[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)
-
客戶端訪問http://zrlog.xuzhichao.com:8080
- 點選“下一步”,建立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,
#新增加的虛擬主機的域名為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 "%r" %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
-
資料庫建立庫名和使用者名稱:
[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)
-
部署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
-
客戶端訪問測試:http://zrlog.xuzhichao.com/