mongodb环境搭建

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_15411661/article/details/83304390

# Mongdb
    依赖环境
    typing-3.6.4
    Markdown-2.1.0
    PyYAML-3.12
    Cheetah-2.4.4
    scon-3.0.0
    gcc-5.3.0
    gmp-4.3.2
    m4-1.4.16
    mpc-0.8.1
    mpfr-2.4.2
    安装mongo-cxx-driver
        安装cmake-3.11.0.tar.gz
            ./configure 
            make 
            make install
        安装mongo-c-driver-1.9.3.tar.gz
            ./configure --disable-automatic-init-and-cleanup
            make 
            sudo make install 
        安装libbson-1.9.0.tar.gz
            ./configure –-prefix=/usr --libdir=/usr/lib64 
            make 
            make install 
            cd mongo-cxx-driver/build
        安装boost_1_67_0.tar.gz
            ./bootstrap.sh –with-libraries=all –with-toolset=gcc 
            ./b2 toolset=gcc
            ./b2 install
            ldconfig
        安装mongocxx driver
            cd mongo-cxx-driver/build
            export CC=/usr/local/gcc-5.3.0/bin/gcc
            export CXX=/usr/local/gcc-5.3.0/bin/g++
            cmake -DCMAKE_BUILD_TYPE=Release  -DBSONCXX_POLY_USE_BOOST=1 -DCMAKE_INSTALL_PREFIX=/home/juzheng/cxx-driver/bin ..
            
            下载core-1.1.0.zip
            cd /tmp/mongo-cxx-driver/build/src/bsoncxx/third_party/EP_mnmlstc_core-prefix/src
            解压core-1.1.0.zip并改名为EP_mnmlstc_core
            vim  build/src/bsoncxx/third_party/EP_mnmlstc_core-prefix/tmp/EP_mnmlstc_core-gitclone.cmake
            注释从# try the clone 3 times in case there is an odd git clone issue
                set(error_code 1)
                set(number_of_tries 0)
                while(error_code AND number_of_tries LESS 3)
                  execute_process(
                    COMMAND "/usr/bin/git" ${git_options} clone ${git_clone_options} --origin "origin" "https://github.com/mnmlstc/core" "EP_mnmlstc_core"
                到最后一行
            sudo make EP_mnmlstc_core
            make && sudo make install
    中控服务
        更新库curl-7.59.0,openssl-1.1.0h

搭建集群
第四节 replica sets + shard (3机高可用 , 一主一备份一仲裁)
 一 方案
  每个分片3服务器,前期采用三台,日后服务器的增加考虑灾备,服务增加的基数最少为三台(或用有双机方案)。
  Server1 10.10.113.122 Server1 10.10.113.132 Server3 10.10.113.133
  

  类型    服务器   用途       系统   说明
   
  存储/数据   Server1    Shard1/Shard2/Shard3  Linux 64位  Shard1:10001;Shard2:10002,Shard3:10003;
       Server2   Shard1/Shard2/Shard3  Linux 64位  Shard1:10001;Shard2:10002,Shard3:10003;
       Server3   Shard1/Shard2/Shard3  Linux 64位  Shard1:10001;Shard2:10002,Shard3:10003;
   
  配置    Server1   Config1      Linux 64位  Config1:20000;
       Server2   Config2      Linux 64位  Config2:20000; 
       Server3   Config3      Linux 64位  Config3:20000;
   
  路由    Server1   Mongos1      Linux 64位  Mongos:30000;
       Server2   Mongos2      Linux 64位  Mongos:30000;
       Server3   Mongos3      Linux 64位  Mongos:30000;
 
 二 准备
  安装mongodb 参照第一节
  
  
  linux 传文件
  # scp mongodb-linux-x86_64-2.0.4.tgz [email protected]:/root
  # ssh 10.10.113.132
 
 
  创建配置、日志、分片、key文件存储目录及验证文件
  
  mkdir /data/mongodb/configsvr/ -p
  
  mkdir /data/mongodb/log/ -p
  
  mkdir /data/mongodb/shard1/ -p
  
  mkdir /data/mongodb/shard2/ -p
  
  mkdir /data/mongodb/shard3/ -p
  
  mkdir /data/mongodb/key/ -p
  
  mkdir /data/mongodb/conf/security/ -p
  mkdir /data/mongodb/conf/nosecurity/ -p
  
  创建配置文件
   1、 创建验证文件security于/data/mongodb/key/目录,关赋予可读权限,命令如下:
   cd /data/mongodb/key/
   echo 'hycloudmongodbkey' > security
   chmod 600 /data/mongodb/key/security
   
   2、 创建shard1.conf、shard2.conf、shard3.conf、configsvr.conf、mongos.conf于/data/mongodb/conf/security/ 和 /data/mongodb/conf/nosecurity/的目录,内容分别如下:
   shard1.conf
   
dbpath = /data/mongodb/shard1
directoryperdb = true
shardsvr = true
replSet = shard1 #或者replSet = shard1/10.15.117.53:27017,10.15.117.50:27018
#bind_ip = 10.10.113.122,localhost
port = 10001
oplogSize = 100
logpath =/data/mongodb/log/shard1.log
logappend = true
profile = 1
slowms = 5
rest = true
fork = true
wiredTigerCacheSizeGB = 15
keyFile = /data/mongodb/key/security  #nosecurity目录将该行删除
    
   shard2.conf
dbpath = /data/mongodb/shard2
directoryperdb = true
shardsvr = true
replSet = shard2 #或者replSet = shard2/10.15.117.53:27017,10.15.117.50:27018
#bind_ip = 10.10.113.122,localhost
port = 10002
oplogSize = 100
wiredTigerCacheSizeGB = 15
logpath = /data/mongodb/log/shard2.log
logappend = true
profile = 1
slowms = 5
rest = true
fork = true
keyFile = /data/mongodb/key/security  #nosecurity目录将该行删除
    
   shard3.conf
dbpath = /data/mongodb/shard3
directoryperdb = true
shardsvr = true
replSet = shard3 #或者replSet = shard3/10.15.117.53:27017,10.15.117.50:27018
#bind_ip = 10.10.113.122,localhost
port = 10003
oplogSize = 100
logpath = /data/mongodb/log/shard3.log
logappend = true
profile = 1
slowms = 5
rest = true
fork = true
wiredTigerCacheSizeGB = 15
keyFile = /data/mongodb/key/security  #nosecurity目录将该行删除
    
   configsvr.conf
dbpath = /data/mongodb/configsvr

bind_ip = 10.15.117.53

directoryperdb = true

configsvr = true

port = 20000

logpath =/data/mongodb/log/configsvr.log

logappend = true

fork = true

replSet = config/10.15.117.53:20000

keyFile = /data/mongodb/key/security  #nosecurity目录将该行删除
    
   mongos.conf
configdb =config/10.10.113.122:20000, 10.10.113.132:20000, 10.10.113.133:20000

port = 30000

bind_ip = 10.15.117.53

chunkSize = 1  #单位 mb 生成环境请使用 200 或删除,有些版本会报错,可以在shell里设置use config   db.settings.save( { _id:"chunksize", value: <sizeInMB> } )

logpath =/data/mongodb/log/mongos.log

logappend = true

fork = true

keyFile = /data/mongodb/key/security  #nosecurity目录将该行删除
   
  分片配置
   说明:分片要在无验证环境中配置,否则会出现无权限等异常。采用以下命令启动Server1\Server2\Server3上的shard1\shard2\shard3:

   # /usr/local/mongodb/bin/mongod -f /data/mongodb/conf/nosecurity/shard1.conf

   # /usr/local/mongodb/bin/mongod -f /data/mongodb/conf/nosecurity/shard2.conf

   # /usr/local/mongodb/bin/mongod -f /data/mongodb/conf/nosecurity/shard3.conf

   以下命令查看是否正常启动:

   # netstat -lnpt # 或 ps -ef | grep mongo
    systemctl stop firewalld.service #停止firewall
    systemctl disable firewalld.service #禁止firewall开机启动
   启动后连接到shard1\shard2\shard3分别进行配置,在任意一台服务器即可,以下是具体配置过程:(注意不能在仲裁机器初始化)

   # /usr/local/mongodb/bin/mongo --port 10001
   
   >use admin
   
   config = {_id:"shard2", members: [

           {_id: 0, host:"10.15.117.50:27017", priority:10},

           {_id: 1, host:"10.15.117.53:27018", priority:8},

           {_id: 2, host:"10.15.117.50:27019","arbiterOnly":true}]

        };

   rs.initiate(config)
    # /usr/local/mongodb/bin/mongo --port 10001
   config = {_id:"shard1", members: [

           {_id: 0, host:"10.15.117.53:27017", priority:10},

           {_id: 1, host:"10.15.117.50:27018", priority:8},

           {_id: 2, host:"10.15.117.53:27019","arbiterOnly":true}]

        };

   rs.initiate(config)
    # /usr/local/mongodb/bin/mongo --port 10001
      config = {_id:"shard3", members: [

           {_id: 0, host:"10.15.117.24:27017", priority:10},

           {_id: 1, host:"10.15.117.18:27018", priority:8},

           {_id: 2, host:"10.14.96.167:27019","arbiterOnly":true}]

        };

   rs.initiate(config)

   >exit


   至此,已完成分片配置
   
  路由设置
   路由是能过config来连接分片服务器,在启动路由进程时,先启动配置进程,路由配置过程如下:

   # /usr/local/mongodb/bin/mongod -f /data/mongodb/conf/nosecurity/configsvr.conf
     >config = {_id:"config", members: [

           {_id: 0, host:"10.15.117.53:20000",priority:10},

           {_id: 1, host:"10.15.117.50:20000",priority:8}]

        };

   >rs.initiate(config)

   # /usr/local/mongodb/bin/mongos -f /data/mongodb/conf/nosecurity/mongos.conf

   启动后,连接路由进行分片添加,只需配置一台路由。注:分片操作需在admin库下进行,另外必需在无验证要求下进行,即采用前面创建于nosecurity文件夹下的配置。

   # /usr/local/mongodb/bin/mongo --port 30000

   mongos> use admin
   # maxsize:20480 #单位 mb 分片限制大小 根据实际服务器来定
   mongos> db.runCommand({addshard:"shard1/10.15.117.18:27017,10.14.96.167:27018,10.15.117.24:27019",name:"shard1"} )

   mongos> db.runCommand({addshard:"shard2/10.14.96.167:27017,10.15.117.24:27018,10.15.117.18:27019",name:"shard2"} )

   mongos> db.runCommand({addshard:"shard3/10.15.117.24:27017,10.15.117.18:27018,10.14.96.167:27019",name:"shard3"} )
   
   #使用分片的数据库
    db.runCommand({addshard:"shard1/10.33.36.224:27017,10.7.52.187:27018,10.14.96.35:27019"})
    db.runCommand({addshard:"shard2/10.7.52.187:27017,10.14.96.35:27018,10.33.36.224:27019"})
    db.runCommand({addshard:"shard3/10.14.96.35:27017,10.33.36.224:27018,10.7.52.187:27019"})
    db.runCommand({listShards:1})
    sh.startBalancer()
    sh.enableSharding("test") 
    sh.shardCollection("test.carTest", {"_id":"hashed"})
    use config
    db.settings.find() 
    db.settings.save( { _id:"chunksize", value: 300 } )       //扩大chunk的大小

  
  
  权限控制
   MongoDB默认为验证模式。如需对数据库进行权限控制,需先采用无验证模式登录,进入admin库创建管理员用户后,再采用验证模式登录。通过前面创建的管理员帐号进行数据库与用户的创建。MongoDB集群的权限与单台的权限控制的不同之处在于,单台是通过-auth属性,集群是通过keyFile来进行服务器间的验证。以下介绍配置全过程。

   前面的所有步骤,都是在nosecurity模式下进行。如果没有采用非验证模式的需要将所有进程(分片、配置、mongos)停止,将切换到无验证模式。

   步骤一:先进行登录,并切换进admin库创建管理员帐号

   # /usr/local/mongodb/bin/mongo --port 30000

   mongos>use admin

   mongos>db.addUser('admin','123456')

   {

     "singleShard" :"192.168.2.88:20000,192.168.2.89:20000,192.168.2.90:20000",

     "n" : 0,

     "connectionId" : 211,

     "err" : null,

     "ok" : 1

   }

   {

     "_id" :ObjectId("4f6c78ddad912a3ac6833ece"),

     "user" : "admin",

     "readOnly" : false,

     "pwd" :"95ec4261124ba5951720b199908d892b"

   }

   验证用户名与密码

   mongos> db.auth('admin','123456')

   1

   mongos>exit

   步骤二:退出后,将Server1\Server2\Server3服务器上MongoDB的所有进程(分片、配置、mongos)停止,将切换到验证模式。具体命令如下:

   # killall mongod mongos

   # netstat -lnpt

   # /usr/local/mongodb/bin/mongod -f /data/mongodb/conf/security/shard1.conf

   # /usr/local/mongodb/bin/mongod -f /data/mongodb/conf/security/shard2.conf

   # /usr/local/mongodb/bin/mongod -f /data/mongodb/conf/security/shard3.conf

   # netstat -lnpt # ps -ef | grep mongo

   # /usr/local/mongodb/bin/mongod -f /data/mongodb/conf/security/configsvr.conf

   # /usr/local/mongodb/bin/mongos -f /data/mongodb/conf/security/mongos.conf

   启动后,如对库进行查看,则会报以下异常:

   # /usr/local/mongodb/bin/mongo 10.10.113.122:30000/admin

   MongoDB shell version: 2.0.4

   connecting to:10.10.113.122:30000/admin

   > show dbs

   Fri Mar 23 22:28:28 uncaughtexception: listDatabases failed:{ "ok" : 0, "errmsg" :"unauthorized" }

   以下是正常登录后显示的信息:

   # /usr/local/mongodb/bin/mongo 10.10.113.122:30000/admin

   MongoDB shell version: 2.0.4

   connecting to:10.10.113.122:30000/admin

   >db.auth('admin','123456')

   1

   mongos>

   步骤三:以下是数据库及数据库用户创建的过程:

   mongos> use hello

   switched to db hello

   mongos>db.addUser('sa','sa')

   {

     "singleShard" :"shard2/10.10.113.122:10002,10.10.113.132:10002,10.10.113.133:10002",

     "n" : 0,

     "lastOp" :NumberLong("5723101431532093441"),

     "connectionId" : 38,

     "err" : null,

     "ok" : 1

   }

   {

     "user" : "sa",

     "readOnly" : false,

     "pwd" :"75692b1d11c072c6c79332e248c4f699",

     "_id" :ObjectId("4f6c8a6e9f67b049a20a00de")

   }

   mongos> exit

   bye

   # /usr/local/mongodb/bin/mongo 10.10.113.122:30000/hello -u sa -p

   MongoDB shell version: 2.0.4

   Enter password:

   connecting to:10.10.113.122:30000/hello

   > show collections

   system.indexes

   system.users

   > db.system.users.find()

   { "_id" :ObjectId("4f6c8a6e9f67b049a20a00de"), "user" :"sa", "readOnly" : false, "pwd" :"75692b1d11c072c6c79332e248c4f699" }


  分片
   # /usr/local/mongodb/bin/mongo -port 30000
   
   > use admin
   > db.runCommand({"enablesharding":"test"})
   > db.runCommand({"shardcollection":"test.doc","key":{"_id":1}})
   > db.runCommand({"shardcollection":"test.txt","key":{"_id":1}})
   索引
   > use test
   > db.fs.chunks.ensureIndex({files_id: 1});  
   > use admin
   > db.runCommand({ shardcollection : "test.fs.chunks", key : { files_id : 1 }}) 

   
   索引
   > use test
   
   > db.doc.ensureIndex({"letter":1})
   
   导入数据
   
   查询数据
   
   分片管理
   > sh.status()
   副本管理
   > rs.status()
   数据库管理
   > use config
   > show collections
   > db.shards.find()
   > db.databases.find() //查看数据库状态
   > db.chunks.find()
   > db.mongos.find()
   > db.printShardingStatus()
   > db.stats()
   > db.tab.stats()  //查看集合状态
   
   二 初始化副本集(只能初始化一次)
  /usr/local/mongodb/bin/mongo --port 30001
  use admin
  方法一:
  db.runCommand({"replSetInitiate":{"_id":"blort","members":[{"_id":0,"host":"10.10.113.122:30001"},{"_id":1,"host":"10.10.113.122:30002"},{"_id":2,"host":"10.10.113.122:30003","arbiterOnly":true}]}})
  
  方法二:
  config={_id:'blort',members:[{"_id":0,host:'10.10.113.122:30001},{"_id":1,host:'10.10.113.122:30002'},{"_id":2,"host":"10.10.113.122:30003","arbiterOnly":true}]};
  rs.initiate(config);

     三 增加和设置副本集
      有几种不同类型的节点可以存在于副本集:
      Standard :存在于副本,参与投票,有可能成为活跃节点(即主节点)
      Passive :存储了完整的数据副本,参与投票,不能成为活跃节点
      Arbiter:仲裁者,只参与投票,不能成为活跃节点
      Priority:优先级,(投票会投优先级高的,如果相同,则投数据最新的)
      以上类型可以通过以下命令对副本集合进行修改或者增加服务器
      db.runCommand({"replSetReconfig":{"_id":"test3","version":2,"members":[{"_id":0,"host":"10.10.113.122:30001"},{"_id":1,"host":"10.10.113.122:30002"},{"_id":2,"host":"10.10.113.122:30003","arbiterOnly":true}]}})
      
      增加副本服务器
      在增加一个从服务器节点
      a.以相同副本集名字启动一台服务器
      b.通过rs.add命令往system.replset添加新的从服务器成员
      rs.add("10.10.113.122:30005"); 或者rs.add({"_id":4,"host":"10.10.113.122:30005"}) 
      添加仲裁
      rs.addArb("10.10.113.122:30004");

      
副本集更换IP
        1.修改配置文件IP
        2.启动所有节点
        3.config = {
                    "members" : [
                    {"_id" : 1,"host" : "10.41.11.51:27017"},
                    {"_id" : 2,"host" : "10.41.11.52:27017"},
                    {"_id" : 3,"host" : "10.41.11.53:27017","arbiterOnly" : true}
                ]
            }
        rs.reconfig(config, {force: true})
集群更换IP
        configSvr = {_id:"configSvr",
                    configsvr:true,
                    members: [

                   {_id: 0, host:"10.41.11.21:20000",priority:10},

                   {_id: 1, host:"10.41.11.20:20000",priority:8}]

                };
                
                
                            原有集群配置:

                    服务器信息:192.168.200.155/156/157

                    服务器155

                    服务器156

                    服务器157

                    mongos

                    mongos

                    mongos

                    config server

                    config server

                    config server

                    shard server1 主节点

                    shard server1 副节点

                    shard server1 仲裁

                    shard server2 仲裁

                    shard server2 主节点

                    shard server2 副节点

                    shard server3 副节点

                    shard server3 仲裁

                    shard server3 主节点

                    端口信息:

                    mongos:27001

                    config:30000

                    shard1:27101

                    shard2:27102

                    shard3:27103

                     

                    现在需要将IP改为正式环境的IP,IP对应关系如下:

                    192.168.200.155--->10.170.130.93

                    192.168.200.156--->10.170.130.94

                    192.168.200.157--->10.170.130.96

                     

                     

                    1、停止所有的mongod、mongos实例

                    ps -ef | grep mongod;查出进程ID后使用kill杀掉

                    ps -ef | grep mongos;查出进程ID后使用kill杀掉

                    2、修改三个配置节点信息(config server)

                    1)以standlone模式启动第一个config server

                    ./bin/mongod --port 30000 --dbpath /data2/mongodb/config/data

                    2)到另外一个xshell中登录config节点

                    ./bin/mongo --port 30000

                    3)查看并修改副本集信息

                    > use local

                    > db.system.replset.find()

                     

                    > cfg = db.system.replset.findOne({_id: 'configs'})

                    > cfg.members[0].host = "10.170.130.93:30000"

                    > cfg.members[1].host = "10.170.130.94:30000"

                    > cfg.members[2].host = "10.170.130.96:30000"

                    > db.system.replset.update({_id: 'configs'}, cfg)

                    4)按照以上方法修改其他config server节点配置信息,修改完成后启动三个节点

                    ./bin/mongod -f conf/configsvr.conf

                    5)登录到primary节点,修改分片信息

                    > use config

                    > cfg=db.shards.findOne({_id:'shard1'})

                    > cfg.host="shard1/10.170.130.93:27101,10.170.130.94:27101"

                    > db.shards.update({_id:'shard1'},cfg)

                    > cfg = db.shards.findOne({_id: 'shard2'})

                    > cfg.host = "shard2/10.170.130.94:27102,10.170.130.96:27102"

                    > db.shards.update({_id: 'shard2'}, cfg)

                    > cfg = db.shards.findOne({_id: 'shard3'})

                    > cfg.host = "shard3/10.170.130.94:27103,10.170.130.96:27103"

                    > db.shards.update({_id: 'shard3'}, cfg)

                     

                    3、修改shard节点信息

                    1)以standlone模式启动其中一个节点:

                    ./bin/mongod --port 27101 --dbpath /data2/mongodb/shard1/data(指定的存储路径)

                    2)登录节点

                    ./bin/mongo --port 27101

                    3)修改配置服务器信息

                    > use admin

                    > db.system.version.find()

                    > db.system.version.update({"_id" : "shardIdentity"},{"$set":{"configsvrConnectionString" : "configs/10.170.130.93:30000,10.170.130.94:30000,10.170.130.96:30000"}})

                    4)修改replica set的配置信息, replica set的信息都保存在local数据库的system.replset集合中

                    > use local

                    > cfg = db.system.replset.findOne({_id: 'shard1'})

                    > cfg.members[0].host="10.170.130.93:27101"

                    > cfg.members[1].host="10.170.130.94:27101"

                    > cfg.members[2].host="10.170.130.96:27101"

                    > db.system.replset.update({_id:'shard1'},cfg)

                     

                    对shard1的其他两个节点以及shard2、shard3的三个节点做一样的操作。

                    5)启动shard节点

                    ./bin/mongod -f conf/sd1.conf

                    ./bin/mongod -f conf/sd2.conf

                    ./bin/mongod -f conf/sd3.conf

                     

                    4、修改mongos配置信息

                    1)修改配置文件

                    修改配置文件中的configdb,改为新IP的configserver

                    2)启动mongos节点

                    ./bin/mongos -f conf/mongos.conf

                    6、验证是否成功

                    ./bin/mongo --port 27001


集群添加节点
    正常添加节点然后
    use face
    db.static_human.createIndex("_id":1)
    db.static_human.ensureIndex({"_id":"hashed"})   
    sh.shardCollection("test.carTest", {"_id":"hashed"})
        
查询数据    

DBQuery.shellBatchSize = 50 

    db.carTest.find({"Pass_time":{"$gte": new Date("1955-01-01T10:00:00.000Z"), "$lte": new Date("1975-12-31T18:10:00.000Z")}}).sort({"Pass_time": -1}).limit(1000).explain("executionStats").executionStats 
    
    db.carTest.find({"$and":[{"Pass_time":{"$gte": new Date("1955-01-01T10:00:00.000Z"), "$lte": new Date("1975-12-31T18:10:00.000Z")}}, {"Plate_color":1}]}).sort({"Pass_time":-1}).limit(1000).explain("executionStats").executionStats 
    
    db.carTest.find({"$and":[{"Pass_time":{"$gte": new Date("1955-01-01T10:00:00.000Z"), "$lte": new Date("1975-12-31T18:10:00.000Z")}}, {"Plate_no": {$regex:/12/}},{"Plate_color":1}]}).sort({"Pass_time":-1}).limit(1000).explain("executionStats").executionStats 
    
    db.carTest.find({"$and":[{"Pass_time":{"$gte": new Date("1955-01-01T10:00:00.000Z"), "$lte": new Date("1975-12-31T18:10:00.000Z")}}, {"Plate_no": {$regex:/12/}},{"Plate_color":1},{"Vehicle_color":1}]}).sort({"Pass_time":-1}).limit(1000).explain("executionStats").executionStats 
    
    db.carTest.find({"$and":[{"Pass_time":{"$gte": new Date("1955-01-01T10:00:00.000Z"), "$lte": new Date("1975-12-31T18:10:00.000Z")}}, {"device_id": {"$in":[123,456,789,147,258,369]}}, {"gender":0}]}, {"_id":1, "snap_time":1, "device_id":1, "model":1}).sort({"snap_time": -1}).limit(1000).explain("executionStats").executionStats 
    
创建索引规则
    1.范围查询和排序,放在组合索引最后。
    2.能过滤90%以上数据的适合做索引。
    3.有多个索引时,用hint指定Mongo对索引的选择
    
mongodb 启动参数
    --quiet                              # 安静输出 
    --port arg                        # 指定服务端口号,默认端口27017 
    --bind_ip arg                  # 绑定服务IP,若绑定127.0.0.1,则只能本机访问,不指定默认本地所有IP 
    --logpath arg                  # 指定MongoDB日志文件,注意是指定文件不是目录 
    --logappend                   # 使用追加的方式写日志 
    --pidfilepath arg             # PID File 的完整路径,如果没有设置,则没有PID文件 
    --keyFile arg                   # 集群的私钥的完整路径,只对于Replica Set 架构有效 
    --unixSocketPrefix arg  # UNIX域套接字替代目录,(默认为 /tmp) 
    --fork                                 # 以守护进程的方式运行MongoDB,创建服务器进程 
    --auth                                # 启用验证 
    --cpu                                 # 定期显示CPU的CPU利用率和iowait 
    --dbpath arg                     # 指定数据库路径 
    --diaglog arg                    # diaglog选项 0=off 1=W 2=R 3=both 7=W+some reads 
    --directoryperdb              # 设置每个数据库将被保存在一个单独的目录 
    --journal                            # 启用日志选项,MongoDB的数据操作将会写入到journal文件夹的文件里 
    --journalOptions arg       # 启用日志诊断选项 
    --ipv6                                 # 启用IPv6选项 
    --jsonp                              # 允许JSONP形式通过HTTP访问(有安全影响) 
    --maxConns arg             # 最大同时连接数 默认2000 
    --noauth                           # 不启用验证 
    --nohttpinterface             # 关闭http接口,默认关闭27018端口访问 
    --noprealloc                     # 禁用数据文件预分配(往往影响性能) 
    --noscripting                    # 禁用脚本引擎 
    --notablescan                  # 不允许表扫描 
    --nounixsocket                # 禁用Unix套接字监听 
    --nssize arg (=16)           # 设置信数据库.ns文件大小(MB) 
    --objcheck                        # 在收到客户数据,检查的有效性, 
    --profile arg                      # 档案参数 0=off 1=slow, 2=all 
    --quota                              # 限制每个数据库的文件数,设置默认为8 
    --quotaFiles arg               #  number of files allower per db, requires --quota 
    --rest                                  # 开启简单的rest API 
    --repair                              # 修复所有数据库run repair on all dbs 
    --repairpath arg               # 修复库生成的文件的目录,默认为目录名称dbpath 
    --slowms arg (=100)       # value of slow for profile and console log 
    --smallfiles                       # 使用较小的默认文件 
    --syncdelay arg (=60)    # 数据写入磁盘的时间秒数(0=never,不推荐) 
    --sysinfo                           # 打印一些诊断系统信息 
    --upgrade                        # 如果需要升级数据库
    
    * Replicaton 参数

   --------------------------------------------------------------------------------

    --fastsync                      # 从一个dbpath里启用从库复制服务,该dbpath的数据库是主库的快照,可用于快速启用同步 
    --autoresync                 # 如果从库与主库同步数据差得多,自动重新同步, 
    --oplogSize arg            # 设置oplog的大小(MB) 
    
    * 主/从参数

   --------------------------------------------------------------------------------

    --master                        # 主库模式 
    --slave                           # 从库模式 
    --source arg                 # 从库 端口号 
    --only arg                      # 指定单一的数据库复制 
    --slavedelay arg          # 设置从库同步主库的延迟时间 
     
    * Replica set(副本集)选项:

   --------------------------------------------------------------------------------

    --replSet arg                   # 设置副本集名称 
    
    * Sharding(分片)选项

   --------------------------------------------------------------------------------

    --configsvr                       # 声明这是一个集群的config服务,默认端口27019,默认目录/data/configdb 
    --shardsvr                        # 声明这是一个集群的分片,默认端口27018 
    --noMoveParanoia        # 关闭偏执为moveChunk数据保存? 

猜你喜欢

转载自blog.csdn.net/sinat_15411661/article/details/83304390
今日推荐