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

MySQL 8.0.2 offline installation and configuration method graphic tutorial

The offline installation method of MySQL_8.0.2 is...

Implementing a simple age calculator based on HTML+JS

Table of contents Preface Demonstration effect HT...

Vue implements a simple shopping cart example

This article shares the specific code of Vue to i...

5 ways to quickly remove the blank space of Inline-Block in HTML

The inline-block property value becomes very usef...

CSS container background 10 color gradient Demo (linear-gradient())

grammar background: linear-gradient(direction,col...

A comprehensive analysis of what Nginx can do

Preface This article only focuses on what Nginx c...

Detailed explanation of how to use Vue to load weather components

This article shares with you how to use Vue to lo...

Implementation of debugging code through nginx reverse proxy

background Now the company's projects are dev...

How to handle long data when displaying it in html

When displaying long data in HTML, you can cut off...

Why is there this in JS?

Table of contents 1. Demand 2. Solution 3. The fi...

Shorten the page rendering time to make the page run faster

How to shorten the page rendering time on the bro...

Simple principles for web page layout design

This article summarizes some simple principles of...

Summary of the use of Datetime and Timestamp in MySQL

Table of contents 1. How to represent the current...

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

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

How to detect if the current browser is a headless browser with JavaScript

Table of contents What is a headless browser? Why...