準備目錄
rm -rf /compile/cluster-restore/shd2*
mkdir -p /compile/cluster-restore/shd21/data/db
mkdir -p /compile/cluster-restore/shd21/log
mkdir -p /compile/cluster-restore/shd22/data/db
mkdir -p /compile/cluster-restore/shd22/log
mkdir -p /compile/cluster-restore/shd23/data/db
mkdir -p /compile/cluster-restore/shd23/log
操作步驟
步(bu)驟 1 準備單節(jie)點(dian)(dian)配置文件和目(mu)錄,以單節(jie)點(dian)(dian)方(fang)式啟動進程。
配置文件如下(restoreconfig/single_40309.yaml)。
net:
bindIp: 127.0.0.1
port: 40309
unixDomainSocket: {enabled: false}
processManagement: {fork: true, pidFilePath: /compile/cluster-restore/shd21/mongod.pid}
storage:
dbPath: /compile/cluster-restore/shd21/data/db/
directoryPerDB: true
engine: wiredTiger
wiredTiger:
collectionConfig: {blockCompressor: snappy}
engineConfig: {directoryForIndexes: true, journalCompressor: snappy}
indexConfig: {prefixCompression: true}
systemLog: {destination: file, logAppend: true, logRotate: reopen, path: /compile/cluster-restore/shd21/log/mongod.log}
準備數據,將解壓后的shardsvr2文件拷貝到單節點dbPath目錄下。
cp -aR
/compile/download/backups/cac1efc8e65e42ecad8953352321bfeein02_92b196d2401041a7af869a2a3cab7079no02/* /compile/cluster-restore/shd21/data/db/
啟動進程。
./mongod -f restoreconfig/single_40309.yaml
步驟(zou) 2 連接單節點,執行配置(zhi)命令。
連接命令:./mongo --host 127.0.0.1 --port 40309
執行如下命令,修改副本集配置信息。
var cf=db.getSiblingDB('local').system.replset.findOne();
cf['members'][0]['host']='127.0.0.1:40309';
cf['members'][1]['host']='127.0.0.1:40310';
cf['members'][2]['host']='127.0.0.1:40311';
cf['members'][0]['hidden']=false;
cf['members'][1]['hidden']=false;
cf['members'][2]['hidden']=false;
cf['members'][0]['priority']=1;
cf['members'][1]['priority']=1;
cf['members'][2]['priority']=1;
db.getSiblingDB('local').system.replset.remove({});
db.getSiblingDB('local').system.replset.insert(cf)
執行如下命令,清理內置賬號。
db.getSiblingDB('admin').dropAllUsers();
db.getSiblingDB('admin').dropAllRoles();
執行如下命令,更新configsvr信息。
var vs = db.getSiblingDB('admin').system.version.find();
while (vs.hasNext()) {
var curr = vs.next();
if (curr.hasOwnProperty('configsvrConnectionString')) {
db.getSiblingDB('admin').system.version.update({'_id' : curr._id}, {$set: {'configsvrConnectionString': 'config/127.0.0.1:40303,127.0.0.1:40304,127.0.0.1:40305'}});
}
}
執行如下命令,關閉單節點進程。
db.getSiblingDB('admin').shutdownServer();
步驟(zou) 3 搭建shardsvr2副本(ben)集。
準備副本集配置文件和目錄,將shardsvr2節點的dbPath文件拷貝到其他兩個節點目錄下。
cp -aR /compile/cluster-restore/shd21/data/db/ /compile/cluster-restore/shd22/data/db/
cp -aR /compile/cluster-restore/shd21/data/db/ /compile/cluster-restore/shd23/data/db/
修改shardsvr2-1節點配置文件,增加副本集配置屬性(restoreconfig/shardsvr_40309.yaml)。
--replication.replSetName 的(de)值(zhi),參考該(gai)章節中的(de)shard的(de)_id信(xin)息(xi)。
net:
bindIp: 127.0.0.1
port: 40309
unixDomainSocket: {enabled: false}
processManagement: {fork: true, pidFilePath: /compile/cluster-restore/shd21/mongod.pid}
replication: {replSetName: shard_2}
sharding: {archiveMovedChunks: false, clusterRole: shardsvr}
storage:
dbPath: /compile/cluster-restore/shd21/data/db/
directoryPerDB: true
engine: wiredTiger
wiredTiger:
collectionConfig: {blockCompressor: snappy}
engineConfig: {directoryForIndexes: true, journalCompressor: snappy}
indexConfig: {prefixCompression: true}
systemLog: {destination: file, logAppend: true, logRotate: reopen, path: /compile/cluster-restore/shd21/log/mongod.log}
啟動進程。
./mongod -f restoreconfig/shardsvr_40309.yaml
修改shardsvr2-2節點配置文件,增加副本集配置屬性(restoreconfig/shardsvr_40310.yaml)。
--replication.replSetName 的值,參考(kao)該章節中(zhong)的shard的_id信息。
net:
bindIp: 127.0.0.1
port: 40310
unixDomainSocket: {enabled: false}
processManagement: {fork: true, pidFilePath: /compile/cluster-restore/shd22/mongod.pid}
replication: {replSetName: shard_2}
sharding: {archiveMovedChunks: false, clusterRole: shardsvr}
storage:
dbPath: /compile/cluster-restore/shd22/data/db/
directoryPerDB: true
engine: wiredTiger
wiredTiger:
collectionConfig: {blockCompressor: snappy}
engineConfig: {directoryForIndexes: true, journalCompressor: snappy}
indexConfig: {prefixCompression: true}
systemLog: {destination: file, logAppend: true, logRotate: reopen, path: /compile/cluster-restore/shd22/log/mongod.log}
啟動進程。
./mongod -f restoreconfig/shardsvr_40310.yaml
修改shardsvr2-3節點(dian)配(pei)置文件,增(zeng)加副本集配(pei)置屬(shu)性(restoreconfig/shardsvr_40311.yaml)。
--replication.replSetName 的(de)值,參考該章節中的(de)shard的(de)_id信息(xi)。
net:
bindIp: 127.0.0.1
port: 40311
unixDomainSocket: {enabled: false}
processManagement: {fork: true, pidFilePath: /compile/cluster-restore/shd23/mongod.pid}
replication: {replSetName: shard_2}
sharding: {archiveMovedChunks: false, clusterRole: shardsvr}
storage:
dbPath: /compile/cluster-restore/shd23/data/db/
directoryPerDB: true
engine: wiredTiger
wiredTiger:
collectionConfig: {blockCompressor: snappy}
engineConfig: {directoryForIndexes: true, journalCompressor: snappy}
indexConfig: {prefixCompression: true}
systemLog: {destination: file, logAppend: true, logRotate: reopen, path: /compile/cluster-restore/shd23/log/mongod.log}
啟動進程。
./mongod -f restoreconfig/shardsvr_40311.yaml
步驟 4 等待(dai)選主成功。
./mongo --host 127.0.0.1 --port 40309
執行命(ming)令rs.status(),查看(kan)是否已存(cun)在主(zhu)節點Primary。