
shell命令
常用的shell命令
查看端口通不通
shell
telnet 30.166.233.103 11434
centos下查看端口占用情况,杀死进程
有端口号
有时候我们知道某个服务端口正在后台运行,想关掉它。比如说我tomcat是8080端口,在后台运行。怎么关掉它呢?
根据端口查看这个进程的pid
shell
netstat -lnp|grep 8080 #8080请换为你的apache需要的端口
查看进程的详细信息
shell
ps 1777 #1777就是上一步得到的pid
杀掉进程
shell
kill -9 [PID] #-9 表示强迫进程立即停止
有服务名称
根据pid查看进程的详细信息
shell
ps -ef|grep redis
root 7474 1 0 14:58 ? 00:00:01 /usr/local/redis/redis-4.0.11/src/redis-server 127.0.0.1:6379
root 7794 2175 0 15:30 pts/0 00:00:00 grep --color=auto redis
## 7474 就是pid
如何通过pid看端口
shell
netstat -antup |grep 2711
通过pid看服务名称
shell
# 查看端口11434的pid 输出: TCP 127.0.0.1:11434 0.0.0.0:0 LISTENING 17556
netstat -aon|findstr 11434
# 查看该进程运行的情况,输出如下:ollama.exe 17556 Console 1 31,856 K
tasklist|findstr "17556"
window下杀死进程
shell
netstat -ano | findstr 9999
taskkill /f /pid 12612
shell
1、Windows平台
在windows命令行窗口下执行:
1.查看所有的端口占用情况
C:\>netstat -ano
协议 本地地址 外部地址 状态 PID
TCP 127.0.0.1:1434 0.0.0.0:0 LISTENING 3236
TCP 127.0.0.1:5679 0.0.0.0:0 LISTENING 4168
TCP 127.0.0.1:7438 0.0.0.0:0 LISTENING 4168
TCP 127.0.0.1:8015 0.0.0.0:0 LISTENING 1456
TCP 192.168.3.230:139 0.0.0.0:0 LISTENING 4
TCP 192.168.3.230:1957 220.181.31.225:443 ESTABLISHED 3068
TCP 192.168.3.230:2020 183.62.96.189:1522 ESTABLISHED 1456
TCP 192.168.3.230:2927 117.79.91.18:80 ESTABLISHED 4732
TCP 192.168.3.230:2929 117.79.91.18:80 ESTABLISHED 4732
TCP 192.168.3.230:2930 117.79.91.18:80 ESTABLISHED 4732
TCP 192.168.3.230:2931 117.79.91.18:80 ESTABLISHED 4732
2.查看指定端口的占用情况
C:\>netstat -aon|findstr "9050"
协议 本地地址 外部地址 状态 PID
TCP 127.0.0.1:9050 0.0.0.0:0 LISTENING 2016
P: 看到了吗,端口被进程号为2016的进程占用,继续执行下面命令: (也可以去任务管理器中查看pid对应的进程)
3.查看PID对应的进程
C:\>tasklist|findstr "2016"
映像名称 PID 会话名 会话# 内存使用
========================= ======== ================
tor.exe 2016 Console 0 16,064 K
P:很清楚吧,tor占用了你的端口。
4.结束该进程
C:\>taskkill /f /t /im tor.exe
系统信息
查看服务器的操作系统
shell
cat /etc/redhat-release
查看CPU信息
shell
lscpu
找不到安装 需要安装
shell
yum install util-linux -y
查看Linux服务器CPU核数
shell
cat /proc/cpuinfo |grep processor |wc -l
查看物理cpu的数量
shell
grep "physical id" /proc/cpuinfo|sort -u|wc -l
查看内存信息
shell
free -h
查看硬盘大小
查看磁盘总大小
shell
fdisk -l
shell
df -h
shell
lsblk
查看服务器网卡设备配置信息
安装lshw
命令查看服务器网卡设备配置信息
shell
yum -y install lshw
shell
lshw -c network
防火墙
查看开启了那些端口
常用于 CentOS/RHEL 7 及以上版本
shell
firewall-cmd --list-ports
这个命令会列出所有临时开放的端口。如果你想要查看所有永久开放的端口,可以使用:
shell
firewall-cmd --list-ports --permanent
查看特定端口是否开启
如果你想要检查特定的端口是否已经开启,可以使用以下命令:
shell
firewall-cmd --query-port=80/tcp
curl命令
查看网页源码
shell
curl www.baidu.com
如果要把这个网页保存下来,可以使用 -o 参数:
shell
curl -o /tmp/baidu.txt www.baidu.com
显示头信息
-i 参数可以显示 http response 的头信息,连同网页代码一起。-I 参数则只显示 http response 的头信息。
shell
$ curl -i www.baidu.com
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: keep-alive
Content-Length: 2381
Content-Type: text/html
Date: Mon, 14 Nov 2022 06:06:56 GMT
Etag: "588604c8-94d"
Last-Modified: Mon, 23 Jan 2017 13:27:36 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>©2017 Baidu <a href=http://www.baidu.com/duty/>使用百度前必读</a> <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a> 京ICP证030173号 <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>