Netdata 是一個免費、開源、實時的服務(wù)器監(jiān)控工具,可以可視化和監(jiān)控實時數(shù)據(jù),如 CPU 使用率、RAM 使用率、負載、SWAP 使用率、帶寬使用率、磁盤使用率等。它可以幫助系統(tǒng)管理員了解您的系統(tǒng)或應(yīng)用程序中正在發(fā)生的事情以及剛剛發(fā)生的事情。它可以安裝在任何物理服務(wù)器、虛擬機、容器和物聯(lián)網(wǎng)設(shè)備上。它提供了一個交互式 Web 界面來查看您的服務(wù)器指標,并支持用于持久存儲的各種數(shù)據(jù)存儲。
在本教程中,我們將向您展示如何在 Alma linux 8 上安裝 Netdata 監(jiān)控工具。
先決條件
- 運行 Alma Linux 8 的服務(wù)器。
- 使用您的服務(wù)器 IP 指向的有效域名。
- 在服務(wù)器上配置了 root 密碼。
安裝所需的依賴項
首先,您需要安裝 EPEL 存儲庫和安裝 Netdata 所需的其他依賴項,您可以通過運行以下命令來安裝所有這些:
dnf install epel-release -y
dnf install git libuuid-devel autoconf automake pkgconfig zlib-devel curl findutils libmnl gcc make -y
安裝完所有軟件包后,您可以繼續(xù)下一步。
安裝網(wǎng)絡(luò)數(shù)據(jù)
默認情況下,Netdata 不包含在 Alma Linux 默認存儲庫中。因此,您需要從源代碼安裝它。
首先,使用以下命令從 Git 存儲庫下載最新版本的 Netdata:
git clone --recurse-submodules https://github.com/netdata/netdata.git --depth=100
下載完成后,將目錄更改為 netdata 并使用以下命令安裝所有必需的依賴項:
cd
netdata ./packaging/installer/install-required-packages.sh --non-interactive --dont-wait netdata
接下來,使用以下命令安裝其他軟件包:
dnf --enablerepo=powertools install libuv-devel
接下來,運行 Netdata 安裝腳本開始安裝。
./netdata-installer.sh
您將獲得以下輸出:
--- real-time performance monitoring, done right! ---
You are about to build and install netdata to your system.
The build process will use /tmp for
any temporary files. You can override this by setting $TMPDIR to a
writable directory where you can execute files.
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.
NOTE:
Anonymous usage stats will be collected and sent to Netdata.
To opt-out, pass --disable-telemetry option to the installer or export
the environment variable DISABLE_TELEMETRY to a non-zero or non-empty value
(e.g: export DISABLE_TELEMETRY=1).
Press ENTER to build and install netdata to your system >
按 Enter 鍵將 Netdata 安裝到您的系統(tǒng)。安裝 Netdata 后,您將獲得以下輸出:
將 netdata.tarball.checksum 設(shè)置為“new_installation”
Setting netdata.tarball.checksum to 'new_installation'
--- We are done! ---
^
|.-. .-. .-. .-. .-. . netdata .-. .-. .-. .-. .-. .-
| '-' '-' '-' '-' '-' '-' '-' '-' '-' '-'
+----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--->
--- is installed and running now! ---
enjoy real-time performance and health monitoring...
systemctl start netdata
systemctl enable netdata
您現(xiàn)在可以使用以下命令檢查 Netdata 的狀態(tài)。
systemctl status netdata
您將獲得以下輸出:
? netdata.service - Real time performance monitoring
Loaded: loaded (/usr/lib/systemd/system/netdata.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2022-03-19 04:22:22 UTC; 4min 16s ago
Main PID: 58935 (netdata)
Tasks: 50 (limit: 11412)
Memory: 103.1M
CGroup: /system.slice/netdata.service
??58935 /usr/sbin/netdata -P /var/run/netdata/netdata.pid -D
??58938 /usr/sbin/netdata --special-spawn-server
??59063 /usr/libexec/netdata/plugins.d/Apps.plugin 1
??59064 /usr/libexec/netdata/plugins.d/ebpf.plugin 1
??59065 /usr/libexec/netdata/plugins.d/go.d.plugin 1
Mar 19 04:22:22 linux systemd[1]: Starting Real time performance monitoring...
Mar 19 04:22:22 linux systemd[1]: Started Real time performance monitoring.
Mar 19 04:22:22 linux netdata[58935]: CONFIG: cannot load cloud config '/var/lib/netdata/cloud.d/cloud.conf'. Running with internal defaults.
Mar 19 04:22:22 linux netdata[58935]: 2022-03-19 04:22:22: netdata INFO : MAIN : CONFIG: cannot load cloud config '/var/lib/netdata/cloud.d/>
Mar 19 04:22:22 linux netdata[58935]: 2022-03-19 04:22:22: netdata INFO : MAIN : Found 0 legacy dbengines, setting multidb diskspace to 256MB
Mar 19 04:22:22 linux netdata[58935]: 2022-03-19 04:22:22: netdata INFO : MAIN : Created file '/var/lib/netdata/dbengine_multihost_size' to >
Mar 19 04:22:22 linux netdata[58935]: Found 0 legacy dbengines, setting multidb diskspace to 256MB
Mar 19 04:22:22 linux netdata[58935]: Created file '/var/lib/netdata/dbengine_multihost_size' to store the computed value
Mar 19 04:22:23 linux ebpf.plugin[59064]: Does not have a configuration file inside `/etc/netdata/ebpf.d.conf. It will try to load stock file.
Mar 19 04:22:23 linux ebpf.plugin[59064]: Cannot read process groups configuration file '/etc/netdata/apps_groups.conf'. Will try '/usr/lib/n>
此時,Netdata 正在運行并監(jiān)聽 19999 端口。您可以使用以下命令檢查它:
ss -antpl | grep netdata
您將獲得以下輸出:
LISTEN 0 128 127.0.0.1:8125 0.0.0.0:* users:(("netdata",pid=58935,fd=29))
LISTEN 0 128 0.0.0.0:19999 0.0.0.0:* users:(("netdata",pid=58935,fd=6))
LISTEN 0 128 [::1]:8125 [::]:* users:(("netdata",pid=58935,fd=28))
LISTEN 0 128 [::]:19999 [::]:* users:(("netdata",pid=58935,fd=7))
完成后,您可以繼續(xù)下一步。
配置防火墻
如果您在系統(tǒng)上使用 firewalld 防火墻,那么您需要允許端口19999和80通過 firewalld。您可以使用以下命令允許它們:
firewall-cmd --permanent --add-port=19999/tcp
firewall-cmd --permanent --add-port=80/tcp
接下來,重新加載 firewalld 守護進程以應(yīng)用更改:
firewall-cmd --reload
完成后,您可以繼續(xù)下一步。
將 Nginx 配置為 Netdata 的反向代理
將 Nginx 安裝和配置為反向代理以訪問 Netdata 始終是一個好主意。首先,使用以下命令安裝 Nginx 服務(wù)器:
dnf install nginx httpd-tools -y
接下來,使用以下命令生成密碼文件:
htpasswd -c /etc/nginx/.htpasswd netadmin
設(shè)置您的管理員密碼,如下所示:
New password:
Re-type new password:
Adding password for user netadmin
接下來,使用以下命令創(chuàng)建一個 Nginx 虛擬主機配置文件:
nano /etc/nginx/conf.d/netdata.conf
添加以下行:
upstream backend {
server 127.0.0.1:19999;
keepalive 64;
}
server {
listen 80;
server_name netdata.example.com;
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_pass_request_headers on;
proxy_set_header Connection "keep-alive";
proxy_store off;
auth_basic "Private Property";
auth_basic_user_file /etc/nginx/.htpasswd;
}
}
保存并關(guān)閉文件,然后驗證 Nginx 是否存在任何語法配置錯誤:
nginx -t
如果一切正常,您將獲得以下輸出:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
接下來,重新啟動 Nginx 服務(wù)以應(yīng)用配置更改:
systemctl restart nginx
您還可以使用以下命令檢查 Nginx 狀態(tài):
systemctl status nginx
您應(yīng)該看到以下輸出:
? nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: active (running) since Sat 2022-03-19 04:28:44 UTC; 4s ago
Process: 61706 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 61705 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 61703 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 61708 (nginx)
Tasks: 2 (limit: 11412)
Memory: 3.7M
CGroup: /system.slice/nginx.service
??61708 nginx: master process /usr/sbin/nginx
??61709 nginx: worker process
Mar 19 04:28:44 linux systemd[1]: Starting The nginx HTTP and reverse proxy server...
Mar 19 04:28:44 linux nginx[61705]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Mar 19 04:28:44 linux nginx[61705]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Mar 19 04:28:44 linux systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Mar 19 04:28:44 linux systemd[1]: Started The nginx HTTP and reverse proxy server.
完成后,您可以繼續(xù)下一步。
訪問網(wǎng)絡(luò)數(shù)據(jù)儀表板
現(xiàn)在,打開您的 Web 瀏覽器并使用 URL http://your-server-ip 訪問 Netdata 儀表板。您應(yīng)該看到 Netdata 登錄頁面:
提供您的管理員用戶名、密碼,然后單擊登錄按鈕。您應(yīng)該在以下頁面上看到 Netdata 儀表板:
結(jié)論
恭喜!您已在 Alma Linux 8 上成功安裝了 Netdata 監(jiān)控工具。您現(xiàn)在可以從 Netdata 儀表板開始實時監(jiān)控您的服務(wù)器矩陣,如果您有任何問題,請隨時問我。