关于ubuntu:Vagrant MongoDB配置连接被拒绝

Vagrant MongoDB provision connection refused

我对Mongo供应有问题。

出于某种原因,当我第一次提供时,它会给我一个错误:

1
2
3
4
5
==> METEOR_Dev_Box_test: ADDING MONGO INITIATE
==> METEOR_Dev_Box_test: MongoDB shell version v3.4.2
==> METEOR_Dev_Box_test: connecting to: 127.0.0.1:27017
==> METEOR_Dev_Box_test: W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
==> METEOR_Dev_Box_test: E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :

但如果我这样做了,我会

然后运行:

1
mongo 127.0.0.1:27017 --eval"db=db.getSiblingDB('local');rs.initiate()"

它工作得很好。

这是我规定的相关部分:

1
2
3
4
5
6
7
8
sudo service mongod stop
sudo sed -i '/#replication:/a replication:
 \ \ replSetName: rs0' /etc/mongod.conf
sudo sed -i '/#replication:/d' /etc/mongod.conf

sudo service mongod restart

mongo 127.0.0.1:27017 --eval"db=db.getSiblingDB('local');rs.initiate()"

Vagrantfile:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# -*- mode: ruby -*-
# vi: set ft=ruby :

require 'yaml'
settings = YAML.load_file('./vagrant_setup.yml')

VAGRANTFILE_API_VERSION = '2'

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    settings.each do |settings|
        config.vm.define settings['name'] do |machine|
            machine.vm.box = settings['box']
            machine.vm.network"private_network", ip: settings['ip']
            machine.vm.hostname = settings['hostname']
            machine.vm.provision :shell, path: './vagrant_bootstrap.sh'
            machine.vm.provision :shell, path: './vagrant_meteor.sh', privileged: false
            machine.vm.network 'forwarded_port', guest: settings['port_1'], host: settings['port_1']
            machine.vm.network 'forwarded_port', guest: settings['port_2'], host: settings['port_2']
            machine.vm.network 'forwarded_port', guest: settings['port_3'], host: settings['port_3']
            machine.vm.provider :virtualbox do |vb|
                vb.name = settings['name']
                vb.memory = settings['memory']
                vb.cpus = settings['cpus']
                vb.customize ["modifyvm", :id,"--usb","on"]
                vb.customize ["usbfilter","add","0","--target", :id,"--name","android","--vendorid","0x18d1"]
                vb.customize ["usbfilter","add","0","--target", :id,"--name","androidSamsung","--vendorid","0x04e8"]
                vb.customize ["usbfilter","add","0","--target", :id,"--name","androidLG","--vendorid","0x1004"]
            end
        end
    end
end

他认为,在提供服务时,127.0.0.1是不可访问的。

提前谢谢。:)


亨利@弗里德里克的谢谢你。你是是的先生!它需要sometime为mongodb到全initialise。 P / < >

我用的sleep 5s到等待直到它会继续。 P / < >

我该怎么暂停我的壳脚本之前,第二次为1 continuing吗? P / < >

所以我的代码,现在看起来像这样: P / < >

1
2
3
4
5
6
7
8
9
10
sudo service mongod stop
sudo sed -i '/#replication:/a replication:
 \ \ replSetName: rs0' /etc/mongod.conf
sudo sed -i '/#replication:/d' /etc/mongod.conf

sudo service mongod start

sleep 5s

mongo 127.0.0.1:27017 --eval"db=db.getSiblingDB('local');rs.initiate()"

和工程flawlessly………………在这2天>。< P / < >