目 录CONTENT

文章目录

CentOS安装部署Tomcat

大T
2022-01-05 / 0 评论 / 0 点赞 / 42 阅读 / 0 字

CentOS安装部署Tomcat

一、安装tomcat

1.1下载安装

下载:

官网:https://tomcat.apache.org/download-80.cgi,这里下载tomcat8.5.73

sudo wget https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.73/bin/apache-tomcat-8.5.73.tar.gz

移动:

软件统一安装在/usr/local/下

```Plain Text sudo mkdir /usr/local/tomcat sudo cp apache-tomcat-8.5.73.tar.gz /usr/local/tomcat/

**解压:**

```Plain Text
cd /usr/local/tomcat/
sudo tar -zxvf apache-tomcat-8.5.73.tar.gz

1.2 启动

修改tomcat目录的归属

非常重要,如果不修改,启动后会报下方1.3的各类错误,最后还是要修改用户才能解决问题。

考虑:是不是应该配置一个普通非登陆的tomcat用户来进行启动。

```Plain Text sudo chown -R HautYundu123 ./apache-tomcat-8.5.73

进入bin目录并启动:

```Plain Text
cd apache-tomcat-8.5.73/bin/
./catalina.sh start  或者 ./startup.sh

1.3 报错处理

如果没有修改tomcat目录的归属用户会报下边的各种错误:

报错:

没有catalina.out的日志写权限

```Plain Text touch: cannot touch ‘/usr/local/tomcat/apache-tomcat-8.5.73/logs/catalina.out’: Permission denied /usr/local/tomcat/apache-tomcat-8.5.73/bin/catalina.sh: line 504: /usr/local/tomcat/apache-tomcat-8.5.73/logs/catalina.out: Permission denied

给logs目录赋权:

```Plain Text
sudo chmod a+rwx -R logs
重新回到bin目录启动

```Plain Text sh startup.sh

检查日志:tail -f catalina.out

报错:找不到配置文件

WARNING: Unable to load server configuration from \[/usr/local/tomcat/apache-tomcat-8.5.73/conf/server.xml\]

Dec 31, 2021 6:05:06 PM org.apache.catalina.startup.Catalina start

SEVERE: Cannot start server. Server instance is not configured.

![image](/upload/2022/01/1641344799-5f9871b921663b7.png)

执行shudown.sh也报同样的错:

java.io.FileNotFoundException: /usr/local/tomcat/apache-tomcat-8.5.73/conf/server.xml (Permission denied)

![image](/upload/2022/01/1641344801-62617a27ebec19f.png)

给bin目录下的启动脚本赋权

```Plain Text
sudo chmod u+x *.sh
重新启动仍然不行,发现进不了/conf目录

```Plain Text [HautYundu123@ecs-209186 apache-tomcat-8.5.73]$ cd conf/ -bash: cd: conf/: Permission denied

![image](/upload/2022/01/1641344801-b4bbcb733331512.png)



修改tomcat的目录权限:

sudo chown -R HautYundu123 ./apache-tomcat-8.5.73

重新启动:

../bin/catalina.sh start

检查启动日志:

tail -f catalina.out

正常启动了

![image](/upload/2022/01/1641344802-c6a81d14df06afa.png)

报这么多错的根本原因是因为Tomcat禁止以root用户启动,默认的情况下,Linux中的Tomcat都由bin目录下的catalina.sh执行,那么Tomcat的启动用户就由有权限启动Tomcat的运行命令的人。

查看tomcat是否启动和启动主

```Plain Text
ps -ef|grep tomcat
开头的即为启动主

image

0

评论区