1

我正在尝试使用ansible-mongodb-cluster脚本来创建一个 mongodb 集群。我已经编辑了主机,以便只有一个主服务器和一个从服务器。我用vagrant分子来测试它。

这是我的分子.yml

ansible:
  playbook: 01_create_cluster.yml
  verbose: vvv
inventory: hosts
vagrant:
  platforms:
    - name: centos
      box: centos/7
  providers:
    - name: virtualbox
      type: virtualbox
      options:
        memory: 512
        cpus: 2
  instances:
    - name: mongo1
      ansible_groups:
        - mongo_servers
        - mongod_primary
        - mongod_slaves
      interfaces:
        - network_name: private_network
          type: static
          ip: 192.168.80.1
    - name: mongo2
      ansible_groups:
        - mongo_servers
        - mongod_primary
        - mongod_slaves
      interfaces:
        - network_name: private_network
          type: static
          ip: 192.168.80.2

这是hosts库存 ansible 文件:

[mongo_servers]
mongo1 mongod_port=27017
mongo2 mongod_port=27017

[mongod_primary]
mongo1 mongod_port=27017

[mongod_slaves]
mongo2 mongod_port=27017

当创建主节点并在其上激活复制后,从尝试连接到主节点时,问题就出现了:

"MongoDB shell version v3.4.4", 
        "connecting to: mongodb://mongo1:27017/", 
        "2017-05-25T15:38:51.399+0000 I NETWORK  [thread1] getaddrinfo(\"mongo1\") failed: Name or service not known", 
        "2017-05-25T15:38:51.400+0000 E QUERY    [thread1] Error: couldn't initialize connection to host mongo1, address is invalid :", 
        "connect@src/mongo/shell/mongo.js:237:13", 
        "@(connect):1:6"

它不知道mongo1主机。

即使我加入/etc/hosts关系

192.168.80.1 mongo1

它告诉我Destination Net Unreachable

我如何解决并让每个虚拟机“看到”网络中的其他虚拟机?

编辑

ping 超时,telnet 也一样

编辑2

这是跟踪路由

[vagrant@mongo2 ~]$ traceroute mongo1
traceroute to mongo1 (192.168.80.1), 30 hops max, 60 byte packets
 1  gateway (10.0.2.2)  0.191 ms  0.111 ms  0.063 ms
 2  192.168.93.254 (192.168.93.254)  0.614 ms  0.716 ms  0.710 ms
 3  10.17.254.1 (10.17.254.1)  3.410 ms  3.366 ms  3.316 ms
 4  93-57-16-193.ip162.fastwebnet.it (93.57.16.193)  5.409 ms  5.384 ms  5.340 ms
 5  93-54-33-65.ip127.fastwebnet.it (93.54.33.65)  21.192 ms  21.135 ms  21.084 ms
 6  10.2.7.101 (10.2.7.101)  10.390 ms  2.447 ms  2.318 ms
 7  10.254.20.77 (10.254.20.77)  2.228 ms 10.254.20.73 (10.254.20.73)  2.171 ms  2.045 ms
 8  * * *
 9  * * *
10  * * *
11  * * *
12  * * *
13  * * *
14  * * *
15  * * *
16  * * *
17  * * *
18  * * *
19  * * *
20  * * *
21  * * *
22  * * *
23  * * *
24  * * *
25  * * *
26  * * *
27  * * *
28  * * *
29  * * *
30  * * *
[vagrant@mongo2 ~]$ 
4

1 回答 1

0

我解决了向molecule.yml添加另外两个配置的问题:

interfaces:
        - network_name: private_network
          type: static
          ip: 192.168.80.1
          auto_config: true
      options:
        append_platform_to_hostname: no


auto_config: true

options:
            append_platform_to_hostname: no

现在,如果我 ping 其他 vm,他们回复成功!

于 2017-05-26T09:30:12.233 回答