Tomcat 8 daemon settings in CentOS 7

Source: Internet
Author: User
Tags syslog apache tomcat

Tomcat 8 is set in the Chszs of the CentOS 7 daemon and must be reproduced. Blog home: http://blog.csdn.net/chszs1, build Jsvc

JSVC is a toolkit developed specifically for Java applications, and the goal is to convert the normal run of Java applications to run as a UNIX daemon. This makes it easy to start/stop the application. The bin subdirectory of the Tomcat installation package contains the source code for the JSVC Toolkit, which is easy to build, as follows.

The script in this article takes Tomcat 8.0.27,centos 7 as an example. Suppose my Java 8 is installed at/OPT/JDK8.

$ cd /opt/tomcat8/bin$ sudo tar zvxf commons-daemon-native.tar.gz$ cd commons-daemon-1.0.15-native-src/unix$ sudo ./configure --with-java=/opt/jdk8$ sudo make$ sudo cp jsvc ../..
2. Create a Tomcat user

The following command creates a dedicated user to run the Tomcat instance and assigns ownership of the/opt/tomcat directory and its files to the newly created Tomcat user.

$ sudo useradd -r -s /sbin/nologin tomcat$ sudo chown -R tomcat: /opt/tomcat8
3. Create a system service

In the case of a centos system (e.g. CentOS 7), follow the steps below.

1) Create a system service script named Tomcat.service.

# vim /usr/lib/systemd/system/tomcat.service

2) Add the following:

  [Unit]description=apache Tomcat 8 WEB Application containerafter=network.target[service]type= forkingpidfile=/var/run/tomcat.pidenvironment=catalina_pid=/var/run/tomcat.pidenvironment=java_home=/opt/ jdk8environment=catalina_home=/opt/tomcat8environment=catalina_base=/opt/tomcat8environment=catalina_opts=             Execstart=/opt/tomcat/bin/jsvc-dcatalina.home=${catalina_home}-dcatalina.base=${catalina_base} -CP ${catalina_home}/bin/commons-daemon.jar:${catalina_home}/bin/bootstrap.jar:${catalina_home}/bin/tomcat-juli . Jar-user Tomcat-java-home ${java_home}-pidfile/var/run/tomcat.pid-er Rfile syslog-outfile SYSLOG $CATALINA _opts Org.apache.catalina.startup.BootstrapExecS Top=/opt/tomcat8/bin/jsvc-pidfile/var/run/tomcat.pid-stop Org.apache.catalina.start Up. Bootstrap[install]wantedby=multi-user.target  

Developers can modify the catalina_opts option to suit their needs.

3) Let the Tomcat service run automatically after it starts:

$ sudo systemctl enable /usr/lib/systemd/tomcat.serviceln -s ‘/usr/lib/systemd/tomcat.service‘ ‘/etc/systemd/system/multi-user.target.wants/tomcat.service‘ln -s ‘/usr/lib/systemd/tomcat.service‘ ‘/etc/systemd/system/tomcat.service‘

4) Use the following command to start, restart, and stop the Tomcat service

$ systemctl start tomcat$ systemctl stop tomcat$ systemctl restart tomcat$ systemctl status tomcat
4. Firewall settings

Firewall Open port 8080

$ firewall-cmd --zone=public --add-port=8080/tcp --permanent$ firewall-cmd --reload

Copyright NOTICE: This article for Bo Master Chszs original article, without Bo Master permission not reproduced.

Tomcat 8 daemon settings in CentOS 7

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.