Configure tomcat listening port to 80
vim /usr/local/tomcat/conf/server.xml
Connector port="8080" protocol="HTTP/1.1"修改为Connector port="80" protocol="HTTP/1.1"
/usr/local/tomcat/bin/shutdown.sh
/usr/local/tomcat/bin/startup.sh
[root@localhost src]# netstat -lntp |grep 80
/etc/init.d/nginx stop //Port conflict, close nginx first. restart tomcat
/usr/local/tomcat/bin/shutdown.sh
/usr/local/tomcat/bin/startup.sh
Configure the virtual host of tomcat
vim /usr/local/tomcat/conf/server.xml
The configuration between <Host> and </Host> is the virtual host configuration part, name defines the domain name,
appBase defines the directory of the application. A Java application is usually a compressed war package. You only need to put the compressed package of the war in the appBase directory. The Tomcat default page that A Ming visited just now is actually under the appBase directory, but in its subdirectory ROOT.
Add a virtual host, edit server.xml, and add the following content under </Host>
<Host name="www.123.cn" appBase=""
unpackWARs= "true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="/data/wwwroot/123.cn/" debug="0" reloadable="true" crossContext="true"/>
</Host
docBase, this parameter is used to define the file storage path of the website. If not defined, the default is under appBase/ROOT. If docBase is defined, this directory is the main one. AppBase and docBase can be the same. In this step of operation, many students have encountered the problem of accessing 404. In fact, docBase does not define the right.
appBase is the application storage directory, usually you need to put the war package directly under this directory, it will be automatically decompressed into a program directory
Next, we will experience the role of the appBase and docBase directories by deploying a java application
download zrlog wget http://dl.zrlog.com/release/zrlog-1.7.1-baaecb9-release.war
mv zrlog-1.7.1-baaecb9-release.war /usr/local/tomcat/webapps/
cp zrlog-1.7.1-baaecb9-release.war /usr/local/tomcat/webapps/
ls /usr/local/tomcat/webapps/
(After changing the name zrlog first, and then deleting the war package, there will be no problem.)
rm -rf /usr/local/tomcat/webapps/zrlog-1.7.1-baaecb9-release.war
cd /usr/local/tomcat/webapps/
cp /usr/local/src/zrlog-1.7.1-baaecb9-release.war .
mv /usr/local/tomcat/webapps/zrlog-1.7.1-baaecb9-release /usr/local/tomcat/webapps/zrlog
ps aux |grep mysql
mysql> create database zrlog;
Query OK, 1 row affected (0.06 sec)
mysql> grant all on zrlog.* to 'zrlog'@127.0.0.1 identified by '123456';
Query OK, 0 rows affected (0.16 sec)
[root @localhost ~]# mysql -uzrlog -h127.0.0.1 -p123456 //Check whether the creation is correct
mv /usr/local/tomcat/webapps/zrlog/* /data/wwwroot/123.cn/
mkdir /data/wwwroot/123.cn/
/usr/local/tomcat/bin/shutdown.sh
/usr/local/tomcat/bin/startup.sh
Tomcat logs
ls /usr/local/tomcat/logs
The log at the beginning of catalina is the comprehensive log of Tomcat, which records the information related to the Tomcat service and also records the error log.
The contents of catalina.2017-xx-xx.log and catalina.out are the same, and the former will generate a new log every day.
host-manager and manager are management-related logs, where host-manager is the management log of the virtual host.
localhost and localhost_access are virtual host related logs. The log with access is the access log, and the log without access is the error log of the default virtual host.
Access logs are not generated by default and need to be configured in server.xml.
The specific method is to add the following configuration to the <Host></Host> of the corresponding virtual host (if the domain name is 123.cn):
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="123.cn_access" suffix=".log"
pattern="%h %l %u %t "%r" %s %b" />
prefix defines the prefix of the access log, suffix defines the suffix of the log, and pattern defines the log format. The newly added virtual host will not generate the localhost.date.log log similar to the default virtual host by default, and the error log will be uniformly recorded in catalina.out. Regarding the Tomcat logs, you need to pay attention to catalina.out most, when there is a problem, we should check it first.