配置Tomcat监听80端口

配置Tomcat及日志_第1张图片

1.编辑配置文件:

[root@weixing01 src]# vim /usr/local/tomcat/conf/server.xml 

修改8080为80


    

2.重启服务:

[root@weixing01 src]# /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@weixing01 src]# /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.查看是否启用80端口:

[root@weixing01 src]# ps aux |grep java
root       2006 20.8  8.3 2280320 83388 pts/0   Sl   22:09   0:03 /usr/local/jdk1.8/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root       2036  0.0  0.0 112676   984 pts/0    R+   22:09   0:00 grep --color=auto java
[root@weixing01 src]# netstat -lntp |grep java
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      2006/java           
tcp6       0      0 :::8009                 :::*                    LISTEN      2006/java           
[root@weixing01 src]# netstat -lntp |grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1002/nginx: master  
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      2006/java           
tcp6       0      0 :::8009                 :::*                    LISTEN      2006/java        

4.发现被Nginx占用,关闭服务:

[root@weixing01 src]# /etc/init.d/nginx stop
Stopping nginx (via systemctl):                            [  确定  ]
[root@weixing01 src]# /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
^[[A[root@weixing01 sr/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.
[root@weixing01 src]# netstat -lntp |grep java
tcp6       0      0 :::80                   :::*                    LISTEN      2126/java           
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      2126/java           
tcp6       0      0 :::8009                 :::*                    LISTEN      2126/java   

配置Tomcat的虚拟主机

配置Tomcat及日志_第2张图片

1.编辑配置文件:

[root@weixing01 src]# vim /usr/local/tomcat/conf/server.xml 

添加一个虚拟主机


      
      
           
      

配置Tomcat及日志_第3张图片

2.下载一个war包做实验:可以自动解压缩

[root@weixing01 src]# wget http://dl.zrlog.com/release/zrlog-1.7.1-baaecb9-release.war
--2018-03-30 22:25:55--  http://dl.zrlog.com/release/zrlog-1.7.1-baaecb9-release.war
正在解析主机 dl.zrlog.com (dl.zrlog.com)... 124.193.230.185, 124.193.230.158, 124.193.230.160, ...
正在连接 dl.zrlog.com (dl.zrlog.com)|124.193.230.185|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:7122027 (6.8M) [application/zip]
正在保存至: “zrlog-1.7.1-baaecb9-release.war”

100%[===========================================================>] 7,122,027    391KB/s 用时 12s    

2018-03-30 22:26:08 (584 KB/s) - 已保存 “zrlog-1.7.1-baaecb9-release.war” [7122027/7122027])

[root@weixing01 src]# ls /usr/local/tomcat/webapps/
docs  examples  host-manager  manager  ROOT
[root@weixing01 src]# cp zrlog-1.7.1-baaecb9-release.war /usr/local/tomcat/webapps/
[root@weixing01 src]# !ls
ls /usr/local/tomcat/webapps/
docs      host-manager  ROOT                         zrlog-1.7.1-baaecb9-release.war
examples  manager       zrlog-1.7.1-baaecb9-release

3.新建一个数据库:

mysql> create database zrlog;
Query OK, 1 row affected (0.13 sec)

mysql> grant all to zrlog.* to 'zrlog'@127.0.0.1 identified by 'wei14'
    -> 
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'to zrlog.* to 'zrlog'@127.0.0.1 identified by 'wei914'' at line 1
mysql> grant all on zrlog.* to 'zrlog'@127.0.0.1 identified by 'wei914';
Query OK, 0 rows affected (0.42 sec)

4.访问网页:
配置Tomcat及日志_第4张图片

5.更换域名:使用配置文件下面的配置

[root@weixing01 webapps]# mkdir /data/wwwroot/123.cn/
[root@weixing01 webapps]# mv /usr/local/tomcat/webapps/zrlog/* /data/wwwroot/123.cn/
[root@weixing01 webapps]# /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
^R
[root@weixing01 webapps]# /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.

6.测试:

配置Tomcat及日志_第5张图片

Tomcat日志

配置Tomcat及日志_第6张图片

1.查看文件:

[root@weixing01 tomcat]# ls logs
catalina.2018-03-30.log  host-manager.2018-03-30.log  localhost_access_log.2018-03-30.txt
catalina.out             localhost.2018-03-30.log     manager.2018-03-30.log
[root@weixing01 tomcat]# 

配置Tomcat及日志_第7张图片