MONGO集群搭建

来源:互联网 发布:淘宝模块怎么添加图片 编辑:程序博客网 时间:2024/04/27 03:47

一、系统环境

平台:Centos6.6_x86_64

实验环境:三台主机部署副本集模式集群

主机:10.218.145.18910.218.145.19010.218.145.191

规划:89master节点,90为副本节点,91为副本节点

二、软件安装

1.软件安装

软件包:mongodb-linux-x86_64-rhel62-3.0.6.tgz

下载地址:wget  https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.0.6.tgz

1
2
3
4
# tar  xf  mongodb-linux-x86_64-rhel62-3.0.6.tgz
#  mv mongodb-linux-x86_64-rhel62-3.0.6   /usr/local/mongodb3.0.6
# cd /usr/local/mongodb3.0.6
# mkdir {etc,logs}

2.创建配置文件


dbpath = /disk1/mongo27018/dataport = 31111pidfilepath = /usr/local/mongo27018/run/mongod.pidfork = truelogpath = /disk1/mongo27018/log/mongodb.log#unixSocketPrefix = /usr/local/mongo27018/runlogappend = truejournal = truereplSet = anav_push/10.218.145.189:31111,10.218.145.190:31111,10.218.145.191:31111#replSet = anav_push#keyFile = /usr/local/mongo27018/conf/keyfile27018.0#auth = truemaxConns = 2000oplogSize = 10240storageEngine = wiredTigerwiredTigerCacheSizeGB = 20wiredTigerStatisticsLogDelaySecs = 0wiredTigerJournalCompressor = snappywiredTigerDirectoryForIndexes = truewiredTigerCollectionBlockCompressor = snappywiredTigerIndexPrefixCompression = 1


3.启动服务

1
# /usr/local/mongodb3.0.6/bin/mongod -f /usr/local/mongodb3.0.6/etc/mongodb.conf

4.设置集群信息

use admin    db.runCommand({"replSetInitiate"  { "_id" : "anav_push" ,"members" :   [ {"_id" : 1, "host" : "10.218.145.189:31111"},  {"_id" : 2, "host" : "10.218.145.190:31111"},  {"_id" : 3, "host" : "10.218.145.191:31111"}]  }})



5.连接数据库,插入一条数据

1
2
# /usr/local/mongodb3.0.6/bin/mongo 192.168.115.21:27017
> db.test.insert({"a":1})

6.为数据库建立用户名密码
#建立用户名密码  http://www.cnblogs.com/zhoujinyi/p/4610050.htmluse admindb.createUser(      {        user: "pushmongodb",        pwd: "push",        roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]      }    )use gate2db.createUser(      {        user: "pushmongodb",        pwd: "push",        roles: [ { role: "readWrite", db: "gate2" } ]      }    )

文章参考:
 #mongo集群搭建
  http://www.cnblogs.com/zhoujinyi/p/3554010.html
  http://hnr520.blog.51cto.com/4484939/1698306
  http://fredjiang.github.io/2015/02/28/mongo-Replica-Set-%E7%AC%94%E8%AE%B0/

0 0
原创粉丝点击