在 CentOS 7 上安装 Tomcat,您需要遵循以下步骤:
sudo yum update
sudo yum install -y wget java-1.8.0-openjdk-devel
wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.56/bin/apache-tomcat-9.0.56.tar.gz
sudo tar xvf apache-tomcat-9.0.56.tar.gz
/opt
目录下:sudo mv apache-tomcat-9.0.56 /opt/tomcat
tomcat.service
的文件:sudo nano /etc/systemd/system/tomcat.service
tomcat.service
文件中,然后保存并退出:[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='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.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl start tomcat
sudo systemctl enable tomcat
http://<your_server_ip>:8080
,您应该能看到 Tomcat 的欢迎页面。请注意,您可能需要根据实际情况调整一些配置,例如更改 Java_HOME 环境变量以指向正确的 JDK 安装路径。