您现在的位置是:首页 > 文章详情

Tomcat on CentOS

日期:2018-05-10点击:495

Installation and Configuration on CentOS

Requirement

Open a terminal and switch to root user.

su - yum install -y java-1.8.0 wget java -version

Create Tomcat Service Account

groupadd tomcat useradd -g tomcat -d /opt/tomcat -s /bin/nologin tomcat

Download & Setup Apache Tomcat

wget http://www-us.apache.org/dist/tomcat/tomcat-8/v8.5.20/bin/apache-tomcat-8.5.20.tar.gz tar -zxvf apache-tomcat-*.tar.gz mv apache-tomcat-8.5.20/* /opt/tomcat/ chown -R tomcat:tomcat /opt/tomcat/

Set Environment Variables

mkdir /opt/tomcat/bin/setenv.sh chmod 777 /opt/tomcat/bin/setenv.sh

Example:

export variableName=value ...

Systemd

vi /etc/systemd/system/tomcat.service

Add below information to Tomcat systemd service file.

[Unit] Description=Apache Tomcat 8.x Web Application Container Wants=network.target After=network.target [Service] Type=forking Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64/jre Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid Environment=CATALINA_HOME=/opt/tomcat Environment='CATALINA_OPTS=-Xms512M -Xmx1G -Djava.net.preferIPv4Stack=true' Environment='JAVA_OPTS=-Djava.awt.headless=true' ExecStart=/opt/tomcat/bin/startup.sh ExecStop=/opt/tomcat/bin/shutdown.sh SuccessExitStatus=143 User=tomcat Group=tomcat UMask=0007 RestartSec=10 Restart=always [Install] WantedBy=multi-user.target

Reload systemd daemon.

systemctl daemon-reload systemctl start tomcat systemctl status tomcat systemctl enable tomcat //Enable the auto start of Tomcat service on system start

Verify Apache Tomcat

By default, Tomcat runs on port no 8080. Use netstat command to check whether the service is listening on port 8080 or not.

netstat -antup | grep 8080

Output:

tcp6 0 0 :::8080 :::* LISTEN 2428/java

Firewall

You may need to allow port 8080 in the firewall so that we can access Tomcat from external networks.

firewall-cmd --permanent --add-port=8080/tcp firewall-cmd --reload
原文链接:https://yq.aliyun.com/articles/592078
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章