单机搭建
#创建docker持久化数据目录
[root@docker ~]# mkdir -p /root/application/program/mongodb/data/master-slaveMode
[root@docker ~]# cd /root/application/program/mongodb
#启动容器
[root@docker mongodb]# docker run -d -v `pwd`/data/master-slaveMode:/mongodb -p 30017:27017 docker.io/mongodb:3.6.3 /usr/sbin/init
ba3b27d855f6486151cc2248e6524d0c737ac3266f6b340c5ac5a29e43a42431
[root@docker mongodb]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ba3b27d855f6 docker.io/mongodb:3.6.3 "/usr/sbin/init" 30 seconds ago Up 29 seconds 28017/tcp, 0.0.0.0:30017->27017/tcp laughing_thompson
f75c4ce68803 docker.io/mongodb:3.6.3 "/usr/sbin/init" 22 hours ago Up 22 hours 0.0.0.0:37017->27017/tcp, 0.0.0.0:38017->28017/tcp dazzling_kowalevski
b23aeb293514 docker.io/mongodb:3.6.3 "/usr/sbin/init" 2 days ago Up 2 days 0.0.0.0:27017->27017/tcp, 0.0.0.0:28017->28017/tcp distracted_bhaskara
[root@docker mongodb]# docker exec -it ba3b27d855f6 bash
[root@ba3b27d855f6 /]#
#查看容器私有IP
[root@ba3b27d855f6 /]# ifconfig
\eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.4 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:acff:fe11:4 prefixlen 64 scopeid 0x20<link>
ether 02:42:ac:11:00:04 txqueuelen 0 (Ethernet)
RX packets 8 bytes 648 (648.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 648 (648.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@ba3b27d855f6 /]# cd /mongodb/mongodb/bin/
[root@ba3b27d855f6 bin]# ll
total 244520
-rwxr-xr-x. 1 root root 5487061 Aug 10 06:33 bsondump
drwxr-xr-x. 4 root root 4096 Aug 10 06:33 datas
-rwxr-xr-x. 1 root root 5792 Aug 10 06:33 install_compass
drwxr-xr-x. 2 root root 103 Aug 10 06:33 logs
-rwxr-xr-x. 1 root root 33065816 Aug 10 06:33 mongo
-rwxr-xr-x. 1 root root 58575600 Aug 10 06:33 mongod
-rw-r--r--. 1 root root 203 Aug 10 06:37 mongodb.conf
-rwxr-xr-x. 1 root root 8667585 Aug 10 06:33 mongodump
-rwxr-xr-x. 1 root root 6620731 Aug 10 06:33 mongoexport
-rwxr-xr-x. 1 root root 6471255 Aug 10 06:33 mongofiles
-rwxr-xr-x. 1 root root 6771267 Aug 10 06:33 mongoimport
-rwxr-xr-x. 1 root root 58105192 Aug 10 06:33 mongoperf
-rwxr-xr-x. 1 root root 9780339 Aug 10 06:33 mongoreplay
-rwxr-xr-x. 1 root root 10082759 Aug 10 06:33 mongorestore
-rwxr-xr-x. 1 root root 33447696 Aug 10 06:33 mongos
-rwxr-xr-x. 1 root root 6833184 Aug 10 06:33 mongostat
-rwxr-xr-x. 1 root root 6441493 Aug 10 06:33 mongotop
[root@ba3b27d855f6 bin]#
#创建主从节点的data目录
[root@ba3b27d855f6 bin]# mkdir -p datas/master datas/slave
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]#
#启动主节点进程
[root@ba3b27d855f6 bin]# ./mongod --master --dbpath /mongodb/mongodb/bin/datas/master --logpath /mongodb/mongodb/bin/logs/mongodb-master.log --bind_ip 172.17.0.4 --port 27017 --fork
about to fork child process, waiting until server is ready for connections.
forked process: 74
child process started successfully, parent exiting
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]# ps -ef | grep mongodb
root 74 0 6 06:42 ? 00:00:00 ./mongod --master --dbpath /mongodb/mongodb/bin/datas/master --logpath /mongodb/mongodb/bin/logs/mongodb-master.log --bind_ip 172.17.0.4 --port 27017 --fork
root 101 26 0 06:42 ? 00:00:00 grep --color=auto mongodb
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]#
#启动从节点进程
[root@ba3b27d855f6 bin]# ./mongod --slave --source 172.17.0.4:27017 --dbpath /mongodb/mongodb/bin/datas/slave --logpath /mongodb/mongodb/bin/logs/mongodb-slave.log --bind_ip 172.17.0.4 --port 27018 --fork
about to fork child process, waiting until server is ready for connections.
forked process: 104
child process started successfully, parent exiting
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]# ps -ef | grep mongodb
root 74 0 1 06:42 ? 00:00:01 ./mongod --master --dbpath /mongodb/mongodb/bin/datas/master --logpath /mongodb/mongodb/bin/logs/mongodb-master.log --bind_ip 172.17.0.4 --port 27017 --fork
root 104 0 21 06:43 ? 00:00:00 ./mongod --slave --source 172.17.0.4:27017 --dbpath /mongodb/mongodb/bin/datas/slave --logpath /mongodb/mongodb/bin/logs/mongodb-slave.log --bind_ip 172.17.0.4 --port 27018 --fork
root 133 26 0 06:43 ? 00:00:00 grep --color=auto mongodb
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]#
#验证
#主节点插入数据
[root@ba3b27d855f6 bin]# ./mongo 172.17.0.4:27017
MongoDB shell version v3.6.3
connecting to: mongodb://172.17.0.4:27017/test
MongoDB server version: 3.6.3
Server has startup warnings:
2018-08-10T06:42:13.217+0000 I CONTROL [initandlisten]
2018-08-10T06:42:13.217+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-08-10T06:42:13.217+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-08-10T06:42:13.217+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-08-10T06:42:13.217+0000 I CONTROL [initandlisten]
2018-08-10T06:42:13.217+0000 I CONTROL [initandlisten]
2018-08-10T06:42:13.217+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-08-10T06:42:13.217+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-08-10T06:42:13.217+0000 I CONTROL [initandlisten]
2018-08-10T06:42:13.217+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-08-10T06:42:13.217+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-08-10T06:42:13.217+0000 I CONTROL [initandlisten]
2018-08-10T06:42:13.217+0000 I CONTROL [initandlisten] ** WARNING: This node was started in master-slave replication mode.
2018-08-10T06:42:13.217+0000 I CONTROL [initandlisten] ** Master-slave replication is deprecated and subject to be removed
2018-08-10T06:42:13.217+0000 I CONTROL [initandlisten] ** in a future version.
2018-08-10T06:42:13.217+0000 I CONTROL [initandlisten]
>
>
> show dbs
admin 0.000GB
local 0.000GB
>
>
> db.school.insert({"name" : "xuaiqi", "date" : new Date()})
WriteResult({ "nInserted" : 1 })
> db.school.find()
{ "_id" : ObjectId("5b6d3436dc9a5ab161c121e1"), "name" : "xuaiqi", "date" : ISODate("2018-08-10T06:44:06.284Z") }
>
>
> exit
bye
#登录从节点查询主从点插入的记录
[root@ba3b27d855f6 bin]# ./mongo 172.17.0.4:27018
MongoDB shell version v3.6.3
connecting to: mongodb://172.17.0.4:27018/test
MongoDB server version: 3.6.3
Server has startup warnings:
2018-08-10T06:43:14.911+0000 I CONTROL [initandlisten]
2018-08-10T06:43:14.911+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-08-10T06:43:14.911+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-08-10T06:43:14.911+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-08-10T06:43:14.911+0000 I CONTROL [initandlisten]
2018-08-10T06:43:14.911+0000 I CONTROL [initandlisten]
2018-08-10T06:43:14.911+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-08-10T06:43:14.911+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-08-10T06:43:14.911+0000 I CONTROL [initandlisten]
2018-08-10T06:43:14.911+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-08-10T06:43:14.911+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-08-10T06:43:14.911+0000 I CONTROL [initandlisten]
2018-08-10T06:43:14.911+0000 I CONTROL [initandlisten] ** WARNING: This node was started in master-slave replication mode.
2018-08-10T06:43:14.911+0000 I CONTROL [initandlisten] ** Master-slave replication is deprecated and subject to be removed
2018-08-10T06:43:14.911+0000 I CONTROL [initandlisten] ** in a future version.
2018-08-10T06:43:14.911+0000 I CONTROL [initandlisten]
>
>
> show dbs
2018-08-10T06:44:23.880+0000 E QUERY [thread1] Error: listDatabases failed:{
"ok" : 0,
"errmsg" : "not master and slaveOk=false",
"code" : 13435,
"codeName" : "NotMasterNoSlaveOk"
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs@src/mongo/shell/mongo.js:65:1
shellHelper.show@src/mongo/shell/utils.js:816:19
shellHelper@src/mongo/shell/utils.js:706:15
@(shellhelp2):1:1
#从节点默认不支持读写操作
> rs.slaveOk()
> show dbs
admin 0.000GB
local 0.000GB
test 0.000GB
> db.school.find()
{ "_id" : ObjectId("5b6d3436dc9a5ab161c121e1"), "name" : "xuaiqi", "date" : ISODate("2018-08-10T06:44:06.284Z") }
> exit
bye
[root@ba3b27d855f6 bin]#
###########################################################################################################################################
#复制单个数据库
[root@ba3b27d855f6 bin]# ./mongod --slave --source 172.17.0.4:27017 --only test --dbpath /mongodb/mongodb/bin/datas/replace --logpath /mongodb/mongodb/bin/logs/mongodb-replace.log --bind_ip 172.17.0.4 --port 27019 --fork
about to fork child process, waiting until server is ready for connections.
forked process: 153
child process started successfully, parent exiting
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]# ps -ef | grep mongodb
root 74 0 0 06:42 ? 00:00:06 ./mongod --master --dbpath /mongodb/mongodb/bin/datas/master --logpath /mongodb/mongodb/bin/logs/mongodb-master.log --bind_ip 172.17.0.4 --port 27017 --fork
root 104 0 0 06:43 ? 00:00:06 ./mongod --slave --source 172.17.0.4:27017 --dbpath /mongodb/mongodb/bin/datas/slave --logpath /mongodb/mongodb/bin/logs/mongodb-slave.log --bind_ip 172.17.0.4 --port 27018 --fork
root 153 0 7 06:55 ? 00:00:00 ./mongod --slave --source 172.17.0.4:27017 --only test --dbpath /mongodb/mongodb/bin/datas/replace --logpath /mongodb/mongodb/bin/logs/mongodb-replace.log --bind_ip 172.17.0.4 --port 27019 --fork
root 182 26 0 06:55 ? 00:00:00 grep --color=auto mongodb
#验证数据
[root@ba3b27d855f6 bin]# ./mongo 172.17.0.4:27019
MongoDB shell version v3.6.3
connecting to: mongodb://172.17.0.4:27019/test
MongoDB server version: 3.6.3
Server has startup warnings:
2018-08-10T06:55:47.033+0000 I CONTROL [initandlisten]
2018-08-10T06:55:47.033+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-08-10T06:55:47.033+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-08-10T06:55:47.033+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-08-10T06:55:47.033+0000 I CONTROL [initandlisten]
2018-08-10T06:55:47.034+0000 I CONTROL [initandlisten]
2018-08-10T06:55:47.034+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-08-10T06:55:47.034+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-08-10T06:55:47.034+0000 I CONTROL [initandlisten]
2018-08-10T06:55:47.034+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-08-10T06:55:47.034+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-08-10T06:55:47.034+0000 I CONTROL [initandlisten]
2018-08-10T06:55:47.034+0000 I CONTROL [initandlisten] ** WARNING: This node was started in master-slave replication mode.
2018-08-10T06:55:47.034+0000 I CONTROL [initandlisten] ** Master-slave replication is deprecated and subject to be removed
2018-08-10T06:55:47.034+0000 I CONTROL [initandlisten] ** in a future version.
2018-08-10T06:55:47.034+0000 I CONTROL [initandlisten]
> show dbs
2018-08-10T06:57:04.298+0000 E QUERY [thread1] Error: listDatabases failed:{
"ok" : 0,
"errmsg" : "not master and slaveOk=false",
"code" : 13435,
"codeName" : "NotMasterNoSlaveOk"
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs@src/mongo/shell/mongo.js:65:1
shellHelper.show@src/mongo/shell/utils.js:816:19
shellHelper@src/mongo/shell/utils.js:706:15
@(shellhelp2):1:1
> rs.slaveOk()
>
>
> show dbs
local 0.000GB
test 0.000GB
> db.school.find()
{ "_id" : ObjectId("5b6d3436dc9a5ab161c121e1"), "name" : "xuaiqi", "date" : ISODate("2018-08-10T06:44:06.284Z") }
>
>
>
> rs.status()
{
"ok" : 0,
"errmsg" : "not running with --replSet",
"code" : 76,
"codeName" : "NoReplicationEnabled"
}
> db.school.insert({"name" : "dddd"})
WriteResult({ "writeError" : { "code" : 10107, "errmsg" : "not master" } })
>
>
> exit
bye
###########################################################################################################################################
#从主从模式切换到副本集模式(停机操作)
#查看mongo进程并杀掉
[root@ba3b27d855f6 bin]# ps -ef | grep mongo
root 74 0 0 06:42 ? 00:00:10 ./mongod --master --dbpath /mongodb/mongodb/bin/datas/master --logpath /mongodb/mongodb/bin/logs/mongodb-master.log --bind_ip 172.17.0.4 --port 27017 --fork
root 104 0 0 06:43 ? 00:00:10 ./mongod --slave --source 172.17.0.4:27017 --dbpath /mongodb/mongodb/bin/datas/slave --logpath /mongodb/mongodb/bin/logs/mongodb-slave.log --bind_ip 172.17.0.4 --port 27018 --fork
root 153 0 0 06:55 ? 00:00:04 ./mongod --slave --source 172.17.0.4:27017 --only test --dbpath /mongodb/mongodb/bin/datas/replace --logpath /mongodb/mongodb/bin/logs/mongodb-replace.log --bind_ip 172.17.0.4 --port 27019 --fork
root 196 26 0 07:03 ? 00:00:00 grep --color=auto mongo
[root@ba3b27d855f6 bin]# kill -9 74
[root@ba3b27d855f6 bin]# kill -9 104
[root@ba3b27d855f6 bin]# kill -9 153
#以replSet启动mongo进程
[root@ba3b27d855f6 bin]# ./mongod --replSet test --dbpath /mongodb/mongodb/bin/datas/master --logpath /mongodb/mongodb/bin/logs/mongodb-master.log --bind_ip 172.17.0.4 --port 27017 --fork
about to fork child process, waiting until server is ready for connections.
forked process: 199
child process started successfully, parent exiting
[root@ba3b27d855f6 bin]# ps -ef | grep mongo
root 199 0 17 07:04 ? 00:00:01 ./mongod --replSet test --dbpath /mongodb/mongodb/bin/datas/master --logpath /mongodb/mongodb/bin/logs/mongodb-master.log --bind_ip 172.17.0.4 --port 27017 --fork
root 232 26 0 07:04 ? 00:00:00 grep --color=auto mongo
#replSet无法与fastsync共用
[root@ba3b27d855f6 bin]# ./mongod --replSet test --fastsync --dbpath /mongodb/mongodb/bin/datas/master --logpath /mongodb/mongodb/bin/logs/mongodb-master.log --bind_ip 172.17.0.4 --port 27018 --fork
BadValue: --fastsync must only be used with --slave
[root@ba3b27d855f6 bin]# ./mongod --replSet test --dbpath /mongodb/mongodb/bin/datas/slave --logpath /mongodb/mongodb/bin/logs/mongodb-slave.log --bind_ip 172.17.0.4 --port 27018 --fork
about to fork child process, waiting until server is ready for connections.
forked process: 240
child process started successfully, parent exiting
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]# ./mongod --replSet test --dbpath /mongodb/mongodb/bin/datas/replace --logpath /mongodb/mongodb/bin/logs/mongodb-replace.log --bind_ip 172.17.0.4 --port 27019 --fork
about to fork child process, waiting until server is ready for connections.
forked process: 272
ERROR: child process failed, exited with error number 62
To see additional information in this output, start without the "--fork" option.
[root@ba3b27d855f6 bin]# ./mongod --replSet test --dbpath /mongodb/mongodb/bin/datas/replace --logpath /mongodb/mongodb/bin/logs/mongodb-replace.log --bind_ip 172.17.0.4 --port 27019
2018-08-10T07:13:13.877+0000 I CONTROL [main] log file "/mongodb/mongodb/bin/logs/mongodb-replace.log" exists; moved to "/mongodb/mongodb/bin/logs/mongodb-replace.log.2018-08-10T07-13-13".
[root@ba3b27d855f6 bin]# vim /mongodb/mongodb/bin/logs/mongodb-replace.log
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]# ./mongod --replSet test --dbpath /mongodb/mongodb/bin/datas/replace --logpath /mongodb/mongodb/bin/logs/mongodb-replace.log --bind_ip 172.17.0.4 --port 27019 --fork^C
[root@ba3b27d855f6 bin]# rm -rf /mongodb/mongodb/bin/datas/replace/*
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]# ./mongod --replSet test --dbpath /mongodb/mongodb/bin/datas/replace --logpath /mongodb/mongodb/bin/logs/mongodb-replace.log --bind_ip 172.17.0.4 --port 27019 --fork
about to fork child process, waiting until server is ready for connections.
forked process: 336
child process started successfully, parent exiting
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]# ps -ef | grep mongodb
root 199 0 1 07:04 ? 00:00:06 ./mongod --replSet test --dbpath /mongodb/mongodb/bin/datas/master --logpath /mongodb/mongodb/bin/logs/mongodb-master.log --bind_ip 172.17.0.4 --port 27017 --fork
root 240 0 1 07:12 ? 00:00:02 ./mongod --replSet test --dbpath /mongodb/mongodb/bin/datas/slave --logpath /mongodb/mongodb/bin/logs/mongodb-slave.log --bind_ip 172.17.0.4 --port 27018 --fork
root 336 0 5 07:14 ? 00:00:00 ./mongod --replSet test --dbpath /mongodb/mongodb/bin/datas/replace --logpath /mongodb/mongodb/bin/logs/mongodb-replace.log --bind_ip 172.17.0.4 --port 27019 --fork
root 363 26 0 07:15 ? 00:00:00 grep --color=auto mongodb
[root@ba3b27d855f6 bin]#
[root@ba3b27d855f6 bin]#
#登录其中一个节点,创建config并加载
[root@ba3b27d855f6 bin]# ./mongo 172.17.0.4:27017
MongoDB shell version v3.6.3
connecting to: mongodb://172.17.0.4:27017/test
MongoDB server version: 3.6.3
Server has startup warnings:
2018-08-10T07:04:44.879+0000 I CONTROL [initandlisten]
2018-08-10T07:04:44.879+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-08-10T07:04:44.879+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-08-10T07:04:44.879+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-08-10T07:04:44.879+0000 I CONTROL [initandlisten]
2018-08-10T07:04:44.880+0000 I CONTROL [initandlisten]
2018-08-10T07:04:44.880+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-08-10T07:04:44.880+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-08-10T07:04:44.880+0000 I CONTROL [initandlisten]
2018-08-10T07:04:44.880+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-08-10T07:04:44.880+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-08-10T07:04:44.880+0000 I CONTROL [initandlisten]
>
>
> rs.config()
2018-08-10T07:15:24.809+0000 E QUERY [thread1] Error: Could not retrieve replica set config: {
"info" : "run rs.initiate(...) if not yet done for the set",
"ok" : 0,
"errmsg" : "no replset config has been received",
"code" : 94,
"codeName" : "NotYetInitialized",
"$clusterTime" : {
"clusterTime" : Timestamp(0, 0),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
} :
rs.conf@src/mongo/shell/utils.js:1323:11
@(shell):1:1
> rs.add("172.17.0.4:27018") #集群没有生效之前,无法使用add增加备份节点
assert failed : no config object retrievable from local.system.replset
doassert@src/mongo/shell/assert.js:18:14
assert@src/mongo/shell/assert.js:35:5
rs.add@src/mongo/shell/utils.js:1277:5
@(shell):1:1
2018-08-10T07:16:08.749+0000 E QUERY [thread1] Error: assert failed : no config object retrievable from local.system.replset :
doassert@src/mongo/shell/assert.js:18:14
assert@src/mongo/shell/assert.js:35:5
rs.add@src/mongo/shell/utils.js:1277:5
@(shell):1:1
> config = {
... "_id" : "test",
... "members" : [
... {"_id" : 0, "host" : "172.17.0.4:27017"},
... {"_id" : 1, "host" : "172.17.0.4:27018"},
... {"_id" : 2, "host" : "172.17.0.4:27019"}
... ]
... }
{
"_id" : "test",
"members" : [
{
"_id" : 0,
"host" : "172.17.0.4:27017"
},
{
"_id" : 1,
"host" : "172.17.0.4:27018"
},
{
"_id" : 2,
"host" : "172.17.0.4:27019"
}
]
}
> rs.initiate(config)
{
"ok" : 1,
"operationTime" : Timestamp(1533885822, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1533885822, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
test:SECONDARY>
test:SECONDARY>
test:SECONDARY> rs.status()
{
"set" : "test",
"date" : ISODate("2018-08-10T07:23:51.350Z"),
"myState" : 2,
"term" : NumberLong(0),
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"appliedOpTime" : {
"ts" : Timestamp(1533885822, 1),
"t" : NumberLong(-1)
},
"durableOpTime" : {
"ts" : Timestamp(1533885822, 1),
"t" : NumberLong(-1)
}
},
"members" : [
{
"_id" : 0,
"name" : "172.17.0.4:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 1148,
"optime" : {
"ts" : Timestamp(1533885822, 1),
"t" : NumberLong(-1)
},
"optimeDate" : ISODate("2018-08-10T07:23:42Z"),
"infoMessage" : "could not find member to sync from",
"configVersion" : 1,
"self" : true
},
{
"_id" : 1,
"name" : "172.17.0.4:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 8,
"optime" : {
"ts" : Timestamp(1533885822, 1),
"t" : NumberLong(-1)
},
"optimeDurable" : {
"ts" : Timestamp(1533885822, 1),
"t" : NumberLong(-1)
},
"optimeDate" : ISODate("2018-08-10T07:23:42Z"),
"optimeDurableDate" : ISODate("2018-08-10T07:23:42Z"),
"lastHeartbeat" : ISODate("2018-08-10T07:23:47.559Z"),
"lastHeartbeatRecv" : ISODate("2018-08-10T07:23:49.776Z"),
"pingMs" : NumberLong(1),
"configVersion" : 1
},
{
"_id" : 2,
"name" : "172.17.0.4:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 8,
"optime" : {
"ts" : Timestamp(1533885822, 1),
"t" : NumberLong(-1)
},
"optimeDurable" : {
"ts" : Timestamp(1533885822, 1),
"t" : NumberLong(-1)
},
"optimeDate" : ISODate("2018-08-10T07:23:42Z"),
"optimeDurableDate" : ISODate("2018-08-10T07:23:42Z"),
"lastHeartbeat" : ISODate("2018-08-10T07:23:47.559Z"),
"lastHeartbeatRecv" : ISODate("2018-08-10T07:23:49.782Z"),
"pingMs" : NumberLong(0),
"configVersion" : 1
}
],
"ok" : 1,
"operationTime" : Timestamp(1533885822, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1533885822, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
test:SECONDARY>
#此时选举还没有结束,还没有确定哪个节点是主节点
test:PRIMARY>
test:PRIMARY>
test:PRIMARY>
test:PRIMARY> rs.status()
{
"set" : "test",
"date" : ISODate("2018-08-10T07:24:08.031Z"),
"myState" : 1,
"term" : NumberLong(1),
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1533885834, 5),
"t" : NumberLong(1)
},
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1533885834, 5),
"t" : NumberLong(1)
},
"appliedOpTime" : {
"ts" : Timestamp(1533885834, 5),
"t" : NumberLong(1)
},
"durableOpTime" : {
"ts" : Timestamp(1533885834, 5),
"t" : NumberLong(1)
}
},
"members" : [
{
"_id" : 0,
"name" : "172.17.0.4:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 1165,
"optime" : {
"ts" : Timestamp(1533885834, 5),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2018-08-10T07:23:54Z"),
"infoMessage" : "could not find member to sync from",
"electionTime" : Timestamp(1533885832, 1),
"electionDate" : ISODate("2018-08-10T07:23:52Z"),
"configVersion" : 1,
"self" : true
},
{
"_id" : 1,
"name" : "172.17.0.4:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 25,
"optime" : {
"ts" : Timestamp(1533885834, 5),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1533885834, 5),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2018-08-10T07:23:54Z"),
"optimeDurableDate" : ISODate("2018-08-10T07:23:54Z"),
"lastHeartbeat" : ISODate("2018-08-10T07:24:06.917Z"),
"lastHeartbeatRecv" : ISODate("2018-08-10T07:24:07.788Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "172.17.0.4:27017",
"configVersion" : 1
},
{
"_id" : 2,
"name" : "172.17.0.4:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 25,
"optime" : {
"ts" : Timestamp(1533885834, 5),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1533885834, 5),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2018-08-10T07:23:54Z"),
"optimeDurableDate" : ISODate("2018-08-10T07:23:54Z"),
"lastHeartbeat" : ISODate("2018-08-10T07:24:06.916Z"),
"lastHeartbeatRecv" : ISODate("2018-08-10T07:24:07.795Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "172.17.0.4:27017",
"configVersion" : 1
}
],
"ok" : 1,
"operationTime" : Timestamp(1533885834, 5),
"$clusterTime" : {
"clusterTime" : Timestamp(1533885834, 5),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
test:PRIMARY>
test:PRIMARY> //验证数据
test:PRIMARY> db.school.find()
{ "_id" : ObjectId("5b6d3436dc9a5ab161c121e1"), "name" : "xuaiqi", "date" : ISODate("2018-08-10T06:44:06.284Z") }
{ "_id" : ObjectId("5b6d37ce1a42350d380cb142"), "nme" : "ddddd" }
test:PRIMARY>
test:PRIMARY>
test:PRIMARY>
test:PRIMARY> exit
bye
[root@ba3b27d855f6 bin]#
- MongoDB高可用集群搭建(主从、分片、路由、安全验证)
目录 一.环境准备 1.部署图 2.模块介绍 3.服务器准备 二.环境变量 1.准备三台集群 2.安装解压 3.配置环境变量 三.集群搭建 1.新建配置目录 2.修改配置文件 3.分发其他节点 4.批 ...
- linux系统——Redis集群搭建(主从+哨兵模式)
趁着这几天刚好有点空,就来写一下redis的集群搭建,我跟大家先说明,本文的redis集群因为linux服务器只是阿里云一台服务器,所以集群是redis启动不同端口,但是也能达到集群的要求.其实不同服 ...
- MongoDB集群搭建-副本集
MongoDB集群搭建-副本集 概念性的知识,可以参考本人博客地址: 一.Master-Slave方案: 主从: 二.Replica Set方案: 副本集: 步骤:(只要按步骤操作,100%成功) 1 ...
- Mongodb集群搭建之 Replica Set
Mongodb集群搭建之 Replica Set Replica Set 中文翻译叫做副本集,不过我并不喜欢把英文翻译成中文,总是感觉怪怪的.其实简单来说就是集群当中包含了多份数据,保证主节点挂掉了, ...
- Mongodb 集群搭建以及常见错误
Mongodb 集群搭建以及常见错误 1 关于Replica Sets +Sharding(主从复制加分片)搭建,不这详细去说,网上有很多,大部分的例子就三台服务器之间做主从复制,分2个shard,架 ...
- MongoDB集群搭建-分片
MongoDB集群搭建-分片 一.场景: 1,机器的磁盘不够用了.使用分片解决磁盘空间的问题. 2,单个mongod已经不能满足写数据的性能要求.通过分片让写压力分散到各个分片上面,使用分片服务器自身 ...
- mongodb集群搭建过程记录
mongodb集群搭建花费比较长的时间,在此记录下过程,方便以后使用 一 软件环境 系统:ubuntu 18.04,mongodb 社区版4.2 https://docs.mongodb.com/ma ...
- Mongodb集群搭建的三种方式
转自:http://blog.csdn.net/luonanqin/article/details/8497860 MongoDB是时下流行的NoSql数据库,它的存储方式是文档式存储,并不是Key- ...
- Mongodb集群搭建之 Sharding+ Replica Sets集群架构(2)
参考http://blog.51cto.com/kaliarch/2047358 一.概述 1.1 背景 为解决mongodb在replica set每个从节点上面的数据库均是对数据库的全量拷贝,从节 ...
随机推荐
- 关于kafka的新的group无法订阅到topic中历史消息的问题
今天在写kafka的java api例子时候,遇到一个问题,比如我创建了一个test主题,往里面写了1,2,3,4,5条消息,在这个时候,我用一个新的group启动了一个消费者,发现该消费者只能读到5 ...
- unzip命令
unzip命令用于解压缩由zip命令压缩的“.zip”压缩包. 语法 unzip(选项)(参数) 选项 -c:将解压缩的结果显示到屏幕上,并对字符做适当的转换: -f:更新现有的文件: -l:显示压缩 ...
- MySQL创建计算字段
数据库中数据表的格式一般不是应用程序所需要的格式,如: 在一个字段中既显示公司名有显示公司地址,但这两个数据一般不在一张表中 城市,州和邮政编码在不同的列中,但邮件标签打印程序需要把他们作为一个恰当的 ...
- FastAdmin 后台前端后端组件说明(待续)
FastAdmin 后台 后端 ThinkPHP 5 fastadmin-addons 待续…… 前端 Bootstrap AdminLTE 二次开发 RequireJS JS 模块管理 Less 样 ...
- Navicat permium工具连接Oracle的配置
目标数据库是Oracle11g R2 64位的 搜索很多说是需要32位的Oracle客户端,而且是要下载 Basic 版本,但是下载32位的Oracle客户端还是不行 最后把Navicat Premi ...
- 用div画一个圣诞树
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Java基础语法 第3节 常用软件安装-Webstorm
Webstorm是专用于web开发的号称最好的的编辑器,使用起来很方便. 一.安装 1.去官网下载正版安装包,官网地址:http://www.jetbrains.com/webstorm/ 2.开始安 ...
- COLUMN_FORMAT 的值:FIXED、DYNAMIC、DEFAULT 的区别(待补充)
参考===MySQL 建表语句 create table 中的列定义: column_definition: data_type [NOT NULL | NULL] [DEFAULT default_ ...
- create-react-app 知识点
用 create-react-app 创建项目时,最好FQ:否则有些安装包会安装不上,报超时错误. create-react-app 创建的项目,执行yarn eject后,按需引入antd的2种方式 ...
- c/c++ 获取数组长度
在C/C++中并没有提供直接获取数组长度的函数 c/c++ 获取数组长度其中一种方法是使用sizeof(array) / sizeof(array[0]). 在C语言中习惯上在使用时都把它定义成一个宏 ...