背景
运行一个springboot的demo,启动发现8080端口被占用
查看8080端口占用情况
➜ lsof -i:8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 849 jijunpeng 6u IPv4 0x310466e16f01fa41 0t0 TCP *:http-alt (LISTEN)
java 877 jijunpeng 45u IPv6 0x310466eb08b2aad9 0t0 TCP *:http-alt (LISTEN)
nginx 1351 jijunpeng 6u IPv4 0x310466e16f01fa41 0t0 TCP *:http-alt (LISTEN)
使用pstree查看进行信息
如果mac没有pstree,可以使用
brew install pstree
进行安装
➜ pstree -p 877
-+= 00001 root /sbin/launchd
--= 00877 jijunpeng /opt/homebrew/opt/openjdk/bin/java -Dzookeeper.log.dir=/opt/homebrew/Cellar/zookeeper/3.7.0_1/libexec/bin/../logs -Dzookeeper.log.file=zookeeper-jijunpeng-server-192.168.0.108.log
使用brew services 关闭对应服务
因为自己之前使用brew
安装过kafka
,kafka
依赖了zookeeper
,没想到这个会开机自启。使用brew services 查看一下启动了哪些服务
➜ brew services
Name Status User File
kafka started jijunpeng ~/Library/LaunchAgents/homebrew.mxcl.kafka.plist
mysql@5.7 started jijunpeng ~/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist
nginx started jijunpeng ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
php none
unbound none
这些started
状态的服务都不是自己需要的,都给他关了
brew services stop kafka
brew services top mysql@5.7
再次使用检查8080端口占用情况已经消失了
➜ lsof -i:8080
我重启电脑,再次使用 brew services
查看,服务也没有重启,可能是 brew
记住了服务状态,开机之后也会保持
➜ brew services
Name Status User File
kafka none
mysql@5.7 none
nginx none
php none
unbound none
zookeeper none