我是网络新手的初学者,而且我刚开始使用虚拟机。 我来自" Ansible for Devops"在第3章中,我应该创建三个虚拟机并使用静态IP设置专用网络。
我的Vagrant文件看起来像这样:
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "geerlingguy/centos7"
config.ssh.insert_key = false
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.provider :virtualbox do |v|
v.memory = 256
v.linked_clone = true
end
config.vm.define "app1" do |app|
app.vm.hostname = "orc-app1.dev"
app.vm.network :private_network, ip: "192.168.60.4"
end
config.vm.define "app2" do |app|
app.vm.hostname = "orc-app2.dev"
app.vm.network :private_network, ip: "192.168.60.5"
end
config.vm.define "db" do |db|
db.vm.hostname = "orc-db.dev"
db.vm.network :private_network, ip: "192.168.60.6"
end
end
Vagrant loges:
❯ vagrant up
Bringing machine 'app1' up with 'virtualbox' provider...
Bringing machine 'app2' up with 'virtualbox' provider...
Bringing machine 'db' up with 'virtualbox' provider...
==> app1: Cloning VM...
==> app1: Matching MAC address for NAT networking...
==> app1: Checking if box 'geerlingguy/centos7' is up to date...
==> app1: Setting the name of the VM: 3_app1_1485309004899_30536
==> app1: Fixed port collision for 22 => 2222. Now on port 2202.
==> app1: Clearing any previously set network interfaces...
==> app1: Preparing network interfaces based on configuration...
app1: Adapter 1: nat
app1: Adapter 2: hostonly
==> app1: Forwarding ports...
app1: 22 (guest) => 2202 (host) (adapter 1)
==> app1: Running 'pre-boot' VM customizations...
==> app1: Booting VM...
==> app1: Waiting for machine to boot. This may take a few minutes...
app1: SSH address: 127.0.0.1:2202
app1: SSH username: vagrant
app1: SSH auth method: private key
app1: Warning: Remote connection disconnect. Retrying...
==> app1: Machine booted and ready!
==> app1: Checking for guest additions in VM...
==> app1: Setting hostname...
==> app1: Configuring and enabling network interfaces...
==> app2: Cloning VM...
==> app2: Matching MAC address for NAT networking...
==> app2: Checking if box 'geerlingguy/centos7' is up to date...
==> app2: Setting the name of the VM: 3_app2_1485309032690_32260
==> app2: Fixed port collision for 22 => 2222. Now on port 2203.
==> app2: Clearing any previously set network interfaces...
==> app2: Preparing network interfaces based on configuration...
app2: Adapter 1: nat
app2: Adapter 2: hostonly
==> app2: Forwarding ports...
app2: 22 (guest) => 2203 (host) (adapter 1)
==> app2: Running 'pre-boot' VM customizations...
==> app2: Booting VM...
==> app2: Waiting for machine to boot. This may take a few minutes...
app2: SSH address: 127.0.0.1:2203
app2: SSH username: vagrant
app2: SSH auth method: private key
app2: Warning: Remote connection disconnect. Retrying...
==> app2: Machine booted and ready!
==> app2: Checking for guest additions in VM...
==> app2: Setting hostname...
==> app2: Configuring and enabling network interfaces...
==> db: Cloning VM...
==> db: Matching MAC address for NAT networking...
==> db: Checking if box 'geerlingguy/centos7' is up to date...
==> db: Setting the name of the VM: 3_db_1485309060266_65663
==> db: Fixed port collision for 22 => 2222. Now on port 2204.
==> db: Clearing any previously set network interfaces...
==> db: Preparing network interfaces based on configuration...
db: Adapter 1: nat
db: Adapter 2: hostonly
==> db: Forwarding ports...
db: 22 (guest) => 2204 (host) (adapter 1)
==> db: Running 'pre-boot' VM customizations...
==> db: Booting VM...
==> db: Waiting for machine to boot. This may take a few minutes...
db: SSH address: 127.0.0.1:2204
db: SSH username: vagrant
db: SSH auth method: private key
db: Warning: Remote connection disconnect. Retrying...
==> db: Machine booted and ready!
==> db: Checking for guest additions in VM...
==> db: Setting hostname...
==> db: Configuring and enabling network interfaces...
和Vagrant SSH-config:
Host app1
HostName 127.0.0.1
User vagrant
Port 2202
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/mst/.vagrant.d/insecure_private_key
IdentitiesOnly yes
LogLevel FATAL
Host app2
HostName 127.0.0.1
User vagrant
Port 2203
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/mst/.vagrant.d/insecure_private_key
IdentitiesOnly yes
LogLevel FATAL
Host db
HostName 127.0.0.1
User vagrant
Port 2204
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/mst/.vagrant.d/insecure_private_key
IdentitiesOnly yes
LogLevel FATAL
因为您可以看到机器没有为我们设置的静态ips,我无法使用它连接到它们。他们只有一个本地主机IP和一些高端口。在那个例子中,我应该使用ansible在那些机器上工作,并在库存文件中使用静态ips,所以他们应该正确设置它。
有什么想法吗?
macOS Sierra 流浪汉1.9.1 VirtualBox 5.1.14
由于
编辑:机器使用的是CentOS,ip addr输出是:[root@orc-app1 vagrant]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:dd:23:fa brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic enp0s3
valid_lft 86067sec preferred_lft 86067sec
inet6 fe80::a00:27ff:fedd:23fa/64 scope link
valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 08:00:27:4d:38:fc brd ff:ff:ff:ff:ff:ff
答案 0 :(得分:0)
我根据示例进行了审核 - 由vagrant
正确创建了网络接口的文件[vagrant@orc-app2 ~]$ cd /etc/sysconfig/network-scripts
[vagrant@orc-app2 network-scripts]$ ll
total 236
-rw-r--r--. 1 root root 353 25 janv. 16:06 ifcfg-enp0s3
-rw-------. 1 vagrant vagrant 214 25 janv. 16:06 ifcfg-enp0s8
并且此新网络接口的内容正确
[vagrant@orc-app2 network-scripts]$ more ifcfg-enp0s8
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
NM_CONTROLLED=no
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.60.5
NETMASK=255.255.255.0
DEVICE=enp0s8
PEERDNS=no
#VAGRANT-END
所以我刚刚重启网络服务试试
[vagrant@orc-app2 network-scripts]$ sudo systemctl restart network
没关系
[vagrant@orc-app2 network-scripts]$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:dd:23:fa brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic enp0s3
valid_lft 86391sec preferred_lft 86391sec
inet6 fe80::a00:27ff:fedd:23fa/64 scope link
valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:42:83:e9 brd ff:ff:ff:ff:ff:ff
inet 192.168.60.5/24 brd 192.168.60.255 scope global enp0s8
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe42:83e9/64 scope link
valid_lft forever preferred_lft forever
我没有另外一个centos7盒子来测试(仍然可以很好地与6一起工作)以确认这个盒子或新的centos的问题
答案 1 :(得分:0)
尝试使用vagrant 1.9.0。我的同事有一个问题,即如果1.9.1,nfs共享将无法安装,并且它与该框没有自动添加一个必要的接口有关。
降级为1.9.0修复此问题。
在流浪者github上有几个未解决的问题,它们与rhel / centos 7有关。