多台服务器实现mongodb主从模式配置从库一连接就自动关闭
现在在学习mongodb的主从模式配置,遇到一个问题,不知道是怎么回事,请高手指教。
在多台服务器里进行主库配置并且启动,很顺利没有问题,但是在另外一个机器启动从库的时候,每次一连接从库,从库就自动关闭。配置如下:
主库:
/usr/local/bin/mongodb/bin/mongod -dbpath /data/db --fork --port 27017 --master --logpath=/data/log/work.log -logappend --auth
从库:
/usr/local/bin/mongodb/bin/mongod -dbpath /data/db --port 28018 --slave --source 192.168.0.4:27017 -auth --autoresync --slavedelay 5
采用shell连接的时候,服务器的信息如下:
Fri Oct 26 11:23:45 [initandlisten] MongoDB starting : pid=17588 port=28018 dbpath=/data/db slave=1 64-bit host=oracle.tq.com
Fri Oct 26 11:23:45 [initandlisten] db version v2.2.0, pdfile version 4.5
Fri Oct 26 11:23:45 [initandlisten] git version: f5e83eae9cfbec7fb7a071321928f00d1b0c5207
Fri Oct 26 11:23:45 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
Fri Oct 26 11:23:45 [initandlisten] options: { auth: true, autoresync: true, dbpath: "/data/db", port: 28018, slave: true, slavedelay: 5, source: "192.168.0.4:27017" }
Fri Oct 26 11:23:45 [initandlisten] journal dir=/data/db/journal
Fri Oct 26 11:23:45 [initandlisten] recover : no journal files present, no recovery needed
Fri Oct 26 11:23:45 [initandlisten] waiting for connections on port 28018
Fri Oct 26 11:23:45 [websvr] admin web console waiting for connections on port 29018
Fri Oct 26 11:23:46 [replslave] repl: --source 192.168.0.4:27017 != 192.168.0.4 from local.sources collection
Fri Oct 26 11:23:46 [replslave] repl: for instructions on changing this slave's source, see:
Fri Oct 26 11:23:46 [replslave] http://dochub.mongodb.org/core/masterslave
Fri Oct 26 11:23:46 [replslave] repl: terminating mongod after 30 seconds
Fri Oct 26 11:24:16 dbexit:
Fri Oct 26 11:24:16 [replslave] shutdown: going to close listening sockets...
Fri Oct 26 11:24:16 [replslave] closing listening socket: 8
Fri Oct 26 11:24:16 [replslave] closing listening socket: 9
Fri Oct 26 11:24:16 [replslave] closing listening socket: 10
Fri Oct 26 11:24:16 [replslave] removing socket file: /tmp/mongodb-28018.sock
Fri Oct 26 11:24:16 [replslave] shutdown: going to flush diaglog...
Fri Oct 26 11:24:16 [replslave] shutdown: going to close sockets...
Fri Oct 26 11:24:16 [replslave] shutdown: waiting for fs preallocator...
Fri Oct 26 11:24:16 [replslave] shutdown: lock for final commit...
Fri Oct 26 11:24:16 [replslave] shutdown: final commit...
Fri Oct 26 11:24:16 [replslave] shutdown: closing all files...
Fri Oct 26 11:24:16 [replslave] closeAllFiles() finished
Fri Oct 26 11:24:16 [replslave] journalCleanup...
Fri Oct 26 11:24:16 [replslave] removeJournalFiles
Fri Oct 26 11:24:16 [replslave] shutdown: removing fs lock...
Fri Oct 26 11:24:16 dbexit: really exiting now
客户端的信息:
[root@oracle ~]# /usr/local/bin/mongodb/bin/mongo --port 28018
MongoDB shell version: 2.2.0
connecting to: 127.0.0.1:28018/test
Fri Oct 26 11:45:15 Socket recv() errno:104 Connection reset by peer 127.0.0.1:28018
Fri Oct 26 11:45:15 SocketException: remote: 127.0.0.1:28018 error: 9001 socket exception [1] server [127.0.0.1:28018]
Fri Oct 26 11:45:15 DBClientCursor::init call() failed
Fri Oct 26 11:45:15 Error: Error during mongo startup. :: caused by :: 10276 DBClientBase::findN: transport error: 127.0.0.1:28018 ns: admin.$cmd query: { whatsmyuri: 1 } src/mongo/shell/mongo.js:93
exception: connect failed
Answers
我是在一台机器上开了两个端口
./mongod --master --dbpath=/data/Chunbai/app/mongodb/data/db --fork --logappend --logpath=/data/Chunbai/app/mongodb/log/mongodb.log
./mongod --bind_ip 10.182.7.88 --port 55360 --slave --source 10.182.7.88:27017 --dbpath=/data/Chunbai/app/mongodb/data/db_slave_5536 --fork --logappend --logpath=/data/Chunbai/app/mongodb/log/slave_mongodb_5536.log
看从的日志 :
2014-06-26T13:44:49.847+0800 ***** SERVER RESTARTED *****
2014-06-26T13:44:49.854+0800 [initandlisten] MongoDB starting : pid=19756 port=55360 dbpath=/data/Chunbai/app/mongodb/data/db_slave_27018 slave=1 64-bit host=VM_7_88
2014-06-26T13:44:49.854+0800 [initandlisten] db version v2.6.2
2014-06-26T13:44:49.854+0800 [initandlisten] git version: 4d06e27876697d67348a397955b46dabb8443827
2014-06-26T13:44:49.854+0800 [initandlisten] build info: Linux build10.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-06-26T13:44:49.854+0800 [initandlisten] allocator: tcmalloc
2014-06-26T13:44:49.854+0800 [initandlisten] options: { net: { bindIp: "10.182.7.88", port: 55360 }, processManagement: { fork: true }, slave: true, source: "10.182.7.88:27017",
storage: { dbPath: "/data/Chunbai/app/mongodb/data/db_slave_5536" }, systemLog: { destination: "file", logAppend: true, path: "/data/Chunbai/app/mongodb/log/slave_mongodb_5536
8.log" } }
2014-06-26T13:44:49.857+0800 [initandlisten] journal dir=/data/Chunbai/app/mongodb/data/db_slave_27018/journal
2014-06-26T13:44:49.858+0800 [initandlisten] recover : no journal files present, no recovery needed
2014-06-26T13:44:50.049+0800 [initandlisten] waiting for connections on port 55360
****2014-06-26T13:44:51.049+0800 [replslave] repl: --source 10.182.7.88:27017 != 10.180.7.88:27017 from local.sources collection****
2014-06-26T13:44:51.049+0800 [replslave] repl: for instructions on changing this slave's source, see:
2014-06-26T13:44:51.049+0800 [replslave] http://dochub.mongodb.org/core/master...
2014-06-26T13:44:51.049+0800 [replslave] repl: terminating mongod after 30 seconds
2014-06-26T13:45:21.049+0800 [replslave] dbexit:
2014-06-26T13:45:21.049+0800 [replslave] shutdown: going to close listening sockets...
2014-06-26T13:45:21.049+0800 [replslave] closing listening socket: 9
2014-06-26T13:45:21.049+0800 [replslave] shutdown: going to flush diaglog...
2014-06-26T13:45:21.049+0800 [replslave] shutdown: going to close sockets...
2014-06-26T13:45:21.049+0800 [replslave] shutdown: waiting for fs preallocator...
2014-06-26T13:45:21.049+0800 [replslave] shutdown: lock for final commit...
2014-06-26T13:45:21.049+0800 [replslave] shutdown: final commit...
2014-06-26T13:45:21.052+0800 [replslave] shutdown: closing all files...
2014-06-26T13:45:21.052+0800 [replslave] closeAllFiles() finished
2014-06-26T13:45:21.052+0800 [replslave] journalCleanup...
2014-06-26T13:45:21.052+0800 [replslave] removeJournalFiles
2014-06-26T13:45:21.053+0800 [replslave] shutdown: removing fs lock...
2014-06-26T13:45:21.053+0800 [replslave] dbexit: really exiting now
我的也是10.182.7.88:27017 != 10.180.7.88:27017 怎么又180? 是咋回事?
但是在windows 上 开两个端口 弄主从 就没事