mongodb副本集自动切换修复节点解决方案

副本集部署
1.启动mongod
在每台运行mongod服务的机器上增加配置文件/etc/mongodb-rs.conf,内容为:
[root@MongodbF-A etc]# vi /etc/mongodb-rs.conf
port = 27017
dbpath = /data/db
logpath = /log/log.log
fork = true
replSet = test
通过下面命令启动mongod:
[root@MongodbF-A etc]# /App/mongo/bin/mongod -f /etc/mongodb-rs.conf
about to fork child process, waiting until server is ready for connections.
all output going to: /log/log.log
log file [/log/log.log] exists; copied to temporary file [/log/log.log.2013-07-18T10-00-56]
forked process: 8513
child process started successfully, parent exiting
[root@MongodbF-A etc]# 
[root@MongodbF-B App]# /App/mongo/bin/mongod -f /etc/mongodb-rs.conf 
about to fork child process, waiting until server is ready for connections.
all output going to: /log/log.log
log file [/log/log.log] exists; copied to temporary file [/log/log.log.2013-07-18T10-00-06]
forked process: 8314
child process started successfully, parent exiting
[root@MongodbF-B App]# 
[root@MongodbF-C App]#  /App/mongo/bin/mongod -f /etc/mongodb-rs.conf 
about to fork child process, waiting until server is ready for connections.
all output going to: /log/log.log
log file [/log/log.log] exists; copied to temporary file [/log/log.log.2013-07-18T10-06-38]
forked process: 8083
[Achild process started successfully, parent exiting
[root@MongodbF-C App]# 
2. 修改每个机器的/etc/hosts
[root@MongodbF-A etc]# vim /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               MongodbF-A localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6
192.168.155.224 mongodb1.example.net
192.168.155.225 mongodb2.example.net
192.168.155.226 mongodb3.example.net
~
2. 使用mongo shell连接mongod,进行配置:
[root@MongodbF-A etc]# /App/mongo/bin/mongo  192.168.155.224
MongoDB shell version: 2.4.5
connecting to: 192.168.155.224/test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
        http://groups.google.com/group/mongodb-user
> config = {_id:'test',members:[
... _id:0,host:'mongodb1.example.net'},
... _id:1,host:'mongodb2.example.net'},
Thu Jul 18 18:10:52.802 JavaScript execution failed: SyntaxError: Unexpected token :
> config = {_id:'test',members:[ _id:0,host:'mongodb1.example.net'}, _id:1,host:'mongodb2.example.net'},{_id:2,host:'mongodb3.example.net'}]}
Thu Jul 18 18:11:54.575 JavaScript execution failed: SyntaxError: Unexpected token :
> config_test={"_id":"test",members:[    --------------定义配置信息
... {_id:0,host:"mongodb1.example.net"},
... {_id:1,host:"mongodb2.example.net"},
... {_id:2,host:"mongodb3.example.net"}]
... }
{
        "_id" : "test",
        "members" : [
                {
                        "_id" : 0,
                        "host" : "mongodb1.example.net"
                },
                {
                        "_id" : 1,
                        "host" : "mongodb2.example.net"
                },
                {
                        "_id" : 2,
                        "host" : "mongodb3.example.net"
                }
        ]
}
>
> rs.initiate(config_test)    -----启动副本集


{
        "info" : "Config now saved locally.  Should come online in about a minute.",
        "ok" : 1
}
test:STARTUP2> 
test:STARTUP2> 
test:SECONDARY> 
test:SECONDARY> 
test:SECONDARY> 
test:SECONDARY> 
test:SECONDARY> 
test:SECONDARY> 
test:SECONDARY> 
test:SECONDARY> 
test:SECONDARY> 
test:SECONDARY> 
test:SECONDARY> 
test:SECONDARY> 
te
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值