How to install tomcat in Linux

1. Before installing tomcat, make sure that jdk has been installed and configured on the linux machine

Enter in the command line: java -version command, as shown below, indicating that jdk has been installed

2. Create a new tomcat installation directory in the usr directory

The command is:

mkdir -p /usr/tomcat/

3. Copy or move apache-tomcat-9.0.2.tar.gz to the java directory (apache-tomcat-9.0.2.tar.gz is already in the /usr/local/tools/ directory of linux)

4. Unzip tomcat to the current directory

tar -zxvf apache-tomcat-9.0.2.tar.gz

Get the folder apache-tomcat-9.0.2

5. Add the tomcat environment variable:

Modify the application environment variables to make the configuration take effect:

6. Start the tomcat service:

Enter the bin directory:

start tomcat:

./startup.sh

7. If you cannot access the server address, it may be a problem with the server firewall. Port 8080 is blocked, so you need to open port 8080, save and restart the firewall:

[root@localhost bin]# iptables -I INPUT -p tcp --dport 8080 -j ACCEPT

[root@localhost bin]# /etc/init.d/iptables save

[root@localhost bin]# /etc/init.d/iptables restart

Re-visit the server tomcat address to access:

8. Configure tomcat account password permissions (login using the Web management interface)

Modify the configuration file tomcat-users.xml under tomcat

Add the following code:

Note: username and password are the account passwords required to log in to the tomcat management interface.

9. Tomcat configuration service:

New script:

Addition script content:

#!/bin/bash

# dcription: Tomcat9 Start Stop Restart

# processname: tomcat9

# chkconfig: 234 20 80



CATALINA_HOME=/usr/tomcat/apache-tomcat-9.0.2



case $1 in

start)

echo "Starting Tomcat..."

sh $CATALINA_HOME/bin/startup.sh

;;

stop)

echo "Stopping Tomcat..."

sh $CATALINA_HOME/bin/shutdown.sh

;;

restart)

echo "Stopping Tomcat..."

sh $CATALINA_HOME/bin/shutdown.sh

sleep 2

echo

echo "Starting Tomcat..."

sh $CATALINA_HOME/bin/startup.sh

;;

*)

echo 'please use : tomcat {start | stop | restart}'

;;

esac

exit 0

Execute scripts to start, stop and restart services.

Start: service tomcat start

Stop: service tomcat stop

Restart: service tomcat restart

When the above error is reported when the script is executed, catalina.sh and .bashrc can be executed successfully by adding the following content

Enter the bin directory of tomcat, edit the catalina.sh file, and add the following content:

export JAVA_HOME=/usr/tomcat/apache-tomcat-9.0.2 export JRE_HOME=/usr/tomcat/apache-tomcat-9.0.2/jre

Edit the .bashrc file and add the following:

set JAVA_HOME=/usr/java/jdk1.8.0_152

export JAVA_HOME

set PATH=$JAVA_HOME/bin:$PATH

export PATH

set CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

export CLASSPATH

10. Tomcat configuration starts automatically when booting:

Add management of tomcat service to chkconfig:

[root@localhost ~]# chkconfig --add tomcat

Set the tomcat service to start automatically:

[root@localhost ~]# chkconfig tomcat on

View the startup status of tomcat;

[root@localhost ~]# chkconfig --list | grep tomcat

Close the tomcat service from starting:

[root@localhost ~]# chkconfig tomcat off

Delete the management of the tomcat service on chkconfig:

[root@localhost ~]# chkconfig --del tomcat

Guess you like

Origin blog.csdn.net/m0_67392661/article/details/126434061