使用 Vagrant 打造跨平台开发环境

72 篇文章 0 订阅

参考地址1: http://segmentfault.com/blog/fenbox/1190000000264347

参考地址2: http://blog.phpor.me/2014/10/12/vagrant-%E6%9C%AC%E5%9C%B0%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83.html

 

下载的系统是centos6.3 64位: https://s3.amazonaws.com/itmat-public/centos-6.3-chef-10.14.2.box

Vagrant 是一款用来构建虚拟开发环境的工具,非常适合 php/python/ruby/java 这类语言开发 web 应用,“代码在我机子上运行没有问题”这种说辞将成为历史。

我们可以通过 Vagrant 封装一个 Linux 的开发环境,分发给团队成员。成员可以在自己喜欢的桌面系统(Mac/Windows/Linux)上开发程序,代码却能统一在封装好的环境里运行,非常霸气。

 

以下是实战内容:

Last login: Tue Mar 24 14:20:44 on console
➜  ~  ls
AFNetworking               Documents                  Music                      Rainforest                 install.log                swift_language_learning.md
AndroidStudioProjects      Downloads                  PhpstormProjects           VirtualBox VMs             mbox                       t.txt
Applications               Library                    Pictures                   a.php                      myfile.in                  test.awk
Desktop                    Movies                     Public                     dead.letter                paros
➜  ~  cd Documents/vagrant_maxwelldu 
➜  vagrant_maxwelldu  ls
movienext
➜  vagrant_maxwelldu  cd movienext 
➜  movienext  ls
➜  movienext  ll
➜  movienext  vagrant box add base ~/Downloads/centos-6.3-chef-10.14.2.box 
==> box: Adding box 'base' (v0) for provider: 
    box: Downloading: file:///Users/michaeldu/Downloads/centos-6.3-chef-10.14.2.box
==> box: Successfully added box 'base' (v0) for 'virtualbox'!
➜  movienext  ls
➜  movienext  ll
➜  movienext  vagrant box list
base (virtualbox, 0)
➜  movienext  vagrant init base
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
➜  movienext  ll
total 8
-rw-r--r--  1 michaeldu  staff  3016 Mar 24 16:00 Vagrantfile
➜  movienext  vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'base'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: movienext_default_1427184057998_56337
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Remote connection disconnect. 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: 4.1.22
    default: VirtualBox Version: 4.3
==> default: Mounting shared folders...
    default: /vagrant => /Users/michaeldu/Documents/vagrant_maxwelldu/movienext
➜  movienext  vagrant ssh
Last login: Fri Sep 14 17:53:41 2012 from 10.0.2.2
[vagrant@localhost ~]$ cd /va
vagrant/ var/     
[vagrant@localhost ~]$ cd /va
vagrant/ var/     
[vagrant@localhost ~]$ cd /vagrant/
[vagrant@localhost vagrant]$ wget http://www.baidu.com
--2015-03-24 09:02:48--  http://www.baidu.com/
Resolving www.baidu.com... ^C
[vagrant@localhost vagrant]$ exit
logout
Connection to 127.0.0.1 closed.
➜  movienext  vim Vagrantfile 
➜  movienext  vagrant reload 
==> default: Attempting graceful shutdown of VM...
==> default: Clearing any previously set forwarded ports...
==> 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 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
==> 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: 4.1.22
    default: VirtualBox Version: 4.3
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /Users/michaeldu/Documents/vagrant_maxwelldu/movienext
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: to force provisioning. Provisioners marked to run always will still run.
➜  movienext  vagrant ssh
Last login: Tue Mar 24 09:01:32 2015 from 10.0.2.2
[vagrant@localhost ~]$ ping www.baidu.com
PING www.a.shifen.com (61.135.169.125) 56(84) bytes of data.
64 bytes from 61.135.169.125: icmp_seq=1 ttl=63 time=5.12 ms
64 bytes from 61.135.169.125: icmp_seq=2 ttl=63 time=5.86 ms
64 bytes from 61.135.169.125: icmp_seq=3 ttl=63 time=4.77 ms
^C
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2112ms
rtt min/avg/max/mdev = 4.775/5.255/5.867/0.459 ms

 

到这里把vagrant安装好了, 进去了, 后面还需要安装lnmp

nginx安装参考地址: http://blog.csdn.net/stuartjing/article/details/8124491

nginx对应版本地址: http://nginx.org/en/download.html

 

安装好了之后, 

 

vagrant box list
vagrant box add base ~/Downloads/centos-6.3-chef-10.14.2.box 
vagrant init base
vi Vagrantfile
config.vm.network "private_network", ip: "192.168.33.10"

vagrant up
vagrant ssh

sudo su -

yum search mysql
yum -y install mysql mysql-devel mysql-server php-mysql
service mysqld start
/usr/bin/mysqladmin -u root password 'root'
 mysql -uroot -proot
 netstat -tunpl
 mysql -uroot -proot
 use mysql
 select Host, User, Password from user;
 update user set Host='%' where User='root' And Host='127.0.0.1';
 update user set Password=password('root');
 select Host, User, Password from user;
 flush privileges;
 exit
 service mysqld restart


 /etc/init.d/iptables stop
 chkconfig --levels 35 iptables off
 
 yum -y install php php-gd php-fpm php-pdo

 yum search nginx
 yum -y install nginx

 /etc/init.d/php-fpm restart
 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果您想在m1上使用Vagrant,可以按照以下步骤进行操作: 1. 首先,您需要在m1上下载并安装Vagrant。您可以从官方网站下载Vagrant的安装程序。根据您的操作系统选择正确的版本并进行安装。 2. 安装完成后,您可以使用Vagrant来创建和管理虚拟运行环境。Vagrant是一个基于虚拟化技术的虚拟运行环境管理工具,可以帮助您快速构建和管理虚拟机。 3. 在使用Vagrant之前,您需要选择一个虚拟机提供程序,例如VirtualBox或VMware。这些提供程序可以让您在m1上创建和运行虚拟机。 4. 安装并配置虚拟机提供程序后,您可以使用Vagrantfile来定义和配置虚拟机。Vagrantfile是一个文本文件,其中包含了虚拟机的配置信息,例如操作系统、网络设置等。 5. 编写完Vagrantfile后,您可以使用vagrant命令来创建和管理虚拟机。例如,您可以使用"vagrant up"命令来启动虚拟机,使用"vagrant halt"命令来关闭虚拟机,使用"vagrant ssh"命令来登录到虚拟机等。 总结起来,要在m1上使用Vagrant,您需要下载并安装Vagrant,选择一个虚拟机提供程序,编写Vagrantfile来配置虚拟机,然后使用vagrant命令来管理虚拟机。这样就可以利用Vagrant快速构建和管理虚拟运行环境了。 [3 [1<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [MAC(m1)-Vagrant下载安装](https://blog.csdn.net/ZHOU_VIP/article/details/128540117)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值