the*_*now 25 lamp virtual-machine windows-7 vagrant knife
我有一个Vagrant VM标准问题lucid32.box正在运行.在此设置LAMP的完整说明是什么?
我看过刀(厨师的一部分)并试图:
vagrant@lucid32:~$ knife cookbook site install apache2
Run Code Online (Sandbox Code Playgroud)
但得到了
WARNING: No knife configuration file found
Run Code Online (Sandbox Code Playgroud)
如何设置刀具配置文件以及我应该在其中包含哪些内容?
我一直在网上搜索很多答案,但是部分解决方案不能解释他们的起点/先决条件.
更新
我的目标是自己回答这个问题,因为其他人似乎并不想这样做.这是我目前的理解 - 我的目标是稍后用红色解决我的未知/问题.

the*_*now 42
OK, I've decided to answer this fully for myself as the original question poster. (Thanks to everyone who contributed prior).
End-to-end setup of LAMP VM on Windows 64 bit host using Vagrant and Oracle VirtualBox
I asked this question originally because although there are plenty of instructions and guides on the web, what they don’t seem to do is:
State which version of Vagrant used. There are two (2) main versions: API version 1 which is all releases before (but NOT including) v1.1.0 And the other is API version 2 - which is releases from v1.1.0 onwards. So the versioning convention is similar to Java. This API version is important as, for example, v1 API scripts simply won't work on API v2 of the Vagrant software unless a clause is put at the beginning of the script to state which version to use.
Personally I think the Vagrant versioning convention could be simpler. NOTE: This guide here is for Vagrant 1. I am told that version 1 has a wide established installed base, while Vagrant 2 was still in draft mid 2013. I therefore like to call version 1 - V1 LTS - Long Term Support - like Ubuntu to show that this is going to be around for a long time yet.
Here is a picture to clarify which API is on which version of the Vagrant software:

For my example setup of using Vagrant here, I would suggest using pre-V1.1.0 (i.e. Vagrant API 1 from the downloads on vagrantup.com ) however you ought to be able to use Vagrant 2 API version of the Vagrant software as mentioned above but you'll need to add a 'directive' at the beginning of your scripts to tell Vagrant that they are for Vagrant 1 otherwise the scripts will fail with an error message. TODO: I'll try to get that directive and put here to help.
( Mitchell Hashimoto, Vagrant creator - please take note of the above for any future editions of your book O'Reilly book: Vagrant: Up and Running: http://shop.oreilly.com/product/0636920026358.do )
What these instructions in this answer should do:
Get you a 32 bit Ubuntu Linux OS with a LAMP (Linux Apache web server, MySQL database, PHP )stack running as a Virtual Machine using Oracle Virtual Box on your Windows 7 64 bit machine (or a Mac or Linux machine, but primarily tested on Windows but should work fine on Mac and this solution is meant to be platform independent). I have tested PHP OK (via standard phpinfo.php file and see that MySQL is running by haven't tested this yet).
Other ways to setup a LAMP stack running on a Vagrant VM
Note: An alternative pretty much out-of-the-box solution for those (like me). who want a LAMP stack with Drupal open source content management framework is here: http://drupal.org/project/vagrant You should be able to follow just my pre-requisites below and then download the .zip from the above URL and follow the instructions on there and run vagrant up from the command line to start the VM and wait as it builds and starts (some of this one off first time as once you have the image setup subsequents should be faster). You get a lot of other developer stuff 'for free' (i.e. save you the effort installing them) - like git, drush (I think), and performance profiling tools. Afterwards go to [server address]/install.php to install Drupal. This seems to work well without issue - I've tried it out but not tested it extensively. You might need to disable the install of xhprof if you get an error message - see http://drupal.org/node/1940668 for details.
另一个选择是使用此配置工具:https://puphpet.com/ - 这是一种用于配置Vagrant设置的可视化点击方法.这适用于Vagrant 2(我认为,更新是的,至少在流浪汉1.2.2上).更新:事实上,我已经成功运行并基于本地运行Drupal的设置 - 请参阅我的指南:https://drupal.org/node/2055947
更新
以下是一些其他开箱即用的Vagrant设置,我发现它们运行良好 - 在Mac和Windows上:
如果您希望在VM中本地使用Solr搜索引擎作为LAMP堆栈的一部分,您可能需要查看:
Even though these alternatives are great, my instructions are still of value to help you understand the workings of such setups or if you want a simpler more basic LAMP stack.
Small extras that you need to find out how to do (will try to include them here)
Logging into the machine once setup - this is done via the standard SSH-based login. You will need free tools putty.exe and puttygen.exe At the moment I have not provided how to login with SSH here but will try to do so in future. You will find references at the end of this answer.
Note that the login will be with the user vagrant up.
(After you have followed the setup instructions below) to use the root user you need to 'unlock' the account to be able to reset the password:
Unlock the root account:
vagrant@lucid32:~$ sudo passwd -u root
passwd: password expiry information changed.
Run Code Online (Sandbox Code Playgroud)
Then change the root password:
vagrant@lucid32:~$ sudo passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Run Code Online (Sandbox Code Playgroud)
(Obviously, password not shown as you type)
Test the new password by logging into root with it:
vagrant@lucid32:~$ su root
Password:
root@lucid32:/home/vagrant#
Run Code Online (Sandbox Code Playgroud)
Credit: https://scottlinux.com/2011/07/22/reset-or-change-user-password-in-linux/ (Article: "Reset or Change User Password in Linux" - This helped me work out how to do it.)
Any errors?
Give it a try - add comments to the answer if problems and I will try to fix. See also trouble shooting at the end.
Future tasks
Currently using Puppet. Do it with Chef instead of Puppet, just to widen the ways of working. Both of these are contenders but have different approaches so I believe: With Puppet I am told that you say what you want and Puppet may make some arbitrary decisions to get you there. Whereas with Chef I believe you define the precise sequence of steps. Again - comment here and correct me if necessary,
Pre-requisites for these instructions:
Separate installs of Ruby and Puppet are not required as these appear to come with Vagrant. To be honest, I did install these to fix some problems but found out those problems were something else. So I uninstalled the Ruby and Puppet and re-ran (vagrant etc) and still works so assuming these extra, separate installs of Ruby and Puppet are not required.
Suggested Vagrant and Virtual Box version combination to use: Virtual Box version 4.2.12 and pre-Vagrant 1.2 (as previously discussed). Certain other combinations could work but I haven't tested those, so am sticking with this combination unless I can see clear benefit of using later versions. One top clear benefit would be speed of provisioning. The combination I state here works for the puphpet.com route to setting up a VM at least which is quite complex, and I would therefore assume should work on my simple setup documented here.
( Credit: These Instructions are based on: http://ox86.tumblr.com/post/23734821654/painless-development-environments-with-virtualbox ...but not and exact copy as they did not work for me)
The instructions
(ensure you have the pre-requisites above)
The host setup work is done in your on your host machine in your Windows user folder, for example for me this is vagrant up
mkdir lamp-project
cd lamp-project
mkdir configs
cd ..
cd lamp-project
mkdir manifests
Run Code Online (Sandbox Code Playgroud)
(following from: http://docs.vagrantup.com/v1/docs/getting-started/index.html )
Download the distro install image, in this case Ubuntu Lucid (10.04). This image is effectively equivalent the install disk (CD or DVD) that you would traditionally use to install an OS on a machine.
C:\Users\rdavis\lamp-project>vagrant box add lucid32 http://files.vagrantup.com/lucid32.box
Run Code Online (Sandbox Code Playgroud)
(By the way, there are several other popular distros on vagrantup.com But if you want to generate the .box file from a distro .ISO then there is a tool called VeeWee to do that: https://github.com/jedi4ever/veewee )
Initialise it
C:\Users\rdavis\lamp-project>vagrant init lucid32
Run Code Online (Sandbox Code Playgroud)
(Note, I just used vagrant init when writing up these instructions because I already had initialised lucid32, but for the first time, you with have to do the above command.)
C:\Users\rdavis\lamp-project>vagrant init
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.
C:\Users\rdavis\lamp-project>
Run Code Online (Sandbox Code Playgroud)
Edit C:\Users\rdavis
- insert the following directly after vagrant init
config.vm.box = "lucid32"
config.vm.provision :puppet do |puppet|
puppet.manifests_path = File.expand_path("../manifests", __FILE__)
end
config.vm.forward_port 80, 8080
config.vm.share_folder "configs", "/configs", File.expand_path("../configs", __FILE__)
Run Code Online (Sandbox Code Playgroud)
So your Vagrantfile should look like:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
config.vm.box = "lucid32"
config.vm.provision :puppet do |puppet|
puppet.manifests_path = File.expand_path("../manifests", __FILE__)
end
config.vm.forward_port 80, 8080
config.vm.share_folder "configs", "/configs", File.expand_path("../configs", __FILE__)
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
# config.vm.box = "lucid32"
# (this is already done above, but if you have a box called 'base' which is an Ubuntu lucid32 then you can use: config.vm.box = "base". This info may be helpful if you get error: "The box 'base' could not be found.")
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
# config.vm.box_url = "http://example.com/path/to/above.box"
# Boot with a GUI so you can see the screen. (Default is headless)
# config.vm.boot_mode = :gui
# Assign this VM to a host-only network IP, allowing you to access it
# via the IP. Host-only networks can talk to the host machine as well as
# any other machines on the same network, but cannot be accessed (through this
# network interface) by any external networks.
# config.vm.network :hostonly, "192.168.33.10"
# Assign this VM to a bridged network, allowing you to connect directly to a
# network using the host's network device. This makes the VM appear as another
# physical device on your network.
# config.vm.network :bridged
# Forward a port from the guest to the host, which allows for outside
# computers to access the VM, whereas host only networking does not.
# config.vm.forward_port 80, 8080
# Share an additional folder to the guest VM. The first argument is
# an identifier, the second is the path on the guest to mount the
# folder, and the third is the path on the host to the actual folder.
# config.vm.share_folder "v-data", "/vagrant_data", "../data"
# Enable provisioning with Puppet stand alone. Puppet manifests
# are contained in a directory path relative to this Vagrantfile.
# You will need to create the manifests directory and a manifest in
# the file base.pp in the manifests_path directory.
#
# An example Puppet manifest to provision the message of the day:
#
# # group { "puppet":
# # ensure => "present",
# # }
# #
# # File { owner => 0, group => 0, mode => 0644 }
# #
# # file { '/etc/motd':
# # content => "Welcome to your Vagrant-built virtual machine!
# # Managed by Puppet.\n"
# # }
#
# config.vm.provision :puppet do |puppet|
# puppet.manifests_path = "manifests"
# puppet.manifest_file = "base.pp"
# end
# Enable provisioning with chef solo, specifying a cookbooks path, roles
# path, and data_bags path (all relative to this Vagrantfile), and adding
# some recipes and/or roles.
#
# config.vm.provision :chef_solo do |chef|
# chef.cookbooks_path = "../my-recipes/cookbooks"
# chef.roles_path = "../my-recipes/roles"
# chef.data_bags_path = "../my-recipes/data_bags"
# chef.add_recipe "mysql"
# chef.add_role "web"
#
# # You may also specify custom JSON attributes:
# chef.json = { :mysql_password => "foo" }
# end
# Enable provisioning with chef server, specifying the chef server URL,
# and the path to the validation key (relative to this Vagrantfile).
#
# The Opscode Platform uses HTTPS. Substitute your organization for
# ORGNAME in the URL and validation key.
#
# If you have your own Chef Server, use the appropriate URL, which may be
# HTTP instead of HTTPS depending on your configuration. Also change the
# validation key to validation.pem.
#
# config.vm.provision :chef_client do |chef|
# chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
# chef.validation_key_path = "ORGNAME-validator.pem"
# end
#
# If you're using the Opscode platform, your validator client is
# ORGNAME-validator, replacing ORGNAME with your organization name.
#
# IF you have your own Chef Server, the default validation client name is
# chef-validator, unless you changed the configuration.
#
# chef.validation_client_name = "ORGNAME-validator"
end
Run Code Online (Sandbox Code Playgroud)
Then, in C:\Users\rdavis\lamp-project\manifests create file default.pp and put in it:
$config_path = "/configs"
$vagrant_base_path = "/vagrant"
Exec { path => "/bin:/usr/bin:/usr/local/bin" }
group { "puppet": ensure => present }
exec { "apt-get update": command => "apt-get update" }
class apache {
exec { "enable-mod_rewrite":
require => Package["apache2"],
before => Service["apache2"],
command => "/usr/sbin/a2enmod rewrite"
}
package { "apache2":
ensure => present
}
service { "apache2":
ensure => running,
require => Package["apache2"]
}
}
class php {
package { "libapache2-mod-php5": ensure => present }
package { "php5": ensure => present }
package { "php5-cli": ensure => present }
package { "php5-dev": ensure => present }
package { "php5-mysql": ensure => present }
package { "php-pear": ensure => present }
exec { "pear upgrade":
command => "/usr/bin/pear upgrade",
require => Package["php-pear"],
}
}
class mysql {
package { "mysql-server":
require => Exec["apt-get update"],
ensure => present,
}
service { "mysql":
enable => true,
ensure => running,
require => Package["mysql-server"],
}
exec { "Set MySQL server root password":
require => Package["mysql-server"],
unless => "/usr/bin/mysqladmin -uroot -proot status",
command => "/usr/bin/mysqladmin -uroot password root",
}
}
include apache
include php
include mysql
Run Code Online (Sandbox Code Playgroud)
(Helpful note (optional), my above versions of C:\Users\rdavis\lamp-project\Vagrantfile and Vagrant::Config.run do |config| (and other Vagrant ancilliary files and folder structure) are available from my GitHub repository, VagrantVMSetups, at: https://github.com/therobyouknow/VagrantVMSetups
- See the Vagrantfile folder - this is the same as the contents of default.pp used in this answer.)
Then run Vagrant:
C:\Users\rdavis\lamp-project>vagrant up
Run Code Online (Sandbox Code Playgroud)
Note this can take a while (5-15 minutes) - but bear with it, it should now run successfully to run a LAMP VM. Then you have finished with the VM in your current work task, if you then keep the VM for use at a later time but shut it down using justlamp (rather than lamp-project to delete the VM image) then I would expect this delay to be a one-off initial setup time, subsequent start ups of the VM (using vagrant halt) should start faster I would think.
Troubleshooting:
Troubleshooting Problem 1: Bad/illegal quotes used - error message seen on host machine after issuing vagrant up command
Background: this happened to me because I pasted in the code snippets from the web page where the instructions came from. The code snippet had open-and-close quotes - which aren’t interpreted as proper quotes by the interpreter/parser that Vagrant uses (or indeed by most script interpreters and compilers I would think.)
Symptom: output like this:
There is a syntax error in the following Vagrantfile. The syntax error
message is reproduced below for convenience:
C:/Users/rdavis/lamp-project/Vagrantfile:6: invalid multibyte char (US-ASCII)
C:/Users/rdavis/lamp-project/Vagrantfile:6: syntax error, unexpected $end
Run Code Online (Sandbox Code Playgroud)
Or this:
Could not parse for environment production: Could not match ?/configs? at /tmp/vagrant-puppet/manifests/default.pp:1 on node lucid32.hsd1.ca.comcast.net.
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
Run Code Online (Sandbox Code Playgroud)
Or this:
There was an error executing the following command with VBoxManage:
["list", "hostonlyifs"]
Run Code Online (Sandbox Code Playgroud)
Remedy: use proper double quotes ". Don’t use open-and-closing quotes.
Troubleshooting Problem 2: Following Error Message on host machine after issuing vagrant up command:
?[1;35merr: /Stage[main]/Apache/File[/etc/apache2/sites-enabled/000-default]: Could not evaluate: Could not retrieve information from environment production source(s) file:/configs/000-default at /tmp
/vagrant-puppet/manifests/default.pp:11?[0m
Run Code Online (Sandbox Code Playgroud)
Remedy: you shouldn’t see this - the original script used contained references to a path containing vagrant destroy. I just remove all lines and constructs referring to it.
Troubleshooting Problem 3: PHP files are treated as downloads (download of file occurs in browser) rather than being executed and displayed.
PHP needs enabling on guest VM machine
Remedy: you may or may not need to do this.
This tip worked: (to enable php, stop the file being seen as a download): https://serverfault.com/questions/243435/getting-php-to-work-with-apache-to-run-php-files-through-browser
vagrant@lucid32:/etc/php5/cli$ a2enmod php5
Module php5 already enabled
vagrant@lucid32:/etc/php5/cli$ sudo apache2ctl restart
Run Code Online (Sandbox Code Playgroud)
Another tip:
PHP needs enabling, suggestion in: http://galleryproject.org/node/55011
is:
edit vagrant up
these are shared extensions (.so files), you need to enable them in php.ini and then you need to restart php
Myself, I didn’t need to edit php.ini after all, by the way, this is at: vagrant up for this lucid32 VM
Troubleshooting Problem 4: Addressing the virtual box additions warning message about version mismatch
[default] The guest additions on this VM do not match the install version of
VirtualBox! This may cause things such as forwarded ports, shared
folders, and more to not work properly. If any of those things fail on
this machine, please update the guest additions and repackage the
box.
Guest Additions Version: 4.2.0
VirtualBox Version: 4.2.4
Run Code Online (Sandbox Code Playgroud)
Not a problem it seems (it doesn’t stop the VM from running successfully), but if you wish to address it:
http://automation.binarysage.net/?p=1198 https://unix.stackexchange.com/questions/58216/automate-installation-of-virtualbox-guest-additio ns-via-command-line
(for linux-like users: http://www.pauloamgomes.net/blog/installing-vagrant )
Troubleshooting problem 5: vagrant up error message seen after running 000-default.
Remedy? Check the line containing the statement php.ini etc. in your /etc/php5/cli/php.ini (see my example The box 'base' could not be found." above) to ensure that it is referring to a Vagrant box (the OS install image) that actually exists on your system - issue command vagrant up to see what boxes you have.
If you have followed my instructions then you should have the config.vm.box = box. Make sure that there are no extraneous Vagrantfile etc. statements in your Vagrantfile. Confession: there was an extraneous vagrant box list in my lucid32 when actually a few lines above, config.vm.box = was already done. I have now corrected this.
FAQ
Q: What is a vagrant box? A: can be considered equivalent to a OS install disk in that it is basis, the starting point for a VM - it’s the OS. It’s a binary file (assumed)
Q: What is a vagrant package? A: a snapshot of the VM plus the configuration that Vagrant has performed from the VagrantFile provides a self-contained means to distribute setup to other people
References:
General Vagrant resources:
What exactly do the Vagrant commands do? - nice description
http://community.opscode.com/questions/81 http://deanstrezovski.com/setting-up-a-cagrant-lamp-stack/ http://www.jasongrimes.org/2012/06/managing-lamp-environments-with-chef-vagrant-and-ec2-1-of-3/ How do I associate a Vagrant project directory with an existing VirtualBox VM? http://docs.vagrantup.com/v1/docs/getting-started/index.html
More on Vagrant Boxes:
http://docs.vagrantup.com/v1/docs/boxes.html Where is Vagrant saving changes to the VM?
SSH key-based logins (logging into the VM box from externally - i.e. from the host machine or from another machine):
http://www.howtoforge.com/ssh_key_based_logins_putty_p2 http://docs.vagrantup.com/v1/docs/getting-started/ssh.html
http://en.wikipedia.org/wiki/Ssh-agent
For Windows SSH-based login to the VM
PuTTY: a free telnet/ssh client www.chiark.greenend.org.uk/~sgtatham/putty/
puttygen:
www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Version History/Updates of this answer
Vagrantfile to remove the extraneous config.vm.box = "base" when actually a few lines above, Vagrantfile was already done. This will help if you encounter the error config.vm.box = "lucid32" Also added a new troubleshooting item explaining the same.| 归档时间: |
|
| 查看次数: |
12716 次 |
| 最近记录: |