Window 搭建mongodb 副本集
【摘要】 网上很多windows平台搭建副本集集群的帖子.今天将自己搭建的过程写下来:准备mongodb包文件:准备各个节点的config文件: Master节点: dbpath=G:\MongoDB-master\Server\3.4\data\db logpath=G:\MongoDB-master\Server\3.4\data\log\master.log ...
网上很多windows平台搭建副本集集群的帖子.
今天将自己搭建的过程写下来:
准备mongodb包文件:
准备各个节点的config文件:
Master节点: dbpath=G:\MongoDB-master\Server\3.4\data\db logpath=G:\MongoDB-master\Server\3.4\data\log\master.log port=27017 serviceDisplayName=MongoDB-master serviceName=MongoDB-master replSet=master auth=1 keyFile=G:\MongoDB-master\Server\3.4\data\key\mongokey slaver节点: dbpath=G:\MongoDB-slaver\Server\3.4\data\db logpath=G:\MongoDB-slaver\Server\3.4\data\log\slaver.log port=27018 serviceDisplayName=MongoDB-slaver serviceName=MongoDB-slaver replSet=master auth=1 keyFile=G:\MongoDB-master\Server\3.4\data\key\mongokey arbiter节点: dbpath=G:\MongoDB-arbiter\Server\3.4\data\db logpath=G:\MongoDB-arbiter\Server\3.4\data\log\arbiter.log port=27019 serviceDisplayName=MongoDB-arbiter serviceName=MongoDB-arbiter replSet=master auth=1 keyFile=G:\MongoDB-master\Server\3.4\data\key\mongokey
3. 安装mongodb服务:
mongod --auth --logpath "G:\MongoDB-master\Server\3.4\data\log\master.log" --port "27018" --dbpath "G:\MongoDB-master\Server\3.4\data\db" --serviceName "MongoDB-master" --serviceDisplayName "MongoDB-master" --replSet "master" --install mongod --auth --logpath "G:\MongoDB-slaver\Server\3.4\data\log\slaver.log" --port "27018" --dbpath "G:\MongoDB-slaver\Server\3.4\data\db" --serviceName "MongoDB-slaver" --serviceDisplayName "MongoDB-slaver" --replSet "master" --install mongod --auth --logpath "G:\MongoDB-arbiter\Server\3.4\data\log\arbiter.log" --port "27019" --dbpath "G:\MongoDB-arbiter\Server\3.4\data\db" --serviceName "MongoDB-arbiter" --serviceDisplayName "MongoDB-arbiter" --replSet "master" --install
4.创建副本集
conf= { "_id" : "master", "members" : [ { "_id" : 0, "host" : "10.105.20.75:27017" }, { "_id" : 1, "host" : "10.105.20.75:27018" }, { "_id" : 2, "host" : "10.105.20.75:27019" ,"arbiterOnly" : 1 } ] } rs.initiate(conf) rs.reconfig(conf,{force:true})
5. 创建副本集用户和普通用户:
db.createUser( { user: "admin", pwd: "admin", roles: [ "userAdminAnyDatabase","clusterAdmin","dbAdmin","dbAdminAnyDatabase","readWriteAnyDatabase" ] } ) use NGS db.createUser( { user: "ngs3", pwd: "ngs3", roles: [ "dbAdmin","readWrite" ] } )
5.mongodb连接:
<add key="MongoConnectionString" value="mongodb://ngs3:ngs3@10.105.20.75:27017,10.105.20.75:27018,10.105.20.75:27019/NGS?connect=replicaset&replicaset=master&authMechanism=SCRAM-SHA-1" /> <add key="ADMINMongoConnectionString" value="mongodb://admin:admin@10.105.20.75:27017,10.105.20.75:27018,10.105.20.75:27019/admin?connect=replicaset&replicaset=master&authMechanism=SCRAM-SHA-1" />
6.mongodb客户端工具,推荐robomongo:
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)