分片集群-规划
10个实例:38017-38026 (1)configserver:38018-38020 3台构成的复制集(1主两从,不支持arbiter)38018-38020(复制集名字configsvr) (2)shard节点: sh1:38021-23 (1主两从,其中一个节点为arbiter,复制集名字sh1) sh2:38024-26 (1主两从,其中一个节点为arbiter,复制集名字sh2) (3):mongos: 38017Shard节点配置过程 目录创建:
mkdir -p /mongodb/38021/{conf,log,data} mkdir -p /mongodb/38022/{conf,log,data} mkdir -p /mongodb/38023/{conf,log,data} mkdir -p /mongodb/38024/{conf,log,data} mkdir -p /mongodb/38025/{conf,log,data} mkdir -p /mongodb/38026/{conf,log,data}修改配置文件: 第一组复制集搭建:21-23 (1主1从 1Ard)
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: 192.168.0.10,127.0.0.1 port: 38021 replication: oplogSizeMB: 2048 replSetName: sh1 sharding: clusterRole: shardsvr processManagement: fork: true security: authorization: enabled 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从 1Ard)
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: 192.168.0.10,127.0.0.1 port: 38024 replication: oplogSizeMB: 2048 replSetName: sh2 sharding: clusterRole: shardsvr processManagement: fork: true security: authorization: enabled 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启动所有节点,并搭建复制集
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: '192.168.0.10:38021'}, {_id: 1, host: '192.168.0.10:38022'}, {_id: 2, host: '192.168.0.10:38023',"arbiterOnly":true}] } rs.initiate(config) mongo --port 38024 use admin config = {_id: 'sh2', members: [ {_id: 0, host: '192.168.0.10:38024'}, {_id: 1, host: '192.168.0.10:38025'}, {_id: 2, host: '192.168.0.10:38026',"arbiterOnly":true}] } rs.initiate(config)config节点配置