🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## Vagrant 常见问题解答 ### 常见命令 ### 常见问题 #### 1.如果Vagrant有很多box,如何切换不同的box 因为每个box的安装路径都是不一样的,所以每次通过`vagrant up`命令去启动时,只要切换到指定box的目录下执行命令`vagrant up`就可以了。 #### 2.vagrant如何同时启动使用多个box(待解决) ```shell $ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Clearing any previously set forwarded ports... Vagrant cannot forward the specified ports on this VM, since they would collide with some other application that is already listening on these ports. The forwarded port to 80 is already in use on the host machine. To fix this, modify your current project's Vagrantfile to use another port. Example, where '1234' would be replaced by a unique host port: config.vm.network :forwarded_port, guest: 80, host: 1234 Sometimes, Vagrant will attempt to auto-correct this for you. In this case, Vagrant was unable to. This is usually because the guest machine is in a state which doesn't allow modifying port forwarding. You could try 'vagrant reload' (equivalent of running a halt followed by an up) so vagrant can attempt to auto-correct this upon booting. Be warned that any unsaved work might be lost. ``` #### 3.简单了解Vagrant的网络三模式 > 1、较为常用是端口映射,就是将虚拟机中的端口映射到宿主机对应的端口直接使用 ,在Vagrantfile中配置:(目前在用) > > ``` > config.vm.network :forwarded_port, guest: 80, host: 8080 > 【guest: 80 表示虚拟机中的80端口, host: 8080 表示映射到宿主机的8080端口。】 > ``` > > 2、如果需要自己自由的访问虚拟机,但是别人不需要访问虚拟机,可以使用private_network,并为虚拟机设置IP ,在Vagrantfile中配置: > > ``` > config.vm.network :private_network, ip: "192.168.1.104" > 【192.168.1.104 表示虚拟机的IP,多台虚拟机的话需要互相访问的话,设置在相同网段即可】 > ``` > > 3、如果需要将虚拟机作为当前局域网中的一台计算机,由局域网进行DHCP,那么在Vagrantfile中配置: > > ``` > config.vm.network :public_network > ``` #### 4.vagrant官网是什么 https://www.vagrantup.com/ #### 5.如何给虚拟机指定私有的固定IP > 参考文章:https://blog.csdn.net/stones_liu/article/details/86764892 ```php //1.打开vagrant配置文件,修改下面配置: config.vm.network "private_network", ip: "192.168.33.10" //2.重新启动vagrant $ vagrant reload //3.在虚拟机下输入命令查询ip,下面enp0s8就是我们刚刚修改的固定IP $ ifconfig enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255 inet6 fe80::a00:27ff:fede:e0e prefixlen 64 scopeid 0x20<link> ether 08:00:27:de:0e:0e txqueuelen 1000 (Ethernet) RX packets 476 bytes 48920 (47.7 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 330 bytes 42988 (41.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.33.10 netmask 255.255.255.0 broadcast 192.168.33.255 inet6 fe80::a00:27ff:fee1:8c65 prefixlen 64 scopeid 0x20<link> ether 08:00:27:e1:8c:65 txqueuelen 1000 (Ethernet) RX packets 13 bytes 2041 (1.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 22 bytes 3042 (2.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 0 (Lokale Schleife) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 //4.同时打开配置文件看一下 $ cd /etc/sysconfig/network-scripts/ $ cat 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.33.10 NETMASK=255.255.255.0 DEVICE=enp0s8 PEERDNS=no #VAGRANT-END ``` #### 6.vagrant中文文档翻译 https://blog.csdn.net/kikajack/article/details/80057876