天天看點

如何在 Ubuntu 上安裝配置管理系統 Chef (大廚)

下面是我們将要在本篇中要設定和配置chef的主要元件。

如何在 Ubuntu 上安裝配置管理系統 Chef (大廚)

<a target="_blank"></a>

我們将在下面的基礎環境下設定chef配置管理系統。

管理和配置工具:chef

基礎作業系統

ubuntu 14.04.1 lts (x86_64)

chef server

version 12.1.0

chef manage

version 1.17.0

chef development kit

version 0.6.2

記憶體和cpu

4 gb  , 2.0+2.0 ghz

我使用下面的指令來下載下傳和安裝它。

<code>root@ubuntu-14-chef:/tmp# wget https://web-dl.packagecloud.io/chef/stable/packages/ubuntu/trusty/chef-server-core_12.1.0-1_amd64.deb</code>

<code>root@ubuntu-14-chef:/tmp# dpkg -i chef-server-core_12.1.0-1_amd64.deb</code>

現在運作下面的指令來啟動所有的chef服務端服務,這一步也許會花費一些時間,因為它需要由許多不同一起工作的服務組成一個可正常運作的系統。

<code>root@ubuntu-14-chef:/tmp# chef-server-ctl reconfigure</code>

chef服務端啟動指令'chef-server-ctl reconfigure'需要運作兩次,這樣就會在安裝後看到這樣的輸出。

<code>chef client finished, 342/350 resources updated in 113.71139964 seconds</code>

<code>opscode reconfigured!</code>

安裝完成後重新開機系統使系統能最好的工作,不然我們或許會在建立使用者的時候看到下面的ssl連接配接錯誤。

<code>error: errno::econnreset: connection reset by peer - ssl_connect</code>

運作下面的指令來建立一個新的管理者賬戶及其配置。建立過程中,使用者的rsa私鑰會自動生成,它需要儲存到一個安全的地方。--file選項會儲存rsa私鑰到指定的路徑下。

<code>root@ubuntu-14-chef:/tmp# chef-server-ctl user-create kashi kashi kashi [email protected] kashi123 --filename /root/kashi.pem</code>

chef manage是一個針對企業級chef使用者的管理控制台,它提供了可視化的web使用者界面,可以管理節點、資料包、規則、環境、cookbook 和基于角色的通路控制(rbac)。

從官網複制連結并下載下傳chef manage的安裝包。

<code>root@ubuntu-14-chef:~# wget https://web-dl.packagecloud.io/chef/stable/packages/ubuntu/trusty/opscode-manage_1.17.0-1_amd64.deb</code>

使用下面的指令在root的家目錄下安裝它。

<code>root@ubuntu-14-chef:~# chef-server-ctl install opscode-manage --path /root</code>

安裝完成後我們需要運作下面的指令來重新開機chef manage和服務端。

<code>root@ubuntu-14-chef:~# opscode-manage-ctl reconfigure</code>

<code>root@ubuntu-14-chef:~# chef-server-ctl reconfigure</code>

我們可以使用localhost或它的域名來通路網頁控制台,并用已經建立的管理者登入

如何在 Ubuntu 上安裝配置管理系統 Chef (大廚)

chef amanage

你或許被要求建立新的組織,或者也可以接受其他組織的邀請。如下所示,使用縮寫和全名來建立一個新的組織。

如何在 Ubuntu 上安裝配置管理系統 Chef (大廚)

create org

我們同樣也可以運作下面的指令來建立新的組織。

<code>root@ubuntu-14-chef:~# chef-server-ctl org-create linux linoxide linux org. --association_user kashi --filename linux.pem</code>

為了設定工作站,我們需要用指令行建立一個新的使用者群組織。

<code>root@ubuntu-14-chef:~# chef-server-ctl user-create bloger bloger kashif [email protected] bloger123 --filename bloger.pem</code>

<code></code>

<code>root@ubuntu-14-chef:~# chef-server-ctl org-create blogs linoxide blogs inc. --association_user bloger --filename blogs.pem</code>

在工作站的網頁控制台中下載下傳并儲存入門套件,它用于與服務端協同工作

如何在 Ubuntu 上安裝配置管理系統 Chef (大廚)

starter kit

如何在 Ubuntu 上安裝配置管理系統 Chef (大廚)

chef開發套件是一款包含開發chef所需的所有工具的軟體包。它捆綁了由chef開發的帶chef用戶端的工具。

我們可以從它的官網連結中下載下傳開發包,并選擇作業系統來下載下傳chef開發包。

如何在 Ubuntu 上安裝配置管理系統 Chef (大廚)

chef dk

複制連結并用wget下載下傳

<code>root@ubuntu-15-wks:~# wget https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chefdk_0.6.2-1_amd64.deb</code>

使用dpkg指令安裝開發套件

<code>root@ubuntu-15-wks:~# dpkg -i chefdk_0.6.2-1_amd64.deb</code>

使用下面的指令驗證用戶端是否已經正确安裝。

<code>root@ubuntu-15-wks:~# chef verify</code>

<code>running verification for component 'berkshelf'</code>

<code>running verification for component 'test-kitchen'</code>

<code>running verification for component 'chef-client'</code>

<code>running verification for component 'chef-dk'</code>

<code>running verification for component 'chefspec'</code>

<code>running verification for component 'rubocop'</code>

<code>running verification for component 'fauxhai'</code>

<code>running verification for component 'knife-spork'</code>

<code>running verification for component 'kitchen-vagrant'</code>

<code>running verification for component 'package installation'</code>

<code>running verification for component 'openssl'</code>

<code>..............</code>

<code>---------------------------------------------</code>

<code>verification of component 'rubocop' succeeded.</code>

<code>verification of component 'knife-spork' succeeded.</code>

<code>verification of component 'openssl' succeeded.</code>

<code>verification of component 'berkshelf' succeeded.</code>

<code>verification of component 'chef-dk' succeeded.</code>

<code>verification of component 'fauxhai' succeeded.</code>

<code>verification of component 'test-kitchen' succeeded.</code>

<code>verification of component 'kitchen-vagrant' succeeded.</code>

<code>verification of component 'chef-client' succeeded.</code>

<code>verification of component 'chefspec' succeeded.</code>

<code>verification of component 'package installation' succeeded.</code>

我們将建立 ~/.chef目錄,并從chef服務端複制兩個使用者群組織的pem檔案到該目錄下。

<code>root@ubuntu-14-chef:~# scp bloger.pem blogs.pem kashi.pem linux.pem [email protected]:/.chef/</code>

<code>[email protected]'s password:</code>

<code>bloger.pem 100% 1674 1.6kb/s 00:00</code>

<code>blogs.pem 100% 1674 1.6kb/s 00:00</code>

<code>kashi.pem 100% 1678 1.6kb/s 00:00</code>

<code>linux.pem 100% 1678 1.6kb/s 00:00</code>

現在使用下面的内容建立"~/.chef/knife.rb"。

<code>root@ubuntu-15-wks:/.chef# vim knife.rb</code>

<code>current_dir = file.dirname(__file__)</code>

<code>log_level :info</code>

<code>log_location stdout</code>

<code>node_name "kashi"</code>

<code>client_key "#{current_dir}/kashi.pem"</code>

<code>validation_client_name "kashi-linux"</code>

<code>validation_key "#{current_dir}/linux.pem"</code>

<code>chef_server_url "https://172.25.10.173/organizations/linux"</code>

<code>cache_type 'basicfile'</code>

<code>cache_options( :path =&gt; "#{env['home']}/.chef/checksums" )</code>

<code>cookbook_path ["#{current_dir}/../cookbooks"]</code>

建立knife.rb中指定的“~/cookbooks”檔案夾。

<code>root@ubuntu-15-wks:/# mkdir cookbooks</code>

運作“knife user list”和“knife client list”來驗證knife是否工作。

<code>root@ubuntu-15-wks:/.chef# knife user list</code>

第一次運作的時候可能會看到下面的錯誤,這是因為工作站上還沒有chef服務端的ssl證書。

<code>error: ssl validation failure connecting to host: 172.25.10.173 - ssl_connect returned=1 errno=0 state=sslv3 read server certificate b: certificate verify failed</code>

<code>error: could not establish a secure connection to the server.</code>

<code>use `knife ssl check` to troubleshoot your ssl configuration.</code>

<code>if your chef server uses a self-signed certificate, you can use</code>

<code>`knife ssl fetch` to make knife trust the server's certificates.</code>

要解決上面的指令的錯誤,運作下面的指令來擷取ssl證書,并重新運作knife user和client list,這時候應該就可以了。

<code>root@ubuntu-15-wks:/.chef# knife ssl fetch</code>

<code>warning: certificates from 172.25.10.173 will be fetched and placed in your trusted_cert</code>

<code>directory (/.chef/trusted_certs).</code>

knife沒有辦法驗證這些是否是有效的證書。你應該在下載下傳時驗證這些證書的真實性。

在/.chef/trusted_certs/ubuntu-14-chef_test_com.crt下面添加ubuntu-14-chef.test.com的證書。

在上面的指令取得ssl證書後,接着運作下面的指令。

<code>root@ubuntu-15-wks:/.chef#knife client list</code>

<code>kashi-linux</code>

節點是執行所有基礎設施自動化的chef用戶端。是以,在配置完chef-server和knife工作站後,通過配置與chef-server互動的新節點,來将新的服務端添加到我們的chef環境下。

我們使用下面的指令來添加與chef服務端協同工作的新節點。

<code>root@ubuntu-15-wks:~# knife bootstrap 172.25.10.170 --ssh-user root --ssh-password kashi123 --node-name mydns</code>

<code>doing old-style registration with the validation key at /.chef/linux.pem...</code>

<code>delete your validation key in order to use your user credentials instead</code>

<code>connecting to 172.25.10.170</code>

<code>172.25.10.170 installing chef client...</code>

<code>172.25.10.170 --2015-07-04 22:21:16-- https://www.opscode.com/chef/install.sh</code>

<code>172.25.10.170 resolving www.opscode.com (www.opscode.com)... 184.106.28.91</code>

<code>172.25.10.170 connecting to www.opscode.com (www.opscode.com)|184.106.28.91|:443... connected.</code>

<code>172.25.10.170 http request sent, awaiting response... 200 ok</code>

<code>172.25.10.170 length: 18736 (18k) [application/x-sh]</code>

<code>172.25.10.170 saving to: ‘stdout’</code>

<code>172.25.10.170</code>

<code>100%[======================================&gt;] 18,736 --.-k/s in 0s</code>

<code>172.25.10.170 2015-07-04 22:21:17 (200 mb/s) - written to stdout [18736/18736]</code>

<code>172.25.10.170 downloading chef 12 for ubuntu...</code>

<code>172.25.10.170 downloading https://www.opscode.com/chef/metadata?v=12&amp;prerelease=false&amp;nightlies=false&amp;p=ubuntu&amp;pv=14.04&amp;m=x86_64</code>

<code>172.25.10.170 to file /tmp/install.sh.26024/metadata.txt</code>

<code>172.25.10.170 trying wget...</code>

之後我們可以在knife節點清單下看到建立的新節點,它也會在新節點下建立新的用戶端。

<code>root@ubuntu-15-wks:~# knife node list</code>

<code>mydns</code>

類似地我們隻要通過給上面的knife指令提供ssh證書,就可以在chef設施上建立多個節點。

本篇我們學習了chef管理工具,并通過安裝和配置設定基本了解了它的元件。我希望你在學習安裝和配置chef服務端以及它的工作站和用戶端節點中獲得樂趣。

本文來自雲栖社群合作夥伴“linux中國”,原文釋出日期:2015-08-10

繼續閱讀