在Linux上安装NetData性能监控工具
NetData 是一个用于系统和应用的分布式实时性能和健康监控工具。它提供了对系统中实时发生的所有事情的全面检测。你可以在高度互动的 Web 仪表板中查看结果。使用 Netdata,你可以清楚地了解现在发生的事情,以及之前系统和应用中发生的事情。你无需成为专家即可在 Linux 系统中部署此工具。NetData 开箱即用,零配置、零依赖。只需安装它然后坐等,之后 NetData 将负责其余部分。
它有自己的内置 Web 服务器,以图形形式显示结果。NetData 非常快速高效,安装后可立即开始分析系统性能。它是用 C 编程语言编写的,所以它非常轻量。它占用的单核 CPU 使用率不到 3%,内存占用 10-15MB。我们可以轻松地在任何现有网页上嵌入图表,并且它还有一个插件 API,以便你可以监控任何应用。
以下是 Linux 系统中 NetData 的监控列表。
- CPU 使用率
- RAM 使用率
- 交换内存使用率
- 内核内存使用率
- 硬盘及其使用率
- 网络接口
- IPtables
- Netfilter
- DDoS 保护
- 进程
- 应用
- NFS 服务器
- Web 服务器 (Apache 和 Nginx)
- 数据库服务器 (MySQL),
- DHCP 服务器
- DNS 服务器
- 电子邮件服务
- 代理服务器
- Tomcat
- PHP
- SNP 设备
- 等等
NetData 是自由开源工具,它支持 Linux、FreeBSD 和 Mac OS。
在 Linux 上安装 NetData
Netdata 可以安装在任何安装了 Bash 的 Linux 发行版上。
最简单的安装 Netdata 的方法是从终端运行以下命令:
<span class="pln">$ </span><span class="kwd">bash</span><span class="pln"> </span><span class="pun"><(</span><span class="pln">curl </span><span class="pun">-</span><span class="typ">Ss</span><span class="pln"> https</span><span class="pun">:</span><span class="com">//my-netdata.io/kickstart-static64.sh)</span>
这将下载并安装启动和运行 Netdata 所需的一切。
有些用户可能不想在没有研究的情况下将某些东西直接注入到 Bash。如果你不喜欢此方法,可以按照以下步骤在系统上安装它。
在 Arch Linux 上
Arch Linux 默认仓库中提供了最新版本。所以,我们可以使用以下 pacman 命令安装它:
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> pacman </span><span class="pun">-</span><span class="pln">S netdata</span>
在基于 DEB 和基于 RPM 的系统上
在基于 DEB (Ubuntu / Debian)或基于 RPM(RHEL / CentOS / Fedora) 系统的默认仓库没有 NetData。我们需要从它的 Git 仓库手动安装 NetData。
首先安装所需的依赖项:
<span class="com">#</span><span class="pln"> </span><span class="typ">Debian</span><span class="pln"> </span><span class="pun">/</span><span class="pln"> </span><span class="typ">Ubuntu</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> </span><span class="kwd">apt-get</span><span class="pln"> install zlib1g</span><span class="pun">-</span><span class="pln">dev uuid</span><span class="pun">-</span><span class="pln">dev libuv1</span><span class="pun">-</span><span class="pln">dev liblz4</span><span class="pun">-</span><span class="pln">dev libjudy</span><span class="pun">-</span><span class="pln">dev libssl</span><span class="pun">-</span><span class="pln">dev libmnl</span><span class="pun">-</span><span class="pln">dev </span><span class="kwd">gcc</span><span class="pln"> </span><span class="kwd">make</span><span class="pln"> </span><span class="kwd">git</span><span class="pln"> autoconf autoconf</span><span class="pun">-</span><span class="pln">archive autogen automake pkg</span><span class="pun">-</span><span class="pln">config curl</span>
<span class="com">#</span><span class="pln"> </span><span class="typ">Fedora</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> dnf install zlib</span><span class="pun">-</span><span class="pln">devel libuuid</span><span class="pun">-</span><span class="pln">devel libuv</span><span class="pun">-</span><span class="pln">devel lz4</span><span class="pun">-</span><span class="pln">devel </span><span class="typ">Judy</span><span class="pun">-</span><span class="pln">devel openssl</span><span class="pun">-</span><span class="pln">devel libmnl</span><span class="pun">-</span><span class="pln">devel </span><span class="kwd">gcc</span><span class="pln"> </span><span class="kwd">make</span><span class="pln"> </span><span class="kwd">git</span><span class="pln"> autoconf autoconf</span><span class="pun">-</span><span class="pln">archive autogen automake pkgconfig curl findutils</span>
<span class="com">#</span><span class="pln"> </span><span class="typ">CentOS</span><span class="pln"> </span><span class="pun">/</span><span class="pln"> </span><span class="typ">Red</span><span class="pln"> </span><span class="typ">Hat</span><span class="pln"> </span><span class="typ">Enterprise</span><span class="pln"> </span><span class="typ">Linux</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> </span><span class="kwd">yum</span><span class="pln"> install epel</span><span class="pun">-</span><span class="pln">release</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> </span><span class="kwd">yum</span><span class="pln"> install autoconf automake curl </span><span class="kwd">gcc</span><span class="pln"> </span><span class="kwd">git</span><span class="pln"> libmnl</span><span class="pun">-</span><span class="pln">devel libuuid</span><span class="pun">-</span><span class="pln">devel openssl</span><span class="pun">-</span><span class="pln">devel libuv</span><span class="pun">-</span><span class="pln">devel lz4</span><span class="pun">-</span><span class="pln">devel </span><span class="typ">Judy</span><span class="pun">-</span><span class="pln">devel lm_sensors </span><span class="kwd">make</span><span class="pln"> </span><span class="typ">MySQL</span><span class="pun">-</span><span class="pln">python nc pkgconfig python python</span><span class="pun">-</span><span class="pln">psycopg2 </span><span class="typ">PyYAML</span><span class="pln"> zlib</span><span class="pun">-</span><span class="pln">devel</span>
<span class="com">#</span><span class="pln"> openSUSE</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> zypper install zlib</span><span class="pun">-</span><span class="pln">devel libuuid</span><span class="pun">-</span><span class="pln">devel libuv</span><span class="pun">-</span><span class="pln">devel liblz4</span><span class="pun">-</span><span class="pln">devel judy</span><span class="pun">-</span><span class="pln">devel openssl</span><span class="pun">-</span><span class="pln">devel libmnl</span><span class="pun">-</span><span class="pln">devel </span><span class="kwd">gcc</span><span class="pln"> </span><span class="kwd">make</span><span class="pln"> </span><span class="kwd">git</span><span class="pln"> autoconf autoconf</span><span class="pun">-</span><span class="pln">archive autogen automake pkgconfig curl findutils</span>
安装依赖项后,在基于 DEB 或基于 RPM 的系统上安装 NetData,如下所示。
Git 克隆 NetData 仓库:
<span class="pln">$ </span><span class="kwd">git</span><span class="pln"> </span><span class="kwd">clone</span><span class="pln"> https</span><span class="pun">:</span><span class="com">//github.com/netdata/netdata.git --depth=100</span>
上面的命令将在当前工作目录中创建一个名为 netdata
的目录。
切换到 netdata
目录:
<span class="pln">$ </span><span class="kwd">cd</span><span class="pln"> netdata</span><span class="pun">/</span>
最后,使用命令安装并启动 NetData:
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> </span><span class="pun">./</span><span class="pln">netdata</span><span class="pun">-</span><span class="pln">installer</span><span class="pun">.</span><span class="pln">sh</span>
示例输出:
<span class="typ">Welcome</span><span class="pln"> to netdata</span><span class="pun">!</span>
<span class="typ">Nice</span><span class="pln"> to see you are giving it a </span><span class="kwd">try</span><span class="pun">!</span>
<span class="typ">You</span><span class="pln"> are about to build </span><span class="kwd">and</span><span class="pln"> install netdata to your system</span><span class="pun">.</span>
<span class="typ">It</span><span class="pln"> will be installed at these locations</span><span class="pun">:</span>
<span class="pun">-</span><span class="pln"> the daemon at </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">sbin</span><span class="pun">/</span><span class="pln">netdata</span>
<span class="pln"> </span><span class="pun">-</span><span class="pln"> config files at </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">netdata</span>
<span class="pln"> </span><span class="pun">-</span><span class="pln"> web files at </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">share</span><span class="pun">/</span><span class="pln">netdata</span>
<span class="pln"> </span><span class="pun">-</span><span class="pln"> plugins at </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">libexec</span><span class="pun">/</span><span class="pln">netdata</span>
<span class="pln"> </span><span class="pun">-</span><span class="pln"> cache files at </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">cache</span><span class="pun">/</span><span class="pln">netdata</span>
<span class="pln"> </span><span class="pun">-</span><span class="pln"> db files at </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">lib</span><span class="pun">/</span><span class="pln">netdata</span>
<span class="pln"> </span><span class="pun">-</span><span class="pln"> log files at </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">log</span><span class="pun">/</span><span class="pln">netdata</span>
<span class="pln"> </span><span class="pun">-</span><span class="pln"> pid </span><span class="kwd">file</span><span class="pln"> at </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">run</span>
<span class="typ">This</span><span class="pln"> installer allows you to change the installation path</span><span class="pun">.</span>
<span class="typ">Press</span><span class="pln"> </span><span class="typ">Control</span><span class="pun">-</span><span class="pln">C </span><span class="kwd">and</span><span class="pln"> run the same command </span><span class="kwd">with</span><span class="pln"> </span><span class="pun">--</span><span class="pln">help </span><span class="kwd">for</span><span class="pln"> help</span><span class="pun">.</span>
<span class="typ">Press</span><span class="pln"> ENTER to build </span><span class="kwd">and</span><span class="pln"> install netdata to your system </span><span class="pun">></span><span class="pln"> </span><span class="com">##</span><span class="pln"> </span><span class="typ">Press</span><span class="pln"> ENTER key</span>
安装完成后,你将在最后看到以下输出:
<span class="pun">-------------------------------------------------------------------------------</span>
<span class="pln">OK</span><span class="pun">.</span><span class="pln"> </span><span class="typ">NetData</span><span class="pln"> </span><span class="kwd">is</span><span class="pln"> installed </span><span class="kwd">and</span><span class="pln"> it </span><span class="kwd">is</span><span class="pln"> running </span><span class="pun">(</span><span class="pln">listening to </span><span class="pun">*:</span><span class="lit">19999</span><span class="pun">).</span>
<span class="pun">-------------------------------------------------------------------------------</span>
<span class="pln">INFO</span><span class="pun">:</span><span class="pln"> </span><span class="typ">Command</span><span class="pln"> line options changed</span><span class="pun">.</span><span class="pln"> </span><span class="pun">-</span><span class="pln">pidfile</span><span class="pun">,</span><span class="pln"> </span><span class="pun">-</span><span class="pln">nd </span><span class="kwd">and</span><span class="pln"> </span><span class="pun">-</span><span class="pln">ch are deprecated</span><span class="pun">.</span>
<span class="typ">If</span><span class="pln"> you </span><span class="kwd">use</span><span class="pln"> custom startup scripts</span><span class="pun">,</span><span class="pln"> please run netdata </span><span class="pun">-</span><span class="pln">h to see the</span>
<span class="pln">corresponding options </span><span class="kwd">and</span><span class="pln"> update your scripts</span><span class="pun">.</span>
<span class="typ">Hit</span><span class="pln"> http</span><span class="pun">:</span><span class="com">//localhost:19999/ from your browser.</span>
<span class="typ">To</span><span class="pln"> stop netdata</span><span class="pun">,</span><span class="pln"> just </span><span class="kwd">kill</span><span class="pln"> it</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">with</span><span class="pun">:</span>
<span class="kwd">killall</span><span class="pln"> netdata</span>
<span class="typ">To</span><span class="pln"> start it</span><span class="pun">,</span><span class="pln"> just run it</span><span class="pun">:</span>
<span class="str">/usr/</span><span class="pln">sbin</span><span class="pun">/</span><span class="pln">netdata</span>
<span class="typ">Enjoy</span><span class="pun">!</span>
<span class="typ">Uninstall</span><span class="pln"> </span><span class="kwd">script</span><span class="pln"> generated</span><span class="pun">:</span><span class="pln"> </span><span class="pun">./</span><span class="pln">netdata</span><span class="pun">-</span><span class="pln">uninstaller</span><span class="pun">.</span><span class="pln">sh</span>
安装 NetData
NetData 已安装并启动。
要在其他 Linux 发行版上安装 Netdata,请参阅官方安装说明页面。
在防火墙或者路由器上允许 NetData 的默认端口
如果你的系统在防火墙或者路由器后面,那么必须允许默认端口 19999
以便从任何远程系统访问 NetData 的 web 界面。
在 Ubuntu/Debian 中
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> ufw allow </span><span class="lit">19999</span>
在 CentOS/RHEL/Fedora 中
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">permanent </span><span class="pun">--</span><span class="pln">add</span><span class="pun">-</span><span class="pln">port</span><span class="pun">=</span><span class="lit">19999</span><span class="pun">/</span><span class="pln">tcp</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">reload</span>
启动/停止 NetData
要在使用 Systemd 的系统上启用和启动 Netdata 服务,请运行:
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> </span><span class="kwd">systemctl</span><span class="pln"> enable netdata</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> </span><span class="kwd">systemctl</span><span class="pln"> start netdata</span>
要停止:
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> </span><span class="kwd">systemctl</span><span class="pln"> stop netdata</span>
要在使用 Init 的系统上启用和启动 Netdata 服务,请运行:
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> service netdata start</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> chkconfig netdata on</span>
要停止:
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> service netdata stop</span>
通过 Web 浏览器访问 NetData
打开 Web 浏览器,然后打开 http://127.0.0.1:19999
或者 http://localhost:19999/
或者 http://ip-address:19999
。你应该看到如下页面。
Netdata 仪表板
在仪表板中,你可以找到 Linux 系统的完整统计信息。向下滚动以查看每个部分。
你可以随时打开 http://localhost:19999/netdata.conf
来下载和/或查看 NetData 默认配置文件。
Netdata 配置文件
更新 NetData
在 Arch Linux 中,只需运行以下命令即可更新 NetData。如果仓库中提供了更新版本,那么就会自动安装该版本。
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> pacman </span><span class="pun">-</span><span class="typ">Syyu</span>
在基于 DEB 或 RPM 的系统中,只需进入已克隆它的目录(此例中是 netdata
)。
<span class="pln">$ </span><span class="kwd">cd</span><span class="pln"> netdata</span>
拉取最新更新:
<span class="pln">$ </span><span class="kwd">git</span><span class="pln"> pull</span>
然后,使用命令重新构建并更新它:
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> </span><span class="pun">./</span><span class="pln">netdata</span><span class="pun">-</span><span class="pln">installer</span><span class="pun">.</span><span class="pln">sh</span>
卸载 NetData
进入克隆 NetData 的文件夹。
<span class="pln">$ </span><span class="kwd">cd</span><span class="pln"> netdata</span>
然后,使用命令卸载它:
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> </span><span class="pun">./</span><span class="pln">netdata</span><span class="pun">-</span><span class="pln">uninstaller</span><span class="pun">.</span><span class="pln">sh </span><span class="pun">--</span><span class="pln">force</span>