2026-11-05
Linux学习
0

目录

系统环境
端口查询
防火墙状态
PS命令
磁盘
Kill命令
rm 删除命令
rpm 软件包的管理工具
SS 查询活动网络Socket
参考

系统环境

  • CentOS 7

端口查询

  • 端口查询 netstat -anp | grep 端口号

    [root@xxxxx ~]# netstat -anp | grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 14681/jwss tcp 0 0 127.0.0.1:51954 127.0.0.1:80 ESTABLISHED 13480/AliYunDun

防火墙状态

  • 查看firewall服务状态 systemctl status firewalld

  • 开启防火墙 systemctl start firewalld

  • 重启防火墙 systemctl restart firewalld

  • 关闭防火墙 systemctl stop firewalld

  • 查看防火墙规则 firewall-cmd --list-all

  • 查询端口是否开放 firewall-cmd --query-port=8080/tcp

  • 开放80端口 firewall-cmd --permanent --add-port=80/tcp

  • 移除端口 firewall-cmd --permanent --remove-port=8080/tcp

  • 重启防火墙(修改配置后要重启防火墙) firewall-cmd --reload

[root@iZaaisf2ubkmstZ ~]# systemctl status firewalld //查看状态 ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: inactive (dead) since Tue 2019-06-11 23:05:06 CST; 2 months 6 days ago Docs: man:firewalld(1) Main PID: 486 (code=exited, status=0/SUCCESS) [root@iZaaisf2ubkmstZ ~]# systemctl start firewalld //开启 [root@iZaaisf2ubkmstZ ~]# systemctl status firewalld //查看状态 为激活 ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2019-08-18 14:23:17 CST; 16min ago Docs: man:firewalld(1) Main PID: 31938 (firewalld) Tasks: 2 Memory: 26.4M CGroup: /system.slice/firewalld.service └─31938 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid Aug 18 14:23:16 iZaaisf2ubkmstZ systemd[1]: Starting firewalld - dynamic firewall daemon... Aug 18 14:23:17 iZaaisf2ubkmstZ systemd[1]: Started firewalld - dynamic firewall daemon. [root@iZaaisf2ubkmstZ ~]# systemctl stop firewalld //停止 [root@iZaaisf2ubkmstZ ~]# systemctl status firewalld //查看状态已停止 ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: inactive (dead) since Sun 2019-08-18 14:41:26 CST; 2s ago Docs: man:firewalld(1) Process: 31938 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS) Main PID: 31938 (code=exited, status=0/SUCCESS) [root@iZaaisf2ubkmstZ ~]# firewall-cmd --list-all //端口列表 可见到有20,21,22,80,39000-4000 public target: default icmp-block-inversion: no interfaces: sources: services: ssh dhcpv6-client ports: 20/tcp 21/tcp 22/tcp 80/tcp 8888/tcp 39000-40000/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: [root@iZaaisf2ubkmstZ ~]# firewall-cmd --query-port=8080/tcp //查询8080 不在 no [root@iZaaisf2ubkmstZ ~]# firewall-cmd --query-port=80/tcp //查询80 在 yes [root@iZaaisf2ubkmstZ ~]# firewall-cmd --permanent --add-port=88/tcp //添加88端口 success [root@iZaaisf2ubkmstZ ~]# firewall-cmd --permanent --remove-port=80/tcp //移除80端口 success [root@iZaaisf2ubkmstZ ~]# firewall-cmd --list-all //查看 可发现刚才添加的88和移除的80没有生效 public target: default icmp-block-inversion: no interfaces: sources: services: ssh dhcpv6-client ports: 20/tcp 21/tcp 22/tcp 80/tcp 8888/tcp 39000-40000/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: [root@iZaaisf2ubkmstZ ~]# firewall-cmd --reload //使用此命令使刚才命令生效 success [root@iZaaisf2ubkmstZ ~]# firewall-cmd --list-all //查看 已生效 public target: default icmp-block-inversion: no interfaces: sources: services: ssh dhcpv6-client ports: 20/tcp 21/tcp 22/tcp 8888/tcp 39000-40000/tcp 88/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:

PS命令

  • 查询进程详情 ps -aux | grep 进程名
[root@iZaaisf2ubkmstZ ~]# ps -aux | grep redis root 1061 0.0 0.0 141848 588 ? Ssl May29 110:29 /usr/redis/parse/redis-server 0.0.0.0:10066 root 1610 0.0 0.0 112708 984 pts/0 R+ 14:53 0:00 grep --color=auto redis

磁盘

  • df命令用于显示目前在Linux系统上的文件系统的磁盘使用情况统计 df -h

  • 磁盘信息 fdisk -l

    [root@iZaaisf2ubkmstZ ~]# df -h //文件系统使用信息 Filesystem Size Used Avail Use% Mounted on /dev/vda1 40G 13G 25G 34% / devtmpfs 486M 0 486M 0% /dev tmpfs 497M 24K 497M 1% /dev/shm tmpfs 497M 416K 496M 1% /run tmpfs 497M 0 497M 0% /sys/fs/cgroup tmpfs 100M 0 100M 0% /run/user/0 [root@iZaaisf2ubkmstZ ~]# fdisk -l //当前磁盘信息 Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x0008d73a

    Device Boot Start End Blocks Id System /dev/vda1 * 2048 83884031 41940992 83 Linux

Kill命令

  • 强制结束进程 kill -9 进程号

    [root@iZaaisf2ubkmstZ ~]# ps -aux | grep redis //查看redis进程 root 1061 0.0 0.0 141848 588 ? Ssl May29 110:30 /usr/redis/parse/redis-server 0.0.0.0:10066 root 2038 0.0 0.0 112712 980 pts/0 S+ 15:01 0:00 grep --color=auto redis [root@iZaaisf2ubkmstZ ~]# kill -9 1061 //杀死进程 [root@iZaaisf2ubkmstZ ~]# ps -aux | grep redis //在使用命令查看 root 2068 0.0 0.0 112708 984 pts/0 S+ 15:01 0:00 grep --color=auto redis

rm 删除命令

  • rm -rf dirname 删除文件夹
  • rm -rf file-* 删除所有以file- 开头的文件

rpm 软件包的管理工具

  • rpm -qa | grep sql 查找所有安装过的包含某个字符串sql的软件包
  • rpm -ql redis rpm包中的文件安装位置

SS 查询活动网络Socket

  • ss -nlp | grep redis 查找redis监听的端口信息

参考

本文作者:Cheng

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 本原创文章未经允许不得转载 许可协议。转载请注明出处!