Linfo：实时显示你的 Linux 服务器运行状况
Linfo 监控
![](/data/attachment/album/201705/27/163719b1e6b30fubbjzrmb.jpg)


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


Linfo 显示的系统信息包括 [CPU 类型/速度](/article-8241-1.html)、服务器的体系结构、挂载点用量、硬盘/光纤／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 命令](https://www.tecmint.com/rsync-local-remote-file-synchronization-commands/) 克隆仓库文件并将其移动到目录 `/var/www/html/linfo` 下：



```
$ sudo mkdir -p /var/www/html/linfo 
$ git clone git://github.com/jrgp/linfo.git 
$ sudo rsync -av linfo/ /var/www/html/linfo/

```

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



```
$ sudo mv sample.config.inc.php config.inc.php 

```

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


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


![Linux Server Health Information](/data/attachment/album/201705/27/163729mc8rssg0km0knvzm.png)


*Linux 服务器运行信息*


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



```
$settings['show_errors'] = true;

```

### 以 Ncurses 模式运行 Linfo


Linfo 有一个基于 `ncurses` 的简单界面，它依赖于 `php` 的 `ncurses` 扩展。



```
# yum install php-pecl-ncurses                    [在 CentOS/RHEL 上]
# dnf install php-pecl-ncurses                    [在 Fedora 上]
$ sudo apt-get install php5-dev libncurses5-dev   [在 Debian/Ubuntu 上] 

```

现在，像下面这样编译这个 php 扩展：



```
$ wget http://pecl.php.net/get/ncurses-1.0.2.tgz
$ tar xzvf ncurses-1.0.2.tgz
$ cd ncurses-1.0.2
$ phpize # generate configure script
$ ./configure
$ make
$ sudo make install

```

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



```
$ sudo echo extension=ncurses.so > /etc/php5/cli/conf.d/ncurses.ini

```

验证 ncurse：



```
$ php -m | grep ncurses

```

现在，运行 Info：



```
$ cd /var/www/html/linfo/
$ ./linfo-curses

```

![Linux Server Information](/data/attachment/album/201705/27/163730jiec484ogsyojk5i.png)


*Linux 服务器信息*


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


1. 支持更多 Unix 操作系统（比如 Hurd、IRIX、AIX 和 HP UX 等）
2. 支持不太出名的操作系统 Haiku/BeOS
3. 额外功能/扩展
4. 在 ncurses 模式中支持 [htop 类](https://www.tecmint.com/install-htop-linux-process-monitoring-for-rhel-centos-fedora/) 特性


如果想了解更多信息，请访问 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](https://www.tecmint.com/author/aaronkili/) 译者：[ucasFL](https://github.com/ucasFL) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
**Linfo** is a free and open source, cross-platform server statistics UI/library which displays a great deal of system information. It is extensible, easy-to-use (via composer) PHP5 library to get extensive system statistics programmatically from your PHP application. It’s a Ncurses CLI view of Web UI, which works in Linux, Windows, *BSD, Darwin/Mac OSX, Solaris, and Minix.

It displays system info including [CPU type/speed](https://www.tecmint.com/corefreq-linux-cpu-monitoring-tool/); architecture, mount point usage, hard/optical/flash drives, hardware devices, network devices and stats, uptime/date booted, hostname, memory usage (RAM and swap, if possible), temperatures/voltages/fan speeds and RAID arrays.

#### Requirements:

- PHP 5.3
- pcre extension
- Linux – /proc and /sys mounted and readable by PHP and Tested with the 2.6.x/3.x kernels

### How to Install Linfo Server Stats UI/library in Linux

First, create a **Linfo** directory in your Apache or Nginx web root directory, then clone and move repository files into `/var/www/html/linfo`

using the [rsync command](https://www.tecmint.com/rsync-local-remote-file-synchronization-commands/) as shown below:

$ sudo mkdir -p /var/www/html/linfo $ git clone git://github.com/jrgp/linfo.git $ sudo rsync -av linfo/ /var/www/html/linfo/

Then rename **sample.config.inc.php** to **config.inc.php**. This is the Linfo config file, you can define your own values in it:

$ sudo mv sample.config.inc.php config.inc.php

Now open the URL `http://SERVER_IP/linfo`

in web browser to see the Web UI as shown in the screenshots below.

This screenshot shows the Linfo Web UI displaying core system info, hardware components, RAM stats, network devices, drives and file system mount points.

![Linux Server Health Information](https://www.tecmint.com/wp-content/uploads/2017/05/Linux-Server-Health-Information.png)

You can add the line below in the config file `config.inc.php`

to yield useful error messages for troubleshooting purposes:

$settings['show_errors'] = true;

### Running Linfo in Ncurses Mode

Linfo has a simple ncurses-based interface, which rely on php’s ncurses extension.

# yum install php-pecl-ncurses [On CentOS/RHEL] # dnf install php-pecl-ncurses [On Fedora] $ sudo apt-get install php5-dev libncurses5-dev [On Debian/Ubuntu]

Now compile the php extension as follows

$ wget http://pecl.php.net/get/ncurses-1.0.2.tgz $ tar xzvf ncurses-1.0.2.tgz $ cd ncurses-1.0.2 $ phpize # generate configure script $ ./configure $ make $ sudo make install

Next, if you successfully compiled and installed the php extension, run the commands below.

$ sudo echo extension=ncurses.so > /etc/php5/cli/conf.d/ncurses.ini

Verify the ncurses.

$ php -m | grep ncurses

Now run the **Linfo**.

$ cd /var/www/html/linfo/ $ ./linfo-curses

![Linux Server Information](https://www.tecmint.com/wp-content/uploads/2017/05/Linux-Server-Information.png)

The following features yet to be added in Linfo:

- Support for more Unix operating systems (such as Hurd, IRIX, AIX, HP UX, etc)
- Support for less known operating systems: Haiku/BeOS
- Extra superfluous features/extensions
- Support for
[htop-like](https://www.tecmint.com/install-htop-linux-process-monitoring-for-rhel-centos-fedora/)features in ncurses mode

For more information, visit Linfo Github repository: [https://github.com/jrgp/linfo](https://github.com/jrgp/linfo)

That’s all! From now on, you can view a Linux system’s information from within a web browser using Linfo. Try it out and share with us your thoughts in the comments. Additionally, have you come across any similar useful tools/libraries? If yes, then give us some info about them as well.

Hi, I did not want “anything” to download files from linfo so I added a

Reply`.htaccess`

file in thelinfodirectory:Hi Aaron Kili,

UI linfois working great but when i tired “Running Linfo in Ncurses Mode” but not able to run even through successful compilation on Ubuntu 14.04 32bit this command give me permission error.“sudo echo extension=ncurses.so > /etc/php5/cli/conf.d/ncurses.ini” ——> bash: /etc/php5/cli/conf.d/ncurses.ini: Permission denied

also

ncurses.inifile is not present after compilation.Can you please help !!!

Reply@Rahul

Try to post an issue about this on the Linfo Github repository to get more clarification.

ReplyHi Thanks Aaron Kili,

Can we run the configure from single system and get the report of multiple Linux server in the environment. And get the email report at specific time interval.

Reply@Imtiyaz

Linfo works on a single system, to offer the functionality you have described you’ll need to modify it a little. But try to find more from the developer at: https://github.com/jrgp/linfo

ReplyCan we installed on siem server

Reply@Imtiyaz

Yes, you can install on SIEM server.

ReplyThank you for your article.

Unfortunately, after running

http://SERVER_IP/linfocommand I can see only the list of files in Linfo catalog:Wha should I do else to have this site running correctly? I can’t see here an index.html file. Is it normally?

Centos 7.3 Minimal on VmWare Workstation 12

Thank you!

Reply@Alexey

Welcome, there is an index.php file, this is the default index file. Make sure that your web server serves .php index files. For Apache, open the httpd.conf set it using the

DirectoryIndexdirective(list them in order of preference) as follows:

ReplyDirectoryIndex index.php index.phtml index.html index.htmThere was just one option in DirectoryIndex – index.html

I added index.php index.phtml index.html index.htm and after that restartng httpd service.

After trying to open the site the other error occured:

scan();

if (isset($_SERVER[‘LINFO_NCURSES’]) && php_sapi_name() == ‘cli’) {

$output = new \Linfo\Output\Ncurses($linfo);

}

else {

switch (array_key_exists(‘out’, $_GET) ? strtolower($_GET[‘out’]) : ‘html’) {

default:

case ‘html’:

$output = new \Linfo\Output\Html($linfo);

break;

case ‘json’:

case ‘jsonp’: // To use JSON-P, pass the GET arg – callback=function_name

$output = new \Linfo\Output\Json($linfo, array_key_exists(‘callback’, $_GET) ? $_GET[‘callback’] : null);

break;

case ‘php_array’:

$output = new \Linfo\Output\Serialized($linfo);

break;

case ‘xml’:

$output = new \Linfo\Output\Xml($linfo);

break;

}

}

$output->output();

} catch (FatalException $e) {

echo $e->getMessage().”\n”;

exit(1);

}

What’s wrong here?

Thank you!

ReplyMight be since I have installed Centos Minimal version no PHP was included during installation.

So, I have just installed PHP 7.1.5, restart httpd service and it works now!

Thank you for your help!

Reply@Alexey

This is great, good to know that you fixed the error. This will definitely help us in future when offering solutions to other readers’ issues/errors.

Many thanks for the feedback.

Thanks for your great tips. I want to know can these tools show the health of HDD and the temperature?

Cheers

Reply@jamshid

Welcome, you can use


Replyhddtempfor this, but you need to find a way of using the output from Linfo web UI.To install hddtemp, type:

sudo apt install hddtempThank you Aaron Kili :)

Reply@Jamshid

Welcome, many thanks for the useful feedback, and always following us.

ReplyHi thanks for the useful tips, can it show the health and temperature of HDD?

Jamshid

Reply