gpt4 book ai didi

vagrant - Centos7 私网丢失固定IP

转载 作者:行者123 更新时间:2023-12-04 13:06:56 25 4
gpt4 key购买 nike

我有一个 centos7 vagrant box 的网络问题。
当我设置一个具有固定 IP 的专用网络时,这个网络首先绑定(bind)得很好,但在几秒钟/几分钟后就会丢失。

 vagrant up
==> default: Forcing shutdown of VM...
==> default: Destroying VM and associated drives...
==> default: Running cleanup tasks for 'shell' provisioner...
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'sfeirbenelux/centos7'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'sfeirbenelux/centos7' is up to date...
==> default: Setting the name of the VM: poc_docker
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 22 => 2200 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2200
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if its present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: The guest additions on this VM do not match the installed version of
default: VirtualBox! In most cases this is fine, but in rare cases it can
default: prevent things such as shared folders from working properly. If you see
default: shared folder errors, please make sure the guest additions within the
default: virtual machine match the version of VirtualBox you have installed on
default: your host and reload your VM.
default:
default: Guest Additions Version: 5.0.2
default: VirtualBox Version: 4.3
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Running provisioner: shell...
default: Running: inline script
==> default: net.ipv4.ip_forward = 1
==> default: Setting up swapspace version 1, size = 2097148 KiB
==> default: no label, UUID=170723d8-1782-4915-a877-4d9874ac7396
➜ install git:(master) ✗ ping 192.168.100.20
PING 192.168.100.20 (192.168.100.20): 56 data bytes
64 bytes from 192.168.100.20: icmp_seq=0 ttl=64 time=0.390 ms
64 bytes from 192.168.100.20: icmp_seq=1 ttl=64 time=0.252 ms
64 bytes from 192.168.100.20: icmp_seq=2 ttl=64 time=0.461 ms
^C
--- 192.168.100.20 ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.252/0.368/0.461/0.087 ms
➜ install git:(master) ✗ ping 192.168.100.20
PING 192.168.100.20 (192.168.100.20): 56 data bytes
64 bytes from 192.168.100.20: icmp_seq=0 ttl=64 time=0.273 ms
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
Request timeout for icmp_seq 4

有了这个 Vagrant 文件:
vagrant.configure(2) do |config|

config.vm.box = "centos7"
config.vm.hostname = "docker-registry"
config.vm.box_url = "https://github.com/holms/vagrant-centos7-box/releases/download/7.1.1503.001/CentOS-7.1.1503-x86_64-netboot.box"

#config.vm.network "public_network"
config.vm.network "private_network", ip: "192.168.100.20"
#config.vm.synced_folder ".", "/vagrant", type: "nfs"

# VirtualBox
config.vm.provider :virtualbox do |vb|
vb.name = "poc_docker"
vb.memory = 3072
vb.cpus = 2
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end


end

当我在盒子上连接时,似乎ip丢失了。
sudo /sbin/ifup eth1

暂时解决问题,但有时IP又会丢失。
重新启动盒子(vagrant halt && vagrant up)似乎可以永久解决问题。
我尝试使用 Packer ( https://atlas.hashicorp.com/sfeirbenelux/boxes/centos7 ) 创建一个自定义的 centos 7 盒子,我也重现了这个问题。

我想这是 Centos 7 的特定问题?
你已经有同样的问题了吗?有没有办法通过添加 vagrant 命令来解决这个问题?

我的环境:

OS X 优胜美地
➜ ~ vagrant --version
Vagrant 1.7.2
➜ ~ VBoxManage --version
4.3.26r98988

最佳答案

在较新的 Vagrant 版本(1.9.1)中似乎存在类似的问题。

修复问题的拉取请求已经合并(尚未发布):

https://github.com/mitchellh/vagrant/pull/8148

如果你想应用该修复,你可以试试这个( sudo 可能需要,取决于文件权限):

  • 找到本地 Vagrant 安装(在 Fedora 上是 /opt/vagrant/ )
  • 移动到 vagrant gem 的文件夹:
    cd embedded/gems/gems/vagrant-1.9.1
  • 初始化一个新的 Git 存储库并添加 GitHub 远程:
    git init
    git remote add origin https://github.com/mitchellh/vagrant.git
    git fetch --all
  • checkout 一个新分支并将其重置为您当前的版本(例如 1.9.1)。

    如果您不确定是否有本地更改,请执行 不是 使用 --hard做一个git diff/git checkout重置后:
    git checkout -b hotfixes
    git reset --hard v1.9.1
  • 现在应用修补程序:
    git cherry-pick 96611341a96d7d19fdade5556a110b22c6add22b

  • 之后是 vagrant reload应该可以很好地启动本地网络。

    关于vagrant - Centos7 私网丢失固定IP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32518591/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com