How to fix 'Sessions collection is not set up' error when trying to convert existing mongodb instance to replica set

Jack picture Jack · Dec 31, 2018 · Viewed 9.3k times · Source

I have installed the latest version of mongodb (v4.0.5) using the following link https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/ Following this now I'm trying to set up replication using the instructions provided in the following tutorial But as soon as i try the command at point "2.Start your mongod instances in their own shell windows by issuing the following commands" it gives me the following error "Sessions collection is not set up; waiting until next sessions refresh interval: Replication has not yet been configured"

Command I used: mongod --replSet rs0 --port 27019 --bind_ip localhost,[MY_IP] --dbpath /srv/mongodb/rs0-2 --smallfiles --oplogSize 128

A more detailed output for the command is as follows:

2018-12-31T15:37:03.618+0530 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2018-12-31T15:37:03.623+0530 I CONTROL  [initandlisten] MongoDB starting : pid=xxx port=27017 dbpath=/srv/mongodb/rs0-0 64-bit host=xxx
2018-12-31T15:37:03.623+0530 I CONTROL  [initandlisten] db version v4.0.5
2018-12-31T15:37:03.623+0530 I CONTROL  [initandlisten] git version: xxx
2018-12-31T15:37:03.623+0530 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
2018-12-31T15:37:03.623+0530 I CONTROL  [initandlisten] allocator: tcmalloc
2018-12-31T15:37:03.623+0530 I CONTROL  [initandlisten] modules: none
2018-12-31T15:37:03.623+0530 I CONTROL  [initandlisten] build environment:
2018-12-31T15:37:03.623+0530 I CONTROL  [initandlisten]     distmod: rhel70
2018-12-31T15:37:03.623+0530 I CONTROL  [initandlisten]     distarch: x86_64
2018-12-31T15:37:03.623+0530 I CONTROL  [initandlisten]     target_arch: x86_64
2018-12-31T15:37:03.623+0530 I CONTROL  [initandlisten] options: { net: { bindIp: "localhost,xxx", port: 27017 }, replication: { replSet: "rs0" }, storage: { dbPath: "/srv/mongodb/rs0-0" } }
2018-12-31T15:37:03.624+0530 I STORAGE  [initandlisten] Detected data files in /srv/mongodb/rs0-0 created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2018-12-31T15:37:03.625+0530 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3399M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
2018-12-31T15:37:04.683+0530 I STORAGE  [initandlisten] WiredTiger message [1546250824:683476][30064:0x7f4cb133db40], txn-recover: Main recovery loop: starting at 5/6144 to 6/256
2018-12-31T15:37:04.796+0530 I STORAGE  [initandlisten] WiredTiger message [1546250824:796244][30064:0x7f4cb133db40], txn-recover: Recovering log 5 through 6
2018-12-31T15:37:04.871+0530 I STORAGE  [initandlisten] WiredTiger message [1546250824:871037][30064:0x7f4cb133db40], txn-recover: Recovering log 6 through 6
2018-12-31T15:37:04.945+0530 I STORAGE  [initandlisten] WiredTiger message [1546250824:945584][30064:0x7f4cb133db40], txn-recover: Set global recovery timestamp: 0
2018-12-31T15:37:04.964+0530 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2018-12-31T15:37:04.975+0530 I CONTROL  [initandlisten]
2018-12-31T15:37:04.975+0530 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-12-31T15:37:04.975+0530 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-12-31T15:37:04.975+0530 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-12-31T15:37:04.975+0530 I CONTROL  [initandlisten]
2018-12-31T15:37:04.975+0530 I CONTROL  [initandlisten]
2018-12-31T15:37:04.976+0530 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-12-31T15:37:04.976+0530 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-12-31T15:37:04.976+0530 I CONTROL  [initandlisten]
2018-12-31T15:37:04.976+0530 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-12-31T15:37:04.976+0530 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-12-31T15:37:04.976+0530 I CONTROL  [initandlisten]
2018-12-31T15:37:04.995+0530 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/srv/mongodb/rs0-0/diagnostic.data'
2018-12-31T15:37:04.996+0530 I REPL     [initandlisten] Did not find local voted for document at startup.
2018-12-31T15:37:04.997+0530 I REPL     [initandlisten] Rollback ID is 1
2018-12-31T15:37:04.997+0530 I REPL     [initandlisten] Did not find local replica set configuration document at startup;  NoMatchingDocument: Did not find replica set configuration document in local.system.replset
2018-12-31T15:37:04.997+0530 I CONTROL  [LogicalSessionCacheRefresh] Sessions collection is not set up; waiting until next sessions refresh interval: Replication has not yet been configured
2018-12-31T15:37:04.997+0530 I NETWORK  [initandlisten] waiting for connections on port 27017
2018-12-31T15:37:04.998+0530 I CONTROL  [LogicalSessionCacheReap] Sessions collection is not set up; waiting until next sessions reap interval: config.system.sessions does not exist

I tried following other tutorials where the commands were without the --ip_bind option but i still faced the same error. I tried searching on the net for this specific error but have not come across any solution for my error.

Answer

Boris picture Boris · Mar 13, 2019

You need to initiate it with rs.initiate().

Once you launched as you did, you can run this from an other terminal

mongo --eval 'rs.initiate();'

If you are familiar with docker, you can reproduce the error and the initialisation:

docker run --rm -it mongo:4.0 /bin/bash -c "\
    mongod --replSet rs0 --fork --logpath /var/log/mongodb/mongod.log &&\
    sleep 5 &&\
    mongo --eval 'rs.initiate();' &&\
    tail -n +0 -f /var/log/mongodb/mongod.log"

I used the --fork to run mongod as a deamon, in order to be able to call the rs.initiate() a bit later