`
dcj3sjt126com
  • 浏览: 1825596 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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

阅读更多

参考地址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
 

 

 

  • 大小: 789.9 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics