Chef 简明教程
Chef - Client Setup
为了使 Chef 节点与 Chef 服务器通信,您需要在节点上设置 Chef 客户端。
In order to make Chef node communicate with Chef server, you need to set up Chef client on the node.
Chef Client
这是 Chef 节点的关键组件之一,它从 Chef 服务器检索食谱并在节点上执行它们。它也被称为 Chef provisioner。
This is one of the key components of Chef node, which retrieves the cookbooks from the Chef server and executes them on the node. It is also known as the Chef provisioner.
在这里,我们将使用 Vagrant 来管理 VM。Vagrant 还可以使用 provisioner 配置,例如 Shell 脚本、Chef 和 Puppet,以使 VM 进入所需状态。在我们的例子中,我们将使用 Vagrant 使用 VirtualBox 和 Chef 客户端管理 VM。
Here, we will use Vagrant to manage VM. Vagrant can also be configured with the provisioner such as Shell script, Chef and Puppet to get VM into a desired state. In our case, we will use Vagrant to manage VMs using VirtualBox and Chef client as a provisioner.
Step 1 − 从 https://www.virtualbox.org/wiki/downlod 下载并安装 VirtualBox
Step 1 − Download and install VirtualBox from https://www.virtualbox.org/wiki/downlod
Step 2 − 从 http://downloads.vagrantup.com 下载并安装 Vagrant
Step 2 − Download and install Vagrant at http://downloads.vagrantup.com
Step 3 − 安装 Vagrant 总线插件,以便 Vagrant 能够在 VM 上安装 Chef 客户端。
Step 3 − Install Vagrant Omnibus plugin to enable Vagrant to install Chef client on the VM.
$ vagrant plugin install vagrant-omnibus
Creating and Booting Virtual
Step 1 − 我们可以从 Opscode vagrant repo 下载所需的 Vagrant box。从以下 URL 下载 opscode-ubuntu-12.04 box https://opscode-vmbento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box
Step 1 − We can download the required Vagrant box from the Opscode vagrant repo. Download the opscode-ubuntu-12.04 box from the following URL https://opscode-vmbento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box
Step 2 − 拥有 Vagrant 文件后,下载需要编辑 Vagrant 文件的路径。
Step 2 − Once you have the Vagrant file, download the path you need to edit the Vagrant file.
vipin@laptop:~/chef-repo $ subl Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "opscode-ubuntu-12.04"
config.vm.box_url = https://opscode-vm-bento.s3.amazonaws.com/
vagrant/opscode_ubuntu-12.04_provisionerless.box
config.omnibus.chef_version = :latest
config.vm.provision :chef_client do |chef|
chef.provisioning_path = "/etc/chef"
chef.chef_server_url = "https://api.opscode.com/
organizations/<YOUR_ORG>"
chef.validation_key_path = "/.chef/<YOUR_ORG>-validator.pem"
chef.validation_client_name = "<YOUR_ORG>-validator"
chef.node_name = "server"
end
end
在上面的程序中,您需要将 <YOUR_ORG> 名称更新为正确的或必需的组织名称。
In the above program, you need to update the <YOUR_ORG> name with the correct or required organization name.
Step 3 − 配置后的下一步是从启动 vagrant box。为此,您需移动到 vagrant box 所在位置并运行以下命令。
Step 3 − Next step after the configuration is, to get the vagrant box up. For this, you need to move to the location where Vagrant box is located and run the following command.
$ vagrant up
Step 4 − 机器启动后,您可以使用以下命令登录到机器。
Step 4 − Once the machine is up, you can login to the machine using the following command.
$ vagrant ssh
在上面的命令中,vagrantfile 在 Ruby 领域特定语言 (DSL) 中编写,用于配置 vagrant 虚拟机。
In the above command, vagrantfile is written in a Ruby Domain Specific Language (DSL) for configuring the vagrant virtual machine.
在 vagrant 文件中,我们有 config 对象。Vagrant 将使用此 config 对象来配置 VM。
In the vagrant file, we have the config object. Vagrant will use this config object to configure the VM.
Vagrant.configure("2") do |config|
…….
End
在 config 块内,您将告诉 vagrant 使用哪个 VM 映像,以便启动节点。
Inside the config block, you will tell vagrant which VM image to use, in order to boot the node.
config.vm.box = "opscode-ubuntu-12.04"
config.vm.box_url = https://opscode-vm-bento.s3.amazonaws.com/
vagrant/opscode_ubuntu-12.04_provisionerless.box
在下一步中,您将告诉 Vagrant 下载总线插件。
In the next step, you will tell Vagrant to download the omnibus plugin.
config.omnibus.chef_version = :latest
在选择要启动的 VM 框后配置如何使用 Chef 进行框配置。
After selecting the VM box to boot, configure how to provision the box using Chef.
config.vm.provision :chef_client do |chef|
…..
End
在此处内,您需要设置有关如何将虚拟节点连接至 Chef 服务器的说明。您需要告知 Vagrant 您需要在节点上存储所有 Chef 相关内容的位置。
Inside this, you need to set up instruction on how to hook up the virtual node to the Chef server. You need to tell Vagrant where you need to store all the Chef stuff on the node.
chef.provisioning_path = "/etc/chef"