featured.jpg

CentOS8.0安装Tomcat9


系统配置

setenforce 0 
sed 's/SELINUX=.*/SELINUX=permissive/g' -i /etc/selinux/config
systemctl stop firewalld
systemctl disable firewalld
yum install epel-release -y
yum update -y && sudo reboot


安装JDK11

yum search java|grep jdk

20190927100915.png

yum install java-11-openjdk.x86_64 -y
java -version

20190927100952.png


安装Tomcat9

groupadd tomcat
mkdir /opt/tomcat
useradd -s /bin/nologin -g tomcat -d /opt/tomcat tomcat
cd /opt
wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.26/bin/apache-tomcat-9.0.26.tar.gz
tar -zxvf apache-tomcat-9.0.26.tar.gz -C /opt/tomcat --strip-components=1


配置权限

cd /opt/tomcat
chgrp -R tomcat conf
chmod g+rwx conf
chmod g+r conf/*
chown -R tomcat logs/ temp/ webapps/ work/

chgrp -R tomcat bin
chgrp -R tomcat lib
chmod g+rwx bin
chmod g+r bin/*


添加服务

vim /etc/systemd/system/tomcat.service
添加
[Unit]
Description=Tomcat 9 servlet container
After=network.target

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/jre"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"

Environment="CATALINA_BASE=/opt/tomcat/"
Environment="CATALINA_HOME=/opt/tomcat/"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

[Install]
WantedBy=multi-user.target

20190927101047.png


安装haveged

yum install haveged -y
systemctl start haveged.service
systemctl enable haveged.service


开启服务

systemctl daemon-reload
systemctl enable tomcat
systemctl start tomcat
systemctl status tomcat

20190927101835.png


配置Tomcat Web Management Interface

vim /opt/tomcat/conf/tomcat-users.xml
找到
<tomcat-users>
    <user username="用户名" password="密码" roles="manager-gui,admin-gui"/>
</tomcat-users>

20190927102502.png


vim /opt/tomcat/webapps/manager/META-INF/context.xml
改为
<Context antiResourceLocking="false" privileged="true" >
<!--
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->
</Context>

20190927100502.png


vim /opt/tomcat/webapps/host-manager/META-INF/context.xml
改为
<Context antiResourceLocking="false" privileged="true" >
<!--
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->
</Context>

20190927100556.png


重启服务

systemctl restart tomcat.service


测试

http://IP:8080

20190927095442.png


http://IP:8080/manager/html

20190927100633.png


http://IP:8080/host-manager/html/

20190927100658.png


更新日期: 2019年09月27日
文章标签: Linux
文章链接: https://www.vos.cn/os/355.html  
版权说明:如非注明,本站文章均为vOS原创,转载请注明出处和附带本文链接。