mgo连接备节点做查询

mgo直接连接主节点是可以的,但是改换备节点提示panic: no reachable servers,这个需要设置什么还是?

session, err := mgo.Dial("10.128.0.23:27017")
if err != nil {
    panic(err)   //进入这里
}

共 2 个回复


jimmykuu

试试用其他客户端能否连上。

# 0

qianlnk

直接在主节点用mongo 10.128.0.23:27017是可以的呀,另外,貌似本机上用内网ip也是连不上的,只能用外网ip。这个是不是设置有问题导致的?

    yiqice:PRIMARY> ^C
bye
root@198-72:/opt/mongodb/bin# ./mongo 10.128.0.23:27017
MongoDB shell version: 3.0.1
connecting to: 10.128.0.23:27017/test
Server has startup warnings: 
2015-04-14T14:34:38.379+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2015-04-14T14:34:38.379+0800 I CONTROL  [initandlisten] 
2015-04-14T14:34:38.423+0800 I CONTROL  [initandlisten] 
2015-04-14T14:34:38.423+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2015-04-14T14:34:38.423+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2015-04-14T14:34:38.423+0800 I CONTROL  [initandlisten] 
2015-04-14T14:34:38.423+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2015-04-14T14:34:38.423+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2015-04-14T14:34:38.423+0800 I CONTROL  [initandlisten] 
yiqice:SECONDARY>
# 1