首页 / 数据库 / MySQL / MongoDB集群搭建步骤
搭建mongodb集群很多次,每次都会或多、或少出现一些见鬼的问题,写这篇文章供以后参考。本次是基于mongodb3.0进行集群的搭建;搭建步骤如下:1、设置操作系统的环境
echo "never">"/sys/kernel/mm/transparent_hugepage/enabled"
echo "never">"/sys/kernel/mm/transparent_hugepage/defrag"
ulimit -n 640002、配置文件的修改[mongod.conf]
shards配置:port=27018、directoryperdb=true 、bind_ip=0.0.0.0
config配置:port=27019、bind_ip=0.0.0.0
monogs配置:mongos --configdb 192.168.12.150:27019 --logpath /var/log/mongodb/mongos.log --pidfilepath /var/run/mongodb/mongos.pid --logappend --logRotate reopen --fo
hosts配置:{shardone.mongodb.local,shardtwo.mongodb.local,shardthree.mongodb.local}添加上每台分片服务器对应的IP地址的域名解析3、添加分片
>>mongo admin
>>db.runCommand({addshard:"shardone.mongodb.local:27018",name:"shardone"}) --添加分片
>>db.runCommand({addshard:"shardtwo.mongodb.local:27018",name:"shardtwo"})
>>db.runCommand({addshard:"shardthree.mongodb.local:27018",name:"shardthree"})分片服务器尽量以域名解析的方式,避免以后服务器的ip地址变更4、对数据库启动分片和添加片键
>>db.runCommand({"enablesharding":"mc_visit"})
>>db.runCommand({"shardcollection":"mc_visit.mc_visit","key":{"visitdate":-1,"virus":1}})5、没有数据情况下修改片键
>>use config
>>db.collections.find() --查看所有的片键
>>db.chunks.find() --查看已有分片的块MongoDB 3.0 正式版发布下载 http://www.linuxidc.com/Linux/2015-03/114414.htmCentOS编译安装MongoDB http://www.linuxidc.com/Linux/2012-02/53834.htmCentOS 编译安装 MongoDB与mongoDB的php扩展 http://www.linuxidc.com/Linux/2012-02/53833.htmCentOS 6 使用 yum 安装MongoDB及服务器端配置 http://www.linuxidc.com/Linux/2012-08/68196.htmUbuntu 13.04下安装MongoDB2.4.3 http://www.linuxidc.com/Linux/2013-05/84227.htmMongoDB入门必读(概念与实战并重) http://www.linuxidc.com/Linux/2013-07/87105.htmUbunu 14.04下MongoDB的安装指南 http://www.linuxidc.com/Linux/2014-08/105364.htm《MongoDB 权威指南》(MongoDB: The Definitive Guide)英文文字版[PDF] http://www.linuxidc.com/Linux/2012-07/66735.htmNagios监控MongoDB分片集群服务实战 http://www.linuxidc.com/Linux/2014-10/107826.htm基于CentOS 6.5操作系统搭建MongoDB服务 http://www.linuxidc.com/Linux/2014-11/108900.htmMongoDB 的详细介绍:请点这里
MongoDB 的下载地址:请点这里本文永久更新链接地址