<span style=”font-family: 宋体; mso-ascii-font-family: Cambria; mso-ascii-theme-font: <br />
major-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: major-fareast; <br />
mso-hansi-font-family: Cambria; mso-hansi-theme-font: major-latin;”>
####
1.升级过程中不允许有以下操作
<span class="pln">sh</span><span class="pun">.</span><span class="pln">enableSharding</span><span class="pun">()</span>
sh.shardCollection()
sh.addShard()
<span class="pln">db</span><span class="pun">.</span><span class="pln">createCollection</span><span class="pun">()</span>
<span class="pln">db</span><span class="pun">.</span><span class="pln">collection</span><span class="pun">.</span><span class="pln">drop</span><span class="pun">()</span>
<span class="pln">db</span><span class="pun">.</span><span class="pln">dropDatabase</span><span class="pun">()</span>
<span class="pln">any operation that creates a database</span>
<span class="pln">any other operation that modifies the cluster metadata in any way</span><span class="pun">.</span><span class="typ">See</span><span class="typ">Sharding</span><span class="typ">Reference</span><span class="kwd">for</span><span class="pln"> a complete list of sharding commands</span><span class="pun">.</span><span class="typ">Note</span><span class="pun">,</span><span class="pln"> however</span><span class="pun">,</span><span class="pln"> that not all commands on the </span><span class="typ">Sharding</span><span class="typ">Reference</span><span class="pln"> page modifies the cluster meta</span><span class="pun">-</span><span class="pln">data</span><span class="pun">.</span>
2,有升级后无法降级
<span style=”font-family: 宋体; mso-ascii-font-family: Cambria; mso-ascii-theme-font: <br />
major-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: major-fareast; <br />
mso-hansi-font-family: Cambria; mso-hansi-theme-font: major-latin;”>
1. 安装,解压到/home/Mongo下,关于Mongo集群环境的搭建详见《【Mongodb】MongoDB分片备份策略与配置迁移示例》
2. 建脚本库存放于文件夹script中,脚本库中权限与内容如下
1.
<span class="pun">-</span><span class="pln">rwxrwxrwx </span><span class="lit">1</span><span class="typ">Mongo</span><span class="typ">Mongodb</span><span class="lit">179</span><span class="typ">Mar</span><span class="lit">22</span><span class="lit">09</span><span class="pun">:</span><span class="lit">05</span><span class="pln"> startconfig</span><span class="pun">.</span><span class="pln">sh</span>
2.3.
<span class="pun">-</span><span class="pln">rwxrwxrwx </span><span class="lit">1</span><span class="typ">Mongo</span><span class="typ">Mongodb</span><span class="lit">191</span><span class="typ">Mar</span><span class="lit">22</span><span class="lit">09</span><span class="pun">:</span><span class="lit">05</span><span class="pln"> startmongos</span><span class="pun">.</span><span class="pln">sh</span>
4.5.
<span class="pun">-</span><span class="pln">rwxrwxrwx </span><span class="lit">1</span><span class="typ">Mongo</span><span class="typ">Mongodb</span><span class="lit">169</span><span class="typ">Mar</span><span class="lit">22</span><span class="lit">09</span><span class="pun">:</span><span class="lit">05</span><span class="pln"> startshard1</span><span class="pun">.</span><span class="pln">sh</span>
6.7.
<span class="pun">-</span><span class="pln">rwxrwxrwx </span><span class="lit">1</span><span class="typ">Mongo</span><span class="typ">Mongodb</span><span class="lit">169</span><span class="typ">Mar</span><span class="lit">22</span><span class="lit">09</span><span class="pun">:</span><span class="lit">05</span><span class="pln"> startshard2</span><span class="pun">.</span><span class="pln">sh</span>
8.9.
<span class="pun">-</span><span class="pln">rwxrwxrwx </span><span class="lit">1</span><span class="typ">Mongo</span><span class="typ">Mongodb</span><span class="lit">169</span><span class="typ">Mar</span><span class="lit">22</span><span class="lit">09</span><span class="pun">:</span><span class="lit">05</span><span class="pln"> startshard3</span><span class="pun">.</span><span class="pln">sh</span>
文件中的内容(此处可以选择配置环境变量)
1.
**<span class="pln">startconfig</span><span class="pun">.</span><span class="pln">sh</span>**
2.3.
<span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="typ">Mongo</span><span class="pun">/</span><span class="pln">mongodb</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">-</span><span class="pln">x86_64</span><span class="pun">-</span><span class="lit">3.0</span><span class="pun">.</span><span class="lit">1</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">mongod </span><span class="pun">-</span><span class="pln">configsvr </span><span class="pun">-</span><span class="pln">port </span><span class="lit">20000</span><span class="pun">-</span><span class="pln">fork </span><span class="pun">-</span><span class="pln">dbpath </span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="typ">Mongo</span><span class="pun">/</span><span class="pln">mongodb</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">-</span><span class="pln">x86_64</span><span class="pun">-</span><span class="lit">3.0</span><span class="pun">.</span><span class="lit">1</span><span class="pun">/</span><span class="pln">config </span><span class="pun">-</span><span class="pln">logpath </span><span class="pun">/</span><span class="pln">data1</span><span class="pun">/</span><span class="pln">data</span><span class="pun">/</span><span class="pln">dblog</span><span class="pun">/</span><span class="pln">config</span><span class="pun">/</span><span class="pln">config</span><span class="pun">.</span><span class="pln">log </span><span class="pun">--</span><span class="pln">upgrade</span>
4.5.
**<span class="pln">startmongos</span><span class="pun">.</span><span class="pln">sh</span>**
6.7.
<span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="typ">Mongo</span><span class="pun">/</span><span class="pln">mongodb</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">-</span><span class="pln">x86_64</span><span class="pun">-</span><span class="lit">3.0</span><span class="pun">.</span><span class="lit">1</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">mongos </span><span class="pun">-</span><span class="pln">fork </span><span class="pun">-</span><span class="pln">port </span><span class="lit">30000</span><span class="pun">-</span><span class="pln">configdb </span><span class="str">"192.168.199.133:20000,192.168.199.134:20000,192.168.199.135:20000"</span><span class="pun">-</span><span class="pln">logpath </span><span class="pun">/</span><span class="pln">data1</span><span class="pun">/</span><span class="pln">data</span><span class="pun">/</span><span class="pln">dblog</span><span class="pun">/</span><span class="pln">mongos</span><span class="pun">/</span><span class="pln">mongos</span><span class="pun">.</span><span class="pln">log</span>
8.9.
**<span class="pln">startshard1</span><span class="pun">.</span><span class="pln">sh</span>**
10.11.
<span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="typ">Mongo</span><span class="pun">/</span><span class="pln">mongodb</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">-</span><span class="pln">x86_64</span><span class="pun">-</span><span class="lit">3.0</span><span class="pun">.</span><span class="lit">1</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">mongod </span><span class="pun">-</span><span class="pln">fork </span><span class="pun">-</span><span class="pln">shardsvr </span><span class="pun">-</span><span class="pln">replSet shard1 </span><span class="pun">-</span><span class="pln">port </span><span class="lit">10001</span><span class="pun">-</span><span class="pln">dbpath </span><span class="pun">/</span><span class="pln">data1</span><span class="pun">/</span><span class="pln">data</span><span class="pun">/</span><span class="pln">db</span><span class="pun">/</span><span class="pln">shard1 </span><span class="pun">-</span><span class="pln">logpath </span><span class="pun">/</span><span class="pln">data1</span><span class="pun">/</span><span class="pln">data</span><span class="pun">/</span><span class="pln">dblog</span><span class="pun">/</span><span class="pln">shard1</span><span class="pun">/</span><span class="pln">shard1</span><span class="pun">.</span><span class="pln">log</span>
12.13.
**<span class="pln">startshard2</span><span class="pun">.</span><span class="pln">sh</span>**
14.15.
<span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="typ">Mongo</span><span class="pun">/</span><span class="pln">mongodb</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">-</span><span class="pln">x86_64</span><span class="pun">-</span><span class="lit">3.0</span><span class="pun">.</span><span class="lit">1</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">mongod </span><span class="pun">-</span><span class="pln">fork </span><span class="pun">-</span><span class="pln">shardsvr </span><span class="pun">-</span><span class="pln">replSet shard2 </span><span class="pun">-</span><span class="pln">port </span><span class="lit">10002</span><span class="pun">-</span><span class="pln">dbpath </span><span class="pun">/</span><span class="pln">data1</span><span class="pun">/</span><span class="pln">data</span><span class="pun">/</span><span class="pln">db</span><span class="pun">/</span><span class="pln">shard2 </span><span class="pun">-</span><span class="pln">logpath </span><span class="pun">/</span><span class="pln">data</span><span class="pun">/</span><span class="pln">data</span><span class="pun">/</span><span class="pln">dblog</span><span class="pun">/</span><span class="pln">shard2</span><span class="pun">/</span><span class="pln">shard2</span><span class="pun">.</span><span class="pln">log</span>
16.17.
**<span class="pln">startshard3</span><span class="pun">.</span><span class="pln">sh</span>**
18.19.
<span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="typ">Mongo</span><span class="pun">/</span><span class="pln">mongodb</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">-</span><span class="pln">x86_64</span><span class="pun">-</span><span class="lit">3.0</span><span class="pun">.</span><span class="lit">1</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">mongod </span><span class="pun">-</span><span class="pln">fork </span><span class="pun">-</span><span class="pln">shardsvr </span><span class="pun">-</span><span class="pln">replSet shard3 </span><span class="pun">-</span><span class="pln">port </span><span class="lit">10003</span><span class="pun">-</span><span class="pln">dbpath </span><span class="pun">/</span><span class="pln">data1</span><span class="pun">/</span><span class="pln">data</span><span class="pun">/</span><span class="pln">db</span><span class="pun">/</span><span class="pln">shard3 </span><span class="pun">-</span><span class="pln">logpath </span><span class="pun">/</span><span class="pln">data1</span><span class="pun">/</span><span class="pln">data</span><span class="pun">/</span><span class="pln">dblog</span><span class="pun">/</span><span class="pln">shard3</span><span class="pun">/</span><span class="pln">shard3</span><span class="pun">.</span><span class="pln">log</span>
3.停止均衡器(Disable the Balancer).
连接到mongos,执行脚本
1.
<span class="pun">./</span><span class="pln"> mongos </span><span class="pun">-</span><span class="pln">port </span><span class="lit">30000</span><span class="com">//30000为路由器端口</span>
2.3.
<span class="pln">sh</span><span class="pun">.</span><span class="pln">stopBalancer</span><span class="pun">()</span>
检查是否已经完全停止
1.
<span class="pln">use config</span>
2.3.
<span class="kwd">while</span><span class="pun">(</span><span class="pln"> sh</span><span class="pun">.</span><span class="pln">isBalancerRunning</span><span class="pun">()</span><span class="pun">)</span><span class="pun">{</span>
4.
<span class="pln"> print</span><span class="pun">(</span><span class="str">"waiting..."</span><span class="pun">);</span>
5.
<span class="pln"> sleep</span><span class="pun">(</span><span class="lit">1000</span><span class="pun">);</span>
6.
<span class="pun">}</span>
4.升级分片元数据(配置服务器)
进入mongod节点,运行升级脚本
1.
<span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="typ">Mongo</span><span class="pun">/</span><span class="pln">mongodb</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">-</span><span class="pln">x86_64</span><span class="pun">-</span><span class="lit">3.0</span><span class="pun">.</span><span class="lit">1</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">mongos </span><span class="pun">-</span><span class="pln">configdb </span><span class="str">"192.168.199.133:20000,192.168.199.134:20000,192.168.199.135:20000"</span><span class="pun">-</span><span class="pln">logpath </span><span class="pun">/</span><span class="pln">data1</span><span class="pun">/</span><span class="pln">data</span><span class="pun">/</span><span class="pln">dblog</span><span class="pun">/</span><span class="pln">mongos</span><span class="pun">/</span><span class="pln">updatemongos</span><span class="pun">.</span><span class="pln">log </span><span class="pun">—</span><span class="pln">upgrade</span>
查看updatemongos中日志信息,如果输出以下语句,则表示配置服务器升级成功
upgrade of config
server to v5 successful
Config database is at
version v5
依次停止旧的配置服务器启动新的配置服务器,备注:升级过程中保至少一台配置服务器正常运转
5.升级分片服务(主从节点升级)
停止10001的备份服务,启动新服务
停止10001的仲裁服务,启动新服务
切换10001的主节点到备份服务
连接至主节点 使用切换命令
1.
<span class="pln">rs</span><span class="pun">.</span><span class="pln">stepDown</span><span class="pun">()</span>
1.
<span class="pln">rs</span><span class="pun">.</span><span class="pln">status</span><span class="pun">()</span>
依次处理10002节点与10003节点
WARNING:Do not upgrade mongod instances until after you have upgraded all
mongos instances.
6.重启主服务,启动Balancer
关闭原来的服务,使用新的脚本启动
下面的脚本启动Balancer
1.
<span class="pln">sh</span><span class="pun">.</span><span class="pln">setBalancerState</span><span class="pun">(</span><span class="kwd">true</span><span class="pun">)</span>
查看版本信息
1.
<span class="pln">db</span><span class="pun">.</span><span class="pln">runCommand</span><span class="pun">({</span><span class="str">"buildInfo"</span><span class="pun">:</span><span class="lit">1</span><span class="pun">})</span>