【51CTO精选译文】说到监控Linux设备,眼下有好多方法可供选择。虽然有许多适用于生产环境的监控解决方案(比如Nagios、Zabbix和Zenoss)声称拥有漂亮的用户界面、监控可扩展性以及全面报告功能等,但这些解决方案对我们大多数最终用户来说恐怕是大材小用。如果你仅仅需要检查远程Linux服务器或桌面系统的基本状况(比如处理器负载、内存使用情况和活动进程),不妨考虑使用Linux-dash。
Linux-dash是一个面向Linux系统、基于Web的轻型监控仪表板,它可以实时显示系统的各种属性,比如处理器负载、内存使用情况、磁盘使用情况、互联网速度、网络连接、RX/TX带宽、已登录用户、运行中进程,等等。linux-dash并不随带用来存储长期统计信息的任何后端服务器。你只要将linux-dash应用程序安装到现有的Web服务器(比如Apache和Nginx服务器)上,就可以了。这是一种快速而简单的方法,可以为个人项目搭建远程监控机制。
我在本教程中将介绍如何在Linux平台上的Nginx Web服务器中安装linux-dash。由于使用轻型引擎,Nginx Web服务器比Apache Web服务器更讨人喜欢。
在Debian、Ubuntu或Linux Mint安装linux-dash
首先,安装Nginx Web服务器以及php-fpm组件。
$ sudo apt-get install git nginx php5-json php5-fpm php5-curl
- 1.
为linux-dash应用程序配置Nginx,为此需要创建/etc/nginx/conf.d/linuxdash.conf,步骤如下所示。在本示例中,我们将使用端口8080。
$ sudo vi /etc/nginx/conf.d/linuxdash.conf
server {
server_name $domain_name;
listen 8080;
root /var/www;
index index.html index.php;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location ~* \.(?:xml|ogg|mp3|mp4|ogv|svg|svgz|eot|otf|woff|ttf|css|js|jpg|jpeg|gif|png|ico)$ {
try_files $uri =404;
expires max;
access_log off;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
location /linux-dash {
index index.html index.php;
}
# PHP-FPM via sockets
location ~ \.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
try_files $uri $uri/ /index.php?$args;
include fastcgi_params;
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
禁用默认站点配置。
$ sudo rm /etc/nginx/sites-enabled/default
- 1.
配置php-fpm,为此需要编辑/etc/php5/fpm/pool.d/www.conf。确保编辑如下所示的"user"、"group"和"listen"指令。配置的其余部分可以保留不变。
$ sudo vi /etc/php5/fpm/pool.d/www.conf
. . .
user = www-data
group = www-data
listen = /var/run/php5-fpm.sock
. . .
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
接着下载和安装linux-dash。
$ git clone https://github.com/afaqurk/linux-dash.git
$ sudo cp -r linux-dash/ /var/www/
$ sudo chown -R www-data:www-data /var/www
- 1.
- 2.
- 3.
重启Nginx Web服务器,并重启php5-fpm,完成安装的***步骤。
$ sudo service php5-fpm restart
$ sudo service nginx restart
- 1.
- 2.
在CentOS、Fedora或RHEL上安装linux-dash
在CentOS上,首先启用EPEL软件库(具体参阅http://xmodulo.com/2013/03/how-to-set-up-epel-repository-on-centos.html),这一步必不可少。
安装Nginx Web服务器和php-fpm组件。
$ sudo yum install git nginx php-common php-fpm
- 1.
想为linux-dash应用程序配置Nginx,就要创建/etc/nginx/conf.d/linuxdash.conf,如下所示。
$ sudo vi /etc/nginx/conf.d/linuxdash.conf
server {
server_name $domain_name;
listen 8080;
root /var/www;
index index.html index.php;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location ~* \.(?:xml|ogg|mp3|mp4|ogv|svg|svgz|eot|otf|woff|ttf|css|js|jpg|jpeg|gif|png|ico)$ {
try_files $uri =404;
expires max;
access_log off;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
location /linux-dash {
index index.html index.php;
}
# PHP-FPM via sockets
location ~ \.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php-fpm.sock;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
try_files $uri $uri/ /index.php?$args;
include fastcgi_params;
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
下一步,配置php-fpm,为此需要编辑/etc/php-fpm.d/www.conf。在该文件中,确保按如下设置"listen"、"user"和"group"等字段。配置的其余部分则保留不变。
$ sudo vi /etc/php-fpm.d/www.conf
. . .
listen = /var/run/php-fpm.sock
user = nginx
group = nginx
. . .
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
下载linux-dash,并安装到/var/www下面。
$ git clone https://github.com/afaqurk/linux-dash.git
$ sudo cp -r linux-dash/ /var/www/
$ sudo chown -R nginx:nginx /var/www
- 1.
- 2.
- 3.
***,重启Nginx Web服务器,并重启php-fpm,将它们设成系统一启动就自动开始运行。
$ sudo service php-fpm restart
$ sudo service nginx restart
$ sudo chkconfig nginx on
$ sudo chkconfig php-fpm on
- 1.
- 2.
- 3.
- 4.
在本示例中,我们配置了linux-dash,以便使用TCP端口8080。所以,确保防火墙没有封阻TCP端口8080。
借助linux-dash监控Linux机器
想从Web浏览器访问linux-dash,只要在你的Web浏览器上进入到http://<linux-IP-address>:8080/linux-dash/。
下面是linux-dash的几个屏幕截图。Web仪表板包括几个窗口组件,每个窗口组件显示特定的系统属性。你可以定制这个Web仪表板的外观,只需重新排列及/或关闭其中一些窗口组件。linux-dash的开发者搭建的演示网站是http://afaq.dreamhosters.com/linux-dash/,有兴趣的读者不妨浏览。
原文链接:http://xmodulo.com/2014/04/monitor-linux-server-desktop-remotely-web-browser.html