我尝试使用ansible-mongodb-cluster脚本来创建mongodb群集。 我已经编辑过主机,只有主要和从属。 我使用molecule和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
库存安全文件:
[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
我如何解决并让每个VM"看到"网络中的其他人?
修改
ping进入超时并且telnet也是
EDIT2
这是traceroute
[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 ~]$
答案 0 :(得分: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其他虚拟机,他们会成功回复!