在CentOS 7上安装netdata

时间:2020-02-23 14:31:20  来源:igfitidea点击:

Netdata是Linux,FreeBSD和MacOS兼容的工具,用于分布式实时性能和系统运行状况监视。 Netdata是与虚拟机,物理服务器,容器和IOT设备配合使用的最佳实时监视工具之一。它利用了现代的交互式Web仪表板。

最新版本的netdata的一些良好功能包括:自动缩放图表单位IP访问列表用于过滤对netdata的访问增强的VM和容器监控突出显示仪表板所有图表的时间范围仪表盘快照,用于加载/保存选定的时间范围时区转换仪表板以允许将图表与服务器日志进行比较零维护,配置和依赖关系易于定制,可扩展和可嵌入将比例缩放到infinityTime后端支持,可以将其指标存储在石墨,opentsdb,Prometheus,JSON文档DB上或者更低的细节。

在CentOS 7上安装Netdata

首先,首先安装netdata所需的缺少的依赖项。这是通过运行来完成的。

# yum -y install curl git
# curl -Ss 'https://raw.githubusercontent.com/firehol/netdata-demo-site/master/install-required-packages.sh'

然后执行下载的脚本。

# bash install-required-packages.sh

这将下载netdata所需的许多软件包。完成后,我们可以继续从Github克隆netdata源代码。

# git clone https://github.com/firehol/netdata.git --depth=1
Cloning into 'netdata'...
remote: Counting objects: 736, done.
remote: Compressing objects: 100% (676/676), done.
remote: Total 736 (delta 99), reused 265 (delta 43), pack-reused 0
Receiving objects: 100% (736/736), 2.54 MiB | 149.00 KiB/s, done.
Resolving deltas: 100% (99/99), done.

然后通过执行netdata-installer.sh脚本开始安装netdata。

# cd netdata/
# ./netdata-installer.sh

^
|.-. .-. .-. .-. . netdata 
| '-' '-' '-' '-' real-time performance monitoring, done right! 
+----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--->

You are about to build and install netdata to your system.

It will be installed at these locations:

- the daemon at /usr/sbin/netdata
- config files in /etc/netdata
- web files in /usr/share/netdata
- plugins in /usr/libexec/netdata
- cache files in /var/cache/netdata
- db files in /var/lib/netdata
- log files in /var/log/netdata
- pid file at /var/run/netdata.pid
- logrotate file at /etc/logrotate.d/netdata

This installer allows you to change the installation path.
Press Control-C and run the same command with --help for help.

Press ENTER to build and install netdata to your system >

要开始安装过程,请按<ENTER>

成功安装后,我们将收到如下消息:

.....
Uninstall script generated: ./netdata-uninstaller.sh
Update script generated : ./netdata-updater.sh

netdata-updater.sh can work from cron. It will trigger an email from cron
only if it fails (it does not print anything when it can update netdata).
Run this to automatically check and install netdata updates once per day:

sudo ln -s /root/netdata/netdata-updater.sh /etc/cron.daily/netdata-updater

--- We are done! --
^
|.-. .-. .-. .-. .-. . netdata .-. .
| '-' '-' '-' '-' '-' is installed and running now! -' '-' 
+----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--->

enjoy real-time performance and health monitoring...

配置内存重复数据删除

如果我们有可用的内核内存重复数据消除程序(称为内核同一页合并,或者KSM),但当前未启用。我们应该通过运行以下命令启用它:

echo 1 >/sys/kernel/mm/ksm/run
echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs

它将使Netdata内存利用率降低40-60%。

要启动netdata运行:

# systemctl start netdata
# systemctl status netdata

在防火墙上打开netdata端口

既然我们已经确认netdata服务正在运行,请在防火墙上打开其服务端口,以便我们可以在外部访问它。使用以下命令:

# firewall-cmd --add-port=19999/tcp --permanent
# firewall-cmd --reload

配置SELinux

我们可以选择禁用SELinux,将其置于许可模式或者配置port19999以与SELinux一起使用。要将SELinux置于许可模式,请运行

# setenforce 0
# sestatus 
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: permissive
Mode from config file: permissive
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 28

# cat /etc/selinux/config | grep -v ^# | grep SELINUX=
SELINUX=permissive

要禁用SELinux,请将行更改为SELINUX = disabled并重新引导服务器。

如果SELinux设置为强制。我们可能需要为此安装semanagetool:

# yum -y install policycoreutils-python

现在,我们可以使用semanage命令行工具标记netdata端口。

# semanage port -a -t ssh_port_t -p tcp 19999
# systemctl restart netdata
# systemctl status netdata
● netdata.service - Real time performance monitoring
 Loaded: loaded (/etc/systemd/system/netdata.service; enabled; vendor preset: disabled)
 Active: active (running) since Wed 2016-02-21 11:14:43 EAT; 3h 43min ago
 Process: 8600 ExecStartPre=/bin/chown -R netdata:netdata /var/cache/netdata (code=exited, status=0/SUCCESS)
 Process: 8598 ExecStartPre=/bin/mkdir -p /var/cache/netdata (code=exited, status=0/SUCCESS)
 Main PID: 8603 (netdata)
 CGroup: /system.slice/netdata.service
 ├─ 8603 /usr/sbin/netdata -P /run/netdata/netdata.pid -D
 ├─ 8639 /usr/bin/python /usr/libexec/netdata/plugins.d/python.d.pl...
 ├─ 8640 /usr/libexec/netdata/plugins.d/apps.plugin 1
 └─23394 bash /usr/libexec/netdata/plugins.d/tc-qos-helper.sh 1

访问服务器IP地址和端口19999. 我们应该正在运行netdata。