How to install Tomcat9 on CentOS7

Source: Internet
Author: User
Tags chmod config create directory gz file mkdir socket port number tomcat

Install the Tomcat9 on the CentOS7

1 Connect to Aliyun CentOS7 server via SECURECRT;

2 Go to directory/usr/local/:

cd/usr/local/

3 Create directory/usr/local/tools, if any, ignore:

Mkdir-p Tools

4 Create the/usr/local/tomcat directory and ignore if it already exists:

Mkdir-p Tomcat

5 Go to directory/usr/local/tools:

CD tools/

6 Download apache-tomcat-9.0.0.m4.tar.gz File:

wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-9/v9.0.0.M4/bin/apache-tomcat-9.0.0.M4.tar.gz

7 Decompression apache-tomcat-9.0.0.m4.tar.gz:

TAR-ZXVF apache-tomcat-9.0.0.m4.tar.gz

8 Copy the extracted APACHE-TOMCAT-9.0.0.M4 files to the/usr/local/tomcat directory:

MV Apache-tomcat-9.0.0.m4. /tomcat/

9 Open the profile file under the/etc directory:

Vim/etc/profile

Append the following code to the end of the profile file:

# idea-tomcat9 Config start-2016-05-01

Catalina_home=/usr/local/tomcat/apache-tomcat-9.0.0.m4

Catalina_base=/usr/local/tomcat/apache-tomcat-9.0.0.m4

Path= $PATH: $CATALINA _base/bin

Export PATH catalina_base

# idea-tomcat9 Config end-2016-05-01

Maintain and launch: wq!

10 Modify Tomcat's port number and character encoding:

Enter into the/usr/local/tomcat/apache-tomcat-9.0.0.m4/conf directory:

Cd.. /tomcat/apache-tomcat-9.0.0.m4/conf

Open the configuration file for the Tomcat service Server.xml:

VI Server.xml

Locate the following code:

Change the 8080 to the default port 80 of the HTTP protocol and change the following code:

11 increase the access rights of the Manager-gui graphical management interface (This step can be ignored if not required):

Open the Tomcat user profile Tomcat-users.xml:

VI Tomcat-users.xml

Add the following code before the label:

The username and password are all password and the role is Manager-gui;

Type ESC and enter ": wq!" Maintain and exit;

12 into the/usr/local/tomcat/apache-tomcat-9.0.0.m4/bin directory:

Cd.. /bin/

13 Open VI catalina.sh file:

In # OS specific support. Before you add the following code:

java_home=/usr/local/jdk/jdk1.8.0_91

Jre_home= $JAVA _home/jre

Type ESC and enter ": wq!" Maintain and exit;

14 Start Tomcat Service:

./startup.sh

Printing the following information indicates the success of starting the Tomcat service:

Using catalina_base:/USR/LOCAL/TOMCAT/APACHE-TOMCAT-9.0.0.M4

Using Catalina_home:/USR/LOCAL/TOMCAT/APACHE-TOMCAT-9.0.0.M4

Using Catalina_tmpdir:/usr/local/tomcat/apache-tomcat-9.0.0.m4/temp

Using Jre_home:/usr/local/jdk/jdk1.8.0_91/jre

Using CLASSPATH:/usr/local/tomcat/apache-tomcat-9.0.0.m4/bin/bootstrap.jar:/usr/local/tomcat/ Apache-tomcat-9.0.0.m4/bin/tomcat-juli.jar

Tomcat started.

Open the browser to enter the IP address look at it! If our cute "little yellow cat" comes out, we have Tomcat service!

15 Turn off the Tomcat service:

./shutdown.sh

Printing the following information indicates that the TOMCAT service was turned off successfully:

Using catalina_base:/USR/LOCAL/TOMCAT/APACHE-TOMCAT-9.0.0.M4

Using Catalina_home:/USR/LOCAL/TOMCAT/APACHE-TOMCAT-9.0.0.M4

Using Catalina_tmpdir:/usr/local/tomcat/apache-tomcat-9.0.0.m4/temp

Using Jre_home:/usr/local/jdk/jdk1.8.0_91/jre

Using CLASSPATH:/usr/local/tomcat/apache-tomcat-9.0.0.m4/bin/bootstrap.jar:/usr/local/tomcat/ Apache-tomcat-9.0.0.m4/bin/tomcat-juli.jar

Note: You cannot perform multiple./shutdown.sh commands repeatedly, and then report the following errors:

SEVERE:Catalina.stop:

Java.net.ConnectException:Connection refused

At Java.net.PlainSocketImpl.socketConnect (Native method)

At Java.net.AbstractPlainSocketImpl.doConnect (abstractplainsocketimpl.java:350)

At Java.net.AbstractPlainSocketImpl.connectToAddress (abstractplainsocketimpl.java:206)

At Java.net.AbstractPlainSocketImpl.connect (abstractplainsocketimpl.java:188)

At Java.net.SocksSocketImpl.connect (sockssocketimpl.java:392)

At Java.net.Socket.connect (socket.java:589)

At Java.net.Socket.connect (socket.java:538)

At Java.net.Socket. (socket.java:434)

At Java.net.Socket. (socket.java:211)

At Org.apache.catalina.startup.Catalina.stopServer (catalina.java:476)

At Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native method)

At Sun.reflect.NativeMethodAccessorImpl.invoke (nativemethodaccessorimpl.java:62)

At Sun.reflect.DelegatingMethodAccessorImpl.invoke (delegatingmethodaccessorimpl.java:43)

At Java.lang.reflect.Method.invoke (method.java:498)

At Org.apache.catalina.startup.Bootstrap.stopServer (bootstrap.java:408)

At Org.apache.catalina.startup.Bootstrap.main (bootstrap.java:497)

16 Add Tomcat9 to the list of system services:

Enter into the/ETC/INIT.D directory:

Cd/etc/init.d

To create a TOMCAT9 service profile:

VI Tomcat9

Write the following code into the TOMCAT9 configuration file:

# idea-tomcat Config start-2016-05-01

#!/bin/bash

# description:tomcat Start Stop Restart

# Processname:tomcat

# chkconfig:2345 20 80

java_home=/usr/local/tomcat/apache-tomcat-9.0.0.m4/

Export Java_home

Path= $JAVA _home/bin: $PATH

Export PATH

catalina_home=/usr/local/tomcat/apache-tomcat-9.0.0.m4/

Case is in

Start

SH $CATALINA _home/bin/startup.sh

;;

Stop

SH $CATALINA _home/bin/shutdown.sh

;;

Restart)

SH $CATALINA _home/bin/shutdown.sh

SH $CATALINA _home/bin/startup.sh

;;

Esac

Exit 0

#chmod 755 Tomcat

#chkconfig--add Tomcat

#chkconfig--level 2345 Tomcat on

#chkconfig--list Tomcat

# idea-tomcat Config end-2016-05-01

Type ESC and enter ": wq!" Maintain and exit;

The point of attention is to set the Java_home and catalina_home variables into a path consistent with our current configuration;

17 Assigning executable permissions to Tomcat9:

chmod +x Tomcat9

18 incorporating TOMCAT9 into the system's list of services, that is, adding tomcat9 to the system service:

Chkconfig--add Tomcat9

19 See what the current system services are:

Chkconfig--list

You can also view the specified system services, as here we specify Tomcat9 this service:

Chkconfig--list Tomcat9

Print the following information:

Tomcat9 0:off 1:off 2:on 3:on 4:on 5:on 6:off

Indicates that the TOMCAT9 has been set to the system service and that 2, 3, 4, 5 are all on representations that can be started automatically with the system;

20 we can perform the shutdown, start, restart Tomcat9 service in any directory:

20.1 Close Tomcat9 Service:

Service Tomcat9 Stop

20.2 Start Tomcat9 Service:

Service Tomcat9 Start

20.3 Restart Tomcat9 Service:

Service Tomcat9 Restart

Postscript:

The/etc directory in the Linux system represents the "device", meaning the information related to the hardware device;

The files in the/ETC/INIT.D directory represent the initialization configuration information for the current device;

Command chkconfig means Add (--add), delete (--del), view (--list) system services;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.