1> 简介:

创新互联建站服务项目包括榆阳网站建设、榆阳网站制作、榆阳网页制作以及榆阳网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,榆阳网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到榆阳省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
vagrant提供了易于配置,重复性好,便携式的工作环境,这些对开发人员非常有用,它可以让开发人员可以创建简单且可重复使用的基于VirtualBox的虚拟机(现在也支持VMware和AWS等),这些虚拟机可以快速的创建和销毁。vagrant也可以和puppet,chef等结合,实现虚拟机管理的自动化。vagrant的官网:http://www.vagrantup.com本文出自cclo的blog,转载时请务必以超链接形式标明文章原始出处:http://xuclv.blog.51cto.com/5503169/1239250
2> 安装:(OS:ubuntu12.04 vagrant:1.2.2)
$ sudo apt-get install virtualbox
$ sudo dpkg -i vagrant_1.2.2_x86_64.deb
版本1.0.x也可以这样安装(OS:ubuntu12.04)
sudo apt-get install vagrant
或
1:sudo apt-get install virtualbox
2:sudo apt-get install ruby1.9.1 rubygems
3:gem install vagrant
NOTE:在物理机的基础上安装virtualbox,如果用vm创建的虚拟机中再安装virtualbox和vagrant,那么vagrant将起不来。这里http://downloads.vagrantup.com/下载相应的vagrant版本,注意1.0.x版本和1.1+版本的配置有较大不同,稍后在做介绍。
3> 一个简单的项目
版本1.1+
$ vagrant init precise32 http://files.vagrantup.com/precise32.box
$ vagrant up
版本1.0.x and 1.1+
$ vagrant box add precise32 http://files.vagrantup.com/precise32.box
$ vagrant init precise32
$ vagrant up
上述命令运行后,将有一个虚拟机VirtualBox运行Ubuntu 12.04 LTS 32位的系统。使用命令$ vagrant ssh进入该系统。
NOTE:"precise32"为虚拟机的名字,可以更改为你想用的名字。
box是一个zip包,包含了vagrant的配置信息和VirtualBox的虚拟机镜像文件
"http://files.vagrantup.com/precise32.box"为镜像所在的路径,可以为本地路径,所以建议将box下载下来后,指定为本地路径,速度会更快
这里http://www.vagrantbox.es/有许多公共的base boxes可供下载和使用,后续将会介绍如何创建一个base box。
4> 常用的vagrant命令:
$ vagrant box add NAME URL #添加一个box
$ vagrant box list #查看本地已添加的box
$ vagrant box remove NAME virtualbox #删除本地已添加的box,如若是版本1.0.x,执行$ vagrant box remove NAME
$ vagrant init NAME #初始化,实质应是创建Vagrantfile文件
$ vagrant up #启动虚拟机
$ vagrant halt #关闭虚拟机
$ vagrant destroy #销毁虚拟机
$ vagrant reload #重启虚拟机
$ vagrant package #当前正在运行的VirtualBox虚拟环境打包成一个可重复使用的box
$ vagrant ssh #进入虚拟环境
5> Vagrantfile
官方解释是这样的:The primary function of the Vagrantfile is to describe the type of machine required for a project, and how to configure and provision these machines。翻译出来太生涩,简单来说就是配置这个虚拟主机网络连接方式,端口转发,同步文件夹,以及怎么和puppet,chef结合的一个配置文件。执行完$ vagrant init后,在工作目录中,你会发现此文件。
NOTE:配置版本说明:
Vagrant.configure("2") do |config|
# ...
end 当前支持的两个版本:"1"和"2". "1":描述是Vagrant 1.0.x的配置(如看到Vagrant::Config.run do |config| 此也为Vagrant 1.0.x 的配置);"2":描述的是1.1+ leading up to 2.0.x的配置。vagrant 1.1+ 的Vagrantfiles能够与vagrant 1.0.x的Vagrantfiles保持向后兼容,也大幅引入新的功能和配置选项。
6> 配置网络(本文将提供2种版本的常用配置,其中版本1的配置经过实践验证)
(1) 端口转发:(假设虚拟机的80端口提供web服务,此处将通过访问物理机的8080端口转发到虚拟机的80端口,来实现web的访问)
版本"2":
Vagrant.configure("2") do |config|
config.vm.network :forwarded_port, guest: 80, host: 8080
end 版本"1"
Vagrant::Config.run do |config|
# Forward guest port 80 to host port 8080
config.vm.forward_port 80, 8080
end
(2)桥接网络(公共网络,局域网DHCP服务器自动分配IP)
版本"2"
Vagrant.configure("2") do |config|
config.vm.network :public_network
end 版本"1"
Vagrant::Config.run do |config|
config.vm.network :bridged
end
$ VBoxManage list bridgedifs | grep ^Name #可通过此命令查看本机的网卡
Name: eth0
指定网卡,配置可写为如下:
Vagrant::Config.run do |config|
config.vm.network :bridged, :bridge => "eth0"
end
(3) 私有网络:允许多个虚拟机通过主机通过网络互相通信,vagrant允许用户分配一个静态IP,然后使用私有网络设置。
版本"2"
Vagrant.configure("2") do |config|
config.vm.network :private_network, ip: "192.168.50.4"
end 版本"1"
Vagrant::Config.run do |config|
config.vm.network :hostonly, "192.168.50.4"
end
7> 同步文件夹
默认的,vagrant将共享你的工作目录(即Vagrantfile所在的目录)到虚拟机中的/vagrant,所以一般不需配置即可,如你需要可配置:
版本"2"
Vagrant.configure("2") do |config|
# other config here
config.vm.synced_folder "src/", "/srv/website"
end "src/":物理机目录;"/srv/website"虚拟机目录
8> vagrant和shell(实现在虚拟机启动的时候自运行需要的shell命令或脚本)
版本"2"
内嵌脚本:
Vagrant.configure("2") do |config|
config.vm.provision :shell,
:inline => "echo Hello, World"
end 复杂点的调用如下:
$script = <
基本
文件
流程
错误
SQL
调试
- 请求信息 : 2026-05-31 23:32:18 HTTP/1.1 GET : /article/godsjd.html
- 运行时间 : 1.7625s ( Load:0.0063s Init:1.0587s Exec:0.6883s Template:0.0092s )
- 吞吐率 : 0.57req/s
- 内存开销 : 2,247.36 kb
- 查询信息 : 12 queries 5 writes
- 文件加载 : 36
- 缓存信息 : 0 gets 0 writes
- 配置加载 : 130
- 会话信息 : SESSION_ID=on9b1a9t1g353ajq49pgovqa63
- /www/wwwroot/tsicrk.com/index.php ( 1.09 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/ThinkPHP.php ( 4.61 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Think.class.php ( 12.26 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Storage.class.php ( 1.37 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Storage/Driver/File.class.php ( 3.52 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Mode/common.php ( 2.82 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Common/functions.php ( 53.56 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Hook.class.php ( 4.01 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/App.class.php ( 13.49 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Dispatcher.class.php ( 14.79 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Route.class.php ( 13.36 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Controller.class.php ( 11.23 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/View.class.php ( 7.59 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/BuildLiteBehavior.class.php ( 3.68 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/ParseTemplateBehavior.class.php ( 3.88 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/ContentReplaceBehavior.class.php ( 1.91 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Conf/convention.php ( 11.15 KB )
- /www/wwwroot/tsicrk.com/App/Common/Conf/config.php ( 2.14 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Lang/zh-cn.php ( 2.55 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Conf/debug.php ( 1.49 KB )
- /www/wwwroot/tsicrk.com/App/Home/Conf/config.php ( 0.31 KB )
- /www/wwwroot/tsicrk.com/App/Home/Common/function.php ( 3.33 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/ReadHtmlCacheBehavior.class.php ( 5.62 KB )
- /www/wwwroot/tsicrk.com/App/Home/Controller/ArticleController.class.php ( 6.02 KB )
- /www/wwwroot/tsicrk.com/App/Home/Controller/CommController.class.php ( 1.60 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Model.class.php ( 60.11 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Db.class.php ( 32.43 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Db/Driver/Pdo.class.php ( 16.74 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Cache.class.php ( 3.83 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Cache/Driver/File.class.php ( 5.87 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Template.class.php ( 28.16 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Template/TagLib/Cx.class.php ( 22.40 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Template/TagLib.class.php ( 9.16 KB )
- /www/wwwroot/tsicrk.com/App/Runtime/Cache/Home/7540f392f42b28b481b30614275e4e55.php ( 17.71 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/WriteHtmlCacheBehavior.class.php ( 0.97 KB )
- /www/wwwroot/tsicrk.com/ThinkPHP/Library/Behavior/ShowPageTraceBehavior.class.php ( 5.24 KB )
- [ app_init ] --START--
- Run Behavior\BuildLiteBehavior [ RunTime:0.000005s ]
- [ app_init ] --END-- [ RunTime:0.000031s ]
- [ app_begin ] --START--
- Run Behavior\ReadHtmlCacheBehavior [ RunTime:0.000285s ]
- [ app_begin ] --END-- [ RunTime:0.000309s ]
- [ view_parse ] --START--
- [ template_filter ] --START--
- Run Behavior\ContentReplaceBehavior [ RunTime:0.000055s ]
- [ template_filter ] --END-- [ RunTime:0.000077s ]
- Run Behavior\ParseTemplateBehavior [ RunTime:0.006304s ]
- [ view_parse ] --END-- [ RunTime:0.006333s ]
- [ view_filter ] --START--
- Run Behavior\WriteHtmlCacheBehavior [ RunTime:0.000163s ]
- [ view_filter ] --END-- [ RunTime:0.000178s ]
- [ app_end ] --START--
- 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 1' at line 1
[ SQL语句 ] : SELECT `id`,`pid`,`navname` FROM `cx_nav` WHERE ( id= ) LIMIT 1
- 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 1' at line 1
[ SQL语句 ] : SELECT `id`,`navname` FROM `cx_nav` WHERE ( id= ) LIMIT 1
- 1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
[ SQL语句 ] : SELECT `id`,`navname` FROM `cx_nav` WHERE ( pid= )
- [8] Undefined index: pid /www/wwwroot/tsicrk.com/App/Home/Controller/ArticleController.class.php 第 47 行.
- [8] Undefined index: db_host /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Db.class.php 第 120 行.
- [8] Undefined index: db_port /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Db.class.php 第 121 行.
- [8] Undefined index: db_name /www/wwwroot/tsicrk.com/ThinkPHP/Library/Think/Db.class.php 第 122 行.

1.7625s
