- Chef 教程
- Chef - 首页
- Chef - 概述
- Chef - 架构
- Chef - 版本控制系统设置
- Chef - 工作站设置
- Chef - 客户端设置
- Chef - Test Kitchen 设置
- Chef - Knife 设置
- Chef - Solo 设置
- Chef - Cookbook
- Chef - Cookbook 依赖关系
- Chef - 角色
- Chef - 环境
- Chef - Chef-Client 作为守护进程
- Chef - Chef-Shell
- Chef - 测试 Cookbook
- Chef - Foodcritic
- Chef - ChefSpec
- 使用 Test Kitchen 测试 Cookbook
- Chef - 节点
- Chef - Chef-Client 运行
- 高级 Chef
- 动态配置菜谱
- Chef - 模板
- Chef - 使用 Chef DSL 的纯 Ruby
- Chef - 使用菜谱的 Ruby Gems
- Chef - 库
- Chef - 定义
- Chef - 环境变量
- Chef - 数据包
- Chef - 数据包脚本
- Chef - 跨平台 Cookbook
- Chef - 资源
- 轻量级资源提供程序
- Chef - 蓝图
- Chef - 文件和包
- Chef - 社区 Cookbook
- Chef 有用资源
- Chef - 快速指南
- Chef - 有用资源
- Chef - 讨论
Chef - 客户端设置
为了使 Chef 节点能够与 Chef 服务器通信,您需要在节点上设置 Chef 客户端。
Chef 客户端
这是 Chef 节点的关键组件之一,它从 Chef 服务器检索 Cookbook 并将其在节点上执行。它也称为 Chef 预配器。
在这里,我们将使用 Vagrant 来管理虚拟机。Vagrant 也可以与诸如 Shell 脚本、Chef 和 Puppet 等预配器配置,以使虚拟机达到所需状态。在本例中,我们将使用 Vagrant 通过 VirtualBox 管理虚拟机,并使用 Chef 客户端作为预配器。
步骤 1 - 从 https://virtualbox.net.cn/wiki/Downloads 下载并安装 VirtualBox
步骤 2 - 从 http://downloads.vagrantup.com 下载并安装 Vagrant
步骤 3 - 安装 Vagrant Omnibus 插件以使 Vagrant 能够在虚拟机上安装 Chef 客户端。
$ vagrant plugin install vagrant-omnibus
创建和启动虚拟机
步骤 1 - 我们可以从 Opscode vagrant 仓库下载所需的 Vagrant box。从以下 URL 下载 opscode-ubuntu-12.04 box:https://opscode-vmbento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box
步骤 2 - 获取 Vagrant 文件后,下载您需要编辑的 Vagrant 文件的路径。
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> 名称更新为正确的或所需的组织名称。
步骤 3 - 配置后的下一步是启动 vagrant box。为此,您需要移动到 Vagrant box 所在的位置并运行以下命令。
$ vagrant up
步骤 4 - 机器启动后,您可以使用以下命令登录到机器。
$ vagrant ssh
在上述命令中,vagrantfile 使用 Ruby 领域特定语言 (DSL) 来配置 vagrant 虚拟机。
在 vagrant 文件中,我们有 config 对象。Vagrant 将使用此 config 对象来配置虚拟机。
Vagrant.configure("2") do |config|
…….
End
在 config 块内,您将告诉 vagrant 使用哪个虚拟机映像来启动节点。
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 下载 omnibus 插件。
config.omnibus.chef_version = :latest
选择要启动的虚拟机 box 后,配置如何使用 Chef 预配 box。
config.vm.provision :chef_client do |chef| ….. End
在其中,您需要设置有关如何将虚拟节点连接到 Chef 服务器的说明。您需要告诉 Vagrant 您需要在节点上存储所有 Chef 内容的位置。
chef.provisioning_path = "/etc/chef"