如何configurationsystemd journal-remote来侦听特定的端口?
我只能find命令行的例子。 基于man page,在journal-remote.conf中似乎没有任何选项。
看到甚至没有一个评论,我决定继续我的研究,最后拼凑在一起。
操作系统:Ubuntu 16.04
systemd:229-1ubuntu2
systemd-journal-remote:229-1ubuntu2
这其实很简单,在线的例子是正确的,只需要触摸一个configuration文件。
使用以下命令安装systemd-journal-remote
sudo apt-get install systemd-journal-remote
编辑/etc/systemd/journal-upload.conf 。
/etc/systemd/journal-upload.conf
[Upload] URL=http://10.0.0.1:19532 # ServerKeyFile=/etc/ssl/private/journal-upload.pem # ServerCertificateFile=/etc/ssl/certs/journal-upload.pem # TrustedCertificateFile=/etc/ssl/ca/trusted.pem
确保启动日志上传自动启动
sudo systemctl enable systemd-journal-upload.service
configuration完成后重新启动日志 – 上传。
sudo systemctl restart systemd-journal-upload.service
如果您使用的是http,您可以按照上面的方法进行操作,并留下最下面的三行注释。 对于主动模式https,取消注释并创build这些证书文件。
URL实际上决定了传输协议(http / https)和要使用的目标端口。
此外,如果您希望防止将来的软件包更新意外覆盖,则可以创build一个/etc/systemd/journal-upload.conf.d目录,并将您的configuration文件放在里面,只要文件以.conf扩展名结尾。
作为一个方面的说明,我正在做一个LXC容器内,似乎服务将不会使用/ etc /主机的DNS解决scheme,我最终在这里使用IP地址。 因此,如果您使用主机名并查看日志上传无法到达目标的错误消息,请尝试使用IP地址。
接收服务器在查找configuration信息时给了我大部分的麻烦。 而不像上传服务器,configuration分散在这一边。
使用以下命令安装systemd-journal-remote并启用侦听端口
sudo apt-get install systemd-journal-remote sudo systemctl enable systemd-journal-remote.socket
主动和被动两种方式来configurationjournal-remote。 我在这里使用被动模式。
端口号
日志侦听端口的configuration文件是/etc/systemd/system/sockets.target.wants/systemd-journal-remote.socket ,如下所示。 ListenStream是端口号。
与上传方面不同,这个设置与使用哪个协议(http / https)无关。 它只指定侦听端口号。
[Unit] Description=Journal Remote Sink Socket [Socket] ListenStream=19532 [Install] WantedBy=sockets.target
协议(http / https)和日志/日志位置
要更改日志传输协议和保存位置, /lib/systemd/system/systemd-journal-remote.service复制到/etc/systemd/system/ ,然后编辑/etc/systemd/system/systemd-journal-remote.service 。
[Unit] Description=Journal Remote Sink Service Documentation=man:systemd-journal-remote(8) man:journal-remote.conf(5) Requires=systemd-journal-remote.socket [Service] ExecStart=/etc/systemd/systemd-journal-remote \ --listen-http=-3 \ --output=/var/log/journal/remote/ User=systemd-journal-remote Group=systemd-journal-remote PrivateTmp=yes PrivateDevices=yes PrivateNetwork=yes WatchdogSec=3min [Install] Also=systemd-journal-remote.socket
--listen-http=-3指定传入日志正在使用http。 如果您想使用https,请将其更改为--listen-https=-3 。
--output=/var/log/journal/remote/指定传入日志的宿(保存目录)。 如果不存在,请创build它并将其所有者更改为systemd-journal-remote 。
sudo mkdir /var/log/journal/remote sudo chown systemd-journal-remote /var/log/journal/remote
configuration完成后重新启动journal-remote.socket。
sudo systemctl daemon-reload
最明显的/etc/systemd/journal-remote.conf呢?
[Remote] # Seal=false # SplitMode=host # ServerKeyFile=/etc/ssl/private/journal-remote.pem # ServerCertificateFile=/etc/ssl/certs/journal-remote.pem # TrustedCertificateFile=/etc/ssl/ca/trusted.pem
由于我没有使用https,所以不需要改变任何东西。