mongod副本集部署

启动命令

mongd -f /etc/mongodb.conf
#不用配置文件自己起得玩
10.142.166.95
mongod --replSet foo --port 27017 --dbpath /data/mongodb1 --logpath /data/mongodb1/mongodb.log &
10.142.164.235
mongod --replSet foo --port 27018 --dbpath /data/mongodb2 --logpath /data/mongodb2/mongodb.log &
10.142.164.238
mongod --replSet foo --port 27019 --dbpath /data/mongodb3 --logpath /data/mongodb3/mongodb.log &

认证
10.142.166.95
mongod --replSet foo --port 27017 --dbpath /data/mongodb1 --logpath /data/mongodb1/mongodb.log --auth &
10.142.164.235
mongod --replSet foo --port 27018 --dbpath /data/mongodb2 --logpath /data/mongodb2/mongodb.log --auth  &
10.142.164.238
mongod --replSet foo --port 27019 --dbpath /data/mongodb3 --logpath /data/mongodb3/mongodb.log --auth  &
db.createUser({user:"james",pwd:"james",roles:[{role:"readWrite",db:"local"}]})
db.auth('james', 'james')


看日志


 tail -f /data/mongodb1/mongodb.log 
tail -f /data/mongodb2/mongodb.log
 tail -f /data/mongodb3/mongodb.log

远程链接


基于mongo实现远程连接
mongo -u dba -p dba  10.142.166.95:27017/admin
mongo -u james -p james  10.142.164.235:27018/local

mongo 10.142.164.235:27018
mongo 10.142.164.238:27019
mongo 10.142.166.95:27017
mongo -u admin -p admin 10.142.166.95:27017

  182  2016-10-24_13:41:04  mongod --replSet foo --port 27019 --dbpath /data/mongodb3 --logpath /data/mongodb3/mongodb.log
  184  2016-10-24_13:50:12  ps -ef | grep mongo
  186  2016-10-24_13:48:47  tail /data/mongodb3/mongodb.log

配置文件


自己的配置
副本集1
systemLog:
   destination: file
   path: "/data/mongodb1/mongodb.log"
   logAppend: true
processManagement:
   fork: true
   pidFilePath: /run/mongo.pid
net:
   port: 27017
   bindIp: 0.0.0.0
#   maxIncomingConnections: 3000
#   http:
#      enabled: true
#     RESTInterfaceEnabled: true
#security:
 #  keyFile:/data/mongodb1/keyfile
#key:   9ff6ee24a568dff6b7e1cf7b4aef1aad1c20b82c39d7a6f5f3
  # authorization: enabled
storage:
   journal:
      enabled: true
   dbPath:/data/mongodb1
   directoryPerDB: true
   syncPeriodSecs: 2
   engine: wiredTiger
   wiredTiger:
      engineConfig:
         cacheSizeGB: 10
replication:
   oplogSizeMB: 51200
   replSetName: foo
###########自己写的
/etc/mongodb.conf
dbpath=/data/james/db
logpath=/data/james/logs/mongo.log
pidfilepath=/run/mongo.pid
directoryperdb=true
logappend=true
#bind_ip=10.183.222.215
port=27017
oplogSize=51200
fork=true
#noprealloc=true
storageEngine=wiredTiger
wiredTigerCacheSizeGB=40

#王静静 跟着dba学习一把



10.149.14.236:937510.149.14.232:937510.149.14.234:9375 


副本1配置
systemLog:
   destination: file
   path: "/data/slot0/bigdata_bigdataops1_mongo/logs/mongo.log"
   logAppend: true
processManagement:
   fork: true
   pidFilePath: /data/slot0/bigdata_bigdataops1_mongo/tmp/mongo.pid
net:
   port: 9375
   bindIp: 10.149.14.236
#   maxIncomingConnections: 3000
#   http:
#      enabled: true
#     RESTInterfaceEnabled: true
security:
   keyFile: /data/slot0/bigdata_bigdataops1_mongo/etc/keyfile
   authorization: enabled
storage:
   journal:
      enabled: true
   dbPath: /data/slot0/bigdata_bigdataops1_mongo/data
   directoryPerDB: true
   syncPeriodSecs: 2
   engine: wiredTiger
   wiredTiger:
      engineConfig:
         cacheSizeGB: 10
replication:
   oplogSizeMB: 51200
   replSetName: bigdataops1

#副本2配置
systemLog:
   destination: file
   path: "/data/slot0/bigdata_bigdataops1_mongo/logs/mongo.log"
   logAppend: true
processManagement:
   fork: true
   pidFilePath: /data/slot0/bigdata_bigdataops1_mongo/tmp/mongo.pid
net:
   port: 9375
   bindIp: 10.149.14.232
#   maxIncomingConnections: 3000
#   http:
#      enabled: true
#     RESTInterfaceEnabled: true
security:
   keyFile: /data/slot0/bigdata_bigdataops1_mongo/etc/keyfile
   authorization: enabled
storage:
   journal:
      enabled: true
   dbPath: /data/slot0/bigdata_bigdataops1_mongo/data
   directoryPerDB: true
   syncPeriodSecs: 2
   engine: wiredTiger
   wiredTiger:
      engineConfig:
         cacheSizeGB: 10
replication:
   oplogSizeMB: 51200
   replSetName: bigdataops1

你可能感兴趣的:(mongodb)