Mongos alway exit unexpectedly - mongodb

I started one Mongos server by the following command:
nohup mongos --port 57017 --configdb configsvr1:47017,configsvr2:47017,configsvr3:47017 > s.nohup 2>&1 &
configsvr* are configuration servers. my problem is that Mongos instance always exit after a few hour.
The Mongos log I found as following:
W SHARDING [LockPinger] Error encountered while stopping ping on mongos_server:
57017:1472436263:-1365656364 :: caused by :: 17382
Can't use connection pool during shutdown
I SHARDING [signalProcessingThread] dbexit: rc:0

Related

MongoDb Sharding on Local Machine

I am trying to create a sharding on my local machine. But when I create MongoDB shard server in the bin directory using this command start mongod --shardsvr --port 2005 -logpath C:\data\shard\s0\log\s0.log --dbpath C:\data\shard\s0 nothing happens so I went on to create mongos router mongos --port 2007 --configdb test/localhost:2001. Mongos created successfully and then I add shard to mongos using command sh.addShard("localhost:2005") then this error appears "errmsg" : "failed to run command { isMaster: 1 } when attempting to add shard localhost:2005 :: caused by :: HostUnreachable: Error connecting to localhost:2005 (127.0.0.1:2005) :: caused by :: No connection could be made because the target machine actively refused it.". I don't know how to deal with this error.

Can't start mongoDB as a service

I'd like to run mongoDB as a service. The instance shall be configured as a single-node replicaset to be able to connect a elasticSearch instance to it with a the connector.
So I extended the mongod.conf:
...
replication:
replSetName: "singleNodeRepl"
...
I tried different ways to start now the mongod, but nothing works.
When I try to start the service by $ service mongod start, following error is thrown:
start: Rejected send message, 1 matched rules; type="method_call", sender=":1.106" (uid=1225 pid=26018 comm="start mongod ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")
When I execute this command as sudo (whats not best-practise, right?), its "running" and following message is shown:
mongod start/running, process 26034
But process 26034 doesn't exist and ps aux | grep mongo also shows nothing?!
Next try: Run it as a normal application
mongod --dbpath /var/lib/mongodb/ --replSet SingleNodeRepl
Here following exception is shown:
2016-04-08T14:31:35.192+0200 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /var/lib/mongodb/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
2016-04-08T14:31:35.192+0200 I CONTROL [initandlisten] dbexit: rc: 100
Everything is fine when I run ~$ sudo mongod --dbpath /var/lib/mongodb/ --replSet SingleNodeRepl, but thats not my target: Its not running as a service and its running as root.
The mongod-logfile often keeps untouched. But the last lines are curious:
2016-04-08T14:24:56.242+0200 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2016-04-08T14:24:56.242+0200 I - [initandlisten] Fatal Assertion 28578
2016-04-08T14:24:56.242+0200 I - [initandlisten]
***aborting after fassert() failure
A mongodb-27017.sock existed, but deleting (what was suggested anywhere) didn't help.
Based on the erros above if tried serveral solutions, but nothing helps.
I think it's a very simple mistake...but which one?
[edit:]
I discovered, that I perhaps should have specified the config-location. So the (working but bad) command looks like:
$ sudo mongod --dbpath /var/lib/mongodb/ --replSet SingleNodeRepl --config /etc/mongod.conf
This brings following error:
warning: bind_ip of 0.0.0.0 is unnecessary; listens on all ips by default
Thats an old thing, which was the solution for this problem and suddenly doesn't work anymore!?
I've had issues stopping and starting mongod as a service. Turns out there was an issue with the upsart script.
I found this discussion which seemed to fix it.
The suggested solution was pretty much: (copy pasting now)
vim /etc/init.d/mongod
look for stop() function (and start() function for good measure) and remove quotes around $PIDFILE in the following line.
killproc -p $PIDFILE -d 300 /usr/bin/mongod
Do this:
sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
sudo service mongodb start
Let me know if this doesn't work!

Mongos distribute too much query to one MongoD

We have a mongodb with 2 shardings, each of the shardings has those servers:
Shard 1: Master, running MongoD and Config server
Shard 1-s1: Slave, running MongoD and MongoS server
Shard 1-s2: Slave, running MongoD and MongoS and Arbiter server
Shard 2: Master, running MongoD and Config Server
Shard 2-s1: Slave, running MongoD and Config and MongoS server
Shard 2-s2: Slave, running MongoD and MongoS and Arbiter server
But the mongodb allways failed in recent days, after days of search, i find out that the MongoD runs at Shard 1(Master) always going down after reviced too many connections, other MongoD don't have this problem.
When the S1Master's MongoD running with too many connections for about 2 hours, the 4 Mongos Server will shut down one by one. Here is the Mongos's error log(10.81.4.72:7100 runs MongoD):
Tue Aug 20 20:01:52 [conn8526] DBClientCursor::init call() failed
Tue Aug 20 20:01:52 [conn3897] ns: user.dev could not initialize cursor across all shards because : stale config detected for ns: user.
dev ParallelCursor::_init # s01/10.36.31.36:7100,10.42.50.24:7100,10.81.4.72:7100 attempt: 0
Tue Aug 20 20:01:52 [conn744] ns: user.dev could not initialize cursor across all shards because : stale config detected for ns: user.d
ev ParallelCursor::_init # s01/10.36.31.36:7100,10.42.50.24:7100,10.81.4.72:7100 attempt: 0
I don't know why this mongod revieved so many connections, the chunks shows the sharding works well.

Shutdown mongos for upgrade

I am upgrading a mongo sharded cluster, and am in the first step of replacing the mongos process. Can I just kill this process or is there a safer way to shut it down before replacing it?
It is the answer. But may be you misunderstood. You cannot shutdown mongos from command line, but you have to logon to the shell. Here is the result I am trying on my own:
$ mongo --port 27077 (please replace with your own port on mongos instance)
**mongos**> db.shutdownServer({timeoutSecs:30})
shutdown command only works with the admin database; try 'use admin'
mongos> use admin
switched to db admin
mongos> db.shutdownServer({timeoutSecs:30})
2015-02-27T12:53:54.408+0800 DBClientCursor::init call() failed
**server should be down...**
2015-02-27T12:53:54.410+0800 trying reconnect to 127.0.0.1:27077 (127.0.0.1) failed
2015-02-27T12:53:54.410+0800 warning: Failed to connect to 127.0.0.1:27077, reason: errno:111 Connection refused
2015-02-27T12:53:54.410+0800 reconnect 127.0.0.1:27077 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27077 (127.0.0.1), connection attempt failed
2015-02-27T12:53:54.413+0800 trying reconnect to 127.0.0.1:27077 (127.0.0.1) failed
2015-02-27T12:53:54.413+0800 warning: Failed to connect to 127.0.0.1:27077, reason: errno:111 Connection refused
2015-02-27T12:53:54.413+0800 reconnect 127.0.0.1:27077 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27077 (127.0.0.1), connection attempt failed
>
Try to run "top" or "htop" to display all processes running on your computer. You shall see the "mongos" process has gone. Read the log file. Here is the last two lines of my log:
2015-02-27T12:53:54.406+0800 [conn1] terminating, shutdown command received
2015-02-27T12:53:54.406+0800 [conn1] dbexit: shutdown called rc:0 shutdown called
And here is the link of my testing script:
https://github.com/babycaseny/QuickStart/blob/master/StartShard.sh
Note that you have to replace the "localhost" in the mongod/mongos command with the hostname of your computer, or you will not be able to config your shards.
See also this one:
https://groups.google.com/forum/#!topic/mongodb-user/TQLlRI6HG1M
In case you need a command line to do the work, here is one:
mongo admin --port portnumber --eval "db.shutdownServer()"
Notice that you have to run the command in localhost.

Mongo sharding without shutdown the existing mongo instance

I need to do sharding without shutdown or restart the existing mongo instance in the port 27017 .
I tried the following, (while the default port is running and mongo instance)
mongod --shardsvr --dbpath /var/lib/mongodb/dba --port 10001 > /var/log/mongodb/shardlog/sharda.log &
mongod --shardsvr --dbpath /var/lib/mongodb/dbb --port 10002 > /var/log/mongodb/shardlog/shardb.log &
mongod --configsvr --dbpath /var/lib/mongodb/config --port 20000 > /var/log/mongodb/shardlog/configdb.log &
mongos --configdb localhost:20000 > /var/log/mongodb/shardlog/mongos.log &
Then mongos log giving an error,
Thu Aug 23 14:44:36 [mongosMain] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
Thu Aug 23 14:44:36 [mongosMain] ERROR: addr already in use
mongos is running on port 20000 but why It's trying to connect the default 27017 port?
Can I start mongos with several shards without disturbing the existing mongo instance on port 27017 ?
From the the list of commands you have given, it looks like you have not told the mongos to start on a different port than default.
You would need to supply the --port argument for mongos to start on a different port.
Try: mongos --configdb localhost:20000 --port 10003
Note: mongos is not running on port 20000 as you have said above. You have the config server running on that port