成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

如何在CentOS6.3系統(tǒng)中部署一個CHEF環(huán)境-創(chuàng)新互聯(lián)

今天就跟大家聊聊有關(guān)如何在CentOS 6.3系統(tǒng)中部署一個CHEF環(huán)境,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

站在用戶的角度思考問題,與客戶深入溝通,找到宜秀網(wǎng)站設(shè)計與宜秀網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:成都網(wǎng)站設(shè)計、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、國際域名空間、網(wǎng)頁空間、企業(yè)郵箱。業(yè)務(wù)覆蓋宜秀地區(qū)。

安裝前的準備:(chef.example.com,node1.example.com)


1.關(guān)閉iptables



代碼如下:


# service iptables stop



2.關(guān)閉SELINUX



代碼如下:


# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled
---------------



3.同步時間(重要)



代碼如下:


# ntpdate asia.pool.ntp.org
# hwclock -w



4.安裝ruby環(huán)境:
詳見: https://www.yisu.com/article/54981.htm

三.chef-server安裝:(chef.example.com)

1.下載chef-server安裝包

進入頁面http://www.opscode.com/chef/install,點擊Chef Server標簽,選擇要下載的版本
或在終端下用以下命令下載11.0.12版本:



代碼如下:


# wget -c --no-check-certificate
<a href="https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-server-11.0.12-1.el6.x86_64.rpm">https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-server-11.0.12-1.el6.x86_64.rpm</a>




2.安裝chef-server

終端內(nèi)進入chef-server軟件包所在目錄,執(zhí)行以下命令:



代碼如下:


# rpm -ivh chef-server-11.0.12-1.el6.x86_64.rpm



注:請使用下載的軟件包名稱替換上面命令中的軟件包名稱.

3.修改本地FQDN名:

1).首先修改主機的hostname



代碼如下:


# vi /etc/sysconfig/network
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-
HOSTNAME=chef.example.com
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-



2).修改本地host,添加server與node的FNDN




代碼如下:


# echo "10.107.91.251 chef.example.com" >> /etc/hosts
# echo "10.107.91.252 node1.example.com" >> /etc/hosts



重啟系統(tǒng). 登錄后驗證:



代碼如下:


# hostname -f
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-
chef.example.com
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-


3.配置chef-server

執(zhí)行以下命令配置chef-server



代碼如下:


# chef-server-ctl reconfigure



注:chef-server 10.x版本默認監(jiān)聽4000端口,chef-server 11.x監(jiān)聽443端口
SO若線上開啟防火墻,需執(zhí)行以下命令防火墻開啟443端口



代碼如下:


# iptables -I INPUT -p tcp --dport 443 -j ACCEPT
# service iptables save



現(xiàn)在瀏覽器打開https://10.107.91.251
輸入:



代碼如下:


username: admin
password: p@ssw0rd1



即可訪問chef-server web頁面.


四.chef-workstation安裝:(chef.example.com)


1.安裝chef-Client
進入頁面http://www.opscode.com/chef/install,點擊Chef Client標簽,選擇要下載的版本.
本例使用11.12.4-1版本:



代碼如下:


# wget -c --no-check-certificate https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-11.12.4-1.el6.x86_64.rpm
# rpm -ivh chef-11.12.4-1.el6.x86_64.rpm




2.安裝配置git

1).yum安裝git:




代碼如下:


# yum -y install git




2).進入root主目錄,git克隆chef repository




代碼如下:

# su -
# cd ~
# git clone git://github.com/opscode/chef-repo.git
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
Initialized empty Git repository in /root/chef-repo/.git/
remote: Reusing existing pack: 223, done.
remote: Total 223 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (223/223), 45.77 KiB | 37 KiB/s, done.
Resolving deltas: 100% (57/57), done.
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;




2.配置chef-workstation

運行命令 knife configure -i ,配置過程如下所示(只需填寫chef repository一項:/root/chef-repo,其他項使用默認值):



代碼如下:


# knife configure --initial
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
WARNING: No knife configuration file found
Where should I put the config file? [/root/.chef/knife.rb]
Please enter the chef server URL: [https://chef.example.com:443]
Please enter a name for the new user: [root]
Please enter the existing admin name: [admin]
Please enter the location of the existing admin's private key: [/etc/chef-server/admin.pem]
Please enter the validation clientname: [chef-validator]
Please enter the location of the validation key: [/etc/chef-server/chef-validator.pem]
Please enter the path to a chef repository (or leave blank): /root/chef-repo
Creating initial API user...
Please enter a password for the new user: 123456
注:這里輸入API user密碼(后面要使用)
Created user[root]
Configuration file written to /root/.chef/knife.rb
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;



注: 沒有出現(xiàn)Please enter a name for the new user: [root] 檢查chef-server的443端口是否可以訪問.

五.chef-workstation與chef-server不在同一服務(wù)器上的配置方法

(本例server與workstation在同一服務(wù)器,如無特殊需可略過這部分)

1.將chef-server的域名解析添加至chef-workstation的hosts文件




代碼如下:


# echo "10.107.91.251 chef.example.com" >>/etc/hosts




2.在chef-workstation先創(chuàng)建/root/.chef目錄,并將chef服務(wù)器上的/etc/chef-server/admin.pem和/etc/chef-server/chef-validator.pem文件拷貝到此目錄



代碼如下:


# mkdir ~/.chef
# scp chef.example.com:/etc/chef-server/admin.pem ~/.chef
# scp chef.example.com:/etc/chef-server/chef-validator.pem ~/.chef




3.執(zhí)行knife configure -i命令進行初始化, 然后刪除~/.chef/admin.pem



代碼如下:


# knife configure --initial
# rm ~/.chef/admin.pem




4.knife configure配置過程:
1).server URL修改為chef服務(wù)器的地址https://chef.example.com:443,
2).admin's private key路徑改為/root/.chef/admin.pem
3).validation key路徑改為/root/.chef/chef-validation.pem
4).chef repository地址輸入/root/chef-repo,其余項保持默認值.



代碼如下:


# knife configure --initial
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
Overwrite /root/.chef/knife.rb? (Y/N) Y
Please enter the chef server URL: [https://workstation:443] https://chef.example.com:443
Please enter a name for the new user: [root]
Please enter the existing admin name: [admin]  
Please enter the location of the existing admin's private key: [/etc/chef-server/admin.pem] /root/.chef/admin.pem
Please enter the validation clientname: [chef-validator]
Please enter the location of the validation key: [/etc/chef-server/chef-validator.pem] /root/.chef/chef-validator.pem
Please enter the path to a chef repository (or leave blank): /root/chef-repo
Creating initial API user...
Please enter a password for the new user: 123456
注:這里輸入API user密碼(后面要使用)
Created user[root]
Configuration file written to /root/.chef/knife.rb
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;




5.配置ruby路徑(之前已安裝RUBY,這里可以略過)

chef默認集成了一個ruby的穩(wěn)定版本,需修改PATH變量,保證chef集成的ruby被優(yōu)先使用.



代碼如下:

# echo 'export PATH="/opt/chef/embedded/bin:$PATH"' >> ~/.bash_profile && source ~/.bash_profile

六.驗證chef-workstation

執(zhí)行knife client list命令返回client列表則配置成功.



代碼如下:


# knife client list
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
chef-validator
chef-webui
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;




七.chef-node配置 (node1.example.com)

node即為被chef-server配置管理的服務(wù)器

1.安裝chef-Client

進入頁面http://www.opscode.com/chef/install,點擊Chef Client標簽,選擇要下載的版本.
本例使用11.12.4-1版本:



代碼如下:


# wget -c --no-check-certificate https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-11.12.4-1.el6.x86_64.rpm
# rpm -ivh chef-11.12.4-1.el6.x86_64.rpm




2.修改本地FQDN名:

1).首先修改主機的hostname



代碼如下:


# vi /etc/sysconfig/network
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-
HOSTNAME=node1.example.com
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-




2).修改本地host,添加本機和server的FNDN




代碼如下:


# echo "10.107.91.251 chef.example.com" >> /etc/hosts
# echo "10.107.91.252 node1.example.com" >> /etc/hosts



重啟系統(tǒng). 登錄后驗證:



代碼如下:


# hostname -f
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-
node1.example.com
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-




3.在chef-worksation執(zhí)行下面命令添加并配置node




代碼如下:


# knife bootstrap node1.example.com -x root -P 123456



注: 這里的密碼是node1系統(tǒng)root賬號的密碼
chef-workstation通過ssh連接到node1(10.107.91.252)上執(zhí)行bootstrap腳本(chef-workstation /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef11.6.0/lib/chef/knife/bootstrap/chef-full.erb)可以使用自定義的bootstrap腳本對node進行初始化配置.
node1會下載https://www.opscode.com/chef/install.sh腳本.腳本檢查操作系統(tǒng)類型并在網(wǎng)絡(luò)上下載符合此系統(tǒng)的chef版本進行安裝(下載安裝較慢).可以在node上預(yù)安裝chef(見workstation安裝chef部分)跳過此腳本.



代碼如下:


&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-
Connecting to node1.example.com
node1.example.com Starting first Chef Client run...
node1.example.com [2014-05-08T15:53:22+08:00] WARN:
node1.example.com * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
node1.example.com SSL validation of HTTPS requests is disabled. HTTPS connections are still
node1.example.com encrypted, but chef is not able to detect forged replies or man in the middle
node1.example.com attacks.
node1.example.com
node1.example.com To fix this issue add an entry like this to your configuration file:
node1.example.com
node1.example.com ```
node1.example.com   # Verify all HTTPS connections (recommended)
node1.example.com   ssl_verify_mode :verify_peer
node1.example.com
node1.example.com   # OR, Verify only connections to chef-server
node1.example.com   verify_api_cert true
node1.example.com ```
node1.example.com
node1.example.com To check your SSL configuration, or troubleshoot errors, you can use the
node1.example.com `knife ssl check` command like so:
node1.example.com
node1.example.com ```
node1.example.com   knife ssl check -c /etc/chef/client.rb
node1.example.com ```
node1.example.com
node1.example.com * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
node1.example.com
node1.example.com Starting Chef Client, version 11.12.4
node1.example.com Creating a new client identity for node1.example.com using the validator key.
node1.example.com resolving cookbooks for run list: []
node1.example.com Synchronizing Cookbooks:
node1.example.com Compiling Cookbooks...
node1.example.com [2014-05-08T15:53:25+08:00] WARN: Node node1.example.com has an empty run list.
node1.example.com Converging 0 resources
node1.example.com
node1.example.com Running handlers:
node1.example.com Running handlers complete
node1.example.com
node1.example.com Chef Client finished, 0/0 resources updated in 2.393659851 seconds
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-



查看是否連接node1成功:



代碼如下:


# knife node list
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
node1
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;



從上面可以看出node1已經(jīng)成功注冊到了chef-server中,整個環(huán)境 chef-workstation => chef-server => chef-client-1 已經(jīng)搭建成功。

八.登陸server web后臺

1.修改瀏覽器本機HOST,這里筆者使用的是MAC系統(tǒng)



代碼如下:

# vi /etc/hosts
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
10.107.91.251 chef.example.com
10.107.91.252 node1.example.com
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;



2.訪問https://chef.example.com
如圖:

如何在CentOS 6.3系統(tǒng)中部署一個CHEF環(huán)境

如何在CentOS 6.3系統(tǒng)中部署一個CHEF環(huán)境

如何在CentOS 6.3系統(tǒng)中部署一個CHEF環(huán)境

如何在CentOS 6.3系統(tǒng)中部署一個CHEF環(huán)境

九.創(chuàng)建一個cookbook實例

1.git克隆chef repository (chef.example.com)
注: chef repository 是一個存儲cookbooks和其他文件的目錄結(jié)構(gòu),初次使用需要從github克隆



代碼如下:


# su -
# cd ~
# git clone git://github.com/opscode/chef-repo.git
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
Initialized empty Git repository in /root/chef-repo/.git/
remote: Reusing existing pack: 223, done.
remote: Total 223 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (223/223), 45.77 KiB | 37 KiB/s, done.
Resolving deltas: 100% (57/57), done.
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;



獲取到的目錄如下:



代碼如下:


# ls
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
Desktop    Downloads  Pictures  Templates  anaconda-ks.cfg  install.log         src
Documents  Music      Public    Videos     chef-repo        install.log.syslog
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
# cd chef-repo/
# ls
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
LICENSE    Rakefile      chefignore  cookbooks  environments
README.md  certificates  config      data_bags  roles
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;



2.創(chuàng)建一個cookbook,取名quick_start (chef.example.com)
注:需要切換到之前clone獲取到的目錄的cookbooks目錄下



代碼如下:


# cd ~/chef-repo/cookbooks
# knife cookbook create quick_start -o ./
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
** Creating cookbook quick_start
** Creating README for cookbook: quick_start
** Creating CHANGELOG for cookbook: quick_start
** Creating metadata for cookbook: quick_start
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;



創(chuàng)建的cookbooks目錄如下



代碼如下:


# # ls -1p quick_start
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
CHANGELOG.md
README.md
attributes/
definitions/
files/
libraries/
metadata.rb
providers/
recipes/
resources/
templates/
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;



注: cookbooks用來在chef中分布共享,大多數(shù)你創(chuàng)建基礎(chǔ)實例都需要cookbooks.
此cookbook實例是創(chuàng)建一個簡單的recipe,用來傳遞給node1一個簡單的帶有一些已經(jīng)定義好的變量屬性的文本.

3.創(chuàng)建一個屬性文件,取名"quick_start.rb" (chef.example.com)



代碼如下:


# vi ~/chef-repo/cookbooks/quick_start/attributes/quick_start.rb
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
normal[:deep_thought] = "If a tree falls in the forest ..."
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;



注: 在cookbook中屬性文件用來在node中創(chuàng)建一些配置,從而你可以從recipe中調(diào)用這些屬性.

4.對default recipe創(chuàng)建一個source template源模板 (chef.example.com)



代碼如下:


# vi ~/chef-repo/cookbooks/quick_start/recipes/default.rb
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
template "/tmp/deep_thought.txt" do
 source "deep_thought.txt.erb"
 variables :deep_thought => node[:deep_thought]
 action :create
end
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;



注: recipes允許你對具體的源進行管理,這個例子中,你創(chuàng)建了一個叫quick_start的recipe,內(nèi)容包括一個單獨的源模板名叫template "/tmp/deep_thought.txt"

5.創(chuàng)建一個template模板文件 (chef.example.com)

注:這個文件調(diào)用源模板的具體屬性,而后被chef傳送給具體的node客戶端



代碼如下:

# vi ~/chef-repo/cookbooks/quick_start/templates/default/deep_thought.txt.erb
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
Today's deep thought: <%= @deep_thought %>
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;



6.將cookbook上傳到Server (chef.example.com)



代碼如下:


# cd ~/chef-repo/cookbooks/
# ls
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
README.md  quick_start
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
# knife cookbook upload -a -o ./
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
Uploading quick_start  [0.1.0]
Uploaded all cookbooks.
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;



確認你剛上傳的cookbook



代碼如下:


# knife cookbook list
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
quick_start   0.1.0
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;



6.將quick_start recipe添加到你的node中 (chef.example.com)



代碼如下:


# knife node run_list add node1.example.com 'recipe[quick_start]'
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
node1.example.com:
run_list: recipe[quick_start]
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;



查看添加好的recipe



代碼如下:


# knife  node show node1.example.com -r
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
node1.example.com:
run_list: recipe[quick_start]
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;



6.在node客戶端注冊,從而獲取server上recipe的具體實例 (node1.example.com)
注:保證/etc/chef下有client.pem與validation.pem證書文件,如果沒有檢查之前的配置.



代碼如下:

# chef-client
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
[2014-05-08T23:55:33+08:00] WARN:
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
SSL validation of HTTPS requests is disabled. HTTPS connections are still
encrypted, but chef is not able to detect forged replies or man in the middle
attacks.
To fix this issue add an entry like this to your configuration file:
```
# Verify all HTTPS connections (recommended)
ssl_verify_mode :verify_peer
# OR, Verify only connections to chef-server
verify_api_cert true
```
To check your SSL configuration, or troubleshoot errors, you can use the
`knife ssl check` command like so:
```
knife ssl check -c /etc/chef/client.rb
```
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Starting Chef Client, version 11.12.4
resolving cookbooks for run list: ["quick_start"]
Synchronizing Cookbooks:
- quick_start
Compiling Cookbooks...
Converging 1 resources
Recipe: quick_start::default
* template[/tmp/deep_thought.txt] action create
   - create new file /tmp/deep_thought.txt
   - update content in file /tmp/deep_thought.txt from none to feb62f
      --- /tmp/deep_thought.txt    2014-05-08 23:55:43.098408727 +0800
      +++ /tmp/chef-rendered-template20140508-8171-11cxwpb    2014-05-08 23:55:43.099454345 +0800
      @@ -1 +1,2 @@
      +Today's deep thought: If a tree falls in the forest ...
Running handlers:
Running handlers complete
Chef Client finished, 1/1 resources updated in 9.915108372 seconds
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;



最終執(zhí)行后,創(chuàng)建 /tmp/deep_thought.txt文件,即實現(xiàn)了server向node的文件分發(fā)



代碼如下:

# vi  /tmp/deep_thought.txt
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
Today's deep thought: If a tree falls in the forest ...
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;


看完上述內(nèi)容,你們對如何在CentOS 6.3系統(tǒng)中部署一個CHEF環(huán)境有進一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。

分享名稱:如何在CentOS6.3系統(tǒng)中部署一個CHEF環(huán)境-創(chuàng)新互聯(lián)
鏈接URL:http://jinyejixie.com/article44/gpsee.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作電子商務(wù)、Google、虛擬主機、網(wǎng)站導(dǎo)航、企業(yè)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)
麻江县| 当涂县| 临湘市| 肥东县| 甘孜县| 高台县| 东城区| 镶黄旗| 伊通| 永吉县| 四子王旗| 嘉祥县| 三河市| 防城港市| 横峰县| 西青区| 澄迈县| 金秀| 志丹县| 临西县| 克东县| 濮阳县| 崇信县| 榆树市| 建德市| 个旧市| 吉林省| 湘潭县| 大新县| 盐源县| 横山县| 双桥区| 武威市| 宁南县| 平果县| 诸城市| 仙居县| 额尔古纳市| 时尚| 桑日县| 玉山县|