简体   繁体   中英

mongodb replicaset host name change error

I have a mongodb replicaset on ubuntu.. In replica set, hosts are defined as localhost. You can see ;

{
    "_id" : "myrep",
    "version" : 4,
    "members" : [
            {
                    "_id" : 0,
                    "host" : "localhost:27017"
            },
            {
                    "_id" : 2,
                    "host" : "localhost:27018"
            },
            {
                    "_id" : 1,
                    "host" : "localhost:27019",
                    "priority" : 0
            }
    ]

}

I want to change host adresses with real ip of server. But when i run rs.reconfig, I get error :

{
    "assertion" : "hosts cannot switch between localhost and hostname",
    "assertionCode" : 13645,
    "errmsg" : "db assertion failure",
    "ok" : 0

}

How can i solve it ? Thank you.

There is a cleaner way to do this:

use local
cfg = db.system.replset.findOne({_id:"replicaSetName"})
cfg.members[0].host="newHost:27017"
db.system.replset.update({_id:"replicaSetName"},cfg)

then restart mongo

我发现更改主机名的唯一方法是重新创建副本集。为了使其正确,需要清理db目录。然后启动所有具有复制模式的服务器,之后创建具有新主机名的新副本集修复它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM