master
md 126 lines 4.99 KB
Rendered Raw
1 # Active journal source without encryption
2
3 This page will guide you through creating an active journal source without the use of encryption.
4
5 Once you enable an active journal source on a server, `systemd-journal-gatewayd` will expose an REST API on TCP port 19531. This API can be used for querying the logs, exporting the logs, or monitoring new log entries remotely.
6
7 > ⚠️ **IMPORTANT**<br/>
8 > These instructions will expose your logs to the network, without any encryption or authorization.<br/>
9 > DO NOT USE THIS ON NON-TRUSTED NETWORKS.
10
11 ## Configuring an active journal source
12
13 On the server you want to expose their logs, install `systemd-journal-gateway`.
14
15 ```bash
16 # change this according to your distro
17 sudo apt-get install systemd-journal-gateway
18 ```
19
20 Optionally, if you want to change the port (the default is `19531`), edit `systemd-journal-gatewayd.socket`
21
22 ```bash
23 # edit the socket file
24 sudo systemctl edit systemd-journal-gatewayd.socket
25 ```
26
27 and add the following lines into the instructed place, and choose your desired port; save and exit.
28
29 ```bash
30 [Socket]
31 ListenStream=<DESIRED_PORT>
32 ```
33
34 Finally, enable it, so that it will start automatically upon receiving a connection:
35
36 ```bash
37 # enable systemd-journal-remote
38 sudo systemctl daemon-reload
39 sudo systemctl enable --now systemd-journal-gatewayd.socket
40 ```
41
42 ## Using the active journal source
43
44 ### Simple Logs Explorer
45
46 `systemd-journal-gateway` provides a simple HTML5 application to browse the logs.
47
48 To use it, open your web browser and navigate to:
49
50 ```url
51 http://server.ip:19531/browse
52 ```
53
54 A simple page like this will be presented:
55
56 ![image](https://github.com/netdata/netdata/assets/2662304/4da88bf8-6398-468b-a359-68db0c9ad419)
57
58 ### Use it with `curl`
59
60 `man systemd-journal-gatewayd` documents the supported API methods and provides examples to query the API using `curl` commands.
61
62 ### Copying the logs to a central journals server
63
64 `systemd-journal-remote` has the ability to query instances of `systemd-journal-gatewayd` to fetch their logs, so that the central server fetches the logs, instead of waiting for the individual servers to push their logs to it.
65
66 However, this kind of logs centralization has a key problem: **there is no guarantee that there will be no gaps in the logs replicated**. Theoretically, the REST API of `systemd-journal-gatewayd` supports querying past data, and `systemd-journal-remote` could keep track of the state of replication and automatically continue from the point it stopped last time. But it does not. So, currently the best logs centralization option is to use a **passive** centralization, where the clients push their logs to the server.
67
68 Given these limitations, if you still want to configure an **active** journals centralization, this is what you need to do:
69
70 On the centralization server install `systemd-journal-remote`:
71
72 ```bash
73 # change this according to your distro
74 sudo apt-get install systemd-journal-remote
75 ```
76
77 Then, copy `systemd-journal-remote.service` to configure it for querying the active source:
78
79 ```bash
80 # replace "clientX" with the name of the active client node
81 sudo cp /lib/systemd/system/systemd-journal-remote.service /etc/systemd/system/systemd-journal-remote-clientX.service
82
83 # edit it to make sure it the ExecStart line is like this:
84 # ExecStart=/usr/lib/systemd/systemd-journal-remote --url http://clientX:19531/entries?follow
85 sudo nano /etc/systemd/system/systemd-journal-remote-clientX.service
86
87 # reload systemd
88 sudo systemctl daemon-reload
89 ```
90
91 ```bash
92 # enable systemd-journal-remote
93 sudo systemctl enable --now systemd-journal-remote-clientX.service
94 ```
95
96 You can repeat this process to create as many `systemd-journal-remote` services, as the active source you have.
97
98 ## Verify it works
99
100 To verify that the central server is receiving logs, run this on the central server:
101
102 ```bash
103 sudo ls -l /var/log/journal/remote/
104 ```
105
106 You should see new files from the client's hostname or IP.
107
108 Also, any of the new service files (`systemctl status systemd-journal-clientX`) should show something like this:
109
110 ```bash
111 ● systemd-journal-clientX.service - Fetching systemd journal logs from 192.168.2.146
112 Loaded: loaded (/etc/systemd/system/systemd-journal-clientX.service; enabled; preset: disabled)
113 Drop-In: /usr/lib/systemd/system/service.d
114 └─10-timeout-abort.conf
115 Active: active (running) since Wed 2023-10-18 07:35:52 EEST; 23min ago
116 Main PID: 77959 (systemd-journal)
117 Tasks: 2 (limit: 6928)
118 Memory: 7.7M
119 CPU: 518ms
120 CGroup: /system.slice/systemd-journal-clientX.service
121 ├─77959 /usr/lib/systemd/systemd-journal-remote --url "http://192.168.2.146:19531/entries?follow"
122 └─77962 curl "-HAccept: application/vnd.fdo.journal" --silent --show-error "http://192.168.2.146:19531/entries?follow"
123
124 Oct 18 07:35:52 systemd-journal-server systemd[1]: Started systemd-journal-clientX.service - Fetching systemd journal logs from 192.168.2.146.
125 Oct 18 07:35:52 systemd-journal-server systemd-journal-remote[77959]: Spawning curl http://192.168.2.146:19531/entries?follow...
126 ```