本文共 7649 字,大约阅读时间需要 25 分钟。
[toc]
[root@xavi ~]# netstat -lntp |grep 80tcp 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 stopStopping 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 80tcp6 0 0 :::80 :::* LISTEN 5836/java tcp6 0 0 :::8009 :::* LISTEN 5836/java
[root@xavi ~]# netstat -lntp |grep 80tcp6 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 ~]# !vimvim /usr/local/tomcat/conf/server.xml
[ ] name 定义域名;
[ ] appBase 定义应用的目录;
[ ] unpackWARs=”true” 是否自动解压;(也是就是说,当我们往站点目录里面直接上传一个war的包,它会自动解压)
增加虚拟主机,编辑server.xml,在</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]# lsdocs 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]# lsdocs 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 mysqlroot 6826 0.0 0.0 112680 972 pts/1 S+ 15:31 0:00 grep --color=auto mysql//没有开启mysql服务,开启[root@xavi webapps]# service mysqld startStarting MySQL.. SUCCESS! [root@xavi webapps]# mysql -uroot -pxavilinuxWarning: 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 1Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.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 -pxavilinux1Warning: 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 2Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.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]# lsadmin favicon.ico log sim.pid zrlog-1.7.1-baaecb9-releaseassets include logs temperror install META-INF WEB-INF[root@xavi www.dsf.com]# rm -rf zrlog-1.7.1-baaecb9-release[root@xavi www.dsf.com]# lsadmin error include log META-INF tempassets 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 80tcp6 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]# lsdocs log ROOT zrlog-1.7.1-baaecb9-releaseexamples logs temp zrlog-1.7.1-baaecb9-release.warhost-manager manager zrlog[root@xavi webapps]# ls ROOTasf-logo-wide.svg bg-nav.png RELEASE-NOTES.txt tomcat-power.gifbg-button.png bg-upper.png tomcat.css tomcat.svgbg-middle.png favicon.ico tomcat.gif WEB-INFbg-nav-item.png index.jsp tomcat.png
在日常运维中,Tomcat用的还是蛮多的,但是一旦出现问题,我们就需要去解决,思路就来自日志文件。
[root@xavi webapps]# ls /usr/local/tomcat/logscatalina.2018-03-31.log localhost.2018-03-31.logcatalina.out localhost_access_log.2018-03-31.txthost-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):
prefix 定义访问日志的前缀;
suffix 定义日志的后缀;
pattern 定义日志格式。
新增加的虚拟主机默认并不会生成类似默认虚拟主机的那个localhost.日期.log日志; 错误日志会统一记录到catalina.out中。
转载于:https://blog.51cto.com/12995218/2093402