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

How to set up jar application startup on CentOS7

Pitfalls encountered during project deployment Wh...

Beginner's guide to building a website ⑥: Detailed usage of FlashFXP

Today I will introduce the most basic functions of...

MySQL briefly understands how "order by" works

For sorting, order by is a keyword we use very fr...

Tutorial on installing mysql8 on linux centos7

1. RPM version installation Check if there are ot...

Implementing image fragmentation loading function based on HTML code

Today we will implement a fragmented image loadin...

A brief discussion on the font settings in web pages

Setting the font for the entire site has always b...

Pitfalls based on MySQL default sorting rules

The default varchar type in MySQL is case insensi...

Docker image import and export code examples

Import and export of Docker images This article i...

Use of Vue3 table component

Table of contents 1. Ant Design Vue 1. Official w...

Installation process of zabbix-agent on Kylin V10

1. Download the installation package Download add...

Simple usage example of MySQL 8.0 recursive query

Preface This article uses the new features of MyS...

Common pitfalls of using React Hooks

React Hooks is a new feature introduced in React ...

What does the n after int(n) in MySQL mean?

You may already know that the length 1 of int(1) ...