Linfo:实时显示你的 Linux 服务器运行状况

Linfo:实时显示你的 Linux 服务器运行状况

Linfo 是一个自由开源的跨平台的服务器统计 UI 或库,它可以显示大量的系统信息。Linfo 是可扩展的,通过 composer,很容易使用 PHP5 库以程序化方式获取来自 PHP 应用的丰富的系统统计数据。它有 Web UI 及其Ncurses CLI 视图,在 Linux、Windows、BSD、Darwin/Mac OSX、Solaris 和 Minix 系统上均可用。

Linfo 显示的系统信息包括 CPU 类型/速度、服务器的体系结构、挂载点用量、硬盘/光纤/Flash 驱动器、硬件设备、网络设备和统计信息、运行时间/启动日期、主机名、内存使用量(RAM 和 swap)、温度/电压/风扇速度和 RAID 阵列等。

环境要求:

  • PHP 5.3
  • pcre 扩展
  • Linux – /proc/sys 已挂载且可对 PHP 可读,已经在 2.6.x/3.x 内核中测试过

如何在 Linux 中安装 Linfo 服务器统计 UI及库

首先,在 Apache 或 Nginx 的 Web 根目录下创建 Linfo 的目录,然后,使用下面展示的 rsync 命令 克隆仓库文件并将其移动到目录 /var/www/html/linfo 下:

  1. <span class="pln">$ </span><span class="kwd">sudo</span><span class="kwd">mkdir</span><span class="pun">-</span><span class="pln">p </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">linfo </span>
  2. <span class="pln">$ </span><span class="kwd">git</span><span class="kwd">clone</span><span class="kwd">git</span><span class="pun">:</span><span class="com">//github.com/jrgp/linfo.git </span>
  3. <span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> rsync </span><span class="pun">-</span><span class="pln">av linfo</span><span class="str">/ /</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">linfo</span><span class="pun">/</span>

接下来,将 sample.config.inc.php 重命名为 config.inc.php。这是 Linfo 的配置文件,你可以在里面定义你想要的值:

  1. <span class="pln">$ </span><span class="kwd">sudo</span><span class="kwd">mv</span><span class="pln"> sample</span><span class="pun">.</span><span class="pln">config</span><span class="pun">.</span><span class="pln">inc</span><span class="pun">.</span><span class="pln">php config</span><span class="pun">.</span><span class="pln">inc</span><span class="pun">.</span><span class="pln">php </span>

现在,在 Web 浏览器中打开链接 http://SERVER_IP/linfo 来查看这个 Web UI,正如下面的截图所展示的。

从截图中可以看到, Linfo 显示了系统内核信息、硬件组成、RAM 统计、网络设备、驱动器以及文件系统挂载点。

Linfo:实时显示你的 Linux 服务器运行状况

Linux 服务器运行信息

你可以将下面一行内容加入配置文件 config.inc.php 中,以便进行故障排查时看到错误信息。

  1. <span class="pln">$settings</span><span class="pun">[</span><span class="str">'show_errors'</span><span class="pun">]</span><span class="pun">=</span><span class="kwd">true</span><span class="pun">;</span>

以 Ncurses 模式运行 Linfo

Linfo 有一个基于 ncurses 的简单界面,它依赖于 PHPncurses 扩展。

  1. <span class="com">#</span><span class="kwd">yum</span><span class="pln"> install php</span><span class="pun">-</span><span class="pln">pecl</span><span class="pun">-</span><span class="pln">ncurses </span><span class="pun">[在</span><span class="typ">CentOS</span><span class="pun">/</span><span class="pln">RHEL </span><span class="pun">上]</span>
  2. <span class="com">#</span><span class="pln"> dnf install php</span><span class="pun">-</span><span class="pln">pecl</span><span class="pun">-</span><span class="pln">ncurses </span><span class="pun">[在</span><span class="typ">Fedora</span><span class="pun">上]</span>
  3. <span class="pln">$ </span><span class="kwd">sudo</span><span class="kwd">apt-get</span><span class="pln"> install php5</span><span class="pun">-</span><span class="pln">dev libncurses5</span><span class="pun">-</span><span class="pln">dev </span><span class="pun">[在</span><span class="typ">Debian</span><span class="pun">/</span><span class="typ">Ubuntu</span><span class="pun">上]</span>

现在,像下面这样编译这个 php 扩展:

  1. <span class="pln">$ </span><span class="kwd">wget</span><span class="pln"> http</span><span class="pun">:</span><span class="com">//pecl.php.net/get/ncurses-1.0.2.tgz</span>
  2. <span class="pln">$ </span><span class="kwd">tar</span><span class="pln"> xzvf ncurses</span><span class="pun">-</span><span class="lit">1.0</span><span class="pun">.</span><span class="lit">2.tgz</span>
  3. <span class="pln">$ </span><span class="kwd">cd</span><span class="pln"> ncurses</span><span class="pun">-</span><span class="lit">1.0</span><span class="pun">.</span><span class="lit">2</span>
  4. <span class="pln">$ phpize </span><span class="com">#</span><span class="pln"> generate configure </span><span class="kwd">script</span>
  5. <span class="pln">$ </span><span class="pun">./</span><span class="pln">configure</span>
  6. <span class="pln">$ </span><span class="kwd">make</span>
  7. <span class="pln">$ </span><span class="kwd">sudo</span><span class="kwd">make</span><span class="pln"> install</span>

接下来,如果编译成功并安装好了该 php 扩展,运行下面的命令:

  1. <span class="pln">$ </span><span class="kwd">sudo</span><span class="kwd">echo</span><span class="pln"> extension</span><span class="pun">=</span><span class="pln">ncurses</span><span class="pun">.</span><span class="pln">so </span><span class="pun">></span><span class="str">/etc/</span><span class="pln">php5</span><span class="pun">/</span><span class="pln">cli</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">ncurses</span><span class="pun">.</span><span class="pln">ini</span>

验证 ncurse:

  1. <span class="pln">$ php </span><span class="pun">-</span><span class="pln">m </span><span class="pun">|</span><span class="kwd">grep</span><span class="pln"> ncurses</span>

现在,运行 Info:

  1. <span class="pln">$ </span><span class="kwd">cd</span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">linfo</span><span class="pun">/</span>
  2. <span class="pln">$ </span><span class="pun">./</span><span class="pln">linfo</span><span class="pun">-</span><span class="pln">curses</span>

Linfo:实时显示你的 Linux 服务器运行状况

Linux 服务器信息

Info 中尚欠缺下面这些功能:

  1. 支持更多 Unix 操作系统(比如 Hurd、IRIX、AIX 和 HP UX 等)
  2. 支持不太出名的操作系统 Haiku/BeOS
  3. 额外功能/扩展
  4. 在 ncurses 模式中支持 htop 类 特性

如果想了解更多信息,请访问 Linfo 的 GitHub 仓库: https://github.com/jrgp/linfo

这就是本文的全部内容了。从现在起,你可以使用 Linfo 在 Web 浏览器中查看 Linux 系统的信息。尝试一下,并在评论中和我们分享你的想法。另外,你是否还知道与之类似的有用工具/库?如果有,请给我们提供一些相关信息。


作者简介:

Aaron Kili 是 Linux 和 F.O.S.S 爱好者,将来的 Linux 系统管理员和网络开发人员,目前是 TecMint 的内容创作者,他喜欢用电脑工作,并坚信分享知识


via: https://www.tecmint.com/linfo-shows-linux-server-health-status-in-real-time/

作者:Aaron Kili 译者:ucasFL 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出

相关推荐