首页 > 系统 > CentOS > 正文

CentOS7安装 Tomcat 8 完整步骤

2024-06-28 16:01:27
字体:
来源:转载
供稿:网友

原文:https://www.vultr.com/docs/how-to-install-apache-tomcat-8-on-centos-7

Apache Tomcat 是特别为java设计的开源WEB服务器,使用非常广泛。 以下是CentOS7中安装Tomcat 8 的步骤教程:

系统要求

1.CentOS7 2.可登陆的非root的ssh账号

Step1 升级CentOS系统

sudo yum install epel-releasesudo yum update -y && sudo reboot

Step2 安装JAVA

sudo yum install java-1.8.0-openjdk.x86_64

安装完毕后,运行java -version 将输出如下内容:

openjdk version "1.8.0_91"OpenJDK Runtime Environment (build 1.8.0_91-b14)OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

Step3 新增Tomcat专用用户

sudo groupadd tomcatsudo mkdir /opt/tomcatsudo useradd -s /bin/nologin -g tomcat -d /opt/tomcat tomcat

注意,用户目录是 /opt/tomcat

Step4 下载并安装最新版本Tomcat

cd ~wget http://www-us.apache.org/dist/tomcat/tomcat-8/v8.0.33/bin/apache-tomcat-8.0.33.tar.gzsudo tar -zxvf apache-tomcat-8.0.33.tar.gz -C /opt/tomcat --strip-components=1

Step5 权限设置

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

Step6 为Tomcat创建systemd unit 文件

sudo vi /etc/systemd/system/tomcat.service

内容如下:

[Unit]Description=Apache Tomcat Web application ContainerAfter=syslog.target network.target[Service]Type=forkingEnvironment=JAVA_HOME=/usr/lib/jvm/jreEnvironment=CATALINA_PID=/opt/tomcat/temp/tomcat.pidEnvironment=CATALINA_HOME=/opt/tomcatEnvironment=CATALINA_BASE=/opt/tomcatEnvironment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'ExecStart=/opt/tomcat/bin/startup.shExecStop=/bin/kill -15 $MAINPIDUser=tomcatGroup=tomcat[Install]WantedBy=multi-user.target

Step7 安装haveged

sudo yum install havegedsudo systemctl start haveged.servicesudo systemctl enable haveged.service

Step8 启动Tomcat 并开启防火墙

sudo systemctl start tomcat.servicesudo systemctl enable tomcat.servicesudo firewall-cmd --zone=public --permanent --add-port=8080/tcpsudo firewall-cmd --reload

访问 http://[Your-Host-IP]:8080 预览是否正常。

Step9 配置Tomcat 管理界面

sudo vi /opt/tomcat/conf/tomcat-users.xml

<tomcat-users ...>...</tomcat-users>中加入一个admin账号:

<user username="yourusername" passWord="yourpassword" roles="manager-gui,admin-gui"/>

之后重启Tomcat

sudo systemctl restart tomcat.service
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表