How to start Tomcat with JSVC (run with normal user)


JSVC introduction

In production, Tomcat should run in the mode of daemon, and if you need to start Tomcat as an ordinary user, you can’t use ports below 1024, which is the limit of Linux system. Only root can use ports less than 1024. So how to configure Tomcat as a service? We can simply encapsulate our own startup script through JSVC, and we can make Tomcat running users and groups at will, and we can also specify JVM running parameters such as memory control, language, character encoding. We can also specify that Tomcat starts pidfile. In short, we can control the operation mode of Tomcat more precisely. It has incomparable advantages over the original script.

Okay! Blowing so much, this article just wants to operate how to use ordinary users to run, I haven’t learned other!

Set permissions for Tomcat directory

Create a Tomcat user (the default is to create a Tomcat group as well)

useradd tomcat

Set the primary user of the Tomcat directory to Tomcat and the group to Tomcat

chown -R tomcat:tomcat /usr/local/tomcat/
enter description here

At this time, the displayed Tomcat root permission actually means that this soft link belongs to the root. The Tomcat directory we linked has the owner of Tomcat and – R recursively passes the permission.

Open the read permissions of all files under Tomcat to users in the group to avoid errors in startup. For example, the server.xml file cannot be read

chmod -R g+r tomcat/

Open the writable permissions of webapps, logs, work, temp directory under Tomcat to users in the group

chmod -R g+w logs/ temp/ webapps/ work/

Install JSVC

The last time I talked about deploying java + Tomcat environment, this is the follow-up of the last time.

Attached is the previous article:

JSVC is bound to Tomcat binary distribution, find the source code package, and prepare to compile into binary files.

Go to the bin directory under Tomcat to findcommons-daemon-native.tar.gz

enter description here

Extract the source code package

tar -zxvf commons-daemon-native.tar.gz

Enter the decompressed directory for compilation

cd commons-daemon-1.0.15-native-src/unix
 ./configure --with-java=$JAVA_HOME
enter description here

The above error is that GCC compilation environment is not installed

yum install gcc-c++ -y

Run it again and the following content will appear

enter description here



After compilation, a JSVC file will be generated in the current folder

enter description here

Copy it to Tomcat bin directory

cp jsvc /usr/local/tomcat/bin/

At this time, we run our Tomcat with the function of “day. Sh”

./ start

Other commands:

./ stop


The above is the introduction of using JSVC to start Tomcat (using ordinary users to run, hope to help you, if you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support of the developepaer website!
If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!