Chef - 客戶端設定



為了使 Chef 節點能夠與 Chef 伺服器通訊,您需要在節點上設定 Chef 客戶端。

Chef 客戶端

這是 Chef 節點的關鍵元件之一,它從 Chef 伺服器檢索 Cookbook 並將其在節點上執行。它也稱為 Chef 預配器。

在這裡,我們將使用 Vagrant 來管理虛擬機器。Vagrant 也可以與諸如 Shell 指令碼、Chef 和 Puppet 等預配器配置,以使虛擬機器達到所需狀態。在本例中,我們將使用 Vagrant 透過 VirtualBox 管理虛擬機器,並使用 Chef 客戶端作為預配器。

步驟 1 - 從 https://www.virtualbox.org/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" 
廣告