标签:tomcat
配置监听端口
1、编辑配置文件
[root@plinuxos ~]# vim /usr/local/tomcat/conf/server.xml <Connector port="80" protocol="HTTP/1.1" ##改成80端口 connectionTimeout="20000" redirectPort="8443" />
2、重启服务
[root@plinuxos ~]# /usr/local/tomcat/bin/shutdown.sh Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/local/jdk1.8 Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar [root@plinuxos ~]# /usr/local/tomcat/bin/startup.sh Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/local/jdk1.8 Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Tomcat started.
3、检查效果
本地验证:
[root@plinuxos ~]# netstat -lntp |grep 80 tcp6 0 0 :::80 :::* LISTEN 107670/java tcp6 0 0 127.0.0.1:8005 :::* LISTEN 107670/java tcp6 0 0 :::8009 :::* LISTEN 107670/java
如果被nginx占用,使用/etc/init.d/nginx stop命令关闭nginx。
远端验证:
配置虚拟主机
1、编辑配置文件
[root@plinuxos ~]# vim /usr/local/tomcat/conf/server.xml ...... <Host name="www.abc.com" appBase="" ##appBase和docBase二取一 unpackWARs= "true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Context path="" docBase="/data/wwwroot/abc.com/" debug="0" reloadable="true" crossContext="true"/> </Host> </Engine> </Service> </Server>
<Host>和</Host>之间的配置为虚拟主机配置部分,name定义域名;
appBase定义应用的目录,Java的应用通常是一个jar的压缩包,只需要将jar的压缩包放到appBase目录下面即可;
docBase,这个参数用来定义网站的文件存放路径,如果不定义,默认是在appBase/ROOT下面,定义了docBase就以该目录为主了,其中appBase和docBase可以一样,访问404的问题,其实就是docBase没有定义准确;
appBase为应用存放目录,通常是需要把war包直接放到该目录下面,它会自动解压成一个程序目录。
2、下载与解压zrlog
[root@plinuxos ~]# cd /usr/local/src [root@plinuxos src]# wget http://dl.zrlog.com/release/zrlog-1.7.1-baaecb9-release.war [root@plinuxos src]# cp zrlog-1.7.1-baaecb9-release.war /usr/local/tomcat/webapps/ [root@plinuxos src]# cd /usr/local/tomcat/webapps/ [root@plinuxos webapps]# ls ##自动解压 docs examples host-manager manager ROOT zrlog-1.7.1-baaecb9-release zrlog-1.7.1-baaecb9-release.war [root@plinuxos webapps]# mv zrlog-1.7.1-baaecb9-release zrlog
3、打开80端口
[root@plinuxos webapps]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
4、远程访问
5、配置数据库
1)检查mysql状态
[root@plinuxos mysql]# ps aux|grep mysql root 109814 0.0 0.0 11760 1588 pts/0 S 22:43 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/plinuxos.pid mysql 109922 2.4 13.4 973052 449528 pts/0 Sl 22:43 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/plinuxos.err --pid-file=/data/mysql/plinuxos.pid root 109971 0.0 0.0 112648 968 pts/0 S+ 22:44 0:00 grep --color=auto mysql
2)创建数据库
[root@plinuxos mysql]# /usr/local/mysql/bin/mysql -uroot 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> create database zrlog; Query OK, 1 row affected (0.00 sec)
3)用户授权
mysql> grant all on zrlog.* to ‘zrlog‘@127.0.0.1 identified by ‘123456‘; Query OK, 0 rows affected (0.01 sec) mysql> exit; Bye
4)检查数据库
[root@plinuxos mysql]# /usr/local/mysql/bin/mysql -uzrlog -h127.0.0.1 -p123456 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | test | | zrlog | +--------------------+ 3 rows in set (0.00 sec)
6、配置zrlog
7、使用域名访问zrlog
[root@plinuxos mysql]# mkdir /data/wwwroot/abc.com [root@plinuxos mysql]# mv /usr/local/tomcat/webapps/zrlog/* /data/wwwroot/abc.com/ [root@plinuxos mysql]# /usr/local/tomcat/bin/shutdown.sh Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/local/jdk1.8 Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar [root@plinuxos mysql]# /usr/local/tomcat/bin/startup.sh Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/local/jdk1.8 Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Tomcat started.
8、测试效果
在本端HOSTS文件内添加解析。
Tomcat日志
1、查看tomcat日志目录
[root@plinuxos mysql]# ls /usr/local/tomcat/logs catalina.2017-08-29.log catalina.out host-manager.2017-08-29.log localhost.2017-08-29.log localhost_access_log.2017-08-29.txt manager.2017-08-29.log
▎日志分为四大类:
1)其中catalina开头的日志为Tomcat的综合日志,它记录Tomcat服务相关信息,也会记录错误日志。
2)其中catalina.2017-xx-xx.log和catalina.out内容相同,带日期的每天生成一个新的日志。
3)host-manager和manager为管理相关的日志,其中host-manager为虚拟主机的管理日志。
4)localhost和localhost_access为虚拟主机相关日志,其中带access字样的日志为访问日志,不带access字样的为默认虚拟主机的错误日志。
2、访问日志默认不会生成,需要在server.xml中配置。
具体方法是在对应虚拟主机的<Host></Host>里面加入下面的配置:
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="abc.com_access" suffix=".log"
pattern="%h %l %u %t "%r" %s %b" />
3、prefix定义访问日志的前缀,suffix定义日志的后缀,pattern定义日志格式。新增加的虚拟主机默认并不会生成类似默认虚拟主机的那个localhost.日期.log日志,错误日志会统一记录到catalina.out中。关于Tomcat日志,你最需要关注catalina.out,当出现问题时,我们首先应该想到去查看它。
本文出自 “Gorilla City” 博客,请务必保留此出处http://juispan.blog.51cto.com/943137/1960966
标签:tomcat
原文地址:http://juispan.blog.51cto.com/943137/1960966