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

Detailed explanation of InnoDB storage files in MySQL

Physically speaking, an InnoDB table consists of ...

Detailed explanation of how Nginx works

How Nginx works Nginx consists of a core and modu...

HTML optimization techniques you must know

To improve the performance of web pages, many dev...

A detailed summary of HTML tag nesting rules suitable for beginners

I have been relearning HTML recently, which can be...

Detailed explanation of the use of vue-resource interceptors

Preface Interceptor In some modern front-end fram...

js+canvas realizes code rain effect

This article shares the specific code of js+canva...

Solve the problem of invalid utf8 settings in mysql5.6

After the green version of mysql5.6 is decompress...

Baidu Input Method opens API, claims it can be ported and used at will

The relevant person in charge of Baidu Input Metho...

Detailed explanation of Tomcat directory structure

Table of contents Directory Structure bin directo...

Implementing access control and connection restriction based on Nginx

Preface Nginx 's built-in module supports lim...

JavaScript to achieve the idea of ​​​​snake game

The implementation idea of ​​the javascript game ...

SQL Aggregation, Grouping, and Sorting

Table of contents 1. Aggregate Query 1. COUNT fun...

Display mode of elements in CSS

In CSS, element tags are divided into two categor...