企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# mongod2.6升级3.0及优化方案 先把大概步骤写出来,背景和细节后续补充 ## 升级副本集的步骤为: 1.master节点执行命令从集群中剔除需要升级的副本节点 ``` goumin:PRIMARY> rs.remove("192.168.56.202:27017") ``` 2.剔除后在副本机器上停止mongo服务 ``` /etc/init.d/mongodb stop ``` 3.修改配置文件,去掉集群的配置 ``` vim /usr/local/mongodb/conf/mongo.conf ``` 4.重新启动副本节点的mongo服务,验证升级条件是否允许 /etc/init.d/mongodb start ``` >use admin >db.upgradeCheckAllDBs() ``` 如果最后返回true就是满足升级的要求 5.检测通过后停止mongo服务使用 ``` /etc/init.d/mongodb stop killall mongod ``` 6.使用3.0的bin文件替换2.0的bin文件 ``` wget http://downloads.mongodb.org/linux/mongodb-linux-x86_64-v3.0-latest.tgz tar zxf mongodb-linux-x86_64-v3.0-latest.tgz \cp -a mongodb-linux-x86_64-3.0.15-19-gb4172b9/bin/* /usr/local/mongodb/bin/ ``` 6.重新启动Mongo查看是否正常 ``` /etc/init.d/mongodb start ``` 7.关闭mongo服务,修改配置文件新的引擎和新的数据目录 ``` /etc/init.d/mongodb stop mkdir /data/mongov3 chown -R mongodb:mongodb /data/mongov3/ ``` 修改配置文件引擎为wiredTiger并且将数据目录修改为新的目录 ``` [root@mongodb-202 ~]# cat /usr/local/mongodb/conf/mongo.conf ##3.0数据目录 dbpath = /data/mongov3 ##日志目录 logpath = /usr/local/mongodb/logs/mongodb.log ##守护模式 fork=true ##pid file pidfilepath=/var/run/mongod.pid ##socket bind_ip=0.0.0.0 ## no password noauth=true oplogSize = 2048 #副本参数 replSet = vim26/172.16.1.202 :27017 #使用wiredTiger引擎 storageEngine=wiredTiger ``` 8.重新启动副本的Mongo,并在主节点执行命令加入集群 ``` goumin:PRIMARY> rs.add("192.168.56.202:27017"); ``` 9.验证写入写入数据同步是否正常 主库操作写入测试数据 ``` goumin:PRIMARY> for(var i=0;i<10000;i++)db.d.insert({uid:i,uname:'osqlfan'+i}); WriteResult({ "nInserted" : 1 }) ``` 查看刚才写入的数据 ``` goumin:PRIMARY> db.d.find().count(); 10000 ``` 副本操作,查看是否有刚才同步的数据,如果有,则同步正常 ``` goumin:SECONDARY> db.d.find().count(); 10000 ``` 10.相同操作完成所有副本 ``` #主库操作 rs.remove("192.168.56.201:27017") #副本操作关闭数据库 /etc/init.d/mongodb stop #修改副本的配置文件,注释复制语句 sed -i 's@replSet@#replSet@' /usr/local/mongodb/conf/mongo.conf #启动mongo服务,验证升级条件是否允许 /etc/init.d/mongodb start >use admin >db.upgradeCheckAllDBs() #停止mongo服务,杀掉mongod进程 /etc/init.d/mongodb stop killall mongod #复制3.0的bin文件替换2.6 \cp -a mongodb-linux-x86_64-3.0.15-19-gb4172b9/bin/* /usr/local/mongodb/bin/ #恢复配置文件,添加引擎文件以及修改数据目录配置 [root@mongodb-201 ~]# egrep "wiredTiger|dbpath" /usr/local/mongodb/conf/mongo.conf dbpath = /data/mongov3 storageEngine=wiredTiger #创建新的数据目录 mkdir /data/mongov3 chown -R mongodb:mongodb /data/mongov3/ #重新启动mongo服务 /etc/init.d/mongodb start #重新加入集群 goumin:PRIMARY> rs.add("192.168.56.201:27017"); { "down" : [ "192.168.56.201:27017" ], "ok" : 1 } #写入数据检查是否正常 ``` 11.副本升级完成后将master进行降级 主库进行降级 ``` goumin:PRIMARY> rs.stepDown() ``` 集群新主库删除主库的节点 ``` rs.remove("192.168.56.201:27017") ``` 剩下的操作和从库一样 #参数调优 ## 升级3.0后提示的警告 ``` 2017-12-11T13:05:46.336+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2017-12-11T13:05:46.336+0800 I CONTROL [initandlisten] 2017-12-11T13:05:46.337+0800 I CONTROL [initandlisten] 2017-12-11T13:05:46.337+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2017-12-11T13:05:46.337+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2017-12-11T13:05:46.337+0800 I CONTROL [initandlisten] 2017-12-11T13:05:46.337+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 7976 processes, 65536 files. Number of processes should be at least 32768 : 0.5 times number of files. 2017-12-08T06:20:07.343+0800 [initandlisten] ** WARNING: You are running on a NUMA machine. 2017-12-08T06:20:07.343+0800 [initandlisten] ** We suggest launching mongod like this to avoid performance problems: 2017-12-08T06:20:07.343+0800 [initandlisten] ** numactl --interleave=all mongod [other options] ``` ## 针对警告进行优化 1.如果条件允许的话,建议重新格式化磁盘为xfs格式 ``` apt-get install xfsprogs mkfs.xfs /dev/sdb mount -t xfs /dev/sdb /data/ ``` 2.优化大内存页 ``` echo "never" > /sys/kernel/mm/transparent_hugepage/enabled echo "never" > /sys/kernel/mm/transparent_hugepage/defrag ``` 4.优化连接数 ``` vim /etc/profile ulimit -f unlimited ulimit -t unlimited ulimit -v unlimited ulimit -n 64000 ulimit -m unlimited ulimit -u 32000 ``` 5.关闭numa - 安装numactl ``` apt-get install numactl ``` - 执行下面2条命令 ``` echo > /proc/sys/vm/zone_reclaim_mode sysctl -w vm.zone_reclaim_mode=0 ``` - 修改启动命令,可以在启动脚本里更改 ``` numactl --interleave=all /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongo.conf ``` # mongo相关博客地址 非常全面的dba博客 http://blog.csdn.net/mchdba/article/category/1381536 mongodb2.6 replSet 升级到 mongodb3.0 http://blog.csdn.net/zhaowenzhong/article/details/50593363 官方对于numa的介绍和解决办法 https://docs.mongodb.com/manual/administration/production-notes/#production-numa 官方对于ulimit的介绍 https://docs.mongodb.com/manual/reference/ulimit/ 官方升级3.0的介绍 https://docs.mongodb.com/manual/release-notes/3.0-upgrade/ mongodb关于ulimit优化操作 http://www.cppblog.com/changshoumeng/archive/2015/04/13/210327.html