How to start tomcat using jsvc (run as a normal user)

How to start tomcat using jsvc (run as a normal user)

Introduction to jsvc

In production, Tomcat should run in daemon mode, and if you need to start Tomcat as a normal user, you cannot use ports below 1024. This is a limitation of the Liunx system. Only the root user can use ports less than 1024. So how do you configure tomcat as a service? We can easily encapsulate our own startup scripts through jsvc, and we can also arbitrarily set the tomcat running user and group, and specify the jvm running parameters such as memory control, language, and character encoding. We can also specify the pidfile that tomcat starts with. In short, we can have more precise control over how tomcat runs. It has incomparable advantages over the original script.

alright! After talking so much, I just want to explain in this article how to run it as a normal user. I haven’t learned the other things yet!

Set the permissions for the Tomcat directory

Create a tomcat user (by default, a tomcat group is also created)

useradd tomcat

Set the owner user of the tomcat directory to tomcat and the group to tomcat group

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

The tomcat root permission displayed at this time actually means that this soft link belongs to root. The tomcat directory we linked to is already owned by tomcat and -R recursively passes permissions.

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

chmod -R g+r tomcat/

Open writable permissions for the webapps, logs, work, and temp directories under Tomcat to users in the group

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

Install jsvc

I have already talked about deploying Java+Tomcat environment last time, this article is a follow-up to the last one.

Attached is the previous article: https://www.jb51.net/article/160936.htm

jsvc is bound to the tomcat binary distribution, finds the source code package, and is ready to compile into a binary file.

Enter the bin directory under tomcat and find commons-daemon-native.tar.gz

enter description here

Unzip the source code package

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

Enter the unzipped directory and compile

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

The above error occurs because the gcc compilation environment is not installed

yum install gcc-c++ -y

Run it again and the following content will appear

enter description here

Compile

make

After compilation is complete, a jsvc file will be generated in the current folder

enter description here

Copy it to the tomcat bin directory

cp jsvc /usr/local/tomcat/bin/

At this time we use daemon.sh to run our tomcat

./daemon.sh start

Other commands:

./daemon.sh stop

Summarize

The above is the introduction of using jsvc to start tomcat (run as a normal user). I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. Thank you very much for your support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

<<:  MySQL case when group by example

>>:  How to monitor array changes in Vue

Recommend

Vue virtual Dom to real Dom conversion

There is another tree structure Javascript object...

CSS3 radar scan map sample code

Use CSS3 to achieve cool radar scanning pictures:...

Two ways to implement HTML page click download file

1. Use the <a> tag to complete <a href=&...

JavaScript uses canvas to draw coordinates and lines

This article shares the specific code of using ca...

VMware configuration hadoop to achieve pseudo-distributed graphic tutorial

1. Experimental Environment serial number project...

Docker Gitlab+Jenkins+Harbor builds a persistent platform operation

CI/CD Overview CI workflow design Git code versio...

Detailed description of HTML table border control

Only show the top border <table frame=above>...

Customization Method of Linux Peripheral File System

Preface Generally speaking, when we talk about Li...

Vue-cli creates a project and analyzes the project structure

Table of contents 1. Enter a directory and create...

Quickly install MySQL5.7 compressed package on Windows

This article shares with you how to install the M...

Tomcat class loader implementation method and example code

Tomcat defines multiple ClassLoaders internally s...

Comparison of the efficiency of different methods of deleting files in Linux

Test the efficiency of deleting a large number of...

iframe adaptive size implementation code

Page domain relationship: The main page a.html bel...

Example of implementing colored progress bar animation using CSS3

Brief Tutorial This is a CSS3 color progress bar ...