Install Tomcat9 on CentOS7

6 Download the 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 解 压缩 apache-tomcat-9.0.0.M4.tar.gz :
 tar -zxvf apache-tomcat-9.0.0.M4.tar.gz

8 Copy the apache-tomcat-9.0.0.M4 file obtained by decompression to the /usr/local/tomcat directory:
 mv apache-tomcat-9.0.0.M4 ../tomcat/

9 Open the profile file in the file /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
 hold and launch: wq!

10 Modify the port number and character encoding of tomcat:
 go to 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 server.xml of the tomcat service:
  vi server.xml
 find the following code:
  <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
 Change 8080 to The default port of HTTP protocol is 80. The modified code is as follows:
  <Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" />

11 Increase the access rights of the manager-gui graphical management interface (if not needed, this step can be ignored):
 Open the tomcat user configuration file tomcat-users.xml: 
  vi tomcat-users.xml
 before the </tomcat-users> tag Add the following code:
  <user username="tomcat" password="tomcat" roles="manager-gui"/>
 The username and password set here are both tomcat and the role is manager-gui;
 type Esc and enter ":wq!" hold and exit;

12 Go to the /usr/local/tomcat/apache-tomcat-9.0.0.M4/bin directory:
 cd ../bin/

13 Open the vi catalina.sh file:
 add the following code in front of # OS specific support.:
  JAVA_HOME=/usr/local/jdk/jdk1.8.0_91
  JRE_HOME=$JAVA_HOME/jre
 Type Esc and type “:wq!” to keep and exit ;

14 启动 tomcat 服务:
 ./startup.sh
 打印如下信息则表明启动 Tomcat 服务成功:
  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.
 打开浏览器输入 IP 地址看看吧!如果出现了我们的可爱的“小黄猫”则表明我们的 Tomcat 已提供服务啦!

15 关闭 tomcat 服务:
 ./shutdown.sh 
 打印如下信息则表明关闭 Tomcat 服务成功:
  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
 注意:不可连续执行多次 ./shutdown.sh 命令,多次后报如下错误:
  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.<init>(Socket.java:434)
   at java.net.Socket.<init>(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 开机启动

vi /lib/systemd/ system /tomcat.service
复制:
[Unit]
Description=tomcat
After=network.target
  
[Service]
Type=forking
ExecStart=/usr/local/tomcat/bin/startup.sh
PrivateTmp= true
  
[Install]
WantedBy=multi-user.target
 
保存完毕后
systemctl enable tomcat.service


 命令 chkconfig 表示添加(--add)、删除(--del)、查看(--list)系统服务;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326314284&siteId=291194637