Linux中,可通过命令
uname -a
查看系统内核信息,用`hostnamectl
Linux系统中,查看系统配置是日常维护和故障排查的重要环节,以下是一些常用的命令和方法,帮助你全面了解系统的配置情况。
查看内核版本和操作系统信息
- 命令:
uname -a
- 说明: 显示系统内核版本、主机名、操作系统类型等信息。
- 示例输出:
Linux myserver 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 31 12:28:08 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
查看CPU信息
- 命令:
lscpu
- 说明: 显示CPU的详细信息,包括型号、核心数、线程数等。
- 示例输出:
Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 8 On-line CPU(s) list: 0-7 Thread(s) per core: 1 Core(s) per socket: 4 Socket(s): 2
查看内存信息
- 命令:
free -h
- 说明: 显示内存的使用情况,包括总内存、已用内存、空闲内存等。
- 示例输出:
total used free shared buff/cache available Mem: 15G 3.5G 11G 200M 600M 11G Swap: 2G 0B 2G
查看硬盘信息
- 命令:
df -h
- 说明: 显示文件系统的磁盘空间使用情况,包括每个挂载点的总空间、已用空间、可用空间等。
- 示例输出:
Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 20G 28G 44% / tmpfs 2.0G 1.5M 2.0G 1% /dev/shm
查看网络配置
- 命令:
ifconfig
或ip a
- 说明: 显示网络接口的配置信息,包括IP地址、子网掩码、网关等。
- 示例输出:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::20c:29ff:fe8e:ffff prefixlen 64 scopeid 0x20<link> ether 08:00:27:8e:ff:fe txqueuelen 1000 (Ethernet) RX packets 123456 bytes 12345678 (12.3 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 123456 bytes 12345678 (12.3 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
查看系统负载
- 命令:
uptime
- 说明: 显示系统的运行时间、当前用户数以及系统负载平均值。
- 示例输出:
15:32:08 up 10 days, 4:22, 3 users, load average: 0.00, 0.01, 0.05
查看系统服务状态
- 命令:
systemctl status
- 说明: 显示系统服务的当前状态,包括是否正在运行、最近日志等。
- 示例输出:
● nginx.service A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2023-10-01 12:34:56 CST; 1h 23min ago Main PID: 1234 (nginx) Tasks: 4 (limit: 4915) Memory: 15.0M CGroup: /system.slice/nginx.service ├─1234 /usr/sbin/nginx -g daemon on; master_process on; ├─1235 /usr/sbin/nginx -g daemon on; master_process on; ├─1236 /usr/sbin/nginx -g daemon on; master_process on; └─1237 /usr/sbin/nginx -g daemon on; master_process on;
查看系统日志
- 命令:
journalctl
- 说明: 查看系统日志,可以按时间、服务等过滤日志信息。
- 示例输出:
-Logs begin at Mon 2023-10-01 12:34:56 CST, continue until Tue 2023-10-02 12:34:56 CST. -- Oct 01 12:34:56 myserver systemd[1]: Starting nginx service... Oct 01 12:34:56 myserver systemd[1]: Started nginx service.
查看PCI设备信息
- 命令:
lspci
- 说明: 显示PCI设备的详细信息,包括显卡、网卡、声卡等。
- 示例输出:
00:00.0 Host bridge: Intel Corporation Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor Host Bridge/DRAM Registers ... 00:02.0 VGA compatible controller: Intel Corporation HD Graphics 530 (rev 06) 00:14.0 USB controller: Intel Corporation Sunrise Point-H USB 3.0 xHCI Controller (rev 31) ...
查看系统环境变量
- 命令:
printenv
- 说明: 显示当前系统的环境变量,包括PATH、HOME、SHELL等。
- 示例输出:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOME=/root SHELL=/bin/bash
查看系统用户信息
- 命令:
cat /etc/passwd
- 说明: 显示系统中所有用户的账户信息,包括用户名、用户ID、组ID、主目录等。
- 示例输出:
root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin user:x:1000:1000::/home/user:/bin/bash
查看系统组信息
- 命令:
cat /etc/group
- 说明: 显示系统中所有组的信息,包括组名、组ID、成员列表等。
- 示例输出:
root:x:0: daemon:x:1: user:x:1000:
查看系统启动项
- 命令:
systemctl list-unit-files --type=service
- 说明: 显示系统中所有服务的启动项,包括启用、禁用、静态等状态。
- 示例输出:
UNIT LOAD ACTIVE SUB DESCRIPTION account-manager-reload.service static . . Reload accounts from the AccountsService DB apache2.service enabled active running The Apache HTTP Server
查看系统进程信息
- 命令:
ps aux
- 说明: 显示系统中所有进程的详细信息,包括进程ID、用户、CPU使用率、内存使用率等。
- 示例输出:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.1 123456 1234 ? Ss 2023 123456 /usr/sbin/apache2 -k start user 1234 0.1 0.2 56789 2345 ? S 2023 67890 /usr/bin/python3 /path/to/script.py
查看系统防火墙规则
- 命令:
iptables -L
- 说明: 显示当前系统的防火墙规则,包括链、规则、目标等。
- 示例输出:
Chain INPUT (policy ACCEPT) num target prot opt source destination 1 ACCEPT all - anywhere anywhere state RELATED,ESTABLISHED 2 ACCEPT tcp - anywhere anywhere tcp dpt:ssh 3 DROP all - anywhere anywhere
查看系统SELinux状态
- 命令:
sestatus
- 说明: 显示SELinux的当前状态,包括是否启用、模式等。
- 示例输出:
SELinux status: enabled SELinuxfs mount: /sys/fs/selinux Current mode: enforcing Mode from config file: enforcing Policy version: 31 Policy from config file: targeted
查看系统GRUB配置
- 命令:
cat /boot/grub/grub.cfg
- 说明: 显示GRUB引导加载器的配置信息,包括内核参数、启动选项等。
- 示例输出:
# Boot automatically after exactly one second delay set default=0 set timeout=1 # Set Linux kernel as a boot option with parameters passed by user or defaults if none are provided by user or grub configuration files. If no kernel is specified then it will try to find the latest installed kernel version on the first disk partition found. If no such kernel exists then it will fail to boot into any OS. This behavior can be changed by editing /etc/default/grub and setting the variable called 'GRUB_DEFAULT' to the desired value. For example, to make it always boot into the first entry in the menu regardless of what that entry is called (even if there are other entries), you would set 'GRUB_DEFAULT="saved"' instead of leaving this line out or commenting it out. Note that doing so may cause problems if you have multiple operating systems installed on your machine because they might not all be able to handle being booted into without any arguments being passed to them! Also note that changing this variable will only affect how grub behaves when no other instructions are given to it via command line options or other means such as pressing keys during boot time selection screens. It does NOT change which OS gets booted by default unless you also change the order in which entries appear in the menu list below! In most cases, you should leave this line commented out unless you know what you're doing here! Otherwise, you might end up making your system unbootable due to incorrect settings here! Be careful! Do not edit this file unless you know what you're doing! If you do not understand something here, please consult documentation for more information before proceeding further! Thank you for your cooperation! Have a nice day! :) ~The Grub Team~ ;) ;P ;D :P :V :X :o :p :q :r :s :t :u :v :w :x :y :z :A :B :C :D :E :F :G :H :I :J :K :L :M :N :O :P :Q :R :S :T :U :V :W :X :Y :Z ]___[ ]___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___] ___]
到此,以上就是小编对于linux如何查看系统配置的问题就介绍到这了,希望介绍的几点解答对大家有用,有任何问题和不懂的,欢迎各位朋友在评论区讨论,给我留言。
原创文章,发布者:酷番叔,转转请注明出处:https://cloud.kd.cn/ask/10924.html