[toc]php
擴展 邱李的tomcat文檔 https://www.linuser.com/forum.php?mod=forumdisplay&fid=37css
JAR、WAR包區別 http://blog.csdn.net/lishehe/article/details/41607725html
tomcat常見配置彙總 http://blog.sina.com.cn/s/blog_4ab26bdd0100gwpk.htmljava
resin安裝 http://fangniuwa.blog.51cto.com/10209030/1763488/mysql
1 tomcat 單機多實例 http://www.ttlsa.com/tomcat/config-multi-tomcat-instance/linux
2 tomcat的jvm設置和鏈接數設置 http://www.cnblogs.com/bluestorm/archive/2013/04/23/3037392.htmlnginx
3 jmx監控tomcat http://blog.csdn.net/l1028386804/article/details/51547408web
4 jvm性能調優監控工具jps/jstack/jmap/jhat/jstatsql
http://blog.csdn.net/wisgood/article/details/25343845 http://guafei.iteye.com/blog/1815222數據庫
5 gvm gc 相關 http://www.cnblogs.com/Mandylover/p/5208055.html http://blog.csdn.net/yohoph/article/details/42041729
[root@xavi ~]# netstat -lntp |grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 5700/nginx: master tcp6 0 0 :::8080 :::* LISTEN 3880/java tcp6 0 0 127.0.0.1:8005 :::* LISTEN 3880/java tcp6 0 0 :::8009 :::* LISTEN 3880/java [root@xavi ~]# /etc/init.d/nginx stop Stopping nginx (via systemctl): [ 肯定 ]
[root@xavi ~]# vim /usr/local/tomcat/conf/server.xml 搜索8080 更改80端口: Connector port="8080" protocol="HTTP/1.1" 修改成: Connector port="80" protocol="HTTP/1.1"
[root@xavi ~]# /usr/local/tomcat/bin/shutdown.sh [root@xavi ~]# /usr/local/tomcat/bin/startup.sh [root@xavi ~]# netstat -lntp |grep 80 tcp6 0 0 :::80 :::* LISTEN 5836/java tcp6 0 0 :::8009 :::* LISTEN 5836/java
[root@xavi ~]# netstat -lntp |grep 80 tcp6 0 0 :::80 :::* LISTEN 5836/java tcp6 0 0 127.0.0.1:8005 :::* LISTEN 5836/java tcp6 0 0 :::8009 :::* LISTEN 5836/java
虛擬主機也就是以前提到的,一個IP地址能夠配置多個站點,綁定多個不一樣的域名,也就是配置多個webserver。
[root@xavi ~]# !vim vim /usr/local/tomcat/conf/server.xml <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <!-- Access log processes all example. Documentation at: /docs/config/valve.html Note: The pattern used is equivalent to using pattern="common" --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host>
[ ] name 定義域名;
[ ] appBase 定義應用的目錄;
[ ] unpackWARs=」true」 是否自動解壓;(也是就是說,當咱們往站點目錄裏面直接上傳一個war的包,它會自動解壓)
[ ] Java的應用一般是一個jar的壓縮包,你只須要將jar的壓縮包放到appBase目錄下面便可。剛剛訪問的Tomcat默認頁其實就是在appBase目錄下面,不過是在它子目錄ROOT裏。
[root@xavi ~]# ls /usr/local/tomcat/webapps/ROOT/ asf-logo-wide.svg bg-middle.png bg-nav.png favicon.ico RELEASE-NOTES.txt tomcat.gif tomcat-power.gif WEB-INF bg-button.png bg-nav-item.png bg-upper.png index.jsp tomcat.css tomcat.png tomcat.svg
[root@xavi ~]# curl localhost:80/tomcat.gif -I HTTP/1.1 200 Accept-Ranges: bytes ETag: W/"2066-1520255503000" Last-Modified: Mon, 05 Mar 2018 13:11:43 GMT Content-Type: image/gif Content-Length: 2066 Date: Sun, 01 Apr 2018 02:26:29 GMT
增長虛擬主機,編輯server.xml,在</Host>下面增長以下內容:
<Host name="www.dsf.com" appBase="" unpackWARs= "true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Context path="" docBase="/data/wwwroot/www.dsf.com/" debug="0" reloadable="true" crossContext="true"/> </Host>
銘哥專業解釋:
docBase,這個參數用來定義網站的文件存放路徑,若是不定義,默認是在appBase/ROOT下面,定義了docBase就以該目錄爲主了,其中appBase和docBase能夠同樣。在這一步操做過程當中不少同窗遇到過訪問404的問題,其實就是docBase沒有定義對。
appBase爲應用存放目錄,一般是須要把war包直接放到該目錄下面,它會自動解壓成一個程序目錄
[root@xavi ~]# wget http://dl.zrlog.com/release/zrlog-1.7.1-baaecb9-release.war
[root@xavi ~]# mkdir /data/wwwroot/www.dsf.com/ ////咱們先把站點程序放到appBASE中解壓,而後再次所有移動到此目錄下
[root@xavi ~]# mv zrlog-1.7.1-baaecb9-release.war /usr/local/tomcat/webapps/ 等待個10幾秒鐘,就會出現一個自動解壓出來包 [root@xavi ~]# ls /usr/local/tomcat/webapps/ docs examples host-manager manager ROOT zrlog-1.7.1-baaecb9-release zrlog-1.7.1-baaecb9-release.war
[root@xavi www.dsf.com]# cd /usr/local/tomcat/webapps/ [root@xavi webapps]# ls docs examples host-manager manager ROOT zrlog-1.7.1-baaecb9-release zrlog-1.7.1-baaecb9-release.war [root@xavi webapps]# mv zrlog-1.7.1-baaecb9-release zrlog [root@xavi webapps]# ls docs examples host-manager manager ROOT zrlog zrlog-1.7.1-baaecb9-release zrlog-1.7.1-baaecb9-release.war
[root@xavi webapps]# ps aux | grep mysql root 6826 0.0 0.0 112680 972 pts/1 S+ 15:31 0:00 grep --color=auto mysql //沒有開啓mysql服務,開啓 [root@xavi webapps]# service mysqld start Starting MySQL.. SUCCESS! [root@xavi webapps]# mysql -uroot -pxavilinux Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.35 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
mysql> create database zrlog; Query OK, 1 row affected (0.00 sec) mysql> grant all on zrlog.* to 'zrlog'@127.0.0.1 identified by 'xavilinux1'; Query OK, 0 rows affected (0.00 sec)
[root@xavi webapps]# mysql -uzrlog -h127.0.0.1 -pxavilinux1 Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.35 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | test | | zrlog | +--------------------+ 3 rows in set (0.00 sec)
增長一個www.dsf.com的java站點。
docBase=」/data/wwwroot/www.dsf.com/」 這個就和我們以前配置LAMP和LNMP差很少了。就是把站點的配置文件上傳到此處。 有時候配置完畢,再次訪問站點會出現404,那麼幾乎都是這個地方沒有定義對,要麼就是appBASE也上傳了站點文件。(若是不知道如何解壓war包,咱們能夠先把站點的包放到appBASE下,而後等到自動解壓完畢,咱們再次move站點的包到自定義的位置。)
[root@xavi webapps]# mkdir /data/wwwroot/www.dsf.com/
[root@xavi webapps]# mv /usr/local/tomcat/webapps/zrlog/ //這裏雙擊tab建看下有哪些目錄文件 admin/ error/ include/ META-INF/ assets/ favicon.ico install/ WEB-INF/ [root@xavi webapps]# mv /usr/local/tomcat/webapps/zrlog/* /data/wwwroot/www.dsf.com/
直接訪問
[root@xavi zrlog]# cd /data/wwwroot/www.dsf.com/ [root@xavi www.dsf.com]# ls admin favicon.ico log sim.pid zrlog-1.7.1-baaecb9-release assets include logs temp error install META-INF WEB-INF [root@xavi www.dsf.com]# rm -rf zrlog-1.7.1-baaecb9-release [root@xavi www.dsf.com]# ls admin error include log META-INF temp assets favicon.ico install logs sim.pid WEB-INF [root@xavi ~]# /usr/local/tomcat/bin/shutdown.sh [root@xavi ~]# /usr/local/tomcat/bin/startup.sh [root@xavi webapps]# netstat -lntp |grep 80 tcp6 0 0 :::80 :::* LISTEN 8287/java tcp6 0 0 127.0.0.1:8005 :::* LISTEN 8287/java tcp6 0 0 :::8009 :::* LISTEN 8287/java
[root@xavi www.dsf.com]# cd /usr/local/tomcat/webapps/ [root@xavi webapps]# ls docs log ROOT zrlog-1.7.1-baaecb9-release examples logs temp zrlog-1.7.1-baaecb9-release.war host-manager manager zrlog [root@xavi webapps]# ls ROOT asf-logo-wide.svg bg-nav.png RELEASE-NOTES.txt tomcat-power.gif bg-button.png bg-upper.png tomcat.css tomcat.svg bg-middle.png favicon.ico tomcat.gif WEB-INF bg-nav-item.png index.jsp tomcat.png
在平常運維中,Tomcat用的仍是蠻多的,可是一旦出現問題,咱們就須要去解決,思路就來自日誌文件。
[root@xavi webapps]# ls /usr/local/tomcat/logs catalina.2018-03-31.log localhost.2018-03-31.log catalina.out localhost_access_log.2018-03-31.txt host-manager.2018-03-31.log manager.2018-03-31.log
其中catalina開頭的日誌爲Tomcat的綜合日誌,它記錄Tomcat服務相關信息,也會記錄錯誤日誌。
其中catalina.2017-xx-xx.log和catalina.out內容相同,前者會天天生成一個新的日誌。
host-manager和manager爲管理相關的日誌,其中host-manager爲虛擬主機的管理日誌。
在對應虛擬主機的<Host></Host>裏面加入下面的配置(剛纔的域名是www.dsf.com):
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="dsf.com_access" suffix=".log" pattern="%h %l %u %t "%r" %s %b" />
prefix 定義訪問日誌的前綴;
suffix 定義日誌的後綴;
pattern 定義日誌格式。
新增長的虛擬主機默認並不會生成相似默認虛擬主機的那個"localhost.日期.log"日誌; 錯誤日誌會統一記錄到catalina.out中。