Tomcat更改默认端口为80
更改的配置文件是: /usr/local/tomcat/conf/server.xml
[root@test-a ~]# vim /usr/local/tomcat/conf/server.xml # 找到 Connector port="8080" protocol="HTTP/1.1"修改为Connector port="80"
[root@test-a ~]#
[root@test-a ~]# netstat -ntlp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1711/nginx: master
[root@test-a ~]# /etc/init.d/nginx stop
Stopping nginx (via systemctl): [ OK ]
[root@test-a ~]#
[root@test-a ~]# netstat -ntlp | grep 80
[root@test-a ~]# /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@test-a ~]#
[root@test-a ~]# netstat -ntlp | grep 80
tcp6 0 0 :::8009 :::* LISTEN 2668/java
tcp6 0 0 :::80 :::* LISTEN 2668/java
[root@test-a ~]#
CentOS通过Tomcat安装zrlog博客系统
- vim /usr/local/tomcat/conf/server.xml
其中<Host>和</Host>之间的配置为虚拟主机配置部分,name定义域名, appBase定义应用的目录,Java的应用通常是一个war的压缩包,只需要将war的压缩包放到appBase目录下面即可
[root@test-a src]# wget http://dl.zrlog.com/release/zrlog-1.7.1-baaecb9-release.war
--2018-12-14 08:54:46-- http://dl.zrlog.com/release/zrlog-1.7.1-baaecb9-release.war
Resolving dl.zrlog.com (dl.zrlog.com)... 124.193.230.187, 124.202.188.152, 124.202.188.151, ...
Connecting to dl.zrlog.com (dl.zrlog.com)|124.193.230.187|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7122027 (6.8M) [application/zip]
Saving to: ‘zrlog-1.7.1-baaecb9-release.war’
100%[================================================================================>] 7,122,027 2.52MB/s in 2.7s
2018-12-14 08:54:54 (2.52 MB/s) - ‘zrlog-1.7.1-baaecb9-release.war’ saved [7122027/7122027]
[root@test-a src]# cp zrlog-1.7.1-baaecb9-release.war /usr/local/tomcat/webapps/
[root@test-a src]# ls /usr/local/tomcat/webapps/ # 可以看到war包被自动解压了
docs examples host-manager manager ROOT zrlog-1.7.1-baaecb9-release zrlog-1.7.1-baaecb9-release.war
[root@test-a src]#
[root@test-a src]# mv /usr/local/tomcat/webapps/zrlog-1.7.1-baaecb9-release /usr/local/tomcat/webapps/zrlog # 重命名
[root@test-a src]# ls /usr/local/tomcat/webapps/
docs examples host-manager manager ROOT zrlog zrlog-1.7.1-baaecb9-release.war
[root@test-a src]#
[root@test-a src]# ls /usr/local/tomcat/webapps/ # 重命名后,又会自动解压war包
docs examples host-manager manager ROOT zrlog zrlog-1.7.1-baaecb9-release zrlog-1.7.1-baaecb9-release.war
[root@test-a src]# rm /usr/local/tomcat/webapps/zrlog-1.7.1-baaecb9-release.war
rm: remove regular file ‘/usr/local/tomcat/webapps/zrlog-1.7.1-baaecb9-release.war’? y
[root@test-a src]# ls /usr/local/tomcat/webapps/ # 删除war包也会自动删除对应解压的目录
docs examples host-manager manager ROOT zrlog
[root@test-a src]#
[root@test-a src]# systemctl stop firewalld.service # 关闭防火墙进行访问测试
访问测试,进入安装页面
需要创建对应的数据库及用户
[root@test-a src]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.23 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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.04 sec)
mysql> grant all on zrlog.* to zrlog identified by 'test111';
Query OK, 0 rows affected, 1 warning (0.10 sec)
mysql> quit
Bye
[root@test-a src]# mysql -uzrlog -p # 测试用新用户登录
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.7.23 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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> quit
Bye
填入mysql用户名和密码后下一步
填入管理员的用户名密码后完成安装
进入主页,说明安装成功
Tomcat配置虚拟主机
-
vim /usr/local/tomcat/conf/server.xml
其中<Host>和</Host>之间的配置为虚拟主机配置部分,name定义域名, appBase定义应用的目录,Java的应用通常是一个war的压缩包,只需要将war的压缩包放到appBase目录下面即可 -
增加虚拟主机,编辑server.xml,在</Host>下面增加如下内容
<Host name="www.666.cn" appBase="" unpackWARs= "true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="/data/wwwroot/666.cn/" debug="0" reloadable="true" crossContext="true"/>
</Host>
- docBase,这个参数用来定义网站的文件存放路径,如果不定义,默认是在appBase/ROOT下面,定义了docBase就以该目录为主了,其中appBase和docBase可以一样。
appBase为应用存放目录,通常是需要把war包直接放到该目录下面,它会自动解压成一个程序目录
[root@test-a src]# vim /usr/local/tomcat/conf/server.xml # 添加虚拟主机配置
[root@test-a ~]# mkdir /data/wwwroot/666.cn # 创建新站目录
[root@test-a ~]# mv /usr/local/tomcat/webapps/zrlog/* /data/wwwroot/666.cn/ # 把之前安装的zrlog所有文件移到虚拟站点
# 重新启动
[root@test-a 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@test-a 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.
修改hosts指定www.666.cn的ip为192.168.77.134后访问:
Tomcat 日志
- 路径 /usr/local/tomcat/logs
- 其中catalina开头的日志为Tomcat的综合日志,它记录Tomcat服务相关信息,也会记录错误日志。
- catalina.2017-xx-xx.log和catalina.out内容相同,前者会每天生成一个新的日志。
- host-manager和manager为管理相关的日志,其中host-manager为虚拟主机的管理日志。
- localhost和localhost_access为虚拟主机相关日志,其中带access字样的日志为访问日志,不带access字样的为默认虚拟主机的错误日志。
- 访问日志默认不会生成,需要在server.xml中配置一下。
- 具体方法是在对应虚拟主机的<Host></Host>里面加入下面的配置(假如域名为666.cn):
-
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="666.cn_access" suffix=".log" pattern="%h %l %u %t %r %s %b" />
- prefix定义访问日志的前缀,suffix定义日志的后缀,pattern定义日志格式。新增加的虚拟主机默认并不会生成类似默认虚拟主机的那个localhost.日期.log日志,错误日志会统一记录到catalina.out中。关于Tomcat日志你最需要关注catalina.out,当出现问题时,应该第一想到去查看它。
转载于:https://my.oschina.net/u/996931/blog/2988307