k8sのコンテナ内でrsyslogにログ出力
rocky linuxのコンテナを起動しましたが、rsyslogがインストールされていなく、アプリのログが確認できなかったので対処法です。
dnf install -y iputils iproute procps rsyslog keepalived
今回必要なものは、rsyslogとkeepalivedです。keepalivedはrsyslogにログが出力されます。
module(load="imuxsock" # provides support for local system logging (e.g. via logger command)
SysSock.Use="on") # Turn off message reception via local log socket;
# local messages are retrieved through imjournal now.
#module(load="imjournal" # provides access to the systemd journal
# UsePid="system" # PID nummber is retrieved as the ID of the process the journal entry originates from
# FileCreateMode="0644" # Set the access permissions for the state file
# StateFile="imjournal.state") # File to store the position in the journal
#module(load="imklog") # reads kernel messages (the same are read from journald)
上記のように、imuxsock側でSysSock.Useを”on”へ変更。
imjournal側は使わないので(使えない)、#でコメントアウト。
rsyslogd -n
上記でrsyslogdを起動します。
keepalived -D -l
上記でkeepalivedを起動します。
Jun 2 12:03:13 rocky-deployment-95bd6974c-hdxhg Keepalived[347]: Starting Keepalived v2.2.8 (04/04,2023), git commit v2.2.7-154-g292b299e+
Jun 2 12:03:13 rocky-deployment-95bd6974c-hdxhg Keepalived[347]: WARNING - keepalived was built for newer Linux 5.14.0, running on Linux 4.18.0-513.18.1.el8_9.x86_64 #1 SMP Wed Feb 2
1 21:34:36 UTC 2024
Jun 2 12:03:13 rocky-deployment-95bd6974c-hdxhg Keepalived[347]: Command line: 'keepalived' '-D' '-l'
Jun 2 12:03:13 rocky-deployment-95bd6974c-hdxhg Keepalived[347]: Opening file '/etc/keepalived/keepalived.conf'.
Jun 2 12:03:13 rocky-deployment-95bd6974c-hdxhg Keepalived[347]: Configuration file /etc/keepalived/keepalived.conf
/var/log/messagesでkeepalivedのログが確認できました。