mongodb cluster upgrade config servers fails - mongodb

I'm trying to create a mongodb cluster with 3 machines by following this link : http://docs.mongodb.org/manual/tutorial/deploy-shard-cluster/ . I have downloaded mongodb 2.6.4 to all machines and started config servers with this command :
mongod --configsvr --dbpath /home/sshusr/mongodb/data/configdb/
and I'm trying to start a mongos instance to upgrade config servers to v5 because it tells me to do that. So I run this command
mongos --upgrade --configdb 10.122.123.64:27019,10.122.123.65:27019,10.122.123.66:27019
but it gives me this
2014-09-26T17:07:55.629+0300 [mongosMain] MongoS version 2.6.4 starting: pid=50066 port=27017 64-bit host=tesla (--help for usage)
2014-09-26T17:07:55.629+0300 [mongosMain] db version v2.6.4
2014-09-26T17:07:55.629+0300 [mongosMain] git version: 3a830be0eb92d772aa855ebb711ac91d658ee910
2014-09-26T17:07:55.629+0300 [mongosMain] build info: Linux build7.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2014-09-26T17:07:55.629+0300 [mongosMain] allocator: tcmalloc
2014-09-26T17:07:55.629+0300 [mongosMain] options: { sharding: { configDB: "10.122.123.64:27019,10.122.123.65:27019,10.122.123.66:27019" }, upgrade: true }
2014-09-26T17:07:55.633+0300 [mongosMain] SyncClusterConnection connecting to [10.122.123.64:27019]
2014-09-26T17:07:55.633+0300 [mongosMain] SyncClusterConnection connecting to [10.122.123.65:27019]
2014-09-26T17:07:55.633+0300 [mongosMain] SyncClusterConnection connecting to [10.122.123.66:27019]
2014-09-26T17:07:55.718+0300 [mongosMain] scoped connection to 10.122.123.64:27019,10.122.123.65:27019,10.122.123.66:27019 not being returned to the pool
2014-09-26T17:08:06.770+0300 [mongosMain] waited 11s for distributed lock configUpgrade for upgrading config database to new format v5
2014-09-26T17:08:17.816+0300 [mongosMain] waited 22s for distributed lock configUpgrade for upgrading config database to new format v5
2014-09-26T17:08:28.863+0300 [mongosMain] waited 33s for distributed lock configUpgrade for upgrading config database to new format v5
2014-09-26T17:08:39.909+0300 [mongosMain] waited 44s for distributed lock configUpgrade for upgrading config database to new format v5
....
what am I missing here? Any help is appreciated. Thanks.

I have resolved the problem.
I executed the command with verbose and saw that there was a time/date difference between servers. I have assigned an ntp server for each server and problem was solved.

Related

loading docker container from existing project, mongo will not connect to database Ubuntu 18.04

At first I had a problem where the mongod service stopped working altogether. Thereupon I completely uninstalled mongodb and reinstalled it and followed instructions per this thread: https://askubuntu.com/questions/921753/failed-to-start-mongod-service-unit-mongod-service-not-found
This caused the mongod service to finally start.
In order for it to work, I also had to follow instructions from this thread:
mongo - couldn't connect to server 127.0.0.1:27017
So far this configuration has worked only 1 time and that was after I followed the instructions to remove the .lock file in the mongod directory and then repair mongod.
I also tried to remove the sock file like stated here: MongoDB Failing to Start - ***aborting after fassert() failure
Full project reset
Then I tried just disconnecting the project entirely; close nodemon for backend, exit ng serve on frontend, stop and remove mongo docker container... And tried again. Here is my step-by-step process after everything should have been fixed:
Restart mongod service
sudo service mongod restart
Restart frontend (executed from frontend directory)
ng serve frontend
Restart backend (executed from backend directory)
npx nodemon backend
Restart mongo container (executed from deploy directory, mongo is the docker container name, I'm building it from existing provided deploy script)
sudo docker-compose up -d mongo
sudo docker ps -a # check container was created and is running
Debugging information:
sudo service mongod status
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset:
Active: active (running) since Thu 2020-01-09 11:21:43 CET; 3min 40s ago
Docs: https://docs.mongodb.org/manual
Main PID: 17242 (mongod)
CGroup: /system.slice/mongod.service
└─17242 /usr/bin/mongod --config /etc/mongod.conf
janv. 09 11:21:43 junior-LIFEBOOK-E752 systemd[1]: Started MongoDB Database Server
sudo mongod2020-01-09T11:25:45.983+0100 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] MongoDB starting : pid=17727 port=27017 dbpath=/data/db 64-bit host=junior-LIFEBOOK-E752
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] db version v4.2.2
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] git version: a0bbbff6ada159e19298d37946ac8dc4b497eadf
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.1d 10 Sep 2019
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] allocator: tcmalloc
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] modules: none
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] build environment:
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] distmod: ubuntu1804
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] distarch: x86_64
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] target_arch: x86_64
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] options: {}
2020-01-09T11:25:45.987+0100 E STORAGE [initandlisten] Failed to set up listener: SocketException: Address already in use
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] now exiting
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] shutting down with code:48
sudo mongo
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("8e813fc2-049c-440d-83ce-0b1d8516c4d0") }
MongoDB server version: 4.2.2
Server has startup warnings:
2020-01-09T11:21:43.352+0100 I STORAGE [initandlisten]
2020-01-09T11:21:43.352+0100 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2020-01-09T11:21:43.352+0100 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2020-01-09T11:21:44.848+0100 I CONTROL [initandlisten]
2020-01-09T11:21:44.848+0100 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-01-09T11:21:44.848+0100 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2020-01-09T11:21:44.848+0100 I CONTROL [initandlisten]
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).
The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.
To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
So something weird is happening here, it doesn't find the database from the project and I have no clue why. As far as I can see, it creates a new database including my system details.
How can I fix this please and connect to the project database? I can't move further until I do.
it's been resolved. First I found out I didn't need to have the mongod service running locally because mongo was already included in the docker container. But actually this wasn't a database issue at all. There were a few things going wrong like there was a proxy but the command had been changed to execute the connection, endpoints were on localhost but weren't supposed to be, and the content I was expecting to see had been hidden by a careless push from another developer. Fun times! But we can move on now. Thanks to the people who tried to help!

The command '/bin/sh -c service mongod start' return a non-zero code: 1 in docker

i'm trying to create a docker image run Mongodb on my Raspberry Pi 3+ with Raspbian buster. But when i build image and run container, mongodb doesn't auto start, so i add command RUN service mongod start then build image. Mongodb seems to be installed, i checked by service --status-all and mongodb listed but not started. Error come when docker try to start mongodb serive: The command '/bin/sh -c service mongod start' return a non-zero code: 1.
This is myDockerfile:
FROM cretzel/rpi-mongodb
WORKDIR /usr/src/mongodb
RUN chmod +x /var/lib/mongodb
RUN service mongod start
EXPOSE 27017
CMD ["mongod"]
I tried to fix this and be told that it doesn't have permission, so i add RUN chmod +x /var/lib/mongodb to my dockerfile but it don't work.
Can someone help?
---------------- Update from #Adiii's answer -----------------------------------
My new dockerfile:
FROM cretzel/rpi-mongodb
WORKDIR /usr/src/mongodb
COPY ./entrypoint.sh .
RUN chmod +x ./entrypoint.sh
VOLUME ./database /data/db
EXPOSE 27017
CMD ["mongod"]
entrypoint.sh
#!/bin/bash
service mongod start
exec "$#"
The change solved my error but mongodb service still cannot start. This is log file:
Starting database: mongodb failed!
db level locking enabled: 1
mongod --help for help and startup options
Mon Nov 11 16:31:15
Mon Nov 11 16:31:15 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Mon Nov 11 16:31:15
warning: some regex utf8 things will not work. pcre build doesn't have --enable-unicode-properties
Mon Nov 11 16:31:15 [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db/ 32-bit host=38271f34412b
Mon Nov 11 16:31:15 [initandlisten]
Mon Nov 11 16:31:15 [initandlisten] ** NOTE: This is a development version (2.1.1-pre-) of MongoDB.
Mon Nov 11 16:31:15 [initandlisten] ** Not recommended for production.
Mon Nov 11 16:31:15 [initandlisten]
Mon Nov 11 16:31:15 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Mon Nov 11 16:31:15 [initandlisten] ** see http://blog.mongodb.org/post/137788967/32-bit-limitations
Mon Nov 11 16:31:15 [initandlisten] ** with --journal, the limit is lower
Mon Nov 11 16:31:15 [initandlisten]
Mon Nov 11 16:31:15 [initandlisten] db version v2.1.1-pre-, pdfile version 4.5
Mon Nov 11 16:31:15 [initandlisten] git version: 47fbbdceb21fc2b791d22db7f01792500647daa9
Mon Nov 11 16:31:15 [initandlisten] build info: Linux raspberrypi 3.2.27+ #102 PREEMPT Sat Sep 1 01:00:50 BST 2012 armv6l BOOST_LIB_VERSION=1_49
Mon Nov 11 16:31:15 [initandlisten] options: {}
Mon Nov 11 16:31:15 [initandlisten] waiting for connections on port 27017
Mon Nov 11 16:31:15 [websvr] admin web console waiting for connections on port 28017
Mon Nov 11 16:32:15 [clientcursormon] mem (MB) res:20 virt:83 mapped:0
I don't understand Docker so much, it don't show any error. Please help!
You should not start the process at RUN command, each run command run at a separate shell and RUN is for installation and configuration not to start the process. To start the process in the container you need to start the process at entrypoint or CMD.
also, the container needs a process to run in foreground so service will not work in case of the container. so
EXPOSE 27017
CMD ["mongod"]
This is enough to start the mongo process, if the container is up and running it's mean mongod process is running, you do not need to check the status using service --status-all. as soon as MongoDB process dies container will die automatically.
Will suggest to use offical mongo docker image.

Mongodb Shrading gives config server not synched error?

I have created three instance of mongodb on localhost with different port like
mongod.exe --configsvr --dbpath C:\MongoDB2.6\mongodb\data --port 2021
mongod.exe --configsvr --dbpath D:\mongodb\data --port 2022
mongod.exe --configsvr --dbpath E:\mongodb\data --port 2023
These 3 are getting instantiated successfully.
Now I am using mongos command for clustring for these three instance and my command is like this
mongos.exe --configdb 127.0.0.1:2021,127.0.0.1:2022,127.0.0.1:2023
BUt it gives me the error which is like this
C:\MongoDB2.6\bin>mongos.exe --configdb 127.0.0.1:2021,127.0.0.1:2022,127.0.0.1:2023 --port 2025
2015-02-26T15:51:22.451+0530 [mongosMain] MongoS version 2.6.7 starting: pid=12256 port=2025 64-bit host=triconnode112 (--help for usage)
2015-02-26T15:51:22.451+0530 [mongosMain] db version v2.6.7
2015-02-26T15:51:22.451+0530 [mongosMain] git version: a7d57ad27c382de82e9cb93bf983a80fd9ac9899
2015-02-26T15:51:22.451+0530 [mongosMain] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOO
ST_LIB_VERSION=1_49
2015-02-26T15:51:22.451+0530 [mongosMain] allocator: system
2015-02-26T15:51:22.466+0530 [mongosMain] options: { net: { port: 2025 }, sharding: { configDB: "127.0.0.1:2021,127.0.0.1:2022,127.0.0.1:2023" } }
2015-02-26T15:51:22.482+0530 [mongosMain] warning: config servers 127.0.0.1:2021 and 127.0.0.1:2022 differ
2015-02-26T15:51:22.482+0530 [mongosMain] warning: config servers 127.0.0.1:2021 and 127.0.0.1:2022 differ
2015-02-26T15:51:22.482+0530 [mongosMain] warning: config servers 127.0.0.1:2021 and 127.0.0.1:2022 differ
2015-02-26T15:51:22.498+0530 [mongosMain] warning: config servers 127.0.0.1:2021 and 127.0.0.1:2022 differ
2015-02-26T15:51:22.498+0530 [mongosMain] ERROR: could not verify that config servers are in sync :: caused by :: config servers 127.0.0.1:2021 and 127.0.0.1:20
22 differ: { chunks: "d41d8cd98f00b204e9800998ecf8427e", shards: "d41d8cd98f00b204e9800998ecf8427e", version: "9c051057927f3ebf9b0ee68b4b0ff78d" } vs { chunks:
"d41d8cd98f00b204e9800998ecf8427e", shards: "d41d8cd98f00b204e9800998ecf8427e", version: "4c0907d023ca1c1216c89d83fcb6a841" }
2015-02-26T15:51:22.498+0530 [mongosMain] configServer connection startup check failed
I am not getting where i am doing mistake. In this full example actually i am trying to implement sharding for the mongodb.
Now I am able to solve this problema nd tried to execute the shard command which is
sh.addShard("127.0.0.1:2021,127.0.0.1:2022,127.0.0.1:2023")
Now it gives me the error
{
"ok" : 0,
"errmsg" : "can't use sync cluster as a shard. for replica set, have to use <setname>/<server1>,<server2>,..."
}
I have no idea why this error is coming.

MongoDB provides a basic authentication system. Has it changed in version 2.2.3?

Scenario: Installed MongoDB 2.2.3 on the machine (Windows 64-bit)
Followed all the steps to enforce authentication on MongoDB server.
Added User to admin database
use admin
db.addUser('me_admin', '12345');
db.auth('me_admin','12345');
Ran database server (mongod.exe process) with the --auth option to enable
authentication
Followed all answers for similar question:
How to secure MongoDB with username and password
Issue: With new version 2.2.3 I am not able set up authentication. After following the same steps I was able to set up the authentication for the version 2.0.8 on the same machine. But its mentioned somewhere in MongoDB docs that "Authentication on Localhost varies slightly between before and after version 2.2"
Question: What is the change and how can enforce the authentication in new versions i.e. 2.2 onwards. Can anybody give some idea or solution to proceed the same with new MongoDB 2.2.3?
Update:
I had checked that authentication works same on 2.2.3 when I start mongod.exe process with --auth parameter from command prompt.
I was using auth=true parameter in config file as mentioned in docs, but this did not work.
Research done:
When mongod.cfg file contains following configurations
logpath=c:\mongodb\log\mongo.log, auth=true, profile=2
The log.txt file contains following logs
Mon Mar 11 15:06:35 Trying to start Windows service 'MongoDB'
Mon Mar 11 15:06:35 Service running
Mon Mar 11 15:06:35 [initandlisten] MongoDB starting : pid=7152 port=27017 dbpath=\data\db\ 64-bit host=AMOL-KULKARNI
Mon Mar 11 15:06:35 [initandlisten] db version v2.2.3, pdfile version 4.5
Mon Mar 11 15:06:35 [initandlisten] git version: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08
Mon Mar 11 15:06:35 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
Mon Mar 11 15:06:35 [initandlisten] options: { config: "C:\mongodb\mongod.cfg", logpath: "c:\mongodb\log\mongo.log auth=true profile=2", service: true }
Mon Mar 11 15:06:35 [initandlisten] journal dir=/data/db/journal
Mon Mar 11 15:06:35 [initandlisten] recover : no journal files present, no recovery needed
Mon Mar 11 15:06:35 [initandlisten] waiting for connections on port 27017
Mon Mar 11 15:06:35 [websvr] admin web console waiting for connections on port 28017
When I run from command prompt mongod --auth, following log will be displayed:
Mon Mar 11 15:09:40 [initandlisten] MongoDB starting : pid=6536 port=27017 dbpath=\data\db\ 64-bit host=AMOL-KULKARNI
Mon Mar 11 15:09:40 [initandlisten] db version v2.2.3, pdfile version 4.5
Mon Mar 11 15:09:40 [initandlisten] git version: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08
Mon Mar 11 15:09:40 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
Mon Mar 11 15:09:40 [initandlisten] options: { auth: true }
Mon Mar 11 15:09:40 [initandlisten] journal dir=/data/db/journal
Mon Mar 11 15:09:40 [initandlisten] recover : no journal files present, no recovery needed
Mon Mar 11 15:09:40 [initandlisten] waiting for connections on port 27017
Mon Mar 11 15:09:40 [websvr] admin web console waiting for connections on port 28017
Note: The change in the options:
options:{ config: "C:\mongodb\mongod.cfg", logpath:
"c:\mongodb\log\mongo.log auth=true profile=2", service: true } //Does not work
options: { auth: true } //Works
Interesting to observe is that,
When its ran from config file.
logpath=c:\mongodb\log\mongo.log, auth=true, profile=2
It got changed to:
logpath: "c:\mongodb\log\mongo.log auth=true profile=2", service: true
I know here is the issue. It should be like:
logpath: "c:\mongodb\log\mongo.log", auth=true, profile="2", service: true
So, the question is how to pass auth=true parameter from config file and run mongod.exe process as service on Windows7
The change is only minor as described under the part you quoted:
In general if there are no users for the admin database, you may connect via the localhost interface. For sharded clusters running version 2.2, if mongod is running with auth then all users connecting over the localhost interface must authenticate, even if there aren’t any users in the admin database.
Basically before 2.2 if you were in a sharded cluster you could connect to localhost and not be forced to auth if there are no users found in the admin database. This means that if you set-up a sharded cluster it might be wise to setup a default user, which you have already done.
Can anybody give some idea or solution to proceed the same with new MongoDB 2.2.3?
The new auth system will just be there, you don't need to do anything; it just will be.
Found out the solution.
To run MongoDB process (mongod.exe) as service with auth=true, following has to be taken care while registering MongoDB service itself (not mentioned in docs)
Service has to be registered with following command:
C:\mongodb\bin\mongod.exe --config C:\mongodb\mongod.cfg --auth --install
mongod.cfg file will have only logpath=c:\mongodb\log\mongo.log
Shared with you all so that effort & time will not be put on the same issue again.
Happy exploring to all.. :-)
Note this time log contains:
Mon Mar 11 15:58:06 Trying to start Windows service 'MongoDB'
Mon Mar 11 15:58:06 Service running
Mon Mar 11 15:58:06 [initandlisten] MongoDB starting : pid=6800 port=27017 dbpath=\data\db\ 64-bit host=AMOL-KULKARNI
Mon Mar 11 15:58:06 [initandlisten] db version v2.2.3, pdfile version 4.5
Mon Mar 11 15:58:06 [initandlisten] git version: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08
Mon Mar 11 15:58:06 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
Mon Mar 11 15:58:06 [initandlisten] options: { auth: true, config: "C:\mongodb\mongod.cfg", logpath: "c:\mongodb\log\mongo.log", service: true }
Mon Mar 11 15:58:06 [initandlisten] journal dir=/data/db/journal
Mon Mar 11 15:58:06 [initandlisten] recover : no journal files present, no recovery needed
Mon Mar 11 15:58:06 [initandlisten] waiting for connections on port 27017
Mon Mar 11 15:58:06 [websvr] admin web console waiting for connections on port 28017

Starting mongodb cluster

I'm starting 3 mongod processes on 3 different machines and try to run the mongos process on the another machine that runs also the application server.
I'm getting this message:
~$ mongos --configdb mongo1:27017,mongo2:27017,mongo3:27017
Mon Sep 24 10:34:05 mongos db version v2.0.4, pdfile version 4.5 starting (--help for usage)
Mon Sep 24 10:34:05 git version: nogitversion
Mon Sep 24 10:34:05 build info: Linux yellow 2.6.24-29-server #1 SMP Tue Oct 11 15:57:27 UTC 2011 x86_64 BOOST_LIB_VERSION=1_46_1
Mon Sep 24 10:34:09 ERROR: config servers mongo1:27017 and mongo2:27017 differconfig servers mongo1:27017 and mongo2:27017 differconfig servers mongo1:27017 and mongo2:27017 differconfig servers mongo1:27017 and mongo2:27017 differconfig servers not in sync! config servers mongo1:27017 and mongo2:27017 differ
chunks: "d41d8cd98f00b204e9800998ecf8427e" EOO
EOO EOO
configServer startup check failed
I've deleted mongod.lock from all config servers and restarted mongod.
That solved the problem.
There are 2 ways it can be done,
1) clear the data folder and restart the server, it will start as usual without any error,
2) delete the mongod lock file and Use the --repair option.