[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中。