• 主页

  • 投资

  • IT

    🔥
  • 设计

  • 销售

关闭

返回栏目

关闭

返回服务器栏目

80 - ubuntu 查看进程,查看服务 - (准备弃用)

作者:

贺及楼

成为作者

更新日期:2022-07-24 23:21:26

13 - Linux - 基本命令 - netstat - 端口占用

  1. ps aux 看所有运行进程
  2. ps aux | grep 程序名 如果你想找特定的进程
  3. kill -9 进程号 结束进程(进程号就是你运行ps命令看到的第二列的4位数字)

sudo netstat -anpl | grep :3306

  1. jiqing@Ubuntu:~$ sudo netstat -anpl | grep :3306
  2. tcp6 0 0 :::3306 :::* LISTEN 1532/mysqld
  3. jiqing@Ubuntu:~$ sudo netstat -anpl | grep :80
  4. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2994/nginx: master
  5. jiqing@Ubuntu:~$ ps -ef | grep nginx
  6. root 2994 1833 0 11:28 ? 00:00:00 nginx: master process nginx
  7. www 2995 2994 0 11:28 ? 00:00:00 nginx: worker process
  8. www 2996 2994 0 11:28 ? 00:00:00 nginx: worker process
  9. www 2997 2994 0 11:28 ? 00:00:00 nginx: worker process
  10. www 2998 2994 0 11:28 ? 00:00:00 nginx: worker process
  11. jiqing 3049 2515 0 11:31 pts/11 00:00:00 grep --color=auto nginx
  12. jiqing@Ubuntu:~$ ps -ef | grep mysql
  13. root 1016 1 0 11:25 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/var --pid-file=/usr/local/mysql/var/Ubuntu.pid
  14. mysql 1532 1016 0 11:25 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/var/Ubuntu.err --open-files-limit=65535 --pid-file=/usr/local/mysql/var/Ubuntu.pid --socket=/tmp/mysql.sock --port=3306
  15. jiqing 3051 2515 0 11:31 pts/11 00:00:00 grep --color=auto mysql

列出所有的tcp端口netstat -ntlp

  1. # netstat -ntlp
  2. Active Internet connections (only servers)
  3. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  4. tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 22473/redis-server
  5. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4293/nginx: master
  6. tcp 0 0 0.0.0.0:8211 0.0.0.0:* LISTEN 4293/nginx: master
  7. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1164/sshd
  8. tcp 0 0 127.0.0.1:8383 0.0.0.0:* LISTEN 23301/xs-indexd: se
  9. tcp 0 0 127.0.0.1:8384 0.0.0.0:* LISTEN 23305/xs-searchd: m
  10. tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 8064/mysqld

列出所有的udp端口netstat -nulp

  1. # netstat -nulp
  2. 激活Internet连接 (仅服务器)
  3. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  4. udp 52224 0 0.0.0.0:68 0.0.0.0:* 2563/dhclient
  5. udp 0 0 0.0.0.0:631 0.0.0.0:* 1238/cups-browsed
  6. udp 0 0 0.0.0.0:58025 0.0.0.0:* 1064/avahi-daemon:
  7. udp 0 0 127.0.0.1:1080 0.0.0.0:* 1739/python
  8. udp 28736 0 0.0.0.0:5353 0.0.0.0:* 6921/nw
  9. udp 9280 0 0.0.0.0:5353 0.0.0.0:* 4243/chrome
  10. udp 31872 0 0.0.0.0:5353 0.0.0.0:* 1064/avahi-daemon:
  11. udp6 0 0 :::35139 :::* 1064/avahi-daemon:
  12. udp6 14656 0 :::5353 :::* 6921/nw
  13. udp6 20672 0 :::5353 :::* 4243/chrome
  14. udp6 20672 0 :::5353 :::* 1064/avahi-daemon:

查看外部的tcp netstat -ntlpa

  1. # netstat -ntlpa
  2. 激活Internet连接 (服务器和已建立连接的)
  3. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  4. tcp 0 0 127.0.0.1:22624 0.0.0.0:* LISTEN 7042/exe
  5. tcp 0 0 127.0.0.1:36395 0.0.0.0:* LISTEN 7042/exe
  6. tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 1183/redis-server 1
  7. tcp 0 0 127.0.0.1:25613 0.0.0.0:* LISTEN 6999/exe
  8. tcp 0 0 127.0.0.1:63342 0.0.0.0:* LISTEN 26309/java
  9. tcp 0 0 127.0.0.1:19471 0.0.0.0:* LISTEN 6999/exe
  10. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1519/nginx.conf
  11. tcp 0 0 0.0.0.0:8211 0.0.0.0:* LISTEN 1519/nginx.conf
  12. tcp 0 0 0.0.0.0:8212 0.0.0.0:* LISTEN 1519/nginx.conf
  13. tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 11230/cupsd
  14. tcp 0 0 127.0.0.1:1080 0.0.0.0:* LISTEN 1739/python
  15. tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 1519/nginx.conf
  16. tcp 0 0 127.0.0.1:6942 0.0.0.0:* LISTEN 26309/java
  17. tcp 0 0 127.0.0.1:40104 127.0.0.1:6379 TIME_WAIT -
  18. tcp 0 0 192.168.1.128:42862 101.132.169.194:22 ESTABLISHED 15204/ssh
  19. tcp 0 0 192.168.1.128:53712 47.75.180.205:2000 ESTABLISHED 4243/chrome
  20. tcp 0 0 127.0.0.1:34122 127.0.0.1:26483 ESTABLISHED 6921/nw
  21. tcp 0 0 127.0.0.1:47234 127.0.0.1:3306 TIME_WAIT -
  22. tcp 0 0 127.0.0.1:40106 127.0.0.1:6379 TIME_WAIT -
  23. tcp 0 0 192.168.1.128:46428 101.226.76.164:443 ESTABLISHED 4243/chrome
  24. tcp 0 0 192.168.1.128:44532 59.111.160.197:80 ESTABLISHED 1317/netease-cloud-
  25. tcp 0 0 127.0.0.1:47238 127.0.0.1:3306 TIME_WAIT -
  26. tcp 0 0 127.0.0.1:36214 127.0.0.1:80 ESTABLISHED 4243/chrome
  27. tcp 0 0 192.168.1.128:60894 223.252.199.69:6003 ESTABLISHED 1317/netease-cloud-
  28. tcp 0 0 127.0.0.1:47144 127.0.0.1:3306 TIME_WAIT -
  29. tcp 0 0 127.0.0.1:55902 127.0.0.1:6379 ESTABLISHED 24062/rdm
  30. tcp 0 0 127.0.0.1:47230 127.0.0.1:3306 TIME_WAIT -
  31. tcp 0 0 192.168.1.128:47122 101.132.169.194:22 ESTABLISHED 16503/ssh
  32. tcp 0 0 192.168.1.128:58480 54.86.169.116:443 ESTABLISHED 27254/Postman
  33. tcp 0 0 127.0.0.1:6379 127.0.0.1:55902 ESTABLISHED 1183/redis-server 1
  34. tcp 0 0 127.0.0.1:40122 127.0.0.1:6379 TIME_WAIT -
  35. tcp 0 0 192.168.1.128:52482 38.143.1.170:2020 ESTABLISHED 4243/chrome
  36. tcp 0 0 127.0.0.1:47232 127.0.0.1:3306 TIME_WAIT -
  37. tcp 0 0 127.0.0.1:80 127.0.0.1:36214 ESTABLISHED 29553/nginx: worker
  38. tcp 0 0 127.0.0.1:47222 127.0.0.1:3306 TIME_WAIT -
  39. tcp 0 0 127.0.0.1:35508 127.0.0.1:26483 ESTABLISHED 6921/nw
  40. tcp 1 0 192.168.1.128:35168 106.15.95.197:80 CLOSE_WAIT 4243/chrome
  41. tcp6 0 0 :::3306 :::* LISTEN 2353/mysqld
  42. tcp6 0 0 :::26483 :::* LISTEN 7042/exe
  43. tcp6 0 0 :::54484 :::* LISTEN 6999/exe
  44. tcp6 0 0 :::21 :::* LISTEN 1560/vsftpd
  45. tcp6 0 0 ::1:631 :::* LISTEN 11230/cupsd
  46. tcp6 0 0 127.0.0.1:26483 127.0.0.1:34122 ESTABLISHED 7042/exe
  47. tcp6 0 0 127.0.0.1:3306 127.0.0.1:47228 TIME_WAIT -
  48. tcp6 0 0 127.0.0.1:3306 127.0.0.1:47224 TIME_WAIT -
  49. tcp6 0 0 127.0.0.1:3306 127.0.0.1:47226 TIME_WAIT -
  50. tcp6 0 0 127.0.0.1:26483 127.0.0.1:35508 ESTABLISHED 7042/exe