Skip to content

Commit 8bfd7d7

Browse files
authored
🔄 Update "Install and secure Netdata using nginx http basic authentication" (hetzneronline#929)
1 parent 24d8800 commit 8bfd7d7

File tree

5 files changed

+125
-49
lines changed

5 files changed

+125
-49
lines changed

‎tutorials/install-secure-netdata/01.en.md

+125-49
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
SPDX-License-Identifier: MIT
33
path: "/tutorials/install-secure-netdata"
44
slug: "install-secure-netdata"
5-
date: "2020-05-13"
5+
date: "2024-08-29"
66
title: "Install and secure Netdata using nginx http basic authentication"
77
short_description: "In this article, we're going to install Netdata, a linux monitoring software, and secure it using nginx http basic authentication"
88
tags: ["netdata", "monitoring", "linux"]
@@ -18,14 +18,19 @@ cta: "cloud"
1818

1919
## Introduction
2020

21-
In this tutorial, we're going to install Netdata and learn how to prevent public access to its web interface since Netdata doesn't provide authentication by itself.
21+
In this tutorial, we're going to install Netdata and learn how to prevent public access to its web interface, since Netdata doesn't provide authentication by itself.
2222

2323
Netdata is a distributed, real-time performance and health monitoring tool for systems and applications. It is a highly-optimized monitoring agent that can be installed on Linux servers.
2424

2525
**Prerequisites**
2626

2727
* A fresh CentOS or Ubuntu installation (almost all mainstream distributions are supported though)
28-
* Root access to the server
28+
* Access to the root user or a user with sudo permissions
29+
30+
**Example terminology**
31+
32+
* Domain: `example.com`
33+
* Username: `holu`
2934

3035
## Step 1 - Install and configure Netdata
3136

@@ -38,41 +43,99 @@ In order to install the latest version of Netdata, you can use a bash script pro
3843
Simply run the following in your terminal:
3944

4045
```bash
41-
bash <(curl -Ss https://my-netdata.io/kickstart.sh)
46+
bash <(curl -Ss https://get.netdata.cloud/kickstart.sh)
4247
```
4348

44-
![Install Netdata](images/install-netdata-1.png)
49+
Example output:
4550

46-
You should see something like the picture above. It'll ask you for your sudo password if you're not running the script as root.
51+
```shellsession
52+
--- Using /tmp/netdata-kickstart-X3dtqRNrP9 as a temporary directory. ---
53+
--- Checking for existing installations of Netdata... ---
54+
--- No existing installations of netdata found, assuming this is a fresh install. ---
55+
--- Attempting to install using native packages... ---
56+
--- Checking for availability of repository configuration package. ---
57+
[/tmp/netdata-kickstart-X3dtqRNrP9]$ /usr/bin/curl --fail -q -sSL --connect-timeout 10 --retry 3 --output /tmp/netdata-kickstart-X3dtqRNrP9/netdata-repo-edge_3-2+ubuntu24.04_all.deb https://repo.netdata.cloud/repos/repoconfig/ubuntu/noble/netdata-repo-edge_3-2+ubuntu24.04_all.deb
58+
OK
4759

48-
After providing the sudo password, it'll let you know what necessary dependencies are missing so you can install them by pressing ENTER.
60+
Root privileges required to run env apt-get update
61+
[/tmp/netdata-kickstart-X3dtqRNrP9]$ sudo env apt-get update
62+
[sudo] password for holu:
63+
```
4964

50-
![Install Netdata Dependencies](images/install-netdata-2.png)
65+
You should see something like the example output above. If you're not running the script as root, it'll ask you for your sudo password.
66+
67+
After providing the sudo password, it'll let you know what necessary dependencies are missing, so you can install them by entering `y`.
68+
69+
```shellsession
70+
The following additional packages will be installed:
71+
debian-keyring
72+
The following NEW packages will be installed:
73+
debian-keyring netdata-repo-edge
74+
0 upgraded, 2 newly installed, 0 to remove and 106 not upgraded.
75+
Need to get 31.3 MB/31.3 MB of archives.
76+
After this operation, 33.1 MB of additional disk space will be used.
77+
Do you want to continue? [Y/n] y
78+
79+
The following NEW packages will be installed:
80+
libbson-1.0-0t64 libmongoc-1.0-0t64 libmongocrypt0 libnetfilter-acct1 libsnappy1v5 libutf8proc3 netdata netdata-plugin-apps
81+
netdata-plugin-chartsd netdata-plugin-debugfs netdata-plugin-ebpf netdata-plugin-go netdata-plugin-network-viewer netdata-plugin-nfacct
82+
netdata-plugin-perf netdata-plugin-pythond netdata-plugin-slabinfo netdata-plugin-systemd-journal
83+
0 upgraded, 18 newly installed, 0 to remove and 107 not upgraded.
84+
Need to get 45.2 MB of archives.
85+
After this operation, 152 MB of additional disk space will be used.
86+
Do you want to continue? [Y/n] y
87+
88+
```
5189

5290
Once done, Netdata is automatically started and enabled on systemd. Check the status via systemctl:
5391

5492
```bash
55-
systemctl status netdata
93+
sudo systemctl status netdata
5694
```
5795

58-
You can now access Netdata web interface via `<your_host>:19999`
96+
If it is not running yet, you can start it with:
97+
98+
```bash
99+
sudo systemctl enable netdata
100+
sudo systemctl start netdata
101+
```
102+
103+
You can now access Netdata web interface via:
104+
105+
```http
106+
<your_host>:19999
107+
```
59108

60109
### Step 1.2 - Configuration
61110

62111
Now we need to make sure Netdata only listens on `127.0.0.1` since we don't want the web interface to be accessible on the internet.
63112

64113
Open the `/etc/netdata/netdata.conf` file with an editor of your choice.
65114

115+
> If the file is still empty, you can download the latest version of this file, using:
116+
> ```bash
117+
> sudo wget -O /etc/netdata/netdata.conf http://localhost:19999/netdata.conf
118+
> ```
119+
66120
```bash
67121
sudo nano /etc/netdata/netdata.conf
68122
```
69123
70-
Find the `[web]` section and uncomment the `bind to` setting and replace it with the following:
124+
Find the `[web]` section and uncomment the `bind to` setting. Replace it with the following:
71125

72126
```
73127
bind to = 127.0.0.1
74128
```
75129

130+
Now, apply the change:
131+
132+
```bash
133+
sudo systemctl restart netdata
134+
sudo systemctl status netdata
135+
```
136+
137+
After the restart, you can no longer access the Netdata web interface at `<your_host>:19999`.
138+
76139
## Step 2 - Install and configure NGINX
77140

78141
In this step, we will install NGINX to set up a reverse proxy so we're able to access the Netdata web interface securely.
@@ -82,29 +145,41 @@ In this step, we will install NGINX to set up a reverse proxy so we're able to a
82145
You can install NGINX and apache2-utils by running the following commands:
83146
(apache2-utils is needed for the second part of this step)
84147

85-
Debian/Ubuntu:
148+
* Debian/Ubuntu:
149+
```bash
150+
sudo apt install nginx apache2-utils
151+
```
152+
153+
* Redhat/CentOS/Fedora:
154+
```bash
155+
sudo yum install nginx httpd-tools
156+
```
157+
158+
Your NGINX setup should be good to go.
86159

87160
```bash
88-
sudo apt install nginx apache2-utils
161+
nginx -version
162+
sudo systemctl status nginx
89163
```
90164

91-
Redhat/CentOS/Fedora:
165+
If it is not running yet, you can start it with:
92166

93167
```bash
94-
sudo yum install nginx apache2-utils
168+
sudo systemctl enable nginx
169+
sudo systemctl start nginx
95170
```
96171

97-
Your NGINX setup should be good to go.
98-
99172
### Step 2.2 - Setup Authentication
100173

101174
Run this command to create a username-password pair:
102175

176+
> Replace `holu` with a username of your choice.
177+
103178
```bash
104-
sudo htpasswd -c /etc/nginx/.htpasswd user1
179+
sudo htpasswd -c /etc/nginx/.htpasswd holu
105180
```
106181

107-
Press Enter and type the password for user1 at the prompts.
182+
Press Enter and type the password for holu at the prompts.
108183

109184
Confirm that the username-password pair has been created by running:
110185

@@ -114,38 +189,39 @@ cat /etc/nginx/.htpasswd
114189

115190
### Step 2.3 - Configuration
116191

117-
Open your NGINX configuration file (`nginx.conf`) and find the `http` block. (Your `nginx.conf` file usually is located in `/usr/local/nginx/conf`, `/etc/nginx`, or `/usr/local/etc/nginx`)
192+
Open your NGINX configuration file (`nginx.conf`) and find the `http` block. Your `nginx.conf` file is usually located in `/usr/local/nginx/conf`, `/etc/nginx`, or `/usr/local/etc/nginx`-
118193

119194
Add the following lines into your `http` block:
120195

196+
> Replace `example.com` with your own domain.
197+
121198
```nginx
122-
upstream backend {
123-
server 127.0.0.1:19999;
124-
keepalive 64;
125-
}
126-
127-
server {
128-
listen <10.0.0.1>:80;
129-
server_name <example.com>;
130-
131-
auth_basic "Protected";
132-
auth_basic_user_file /etc/nginx/.htpasswd;
133-
134-
location / {
135-
proxy_set_header X-Forwarded-Host $host;
136-
proxy_set_header X-Forwarded-Server $host;
137-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
138-
proxy_pass http://backend;
139-
proxy_http_version 1.1;
140-
proxy_pass_request_headers on;
141-
proxy_set_header Connection "keep-alive";
142-
proxy_store off;
143-
}
144-
}
145-
```
146-
147-
* Replace `<10.0.0.1>` with your public IP Address.
148-
* Replace `<example.com>` with your own domain.
199+
upstream backend {
200+
server 127.0.0.1:19999;
201+
keepalive 64;
202+
}
203+
204+
server {
205+
listen 80;
206+
# Uncomment the line below for IPv6
207+
#listen [::]:80;
208+
server_name example.com;
209+
210+
auth_basic "Protected";
211+
auth_basic_user_file /etc/nginx/.htpasswd;
212+
213+
location / {
214+
proxy_set_header X-Forwarded-Host $host;
215+
proxy_set_header X-Forwarded-Server $host;
216+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
217+
proxy_pass http://backend;
218+
proxy_http_version 1.1;
219+
proxy_pass_request_headers on;
220+
proxy_set_header Connection "keep-alive";
221+
proxy_store off;
222+
}
223+
}
224+
```
149225

150226
Save the configuration file and close it. Then verify the configuration to check if everything is OK.
151227

@@ -159,9 +235,9 @@ Go ahead and reload NGINX if there was no error:
159235
sudo systemctl reload nginx
160236
```
161237

162-
Open your browser and navigate to `<10.0.0.1>` or `<example.com>`. Use your username-password pair to access the web interface.
238+
Open your browser and navigate to the public IP of your server or `<example.com>`. Use your username-password pair to access the web interface.
163239

164-
![Netdata Web Interface](images/netdata-web-interface.gif)
240+
![Netdata Web Interface](images/netdata-web-interface.png)
165241

166242
## Conclusion
167243

Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 commit comments

Comments
 (0)