测试环境搭建踩坑记录—Tomcat添加到chkconfig
tomcat的启动和停止,一般要在安装目录/bin下执行 相关命令,比较麻烦。
./startup -----启动tomcat
./shutdown -----停止tomcat
可以将tomcat添加到linux系统服务,然后就可以通过 service tomcat start/stop来启动和停止tomcat了。
操作步骤:
-
将tomcat bin目录下的 catalina.sh文件拷贝到 /etc/init.d目录下,并重命名为tomcat。
[root@localhost tomcat]# cd bin [root@localhost bin]# ll total 892 -rw-r-----. 1 root root 36659 Jan 10 16:09 bootstrap.jar -rw-r-----. 1 root root 16840 Jan 10 16:09 catalina.bat [root@localhost bin]# mv catalina.sh /etc/init.d/tomcat [root@localhost bin]# cd /etc/init.d/ [root@localhost init.d]# ll total 68 -rw-r--r--. 1 root root 18281 Aug 24 2018 functions -rwxr-xr-x. 1 root root 4569 Aug 24 2018 netconsole -rwxr-xr-x. 1 root root 7923 Aug 24 2018 network -rw-r--r--. 1 root root 1160 Oct 30 2018 README -rwxr-x---. 1 root root 25294 Jan 10 16:09 tomcat
-
编辑tomcat文件,在文件中加入:
chkconfig: 2345 80 90 --2345是默认启动级别,80是启动优先级,90是停止优先级
CATALINA_HOME=/usr/local/tomcat/tomcat --tomcat安装目录
JAVA_HOME=/usr/local/jdk/jdk1.8.0_211 --jdk安装目录tips:注意chkconfig:2345 80 90 这一行前面有#,且检查chkfonfig拼写是否正确,否则可能会出现:
[root@localhost init.d]# chkconfig --add tomcat service tomcat does not support chkconfig
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-OGmNQsVq-1690425110172)(C:\Users\DELL\AppData\Roaming\Typora\typora-user-images\image-20230509130331913.png)]
-
给tomcat文件添加可执行权限
[root@localhost init.d]# chmod 755 tomcat [root@localhost init.d]# ll total 68 -rw-r--r--. 1 root root 18281 Aug 24 2018 functions -rwxr-xr-x. 1 root root 4569 Aug 24 2018 netconsole -rwxr-xr-x. 1 root root 7923 Aug 24 2018 network -rw-r--r--. 1 root root 1160 Oct 30 2018 README -rwxr-xr-x. 1 root root 25420 May 8 20:18 tomcat
-
添加tomcat到chkconfig。
[root@localhost init.d]# chkconfig --add tomcat [root@localhost init.d]# chkconfig --list Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off tomcat 0:off 1:off 2:on 3:on 4:on 5:on 6:off
-
可以通过service tomcat start/stop启动和关闭tomcat了。
[root@localhost init.d]# service tomcat stop Using CATALINA_BASE: /usr/local/tomcat/tomcat Using CATALINA_HOME: /usr/local/tomcat/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/tomcat/temp Using JRE_HOME: /usr/local/jdk/jdk1.8.0_202 Using CLASSPATH: /usr/local/tomcat/tomcat/bin/bootstrap.jar:/usr/local/tomcat/tomcat/bin/tomcat-juli.jar Using CATALINA_OPTS: [root@localhost init.d]# service tomcat start Using CATALINA_BASE: /usr/local/tomcat/tomcat Using CATALINA_HOME: /usr/local/tomcat/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/tomcat/temp Using JRE_HOME: /usr/local/jdk/jdk1.8.0_202 Using CLASSPATH: /usr/local/tomcat/tomcat/bin/bootstrap.jar:/usr/local/tomcat/tomcat/bin/tomcat-juli.jar Using CATALINA_OPTS: Tomcat started.
设置tomcat服务随系统启动而自启动
[root@localhost init.d]# vim /etc/rc.local