测试环境搭建踩坑记录---Tomcat添加到chkconfig

测试环境搭建踩坑记录—Tomcat添加到chkconfig

参考文档:(70条消息) 虚拟机搭建测试环境(三)_飞流月色24的博客-CSDN博客

tomcat的启动和停止,一般要在安装目录/bin下执行 相关命令,比较麻烦。

./startup   -----启动tomcat
./shutdown  -----停止tomcat

可以将tomcat添加到linux系统服务,然后就可以通过 service tomcat start/stop来启动和停止tomcat了。

操作步骤:
  1. 将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
    
  2. 编辑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)]

  3. 给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
    
  4. 添加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
    
  5. 可以通过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

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-plCCeEnW-1690425110176)(C:\Users\DELL\AppData\Roaming\Typora\typora-user-images\image-20230509131445108.png)]

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值