MongoDB设置 Replication Sets 复制集(2)


 mongod --keyFile <path-to-keyfile> --replSet <replicaSetName>
   
    配置带密钥文件的 Replication Sets:
   
    [root@node1 ~]# openssl rand -base64 756 > /mongodb/mongokey
    [root@node1 ~]# cat /mongodb/mongokey
 gxpcgjyFj2qE8b9TB/0XbdRVYH9VDb55NY03AHwxCFU58MUjJMeez844i1gaUo/t
 .....
 .....
 
    [root@node1 ~]# chmod 400 /mongodb/mongokey
 [root@node1 ~]# chown mongod:mongod /mongodb/mongokey
 [root@node1 ~]# ll /mongodb/
 total 8
 drwxr-xr-x 4 mongod mongod 4096 May 19 18:39 data
 -r-------- 1 mongod mongod 1024 May 19 18:29 mongokey


    [root@node1 ~]# vim /etc/mongod.conf
    #security:
 security:
  keyFile: /mongodb/mongokey


 #operationProfiling:


 #replication:
 replication:
  oplogSizeMB: 1024
  replSetName: rs0
   
    [root@node1 ~]# service mongod restart
 Stopping mongod:                                          [  OK  ]
 Starting mongod:                                          [  OK  ]
   
    [root@node1 ~]# iptables -I INPUT 4 -m state --state NEW -p tcp --dport 27017  -j ACCEPT
   
    复制hosts文件:
    [root@node1 ~]# rsync -avH --progress '-e ssh -p 22' /etc/hosts root@node2.pancou.com:/mongodb/
    [root@node1 ~]# rsync -avH --progress '-e ssh -p 22' /etc/hosts root@node3.pancou.com:/mongodb/
    复制密钥文件:
    [root@node1 ~]# rsync -avH --progress '-e ssh -p 22' /mongodb/mongokey root@node3.pancou.com:/mongodb/
    [root@node1 ~]# rsync -avH --progress '-e ssh -p 22' /mongodb/mongokey root@node3.pancou.com:/mongodb/
   
    复制配置文件:
    [root@node1 ~]# rsync -avH --progress '-e ssh -p 22' /etc/mongod.conf root@node2.pancou.com:/etc/
    [root@node1 ~]# rsync -avH --progress '-e ssh -p 22' /etc/mongod.conf root@node3.pancou.com:/etc/


    注意:双方都要按照rsync和openssh-clients


    [root@node1 ~]# mongo
    > help
 db.help()                    help on db methods
 db.mycoll.help()            help on collection methods
 sh.help()                    sharding helpers
 rs.help()                    replica set helpers
    .....


    > rs.help()
    rs.status()                                { replSetGetStatus : 1 } checks repl set status
 rs.initiate()                              { replSetInitiate : null } initiates set with default settings
 rs.initiate(cfg)                          { replSetInitiate : cfg } initiates set with configuration cfg
 rs.conf()                                  get the current configuration object from local.system.replset
    .....


    > rs.status()
 {
  "info" : "run rs.initiate(...) if not yet done for the set",
  "ok" : 0,
  "errmsg" : "no replset config has been received",
  "code" : 94,
  "codeName" : "NotYetInitialized"
    }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/d63e6ebf4a92b37e2f81522de35bff98.html