Envío de journal a otra máquina: systemd-journal-remote
El servicio systemd-journal-remote.service nos permitirá enviar journal a una máquina remota utilizando para ello los protocolos https o http.
En este ejemplo se transmitirán los datos utilizando http en aras de la simplicidad, para evitar tener que utilizar certificados. Si la red no es de confianza se debería utilizar https.
El primer paso consistirá en instalar el paquete systemd-journal-remote en los dos equipos.
En la máquina que va a enviar el journal podremos editar el fichero /etc/systemd/journal-upload.conf para indicar la URL del servidor de destino. El puerto por defecto es el 19532.
[Upload]
URL=http://192.168.0.23:19532
# ServerKeyFile=/etc/ssl/private/journal-upload.pem
# ServerCertificateFile=/etc/ssl/certs/journal-upload.pem
# TrustedCertificateFile=/etc/ssl/ca/trusted.pem
En la máquina que va a recibir los datos deberemos editar el fichero /lib/systemd/system/systemd-journal-remote.service para cambiar el parámetro --listen-https por --listen-http.
[Unit] Description=Journal Remote Sink Service Documentation=man:systemd-journal-remote(8) man:journal-remote.conf(5) Requires=systemd-journal-remote.socket [Service] ExecStart=/lib/systemd/systemd-journal-remote --listen-http=-3 --output=/var/log/journal/remote/ LockPersonality=yes LogsDirectory=journal/remote MemoryDenyWriteExecute=yes NoNewPrivileges=yes PrivateDevices=yes PrivateNetwork=yes PrivateTmp=yes ProtectProc=invisible ProtectClock=yes ProtectControlGroups=yes ProtectHome=yes ProtectHostname=yes ProtectKernelLogs=yes ProtectKernelModules=yes ProtectKernelTunables=yes ProtectSystem=strict RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 RestrictNamespaces=yes RestrictRealtime=yes RestrictSUIDSGID=yes SystemCallArchitectures=native User=systemd-journal-remote WatchdogSec=3min # If there are many split up journal files we need a lot of fds to access them # all in parallel. LimitNOFILE=524288 [Install] Also=systemd-journal-remote.socket
Finalmente en el servidor que recibe los datos tendremos que activar:
systemctl enable --now systemd-journal-remote.socket
systemctl enable --now systemd-journal-remote.service
Y en el ordenador que envía journal
systemctl enable --now systemd-journal-upload.service
Podremos comprobar que en el servidor de destino tendremos los datos recibidos en /var/log/journal/remote. Y será posible utilizar el parámetro --file de journalctl para consultar los datos recibidos.
Por ejemplo:
journalctl -f --file=/var/log/journal/remote/remote-192.168.0.10.journal
Si systemd-journal-upload.service se encuentra con un problema al transmitir datos (por ejemplo el receptor está apagado) falla. Por eso es importante añadir los parámetros (Restart=on-failure y RestartSec=2min) al fichero /lib/systemd/system/systemd-journal-upload.service para reiniciar el servicio cuando falle.
[Unit] Description=Journal Remote Upload Service Documentation=man:systemd-journal-upload(8) Wants=network-online.target After=network-online.target [Service] DynamicUser=yes ExecStart=/lib/systemd/systemd-journal-upload --save-state LockPersonality=yes MemoryDenyWriteExecute=yes PrivateDevices=yes ProtectProc=invisible ProtectControlGroups=yes ProtectHome=yes ProtectHostname=yes ProtectKernelLogs=yes ProtectKernelModules=yes ProtectKernelTunables=yes RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 RestrictNamespaces=yes RestrictRealtime=yes StateDirectory=systemd/journal-upload SupplementaryGroups=systemd-journal SystemCallArchitectures=native User=systemd-journal-upload WatchdogSec=3min # Queremos reiniciar si falla el destino Restart=on-failure RestartSec=2min # If there are many split up journal files we need a lot of fds to access them # all in parallel. LimitNOFILE=524288 [Install] WantedBy=multi-user.target
Más información:
