跳到主要内容

命令行界面

While most tasks in Unraid can be performed through the WebGUI, certain operations - especially those related to diagnostics, drive management, or scripting - require using the system console or SSH terminal. This page offers Unraid-specific command-line tools and examples that can be used without needing extensive Linux knowledge.

Device 路径

Many disk-level Unraid operations depend on Linux device names, like /dev/sdX. You can find the device identifier for any drive in the Main tab of the WebGUI. Look for the three-letter label sdX or nvmeX next to each disk. Use the appropriate identifier in all commands, replacing sdX with your specific disk.

访问终端

Unraid includes a built-in web terminal that you can access directly from the WebGUI. Simply use the top-right dropdown menu and select ">_". This opens a command-line session as the root user, giving you full administrative access to your system.

您也可以使用 %SSH|ssh%(安全壳)与 PuTTY 等客户端外部连接到 Unraid 服务器。

When 我应该使用终端吗?

终端访问对于以下情况很有用:

  • 运行例如 smartctlxfs_repairtailtop 等诊断和命令行工具
  • 执行不需要用户界面的插件脚本或工具
  • Troubleshooting issues related to connectivity, system services, or user shares

使用 PuTTY(仅限 Windows)

如果您使用的是Windows,可能更喜欢使用PuTTY进行SSH访问,而不是内置终端。这个软件轻量级、免费,并允许您保存会话以便日后轻松访问。

如何安装和使用PuTTY - 点击展开/折叠
  1. 官方网站下载 PuTTY
  2. 启动 PuTTY 应用程序。
  3. 输入您的 Unraid 服务器的 IP 地址或主机名(如 tower.local)。
  4. 将连接类型设置为 %%SSH|ssh%%
  5. (可选)保存会话名称以供将来使用。
  6. 点击 打开 开始会话。
  7. 遇到提示时,以 root 登录,然后输入您的密码。

Once you've logged in, you're in the Unraid shell environment. Type exit when you're finished to close the session.

备注

Unraid automatically configures the SSH server on the first boot. Ensure your networking is working properly and that your root password is set before attempting a remote connection.

驱动器测试和监控

These tools assist with evaluating performance, checking drive health, and troubleshooting array slowness. All commands should be executed from the terminal or via SSH.

hdparm

使用此命令测试读取速度并显示驱动器特性。

查看hdparm选项 - 点击展开/折叠

测试驱动器读取速度:

hdparm -tT /dev/sdX

-t标记测试缓冲磁盘读取,而-T则测试缓存读取。这主要测量顺序读取性能,帮助识别异常缓慢的驱动器。

多次测试以保证准确性:

for ((i=0;i<5;i++)); do hdparm -tT /dev/sdX; done

查看驱动信息:

hdparm -I /dev/sdX

这将显示型号、固件、缓存大小和支持的功能,帮助验证磁盘类型和控制器行为。

smartctl

此命令运行 SMART 诊断并监控驱动器健康。

查看smartctl选项 - 点击展开/折叠

基本SMART报告:

smartctl -a /dev/sdX

如果此命令返回错误,请尝试指定设备类型:smartctl -a -d ata /dev/sdX(使用-d nvme用于NVMe驱动器)。

启动SMART自检:

短测试(需几分钟)

smartctl -t short /dev/sdX

延展测试(可能需数小时)

smartctl -t long /dev/sdX

SMART报告保存到文件:

smartctl -a /dev/sdX > /boot/smart_report.txt

这将报告保存到您的Unraid闪存驱动器中,供以后查看或在论坛上分享。

diskspeed.sh

此脚本允许进行全面的表面性能测试,并生成可视化报告。

查看diskspeed.sh用法 - 点击展开/折叠

This used to be a script you would download from the Unraid forums. DiskSpeed is available now in a more refined package:

通过搜索"DiskSpeed",从社区应用程序安装DiskSpeed(应用程序选项卡),或访问GitHub仓库获取手动安装说明。


系统监控

WebGUI 不可用或需要更详细诊断时,使用这些命令监控内存、进程和系统性能。

top

此命令提供实时的进程和资源监控。

查看top用法 - 点击展开/折叠
top
  • 实时显示每个进程的 CPU 和内存使用情况。

  • q 退出。

  • 使用方向键滚动,按 k 终止进程。

    提示

考虑使用htop以获得更友好的界面和增强的控制。

:::

free

此命令显示内存使用统计信息。

查看free用法 - 点击展开/折叠
free -h

这以易读格式显示RAM使用情况。-h标志表示尺寸将以KB、MB或GB而非字节显示。

了解输出

低的"可用"内存读数不一定表示问题——Linux为性能而积极地缓存数据。

ps

使用此命令显示正在运行的进程及其详细信息。

查看ps选项 - 点击展开/折叠

列出所有进程并显示详细信息:

ps aux

按内存使用排序:

ps aux --sort=-%mem | head -20

按CPU使用排序:

ps aux --sort=-%cpu | head -20

存储工具

这些命令有助于检查磁盘使用情况、分区信息和识别存储设备。

df

此命令显示文件系统磁盘空间使用情况。

查看df用法 - 点击展开/折叠
df -h

This command displays the used and available space on all mounted file systems. It’s convenient for checking /var/log (which utilizes RAM-based logging) in Unraid. For more information on system logging.

fdisk

查看磁盘分区表和几何布局。

查看fdisk用法 - 点击展开/折叠
fdisk -l /dev/sdX

此命令显示分区布局、尺寸以及磁盘几何。这有助于排查磁盘尺寸不匹配的问题,特别是在更换磁盘时。

lsblk

以树形格式列出所有块设备。

查看lsblk用法 - 点击展开/折叠
lsblk

此命令以简单的树形结构显示所有存储设备及其挂载点。它非常适合获取您的存储布局概览。

blockdev -getsz

帮助确定替换驱动器在重建前是否有足够的空间。

查看blockdev用法 - 点击展开/折叠

语法:

blockdev --getsz /dev/sdX

返回设备上的512字节扇区的原始数量——这对于在重建之前确认替换驱动器是否足够大很有用。

blkid

识别文件系统标签。

查看blkid用法 - 点击展开/折叠

语法:

blkid /dev/sdX1

输出文件系统类型和标签。当验证Unraid闪存标记为“UNRAID”时,请使用此命令而非已弃用的vol_id命令。


网络诊断

用于排除网络连接和接口配置问题的工具。

ss

显示套接字统计和网络连接。这是netstat的现代替代品。

查看ss选项 - 点击展开/折叠

显示所有监听端口:

ss -tuln
  • -t:TCP 套接字
  • -u:UDP 套接字
  • -l:仅显示监听套接字
  • -n:显示端口号而不是服务名称

显示已建立的连接:

ss -tup

此命令显示活动连接及其进程信息。

ip

配置和显示网络接口信息。这是ifconfig的现代替代品。

查看ip选项 - 点击展开/折叠

显示所有网络接口:

ip addr show

用颜色显示网络接口:

ip -c addr show

显示路由表:

ip route show

ping

测试网络连接。

查看ping用法 - 点击展开/折叠

通过发送有限的包数测试连接性:

ping -c 4 google.com

此命令向目标发送四个包然后停止,适合于基本的连通性测试而不会持续输出。

ethtool

用于查询和调整网络接口卡 (NIC) 参数的实用工具,例如链接速度、卸载功能和统计数据。

查看ethtool用法 - 点击展开/折叠

基本驱动和固件信息:

使用此命令获取有关您网络接口的驱动和固件的信息:

ethtool -i eth0

显示当前链接速度和设置:

要检查接口的当前链接速度和设置,请运行:

ethtool eth0

显示扩展接口统计:

对于与接口相关的扩展统计,请使用以下命令:

ethtool -S eth0

这些命令可以帮助您确认千兆、2.5 GbE或10 GbE连接的协商速度,诊断电缆问题,或识别可能由卸载不匹配引起的丢包。


系统信息

获取关于硬件、内核和整体系统配置的详细信息。

CPU 架构概况:

lscpu

此命令显示有关核心、线程、虚拟化支持和缓存详细信息。

功能检测:

grep -E 'lm|vmx|svm' /proc/cpuinfo
  • lm:表示支持 64 位
  • vmx:Intel VT-x 虚拟化
  • svm:AMD-V 虚拟化

系统维护

系统关闭、日志监控和服务管理的命令。

实时监控日志文件。

查看tail用法 - 点击展开/折叠
tail -f /var/log/syslog

此命令显示系统日志的实时更新。要退出,请使用Ctrl+C

显示指定行数:

tail -n 50 /var/log/syslog

关机

安全关闭系统。

查看powerdown用法 - 点击展开/折叠
powerdown

This command utilizes Unraid's built-in shutdown process to stop the array and power down the system safely. It's preferred over manual shutdown methods.