[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
偶尔用到这个指令,每次都要搜,索性自己记个笔记
直接进入主题,首先cd进入tomcat的bin文件夹下,然后可以尝试以下三种启动方式:
<>第一种(当前会话启动):
./startup.sh
效果:
然后tomcat就在后台启动了,我们还可以在当前会话中继续输入其它指令,比如
ps -ef | grep 'tomcat'
来查看我们刚才启动的tomcat服务:
可以看到它的进程id是6951,我们可以使用如下指令将其关闭
kill 6951
这种启动方式是直接后台启动,但不是让tomcat一直就在后台跑了,当我们关闭当前连接linux的会话窗口,tomcat服务也将随之关闭。
<>第二种(带日志的当前会话启动):
./catalina.sh run
效果:
与第一种方式不同的是,第二种方式启动后会显示日志,相当于当前Linux连接会话已经成为了控制台,不能再输入其它Linux指令,而与第一种方式相同的是,当当前连接关闭时,本次启动的tomcat服务也会随之关闭。当然,启动成功后我们也可以使用
ctrl + c来直接关闭本次链接会话中tomcat的启动。
<>第三种(后台永久启动):
最简单的写法:
nohup ./startup.sh &
手动指定tomcat启动时的日志路径:
nohup ./startup.sh > log.file 2>&1 &
想要明白这两者的区别,就要看nohup的具体使用方法了:
* >log.file是将command的输出重定向到log.file文件,即输出内容不打印到屏幕上,而是输出到log.file文件中。
* 2>&1 是将标准出错重定向到标准输出,这里的标准输出已经重定向到了log.file文件,即将标准出错也输出到log.file文件中。最后一个&,
是让该命令在后台执行。
*
试想2>1代表什么,2与>结合代表错误重定向,而1则代表错误重定向到一个文件1,而不代表标准输出;换成2>&1,&与1结合就代表标准输出了,就变成错误重定向到标准输出。