CentOS7 downloads a detailed tutorial on installing Tomcat 9

  • 2020-11-30 08:41:41
  • OfStack

tomcat, without further explanation, drove directly;

1. Download the installation package from the official website

Install tomcat to the /usr/local/tomcat/ directory


cd /usr/local/
mkdir tomcat/
cd tomcat/
wget http://archive.apache.org/dist/tomcat/tomcat-9/v9.0.0.M18/bin/apache-tomcat-9.0.0.M18.tar.gz

2. Unzip and execute the following command


tar -zxvf apache-tomcat-9.0.0.M18.tar.gz

3. Rename the directory


mv apache-tomcat-9.0.0.M18 tomcat_8080 (/path (Target path) )

4. Configure from startup, switch to bin directory of Tomcat to execute vi ES22en.sh, and press i to enter edit mode, copy and paste the following code


#add tomcat pid
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
#add java opts
JAVA_OPTS="-server -XX:PermSize=256M -XX:MaxPermSize=1024m -Xms512M -Xmx1024M -XX:MaxNewSize=256m"

After that, press the esc key, and press shift+ (" : "will appear in the lower left corner), and then enter wq to save and exit.

The last execution chmod +x setenv.sh  Ensure that file setenv.sh is executable.

5. Configuration service implement cd/usr/lib/systemd/system switch to the directory and execute vi tomcat. service (may also directly vi usr/lib systemd/system/tomcat service),

Copy and paste the following code (note that Tomcat path /usr/local/ ES59en-ES60en-9.0.0.es61EN18 is replaced with the absolute path of your own Tomcat)


[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/tomcat/tomcat_8080/tomcat.pid     # Set to your own path 
ExecStart=/usr/local/tomcat/tomcat_8080/bin/startup.sh  # Set to your own path 
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

Boot to boot


// Configure boot up  systemctl enable tomcat
// Start the tomcatsystemctl start tomcat
// stop tomcatsystemctl stop tomcat
// restart tomcatsystemctl restart tomcat

When the configuration is complete, it is recommended to restart the server, that is, enter the command reboot (or sudo reboot) to enter your server address +8080 port in the browser

(for example: 192.168.1.161:8080). If you see the kitten, it means success. Otherwise, please check if all the above steps are performed correctly.

Configure environment variables


vi /etc/profile

increase


export CATALINA_HOME=/usr/local/tomcat/tomcat_8080
export PATH=$TOMCAT_HOME/bin:$PATH

If you can't access it, it's probably because of a firewall


systemctl stop firewalld.service   Turn off the firewall 
cd /usr/local/tomcat/tomcat_8080/bin  Enter the tomcat The root directory 
./startup.sh  open tomcat

6. Modify the port to switch to Tomcat conf directory


cd /usr/local/tomcat/tomcat_8080/conf
// Enter the command to open the file 
vi server.xml
// The input  /8080  And press enter to search 8080  String, find the following two places 
<<Connector port="8080" protocol="HTTP/1.1"
        connectionTimeout="20000"
        redirectPort="8443" />
  <!-- A "Connector" using the shared thread pool-->
  <!--
  <Connector executor="tomcatThreadPool"
        port="8080" protocol="HTTP/1.1"
        connectionTimeout="20000"
        redirectPort="8443" />
// Press the" i "Enter edit mode, will port="8080" to port="80"
<Connector port="80" protocol="HTTP/1.1"
        connectionTimeout="20000"
        redirectPort="8443" />
  <!-- A "Connector" using the shared thread pool-->
  <!--
  <Connector executor="tomcatThreadPool"
        port="80" protocol="HTTP/1.1"
        connectionTimeout="20000"
        redirectPort="8443" />

After pressing esc, press shift+ : (the ":" will appear in the lower left corner), then enter wq to save and exit.

7. Configure gui-ES96en project deployment mode, switch to Tomcat conf directory, and enter vi tomcat-users.xml Open the file, press "i" to enter edit mode, and copy the following code to place </tomcat-users> Between the tags (note to change password and username to your own)


tar -zxvf apache-tomcat-9.0.0.M18.tar.gz
0

After pressing esc, press shift+ : (the ":" will appear in the lower left corner), then enter wq to save and exit.

Enter cd webapps/manager/ META-ES116en/to switch to the directory, enter vi ES118en.xml to open the file, press i to enter edit mode and will < /Context > Under the label of < Valve > Tag comment out


tar -zxvf apache-tomcat-9.0.0.M18.tar.gz
1

Then press esc and press shift+ : (the ":" will appear in the lower left corner), then enter wq to save and exit.

8. Restart Tomcat


tar -zxvf apache-tomcat-9.0.0.M18.tar.gz
2

Enter your server address directly in the browser, such as 192.168.1.161 (no need to enter the port number). When you see the Kitty, click manager to enter your account password to deploy your project.

conclusion


Related articles: