1,准备工作:

JKD:jdk-7u72-Linux-x64.gz

Tomcat:apache-tomcat-7.0.70.tar.gz

OS:CentOS linux release 7.2.1511 (Core)

2,安装jdk

A,解压jdk在 /usr/ 目录下

B, root用户配置全局环境变量,

[plain] view plain copy

  1. vi /etc/profile
  2. 追加以下内容
  3. export JAVA_HOME=/usr/jdk1.7.0_72
  4. export PATH=$JAVA_HOME/bin:$PATH
  5. export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  6. 生效:source /etc/profile

3,安装tomcat7

A,解压tomcat至 /usr/目录下

B,在/usr/lib/systemd/system/目录下新建文件tomcat7.service,内容如下:

[html] view plain copy

  1. [Unit]
  2. Description=Tomcat7
  3. After=syslog.target network.target remote-fs.target nss-lookup.target
  4. [Service]
  5. Type=forking
  6. Environment=‘JAVA_HOME=/usr/jdk1.7.0_72’
  7. Environment=‘CATALINA_PID=/usr/apache-tomcat-7.0.70/bin/tomcat.pid’
  8. Environment=‘CATALINA_HOME=/usr/apache-tomcat-7.0.70/’
  9. Environment=‘CATALINA_BASE=/usr/apache-tomcat-7.0.70/’
  10. Environment=‘CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC’
  11. WorkingDirectory=/usr/apache-tomcat-7.0.70/
  12. ExecStart=/usr/apache-tomcat-7.0.70/bin/startup.sh
  13. ExecReload=/bin/kill -s HUP $MAINPID
  14. ExecStop=/bin/kill -s QUIT $MAINPID
  15. PrivateTmp=true
  16. [Install]
  17. WantedBy=multi-user.target

 

C,设置为开启机启动:systemctl enable tomcat7

4,启停服务

A,启动服务:systemctl start tomcat7

B,停止服务:systemctl stop tomcat7

C,重启服务:systemctl restart tomcat7

检查状态:systemctl status tomcat7

运行的状态:

[plain] view plain copy

  1. [root@localhost merrick]# systemctl status tomcat7
  2. ● tomcat7.service – Tomcat7
  3.    Loaded: loaded (/usr/lib/systemd/system/tomcat7.service; disabled; vendor preset: disabled)
  4.    Active: active (running) since 四 2016-09-08 11:34:16 CST; 17min ago
  5.   Process: 3231 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=0/SUCCESS)
  6.   Process: 3239 ExecStart=/usr/apache-tomcat-7.0.70/bin/startup.sh (code=exited, status=0/SUCCESS)
  7.  Main PID: 3249 (java)
  8.    CGroup: /system.slice/tomcat7.service
  9.            └─3249 /usr/jdk1.7.0_72/bin/java -Djava.util.logging.config.file=/usr/apache-tomcat-7.0.70//conf/logging.properties -D…
  10. 9月 08 11:34:16 localhost.localdomain startup.sh[3239]: Using CATALINA_BASE:   /usr/apache-tomcat-7.0.70/
  11. 9月 08 11:34:16 localhost.localdomain startup.sh[3239]: Using CATALINA_HOME:   /usr/apache-tomcat-7.0.70/
  12. 9月 08 11:34:16 localhost.localdomain startup.sh[3239]: Using CATALINA_TMPDIR: /usr/apache-tomcat-7.0.70//temp
  13. 9月 08 11:34:16 localhost.localdomain startup.sh[3239]: Using JRE_HOME:        /usr/jdk1.7.0_72
  14. 9月 08 11:34:16 localhost.localdomain startup.sh[3239]: Using CLASSPATH:       /usr/apache-tomcat-7.0.70//bin/bootstrap.jar…i.jar
  15. 9月 08 11:34:16 localhost.localdomain startup.sh[3239]: Using CATALINA_PID:    /usr/apache-tomcat-7.0.70/bin/tomcat.pid
  16. 9月 08 11:34:16 localhost.localdomain startup.sh[3239]: Existing PID file found during start.
  17. 9月 08 11:34:16 localhost.localdomain startup.sh[3239]: Removing/clearing stale PID file.
  18. 9月 08 11:34:16 localhost.localdomain startup.sh[3239]: Tomcat started.
  19. 9月 08 11:34:16 localhost.localdomain systemd[1]: Started Tomcat7.
  20. Hint: Some lines were ellipsized, use -l to show in full.

 

5,测试服务

浏览器中输入 : http://ip:8080/

检查服务器能正确响应。

或者终端命令行输入: wget htp://localhost:8080/

正常响应:

[plain] view plain copy

  1. [root@localhost merrick]# wget http://localhost:8080/
  2. –2016-09-08 11:54:47–  http://localhost:8080/
  3. 正在解析主机 localhost (localhost)… ::1, 127.0.0.1
  4. 正在连接 localhost (localhost)|::1|:8080… 已连接。
  5. 已发出 HTTP 请求,正在等待回应… 200 OK
  6. 长度:未指定 [text/html]
  7. 正在保存至: “index.html”
  8.     [ <=>                                                                                       ] 11,197      –.-K/s 用时 0s
  9. 2016-09-08 11:54:47 (245 MB/s) – “index.html” 已保存 [11197]

Leave a Reply

Your email address will not be published. Required fields are marked *