码迷,mamicode.com
首页 > 数据库 > 详细

MongoDB -MSC集群的部署

时间:2020-05-25 09:36:11      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:组复制   system   comm   rect   clust   mon   div   res   官方   

一.Shard节点配置过程
1. 目录创建:
mkdir -p /mongodb/38021/conf  /mongodb/38021/log  /mongodb/38021/data
mkdir -p /mongodb/38022/conf  /mongodb/38022/log  /mongodb/38022/data
mkdir -p /mongodb/38023/conf  /mongodb/38023/log  /mongodb/38023/data
mkdir -p /mongodb/38024/conf  /mongodb/38024/log  /mongodb/38024/data
mkdir -p /mongodb/38025/conf  /mongodb/38025/log  /mongodb/38025/data
mkdir -p /mongodb/38026/conf  /mongodb/38026/log  /mongodb/38026/data

2. 修改配置文件:
第一组复制集搭建:21-23(1主 1从 1Arb)
cat >  /mongodb/38021/conf/mongodb.conf  <<EOF
systemLog:
  destination: file
  path: /mongodb/38021/log/mongodb.log  
  logAppend: true
storage:
  journal:
    enabled: true
  dbPath: /mongodb/38021/data
  directoryPerDB: true
  #engine: wiredTiger
  wiredTiger:
    engineConfig:
      cacheSizeGB: 1
      directoryForIndexes: true
    collectionConfig:
      blockCompressor: zlib
    indexConfig:
      prefixCompression: true
net:
  bindIp: 10.0.0.51,127.0.0.1
  port: 38021
replication:
  oplogSizeMB: 2048
  replSetName: sh1
sharding:
  clusterRole: shardsvr
processManagement:
  fork: true
EOF
\cp  /mongodb/38021/conf/mongodb.conf  /mongodb/38022/conf/
\cp  /mongodb/38021/conf/mongodb.conf  /mongodb/38023/conf/
sed ‘s#38021#38022#g‘ /mongodb/38022/conf/mongodb.conf -i
sed ‘s#38021#38023#g‘ /mongodb/38023/conf/mongodb.conf -i
第二组节点:24-26(1主1从1Arb)
cat > /mongodb/38024/conf/mongodb.conf <<EOF
systemLog:
  destination: file
  path: /mongodb/38024/log/mongodb.log  
  logAppend: true
storage:
  journal:
    enabled: true
  dbPath: /mongodb/38024/data
  directoryPerDB: true
  wiredTiger:
    engineConfig:
      cacheSizeGB: 1
      directoryForIndexes: true
    collectionConfig:
      blockCompressor: zlib
    indexConfig:
      prefixCompression: true
net:
  bindIp: 10.0.0.51,127.0.0.1
  port: 38024
replication:
  oplogSizeMB: 2048
  replSetName: sh2
sharding:
  clusterRole: shardsvr
processManagement:
  fork: true
EOF
\cp  /mongodb/38024/conf/mongodb.conf  /mongodb/38025/conf/
\cp  /mongodb/38024/conf/mongodb.conf  /mongodb/38026/conf/
sed ‘s#38024#38025#g‘ /mongodb/38025/conf/mongodb.conf -i
sed ‘s#38024#38026#g‘ /mongodb/38026/conf/mongodb.conf -i
3.启动所有节点,并搭建复制集
mongod -f  /mongodb/38021/conf/mongodb.conf
mongod -f  /mongodb/38022/conf/mongodb.conf
mongod -f  /mongodb/38023/conf/mongodb.conf
mongod -f  /mongodb/38024/conf/mongodb.conf
mongod -f  /mongodb/38025/conf/mongodb.conf
mongod -f  /mongodb/38026/conf/mongodb.conf 
ps -ef |grep mongod
mongo --port 38021
use  admin
config = {_id: ‘sh1‘, members: [
                          {_id: 0, host: ‘10.0.0.51:38021‘},
                          {_id: 1, host: ‘10.0.0.51:38022‘},
                          {_id: 2, host: ‘10.0.0.51:38023‘,"arbiterOnly":true}]
           }
rs.initiate(config)
 
 mongo --port 38024
 use admin
config = {_id: ‘sh2‘, members: [
                          {_id: 0, host: ‘10.0.0.51:38024‘},
                          {_id: 1, host: ‘10.0.0.51:38025‘},
                          {_id: 2, host: ‘10.0.0.51:38026‘,"arbiterOnly":true}]
           }
 
rs.initiate(config)
4. config节点配置
5. 目录创建
mkdir -p /mongodb/38018/conf  /mongodb/38018/log  /mongodb/38018/data
mkdir -p /mongodb/38019/conf  /mongodb/38019/log  /mongodb/38019/data
mkdir -p /mongodb/38020/conf  /mongodb/38020/log  /mongodb/38020/data
6.修改配置文件:
cat > /mongodb/38018/conf/mongodb.conf <<EOF
systemLog:
  destination: file
  path: /mongodb/38018/log/mongodb.conf
  logAppend: true
storage:
  journal:
    enabled: true
  dbPath: /mongodb/38018/data
  directoryPerDB: true
  #engine: wiredTiger
  wiredTiger:
    engineConfig:
      cacheSizeGB: 1
      directoryForIndexes: true
    collectionConfig:
      blockCompressor: zlib
    indexConfig:
      prefixCompression: true
net:
  bindIp: 10.0.0.51,127.0.0.1
  port: 38018
replication:
  oplogSizeMB: 2048
  replSetName: configReplSet
sharding:
  clusterRole: configsvr
processManagement:
  fork: true
EOF
\cp /mongodb/38018/conf/mongodb.conf /mongodb/38019/conf/
\cp /mongodb/38018/conf/mongodb.conf /mongodb/38020/conf/
sed ‘s#38018#38019#g‘ /mongodb/38019/conf/mongodb.conf -i
sed ‘s#38018#38020#g‘ /mongodb/38020/conf/mongodb.conf -i
7.启动节点,并配置复制集
mongod -f /mongodb/38018/conf/mongodb.conf
mongod -f /mongodb/38019/conf/mongodb.conf
mongod -f /mongodb/38020/conf/mongodb.conf
mongo --port 38018
use  admin
 config = {_id: ‘configReplSet‘, members: [
                          {_id: 0, host: ‘10.0.0.51:38018‘},
                          {_id: 1, host: ‘10.0.0.51:38019‘},
                          {_id: 2, host: ‘10.0.0.51:38020‘}]
           }
rs.initiate(config) 
 
注:configserver 可以是一个节点,官方建议复制集。configserver不能有arbiter。
新版本中,要求必须是复制集。
注:mongodb 3.4之后,虽然要求config server为replica set,但是不支持arbiter
 
8. mongos节点配置:
9.创建目录:
mkdir -p /mongodb/38017/conf  /mongodb/38017/log
10.配置文件:
cat > /mongodb/38017/conf/mongos.conf <<EOF
systemLog:
  destination: file
  path: /mongodb/38017/log/mongos.log
  logAppend: true
net:
  bindIp: 10.0.0.51,127.0.0.1
  port: 38017
sharding:
  configDB: configReplSet/10.0.0.51:38018,10.0.0.51:38019,10.0.0.51:38020
processManagement:
  fork: true
EOF
11.启动mongos
 mongos -f /mongodb/38017/conf/mongos.conf
12. 分片集群添加节点
 连接到其中一个mongos(10.0.0.51),做以下配置
(1)连接到mongs的admin数据库
# su - mongod
$ mongo 10.0.0.51:38017/admin
(2)添加分片
db.runCommand( { addshard : "sh1/10.0.0.51:38021,10.0.0.51:38022,10.0.0.51:38023",name:"shard1"} )
db.runCommand( { addshard : "sh2/10.0.0.51:38024,10.0.0.51:38025,10.0.0.51:38026",name:"shard2"} )
(3)列出分片
mongos> db.runCommand( { listshards : 1 } )
(4)整体状态查看
mongos> sh.status();
 
 
 

MongoDB -MSC集群的部署

标签:组复制   system   comm   rect   clust   mon   div   res   官方   

原文地址:https://www.cnblogs.com/wx1899325/p/12954800.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!