跳转至

CentOS 7 部署 Tomcat9


2016-09-21 by dongnan

环境描述

java环境

# 安装jdk
yum install java java-1.8.0-openjdk-devel

# 版本
java -version
openjdk version "1.8.0_101"
OpenJDK Runtime Environment (build 1.8.0_101-b13)
OpenJDK 64-Bit Server VM (build 25.101-b13, mixed mode)

操作步骤

部署 tomcat

# 软件包
wget -c http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.0.M9/bin/apache-tomcat-9.0.0.M9.tar.gz
wget -c https://www.apache.org/dist/tomcat/tomcat-9/v9.0.0.M9/bin/apache-tomcat-9.0.0.M9.tar.gz.md5

# 校验
md5sum -c apache-tomcat-9.0.0.M9.tar.gz.md5
apache-tomcat-9.0.0.M9.tar.gz: OK

# 目录
tar zxf apache-tomcat-9.0.0.M9.tar.gz
mv apache-tomcat-9.0.0.M9 /usr/local/tomcat

配置 tomcat

环境变量

# 类似如下输出
tail -n2 /etc/profile

export JAVA_HOME='/usr/lib/jvm/jre'
export CATALINA_HOME='/usr/local/tomcat'

立即生效

source /etc/profile

启动 tomcat

/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/lib/jvm/jre
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.

验证

# tomcat 默认使用 8080端口
lsof -i :8080
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
java    12694 root   44u  IPv6  25460      0t0  TCP *:webcache (LISTEN)

扩展:配置 webui 权限

配置文件 tomcat-users.xml

# 命令行执行
tail -n3 tomcat-users.xml

<role rolename="manager-gui"/>
<user username="admin" password="dongnan" roles="manager-gui"/>
</tomcat-users>

配置文件 manager.xml

# 命令行执行
cat Catalina/localhost/manager.xml

<Context privileged="true" antiResourceLocking="false"
docBase="${catalina.home}/webapps/manager">
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
</Context>

重启服务器

/usr/local/tomcat/bin/shutdown.sh
/usr/local/tomcat/bin/startup.sh

登录

参考

回到页面顶部