§2024-05-30

The replicationSet odroid-01 has a srv record of

 % dig +short SRV _mongodb._tcp.inLaneCatch.yushei.com.tw
0 0 27017 n2Jammy.yushei.com.tw.        --> 192.168.2.177, db version v7.1.0-alpha
0 0 27017 n2Boookworm.yushei.com.tw.    --> 192.168.2.239, db version v7.0.0-rc8
0 0 27017 x8664Arch.yushei.com.tw.      --> 192.168.2.132, db version v7.0.0-rc8
0 0 27017 hc4Jammy.yushei.com.tw.       --> 192.168.2.195, db version v7.0.0-rc8

All the log file will be logged into @hc4Jammy.yushei.com.tw, /var/log/mongoDB-odroid-01.log .

This documents how it were done.

  1. for example at x8664Arch.yushei.com.tw
$ sudo pacman -S syslog-ng # sudo apt install syslog-ng

In ArchLinux

[alexlai@x8664Arch ~]$ sudo systemctl enable syslog-ng@default
Created symlink /etc/systemd/system/multi-user.target.wants/syslog-ng@default.service → /usr/lib/systemd/system/syslog-ng@.service.
[alexlai@x8664Arch ~]$ sudo systemctl status  syslog-ng@default
○ syslog-ng@default.service - System Logger Daemon "default" instance
     Loaded: loaded (/usr/lib/systemd/system/syslog-ng@.service; enabled; preset: disabled)
     Active: inactive (dead)
       Docs: man:syslog-ng(8)

[alexlai@x8664Arch ~]$ syslog-ng --version
syslog-ng 4 (4.6.0)
Config version: 4.2
Installer-Version: 4.6.0
Revision: 
Compile-Date: May 24 2024 16:10:11
Module-Directory: /usr/lib/syslog-ng
Module-Path: /usr/lib/syslog-ng
Include-Path: /usr/share/syslog-ng/include
Error opening plugin module; module='geoip2-plugin', error='libmaxminddb.so.0: cannot open shared object file: No such file or directory'
Error opening plugin module; module='afsnmp', error='libnetsnmp.so.40: cannot open shared object file: No such file or directory'
Error opening plugin module; module='afsql', error='libdbi.so.1: cannot open shared object file: No such file or directory'
Error opening plugin module; module='redis', error='libhiredis.so.1.1.0: cannot open shared object file: No such file or directory'
Error opening plugin module; module='afamqp', error='librabbitmq.so.4: cannot open shared object file: No such file or directory'
Error opening plugin module; module='kafka', error='librdkafka.so.1: cannot open shared object file: No such file or directory'
Error opening plugin module; module='afsmtp', error='libesmtp.so.6.2.0: cannot open shared object file: No such file or directory'
Available-Modules: graphite,bigquery,hook-commands,sdjournal,tags-parser,afprog,otel,correlation,affile,confgen,stardate,cryptofuncs,basicfuncs,afmongodb,linux-kmsg-format,disk-buffer,kvformat,azure-auth-header,tfgetent,timestamp,syslogformat,regexp-parser,afuser,add-contextual-data,pseudofile,metrics-probe,mod-python,system-source,csvparser,appmodel,rate-limit-filter,map-value-pairs,http,afstomp,json-plugin,xml,examples,cloud_auth,afsocket,cef,secure-logging,loki
Enable-Debug: off
Enable-GProf: off
Enable-Memtrace: off
Enable-IPv6: on
Enable-Spoof-Source: on
Enable-TCP-Wrapper: off
Enable-Linux-Caps: on
Enable-Systemd: on
  1. setup /etc/syslog-ng/syslog-ng.conf
$ sudo cp -v /etc/syslog-ng/syslog-ng.conf /etc/syslog-ng/syslog-ng.conf.backup
'/etc/syslog-ng/syslog-ng.conf' -> '/etc/syslog-ng/syslog-ng.conf.backup'
@version: 4.6.0
@include "scl.conf"

options {
    keep-hostname(yes);
};

# Sources
source s_mongo_log {
    file("/opt/package/mongoDB/log/mongod.log" flags(no-parse));
};

# Destination
destination d_mongoDB {
    syslog("hc4Jammy.yushei.net" transport("udp") port(514));
};

# Log Statements
log {
    source(s_mongo_log);
#     parser {
#         json-parser(prefix("json."));
#     };
    destination(d_mongoDB);
};

For n2Jammy.yushei.com.tw

$ sudo apt install syslog-ng
$ sudo apt install syslog-ng
alexlai@n2Jammy:~$ cat /etc/syslog-ng/syslog-ng.conf
@version: 3.27
@include "scl.conf"

source s_mongo_log {
    file("/var/log/mongodb/mongod.log" flags(no-parse));
};

# Destinations
destination d_hc4Jammy {
    syslog("hc4Jammy.yushei.com.tw" transport("udp") port(514));
};

# Filters
# filter f_hc4Jammy {
#     host("hc4Jammyyushei.com.tw");
# };

# Bind Sources, Destinations, and Filters

# Send mongod.log from redismongo03.yushei.com.tw to hc4nas02.yushei.net
log {
    source(s_mongo_log);
    # filter(f_hc4Jammy);
    destination(d_hc4Jammy);
};

alexlai@n2Jammy:~$ sudo cat  /etc/logrotate.d/mongodb
/var/log/mongodb/mongod.log {
    daily
    rotate 7
    compress
    delaycompress
    missingok
    notifempty
    create 0640 syslog sudo
    sharedscripts
    su root syslog
    postrotate
        /usr/bin/killall -SIGUSR1 mongod
    endscript
}

alexlai@n2Jammy:~$ sudo logrotate -d /etc/logrotate.d/mongodb 
WARNING: logrotate in debug mode does nothing except printing debug messages!  Consider using verbose mode (-v) instead if this is not what you want.

reading config file /etc/logrotate.d/mongodb
Reading state from file: /var/lib/logrotate/status
Allocating hash table for state file, size 64 entries
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state

Handling 1 logs

rotating pattern: /var/log/mongodb/mongod.log  after 1 days (7 rotations)
empty log files are not rotated, old logs are removed
switching euid from 0 to 0 and egid from 0 to 111 (pid 8303)
considering log /var/log/mongodb/mongod.log
Creating new state
  Now: 2024-05-30 08:05
  Last rotated at 2024-05-30 08:00
  log does not need rotating (log has already been rotated)
not running postrotate script, since no logs were rotated
switching euid from 0 to 0 and egid from 111 to 0 (pid 8303)

alexlai@n2Jammy:~$ sudo logrotate -f /etc/logrotate.d/mongodb 
alexlai@n2Jammy:~$ ls -l /var/log/mongodb/mongod.log*
-rw------- 1 mongodb mongodb   2715 May 30 08:06 /var/log/mongodb/mongod.log
-rw------- 1 mongodb mongodb 638093 May 30 08:06 /var/log/mongodb/mongod.log.1
-rw-r----- 1 syslog  sudo         0 May 30 08:06 /var/log/mongodb/mongod.log.2024-05-30T00-06-05