<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DevOps技术分享 &#187; RUBY</title>
	<atom:link href="http://www.showerlee.com/archives/category/programming/ruby/feed" rel="self" type="application/rss+xml" />
	<link>http://www.showerlee.com</link>
	<description>与你共同学习运维开发</description>
	<lastBuildDate>Mon, 19 Oct 2020 05:51:41 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.6</generator>
		<item>
		<title>CentOS 6.3下CHEF环境部署</title>
		<link>http://www.showerlee.com/archives/1138</link>
		<comments>http://www.showerlee.com/archives/1138#comments</comments>
		<pubDate>Thu, 29 May 2014 04:18:47 +0000</pubDate>
		<dc:creator>showerlee</dc:creator>
				<category><![CDATA[CHEF]]></category>
		<category><![CDATA[RUBY]]></category>
		<category><![CDATA[chef]]></category>

		<guid isPermaLink="false">http://www.showerlee.com/?p=1138</guid>
		<description><![CDATA[一.前言： 初识Chef，我们可以先了解一下DevOps运动http://zh.wikipedia.org/w [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>
	一.前言：
</p>
<p>
	初识Chef，我们可以先了解一下DevOps运动http://zh.wikipedia.org/wiki/DevOps,<span style="line-height:1.5;">简单点说，就是传统的软件组织将开发、IT运营和质量保障设为各自分离的部门，而DevOps运动的出现是由于软件行业日益清晰地认识到：为了按时交付软件产品和服务，开发和运营工作必须紧密合作。</span>
</p>
<p>
	所以Chef简单点说，就是DevOps运动中的一项重要工具成员，是一个同时面向开发与运维的集中管理工具。
</p>
<p>
	
</p>
<p>
	就服务器的集中管理工具而言，知名度与Chef平分天下的是叫“Puppet”的工具，它们是OSS知名度排名最前的2个<span>。</span>
</p>
<p>
	想像一下我们现在需要搭建一台MySQL Database Slave服务器，安装过程我们手动操作了没过多久，又需要第二台，这时候我们会想，如果之后安装第一台的时候把操作过程执行的命令写成脚本，现在安装第二台，运行一下脚本就行了，节约时间而且不容易出错。
</p>
<p>
	<span style="line-height:1.5;">Chef就相当于这样的一个脚本管理工具，但功能要强大得多，可定制性强，Chef将脚本命令代码化，定制时只需要修改代码，安装的过程就是执行代码的过程。</span><span style="line-height:1.5;">打个比方，Chef就像一个制作玩具的工厂，它可以把一些原材料做成漂亮的玩具，<br />
它有一些模板，你把原材料放进去，选择一个模板(比如怪物史莱克)，它就会制造出这个玩具，服务器的配置也是这样，一台还没有配置的服务器，你给它指定一</span><span style="line-height:1.5;">个模板(role或recipe)， Chef就会把它配置成你想要的线上服务器。</span>
</p>
<p>
	Chef使用服务器—客户端模式管理所有需要配置的机器，使用Chef涉及至少三台机器：
</p>
<p>
	一台开发机器(Workstation)，在上面编写大餐的做法；
</p>
<p>
	一台Chef服务器(server)，管理所有要配置的Chef客户端，给它们下发配置信息；
</p>
<p>
	多台Chef客户端(Node)，就是我将要烹调出的大餐。
</p>
<p>
	操作系统：CentOS-6.3-x86-64
</p>
<p>
	CHEF： &nbsp; <a href="http://www.showerlee.com/archives/tag/chef-2" title="查看chef中的全部文章" class="tag_link">chef</a>-server-11.0.12-1.el6.x86_64
</p>
<p>
	Server : &nbsp; &nbsp; 10.107.91.251 (<a href="http://www.showerlee.com/archives/tag/chef-2" title="查看chef中的全部文章" class="tag_link">chef</a>.example.com)
</p>
<p>
	Workstation: &nbsp; &nbsp; 10.107.91.251 (<a href="http://www.showerlee.com/archives/tag/chef-2" title="查看chef中的全部文章" class="tag_link">chef</a>.example.com)
</p>
<p>
	node: &nbsp; &nbsp; &nbsp; &nbsp; 10.107.91.252 (node1.example.com) &nbsp; &nbsp;
</p>
<p>
	二.安装前的准备:(<a href="http://www.showerlee.com/archives/tag/chef-2" title="查看chef中的全部文章" class="tag_link">chef</a>.example.com,node1.example.com)
</p>
<p>
	1.关闭iptables
</p>
<p>
	# service iptables stop
</p>
<p>
	2.关闭SELINUX
</p>
<p>
	# setenforce 0
</p>
<p>
	# vi /etc/sysconfig/selinux
</p>
<p>
	---------------
</p>
<p>
	SELINUX=disabled
</p>
<p>
	---------------
</p>
<p>
	3.同步时间(重要)
</p>
<p>
	# ntpdate asia.pool.ntp.org
</p>
<p>
	# hwclock -w
</p>
<p>
	4.安装ruby环境:
</p>
<p>
	详见: <a href="http://showerlee.blog.51cto.com/2047005/1393485" rel="nofollow">http://showerlee.blog.51cto.com/2047005/1393485</a>
</p>
<p>
	三.<a href="http://www.showerlee.com/archives/tag/chef-2" title="查看chef中的全部文章" class="tag_link">chef</a>-server安装:(<a href="http://www.showerlee.com/archives/tag/chef-2" title="查看chef中的全部文章" class="tag_link">chef</a>.example.com)
</p>
<p>
	1.下载<a href="http://www.showerlee.com/archives/tag/chef-2" title="查看chef中的全部文章" class="tag_link">chef</a>-server安装包
</p>
<p>
	进入页面http://www.opscode.com/<a href="http://www.showerlee.com/archives/tag/chef-2" title="查看chef中的全部文章" class="tag_link">chef</a>/install，点击Chef Server标签，选择要下载的版本
</p>
<p>
	或在终端下用以下命令下载11.0.12版本：
</p>
<p>
	#&nbsp;<span style="line-height:1.5;">wget -c --no-check-certificate </p>
<p><a href="https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-server-11.0.12-1.el6.x86_64.rpm" rel="nofollow">https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-server-11.0.12-1.el6.x86_64.rpm</a></span></p>
<p>
	2.安装chef-server
</p>
<p>
	终端内进入chef-server软件包所在目录，执行以下命令：
</p>
<p>
	# rpm -ivh chef-server-11.0.12-1.el6.x86_64.rpm
</p>
<p>
	<span style="color:#E53333;"><span style="background-color:;">注：</span>请使用下载的软件包名称替换上面命令中的软件包名称.</span>
</p>
<p>
	3.修改本地FQDN名:
</p>
<p>
	1).首先修改主机的hostname&nbsp;
</p>
<p>
	# vi /etc/sysconfig/network
</p>
<p>
	———————-———————-———————-———————-
</p>
<p>
	HOSTNAME=chef.example.com
</p>
<p>
	———————-———————-———————-———————-
</p>
<p>
	2).修改本地host,添加server与node的FNDN
</p>
<p>
	# echo "10.107.91.251 chef.example.com" &gt;&gt; /etc/hosts
</p>
<p>
	# echo "10.107.91.252 node1.example.com" &gt;&gt; /etc/hosts
</p>
<p>
	重启系统. 登录后验证:
</p>
<p>
	# hostname -f
</p>
<p>
	———————-———————-———————-———————-
</p>
<p>
	chef.example.com
</p>
<p>
	———————-———————-———————-———————-
</p>
<p>
	3.配置chef-server&nbsp;
</p>
<p>
	执行以下命令配置chef-server
</p>
<p>
	# chef-server-ctl reconfigure
</p>
<p>
	<span style="color:#E53333;">注:chef-server 10.x版本默认监听4000端口，chef-server 11.x监听443端口</span>
</p>
<p>
	SO若线上开启防火墙,需执行以下命令防火墙开启443端口
</p>
<p>
	# iptables -I INPUT -p tcp --dport 443 -j ACCEPT
</p>
<p>
	# service iptables save
</p>
<p>
	现在浏览器打开https://10.107.91.251
</p>
<p>
	输入:
</p>
<p>
	username: admin
</p>
<p>
	password: p@ssw0rd1
</p>
<p>
	即可访问chef-server web页面.
</p>
<p>
	四.chef-workstation安装:(chef.example.com)
</p>
<p>
	1.安装chef-Client
</p>
<p>
	进入页面http://www.opscode.com/chef/install，点击Chef Client标签，选择要下载的版本.
</p>
<p>
	本例使用11.12.4-1版本：
</p>
<p>
	# wget -c --no-check-certificate <a href="https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-11.12.4-1.el6.x86_64.rpm" rel="nofollow">https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-11.12.4-1.el6.x86_64.rpm</a>
</p>
<p>
	# rpm -ivh chef-11.12.4-1.el6.x86_64.rpm
</p>
<p>
	2.安装配置git
</p>
<p>
	1).yum安装git:
</p>
<p>
	# yum -y install git
</p>
<p>
	2).进入root主目录，git克隆chef repository
</p>
<p>
	# su -
</p>
<p>
	# cd ~
</p>
<p>
	# git clone git://github.com/opscode/chef-repo.git
</p>
<p>
	————————————————————————————————————————————————————————————
</p>
<p>
	Initialized empty Git repository in /root/chef-repo/.git/
</p>
<p>
	remote: Reusing existing pack: 223, done.
</p>
<p>
	remote: Total 223 (delta 0), reused 0 (delta 0)
</p>
<p>
	Receiving objects: 100% (223/223), 45.77 KiB | 37 KiB/s, done.
</p>
<p>
	Resolving deltas: 100% (57/57), done.
</p>
<p>
	————————————————————————————————————————————————————————————
</p>
<p>
	2.配置chef-workstation
</p>
<p>
	运行命令 knife configure -i ,配置过程如下所示(只需填写chef repository一项:/root/chef-repo,其他项使用默认值):
</p>
<p>
	# knife configure --initial
</p>
<p>
	————————————————————————————————————————————————————————————
</p>
<p>
	WARNING: No knife configuration file found
</p>
<p>
	Where should I put the config file? [/root/.chef/knife.rb]
</p>
<p>
	Please enter the chef server URL: [https://chef.example.com:443]&nbsp;
</p>
<p>
	Please enter a name for the new user: [root]
</p>
<p>
	Please enter the existing admin name: [admin]&nbsp;
</p>
<p>
	Please enter the location of the existing admin's private key: [/etc/chef-server/admin.pem]&nbsp;
</p>
<p>
	Please enter the validation clientname: [chef-validator]&nbsp;
</p>
<p>
	Please enter the location of the validation key: [/etc/chef-server/chef-validator.pem]&nbsp;
</p>
<p>
	Please enter the path to a chef repository (or leave blank): /root/chef-repo&nbsp;
</p>
<p>
	Creating initial API user...
</p>
<p>
	Please enter a password for the new user: 123456
</p>
<p>
	<span style="color:#E53333;">注:这里输入API user密码(后面要使用)</span>
</p>
<p>
	Created user[root]
</p>
<p>
	Configuration file written to /root/.chef/knife.rb
</p>
<p>
	————————————————————————————————————————————————————————————
</p>
<p>
	<span style="color:#E53333;">注: 没有出现Please enter a name for the new user: [root] 检查chef-server的443端口是否可以访问.</span>
</p>
<p>
	五.chef-workstation与chef-server不在同一服务器上的配置方法
</p>
<p>
	(本例server与workstation在同一服务器,如无特殊需可略过这部分)
</p>
<p>
	1.将chef-server的域名解析添加至chef-workstation的hosts文件
</p>
<p>
	# echo "10.107.91.251 chef.example.com" &gt;&gt;/etc/hosts
</p>
<p>
	2.在chef-workstation先创建/root/.chef目录,并将chef服务器上的/etc/chef-server/admin.pem和/etc/chef-server/chef-validator.pem文件拷贝到此目录
</p>
<p>
	# mkdir ~/.chef
</p>
<p>
	# scp chef.example.com:/etc/chef-server/admin.pem ~/.chef
</p>
<p>
	# scp chef.example.com:/etc/chef-server/chef-validator.pem ~/.chef
</p>
<p>
	3.执行knife configure -i命令进行初始化, 然后删除~/.chef/admin.pem
</p>
<p>
	# knife configure --initial
</p>
<p>
	# rm ~/.chef/admin.pem
</p>
<p>
	4.knife configure配置过程:
</p>
<p>
	1.server URL修改为chef服务器的地址https://chef.example.com:443,&nbsp;
</p>
<p>
	2.admin's private key路径改为/root/.chef/admin.pem
</p>
<p>
	3.validation key路径改为/root/.chef/chef-validation.pem
</p>
<p>
	4.chef repository地址输入/root/chef-repo,其余项保持默认值.
</p>
<p>
	# knife configure --initial
</p>
<p>
	————————————————————————————————————————————————————————————
</p>
<p>
	Overwrite /root/.chef/knife.rb? (Y/N) Y
</p>
<p>
	Please enter the chef server URL: [https://workstation:443] <a href="https://chef.example.com:443" rel="nofollow">https://chef.example.com:443</a>
</p>
<p>
	Please enter a name for the new user: [root]
</p>
<p>
	Please enter the existing admin name: [admin] &nbsp;
</p>
<p>
	Please enter the location of the existing admin's private key: [/etc/chef-server/admin.pem] /root/.chef/admin.pem
</p>
<p>
	Please enter the validation clientname: [chef-validator]&nbsp;
</p>
<p>
	Please enter the location of the validation key: [/etc/chef-server/chef-validator.pem] /root/.chef/chef-validator.pem
</p>
<p>
	Please enter the path to a chef repository (or leave blank): /root/chef-repo
</p>
<p>
	Creating initial API user...
</p>
<p>
	Please enter a password for the new user: 123456
</p>
<p>
	<span style="color:#E53333;">注:这里输入API user密码(后面要使用)</span>
</p>
<p>
	Created user[root]
</p>
<p>
	Configuration file written to /root/.chef/knife.rb
</p>
<p>
	————————————————————————————————————————————————————————————
</p>
<p>
	5.配置ruby路径(之前已安装RUBY,这里可以略过)
</p>
<p>
	chef默认集成了一个ruby的稳定版本,需修改PATH变量，保证chef集成的ruby被优先使用.
</p>
<p>
	# echo 'export PATH="/opt/chef/embedded/bin:$PATH"' &gt;&gt; ~/.bash_profile &amp;&amp; source ~/.bash_profile
</p>
<p>
	六.验证chef-workstation
</p>
<p>
	执行knife client list命令返回client列表则配置成功.
</p>
<p>
	# knife client list
</p>
<p>
	——————————————————
</p>
<p>
	chef-validator
</p>
<p>
	chef-webui&nbsp;
</p>
<p>
	——————————————————
</p>
<p>
	七.chef-node配置 (node1.example.com)
</p>
<p>
	node即为被chef-server配置管理的服务器
</p>
<p>
	
</p>
<p>
	1.安装chef-Client
</p>
<p>
	进入页面http://www.opscode.com/chef/install，点击Chef Client标签，选择要下载的版本.
</p>
<p>
	本例使用11.12.4-1版本：
</p>
<p>
	# wget -c --no-check-certificate <a href="https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-11.12.4-1.el6.x86_64.rpm" rel="nofollow">https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-11.12.4-1.el6.x86_64.rpm</a>
</p>
<p>
	# rpm -ivh chef-11.12.4-1.el6.x86_64.rpm
</p>
<p>
	
</p>
<p>
	2.修改本地FQDN名:
</p>
<p>
	1).首先修改主机的hostname&nbsp;
</p>
<p>
	# vi /etc/sysconfig/network
</p>
<p>
	———————-———————-———————-———————-
</p>
<p>
	HOSTNAME=node1.example.com
</p>
<p>
	———————-———————-———————-———————-
</p>
<p>
	2).修改本地host,添加本机和server的FNDN
</p>
<p>
	# echo "10.107.91.251 chef.example.com" &gt;&gt; /etc/hosts
</p>
<p>
	# echo "10.107.91.252 node1.example.com" &gt;&gt; /etc/hosts
</p>
<p>
	重启系统. 登录后验证:
</p>
<p>
	# hostname -f
</p>
<p>
	———————-———————-———————-———————-
</p>
<p>
	node1.example.com
</p>
<p>
	———————-———————-———————-———————-
</p>
<p>
	
</p>
<p>
	3.在chef-worksation执行下面命令添加并配置node
</p>
<p>
	# knife bootstrap node1.example.com -x root -P 123456
</p>
<p>
	<span style="color:#E53333;">注: 这里的密码是node1系统root账号的密码</span>
</p>
<p>
	chef-workstation通过ssh连接到node1(10.107.91.252)上执行bootstrap脚本(chef-workstation /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef<span style="line-height:1.5;">11.6.0/lib/chef/knife/bootstrap/chef-full.erb)可以使用自定义的bootstrap脚本对node进行初始化配置.</span>
</p>
<p>
	<span style="line-height:1.5;">node1会下载https://www.opscode.com/chef/install.sh脚本.脚本检查操作系统类型并在网络上下载符合此系统的chef版本进行安装(下载安装较慢).可以在node上预</span><span style="line-height:1.5;">安装chef(见workstation安装chef部分)跳过此脚本.</span>
</p>
<p>
	———————-———————-———————-———————-—-———————-—-———————-
</p>
<p>
	Connecting to node1.example.com
</p>
<p>
	node1.example.com Starting first Chef Client run...
</p>
<p>
	node1.example.com [2014-05-08T15:53:22+08:00] WARN:&nbsp;
</p>
<p>
	node1.example.com * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *&nbsp;
</p>
<p>
	node1.example.com SSL validation of HTTPS requests is disabled. HTTPS connections are still
</p>
<p>
	node1.example.com encrypted, but chef is not able to detect forged replies or man in the middle
</p>
<p>
	node1.example.com attacks.
</p>
<p>
	node1.example.com&nbsp;
</p>
<p>
	node1.example.com To fix this issue add an entry like this to your configuration file:
</p>
<p>
	node1.example.com&nbsp;
</p>
<p>
	node1.example.com ```
</p>
<p>
	node1.example.com &nbsp; # Verify all HTTPS connections (recommended)
</p>
<p>
	node1.example.com &nbsp; ssl_verify_mode :verify_peer
</p>
<p>
	node1.example.com&nbsp;
</p>
<p>
	node1.example.com &nbsp; # OR, Verify only connections to chef-server
</p>
<p>
	node1.example.com &nbsp; verify_api_cert true
</p>
<p>
	node1.example.com ```
</p>
<p>
	node1.example.com&nbsp;
</p>
<p>
	node1.example.com To check your SSL configuration, or troubleshoot errors, you can use the
</p>
<p>
	node1.example.com `knife ssl check` command like so:
</p>
<p>
	node1.example.com&nbsp;
</p>
<p>
	node1.example.com ```
</p>
<p>
	node1.example.com &nbsp; knife ssl check -c /etc/chef/client.rb
</p>
<p>
	node1.example.com ```
</p>
<p>
	node1.example.com&nbsp;
</p>
<p>
	node1.example.com * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *&nbsp;
</p>
<p>
	node1.example.com&nbsp;
</p>
<p>
	node1.example.com Starting Chef Client, version 11.12.4
</p>
<p>
	node1.example.com Creating a new client identity for node1.example.com using the validator key.
</p>
<p>
	node1.example.com resolving cookbooks for run list: []
</p>
<p>
	node1.example.com Synchronizing Cookbooks:
</p>
<p>
	node1.example.com Compiling Cookbooks...
</p>
<p>
	node1.example.com [2014-05-08T15:53:25+08:00] WARN: Node node1.example.com has an empty run list.
</p>
<p>
	node1.example.com Converging 0 resources
</p>
<p>
	node1.example.com&nbsp;
</p>
<p>
	node1.example.com Running handlers:
</p>
<p>
	node1.example.com Running handlers complete
</p>
<p>
	node1.example.com&nbsp;
</p>
<p>
	node1.example.com Chef Client finished, 0/0 resources updated in 2.393659851 seconds
</p>
<p>
	———————-———————-———————-———————-—-———————-—-———————-
</p>
<p>
	查看是否连接node1成功:
</p>
<p>
	# knife node list
</p>
<p>
	———————-———————-———————
</p>
<p>
	node1
</p>
<p>
	———————-———————-———————
</p>
<p>
	从上面可以看出node1已经成功注册到了chef-server中，整个环境 chef-workstation =&gt; chef-server =&gt; chef-client-1 已经搭建成功。
</p>
<p>
	
</p>
<p>
	八.登陆server web后台
</p>
<p>
	1.修改浏览器本机HOST,这里笔者使用的是MAC系统
</p>
<p>
	# vi /etc/hosts
</p>
<p>
	———————-———————-———————
</p>
<p>
	10.107.91.251 chef.example.com
</p>
<p>
	10.107.91.252 node1.example.com
</p>
<p>
	———————-———————-———————
</p>
<p>
	2.访问https://chef.example.com
</p>
<p>
	
</p>
<p>
	如图:
</p>
<p>
	
</p>
<p>
	
</p>
<p>
	<a href="http://www.showerlee.com/wp-content/uploads/2014/05/1.jpg"><br />
<img onerror="javascript:this.src='http://www.showerlee.com/wp-content/themes/BYMT/images/images_error.jpg'" src="http://www.showerlee.com/wp-content/uploads/2014/05/1-1024x456.jpg" alt="1" width="1024" height="456" /></a><a href="http://www.showerlee.com/wp-content/uploads/2014/05/2.jpg"><img onerror="javascript:this.src='http://www.showerlee.com/wp-content/themes/BYMT/images/images_error.jpg'" src="http://www.showerlee.com/wp-content/uploads/2014/05/2-1024x309.jpg" alt="2" width="1024" height="309" /></a><a href="http://www.showerlee.com/wp-content/uploads/2014/05/3.jpg"><img onerror="javascript:this.src='http://www.showerlee.com/wp-content/themes/BYMT/images/images_error.jpg'" src="http://www.showerlee.com/wp-content/uploads/2014/05/3-1024x502.jpg" alt="3" width="1024" height="502" /></a><a href="http://www.showerlee.com/wp-content/uploads/2014/05/4.jpg"><img onerror="javascript:this.src='http://www.showerlee.com/wp-content/themes/BYMT/images/images_error.jpg'" src="http://www.showerlee.com/wp-content/uploads/2014/05/4-1024x504.jpg" alt="4" width="1024" height="504" /></a>
</p>
<p>
	
</p>
<p>
	九.创建一个cookbook实例
</p>
<p>
	
</p>
<p>
	1.git克隆chef repository (chef.example.com)
</p>
<p>
	<span style="color:#E53333;">注: chef repository 是一个存储cookbooks和其他文件的目录结构,初次使用需要从github克隆</span>
</p>
<p>
	# su -
</p>
<p>
	# cd ~
</p>
<p>
	# git clone git://github.com/opscode/chef-repo.git
</p>
<p>
	———————————————————————————————————
</p>
<p>
	Initialized empty Git repository in /root/chef-repo/.git/
</p>
<p>
	remote: Reusing existing pack: 223, done.
</p>
<p>
	remote: Total 223 (delta 0), reused 0 (delta 0)
</p>
<p>
	Receiving objects: 100% (223/223), 45.77 KiB | 37 KiB/s, done.
</p>
<p>
	Resolving deltas: 100% (57/57), done.<br />
———————————————————————————————————
</p>
<p>
	获取到的目录如下:
</p>
<p>
	<span style="line-height:1.5;"># ls</span>
</p>
<p>
	——————————————————————————————————
</p>
<p>
	Desktop &nbsp; &nbsp;Downloads &nbsp;Pictures &nbsp;Templates &nbsp;anaconda-ks.cfg &nbsp;install.log &nbsp; &nbsp; &nbsp; &nbsp; src
</p>
<p>
	Documents &nbsp;Music &nbsp; &nbsp; &nbsp;Public &nbsp; &nbsp;Videos &nbsp; &nbsp; chef-repo &nbsp; &nbsp; &nbsp; &nbsp;install.log.syslog
</p>
<p>
	——————————————————————————————————
</p>
<p>
	# cd chef-repo/
</p>
<p>
	# ls
</p>
<p>
	——————————————————————————————————
</p>
<p>
	LICENSE &nbsp; &nbsp;Rakefile &nbsp; &nbsp; &nbsp;chefignore &nbsp;cookbooks &nbsp;environments
</p>
<p>
	README.md &nbsp;certificates &nbsp;config &nbsp; &nbsp; &nbsp;data_bags &nbsp;roles
</p>
<p>
	——————————————————————————————————
</p>
<p>
	
</p>
<p>
	2.创建一个cookbook,取名quick_start (chef.example.com)
</p>
<p>
	<span style="color:#E53333;">注:需要切换到之前clone获取到的目录的cookbooks目录下</span>
</p>
<p>
	# cd ~/chef-repo/cookbooks
</p>
<p>
	# knife cookbook create quick_start -o ./
</p>
<p>
	——————————————————————————————————
</p>
<p>
	** Creating cookbook quick_start
</p>
<p>
	** Creating README for cookbook: quick_start
</p>
<p>
	** Creating CHANGELOG for cookbook: quick_start
</p>
<p>
	** Creating metadata for cookbook: quick_start
</p>
<p>
	——————————————————————————————————
</p>
<p>
	创建的cookbooks目录如下
</p>
<p>
	# # ls -1p quick_start
</p>
<p>
	—————————————
</p>
<p>
	CHANGELOG.md
</p>
<p>
	README.md
</p>
<p>
	attributes/
</p>
<p>
	definitions/
</p>
<p>
	files/
</p>
<p>
	libraries/
</p>
<p>
	metadata.rb
</p>
<p>
	providers/
</p>
<p>
	recipes/
</p>
<p>
	resources/
</p>
<p>
	templates/
</p>
<p>
	—————————————
</p>
<p>
	<span style="color:#E53333;">注: cookbooks用来在chef中分布共享,大多数你创建基础实例都需要cookbooks.</span>
</p>
<p>
	<span style="color:#E53333;">&nbsp; &nbsp; 此cookbook实例是创建一个简单的recipe,用来传递给node1一个简单的带有一些已经定义好的变量属性的文本.</span>
</p>
<p>
	
</p>
<p>
	
</p>
<p>
	3.创建一个属性文件,取名"quick_start.rb" (chef.example.com)
</p>
<p>
	# vi ~/chef-repo/cookbooks/quick_start/attributes/quick_start.rb
</p>
<p>
	——————————————————————————
</p>
<p>
	normal[:deep_thought] = "If a tree falls in the forest ..."
</p>
<p>
	——————————————————————————
</p>
<p>
	<span style="color:#E53333;">注: 在cookbook中属性文件用来在node中创建一些配置,从而你可以从recipe中调用这些属性.</span>
</p>
<p>
	
</p>
<p>
	
</p>
<p>
	4.对default recipe创建一个source template源模板 (chef.example.com)
</p>
<p>
	# vi ~/chef-repo/cookbooks/quick_start/recipes/default.rb
</p>
<p>
	——————————————————————————
</p>
<p>
	template "/tmp/deep_thought.txt" do
</p>
<p>
	&nbsp; source "deep_thought.txt.erb"
</p>
<p>
	&nbsp; variables :deep_thought =&gt; node[:deep_thought]
</p>
<p>
	&nbsp; action :create
</p>
<p>
	end
</p>
<p>
	——————————————————————————
</p>
<p>
	<span style="color:#E53333;">注: recipes允许你对具体的源进行管理,这个例子中,你创建了一个叫quick_start的recipe,内容包括一个单独的源模板名叫template "/tmp/deep_thought.txt"&nbsp;</span>
</p>
<p>
	
</p>
<p>
	5.创建一个template模板文件 (chef.example.com)
</p>
<p>
	<span style="color:#E53333;">注:这个文件调用源模板的具体属性,而后被chef传送给具体的node客户端</span>
</p>
<p>
	# vi ~/chef-repo/cookbooks/quick_start/templates/default/deep_thought.txt.erb
</p>
<p>
	——————————————————————————
</p>
<p>
	Today's deep thought: &lt;%= @deep_thought %&gt;
</p>
<p>
	——————————————————————————
</p>
<p>
	
</p>
<p>
	6.将cookbook上传到Server (chef.example.com)
</p>
<p>
	# cd ~/chef-repo/cookbooks/
</p>
<p>
	# ls
</p>
<p>
	——————————————————————————
</p>
<p>
	README.md &nbsp;quick_start
</p>
<p>
	——————————————————————————
</p>
<p>
	
</p>
<p>
	# knife cookbook upload -a -o ./
</p>
<p>
	——————————————————————————
</p>
<p>
	Uploading quick_start &nbsp;[0.1.0]
</p>
<p>
	Uploaded all cookbooks.
</p>
<p>
	——————————————————————————
</p>
<p>
	
</p>
<p>
	确认你刚上传的cookbook
</p>
<p>
	# knife cookbook list
</p>
<p>
	——————————————————————————
</p>
<p>
	quick_start &nbsp; 0.1.0
</p>
<p>
	——————————————————————————
</p>
<p>
	
</p>
<p>
	6.将quick_start recipe添加到你的node中 (chef.example.com)
</p>
<p>
	# knife node run_list add node1.example.com 'recipe[quick_start]'
</p>
<p>
	——————————————————————————
</p>
<p>
	node1.example.com:
</p>
<p>
	run_list: recipe[quick_start]
</p>
<p>
	——————————————————————————
</p>
<p>
	
</p>
<p>
	查看添加好的recipe
</p>
<p>
	# knife &nbsp;node show node1.example.com -r
</p>
<p>
	——————————————————————————
</p>
<p>
	node1.example.com:
</p>
<p>
	run_list: recipe[quick_start]
</p>
<p>
	——————————————————————————
</p>
<p>
	
</p>
<p>
	6.在node客户端注册,从而获取server上recipe的具体实例&nbsp;(node1.example.com)
</p>
<p>
	<span style="color:#E53333;">注:保证/etc/chef下有client.pem与validation.pem证书文件,如果没有检查之前的配置.</span>
</p>
<p>
	# chef-client
</p>
<p>
	————————————————————————————————————
</p>
<p>
	<span style="line-height:1.5;">[2014-05-08T23:55:33+08:00] WARN:&nbsp;</span>
</p>
<p>
	<span style="line-height:1.5;">* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *&nbsp;</span>
</p>
<p>
	<span style="line-height:1.5;">SSL validation of HTTPS requests is disabled. HTTPS connections are still</span>
</p>
<p>
	<span style="line-height:1.5;">encrypted, but chef is not able to detect forged replies or man in the middle</span>
</p>
<p>
	<span style="line-height:1.5;">attacks.</span>
</p>
<p>
	
</p>
<p>
	To fix this issue add an entry like this to your configuration file:
</p>
<p>
	```
</p>
<p>
	&nbsp;# Verify all HTTPS connections (recommended)
</p>
<p>
	<span style="line-height:1.5;">&nbsp;ssl_verify_mode :verify_peer</span>
</p>
<p>
	
</p>
<p>
	&nbsp;# OR, Verify only connections to chef-server
</p>
<p>
	&nbsp;verify_api_cert true
</p>
<p>
	```
</p>
<p>
	To check your SSL configuration, or troubleshoot errors, you can use the
</p>
<p>
	`knife ssl check` command like so:
</p>
<p>
	```
</p>
<p>
	&nbsp;knife ssl check -c /etc/chef/client.rb
</p>
<p>
	```
</p>
<p>
	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *&nbsp;
</p>
<p>
	Starting Chef Client, version 11.12.4
</p>
<p>
	resolving cookbooks for run list: ["quick_start"]
</p>
<p>
	Synchronizing Cookbooks:
</p>
<p>
	&nbsp;- quick_start
</p>
<p>
	Compiling Cookbooks...
</p>
<p>
	Converging 1 resources
</p>
<p>
	Recipe: quick_start::default
</p>
<p>
	&nbsp;* template[/tmp/deep_thought.txt] action create
</p>
<p>
	<span style="line-height:1.5;">&nbsp; &nbsp; - create new file /tmp/deep_thought.txt</span>
</p>
<p>
	<span style="line-height:1.5;">&nbsp; &nbsp; - update content in file /tmp/deep_thought.txt from none to feb62f</span>
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp;--- /tmp/deep_thought.txt &nbsp; &nbsp;2014-05-08 23:55:43.098408727 +0800<br />
&nbsp; &nbsp; &nbsp; &nbsp;+++ /tmp/chef-rendered-template20140508-8171-11cxwpb &nbsp; &nbsp;2014-05-08 23:55:43.099454345 +0800<br />
&nbsp; &nbsp; &nbsp; &nbsp;@@ -1 +1,2 @@<br />
&nbsp; &nbsp; &nbsp; &nbsp;+Today's deep thought: If a tree falls in the forest ...
</p>
<p>
	Running handlers:
</p>
<p>
	Running handlers complete
</p>
<p>
	Chef Client finished, 1/1 resources updated in 9.915108372 seconds
</p>
<p>
	<span style="line-height:1.5;">————————————————————————————————————</span>
</p>
<p>
	
</p>
<p>
	最终执行后,创建 /tmp/deep_thought.txt文件,即实现了server向node的文件分发
</p>
<p>
	# vi &nbsp;/tmp/deep_thought.txt
</p>
<p>
	————————————————————————————————————
</p>
<p>
	Today's deep thought: If a tree falls in the forest ...
</p>
<p>
	————————————————————————————————————
</p>
<p>
	<span style="color:#E53333;">注: warning问题将在以后的文档中解决...</span>
</p>
<p>
	大功告成....</p>
<div>声明: 本文采用 <a rel="external" href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" title="署名-非商业性使用-相同方式共享 3.0 Unported">CC BY-NC-SA 3.0</a> 协议进行授权</div><div>转载请注明来源：<a rel="external" title="DevOps技术分享" href="http://www.showerlee.com/archives/1138">DevOps技术分享</a></div><div>本文链接地址：<a rel="external" title="CentOS 6.3下CHEF环境部署" href="http://www.showerlee.com/archives/1138">http://www.showerlee.com/archives/1138</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.showerlee.com/archives/1138/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CentOS 6.3下编译安装Ruby 2.0</title>
		<link>http://www.showerlee.com/archives/1123</link>
		<comments>http://www.showerlee.com/archives/1123#comments</comments>
		<pubDate>Thu, 10 Apr 2014 08:58:40 +0000</pubDate>
		<dc:creator>showerlee</dc:creator>
				<category><![CDATA[RUBY]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.showerlee.com/?p=1123</guid>
		<description><![CDATA[LINUX操作系统: CentOS6.3 64bit Ruby: ruby-2.0.0-p247 一.安装开发 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p class="p1">
	LINUX操作系统: CentOS6.3 64bit
</p>
<p class="p1">
	Ruby: <a href="http://www.showerlee.com/archives/tag/ruby-2" title="查看ruby中的全部文章" class="tag_link">ruby</a>-2.0.0-p247
</p>
<p class="p1">
	一.安装开发包(使用默认CENTOS更新源):
</p>
<p class="p1">
	# yum install openssl* openssl-devel zlib-devel gcc gcc-c++ make autoconf readline-devel curl-devel expat-devel gettext-devel
</p>
<p class="p2">
	
</p>
<p class="p1">
	二.关闭iptables和SELINUX
</p>
<p class="p1">
	# service iptables stop
</p>
<p class="p1">
	# setenforce 0
</p>
<p class="p1">
	# vi /etc/sysconfig/selinux
</p>
<p class="p1">
	---------------
</p>
<p class="p1">
	SELINUX=disabled
</p>
<p class="p1">
	---------------
</p>
<p class="p2">
	
</p>
<p class="p1">
	三.安装Ruby
</p>
<p class="p1">
	# wget <a href="http://ftp" rel="nofollow">http://ftp</a>.<a href="http://www.showerlee.com/archives/tag/ruby-2" title="查看ruby中的全部文章" class="tag_link">ruby</a>-lang.org/pub/<a href="http://www.showerlee.com/archives/tag/ruby-2" title="查看ruby中的全部文章" class="tag_link">ruby</a>/2.0/<a href="http://www.showerlee.com/archives/tag/ruby-2" title="查看ruby中的全部文章" class="tag_link">ruby</a>-2.0.0-p247.tar.gz
</p>
<p class="p1">
	# tar zxvf <a href="http://www.showerlee.com/archives/tag/ruby-2" title="查看ruby中的全部文章" class="tag_link">ruby</a>-2.0.0-p247.tar.gz
</p>
<p class="p1">
	# cd ruby-2.0.0-p247
</p>
<p class="p1">
	# ./configure --enable-shared --enable-pthread --prefix=/usr/local/ruby
</p>
<p class="p1">
	# make &amp;&amp; make install
</p>
<p class="p2">
	
</p>
<p class="p3">
	编译时报错
</p>
<p class="p3">
	———————————————————————————
</p>
<p class="p3">
	ossl_pkey_ec.c:815: error: ‘EC_GROUP_new_curve_GF2m’ undeclared (first use in this function)
</p>
<p class="p3">
	————————————————————————————
</p>
<p class="p3">
	google后找到官方的一个解决补丁，也就是替换两个ssl库文件，以下为该补丁文件打包下载地址
</p>
<p class="p3">
	<a href="http://www.showerlee.com/wp-content/uploads/2014/04/package.zip" target="_blank"><span style="color:#E53333;">本地下载</span></a>
</p>
<p class="p3">
	<span class="s1">详见：<a href="https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/41808"><span class="s2"><a href="https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/41808" rel="nofollow">https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/41808</a></span></a></span>
</p>
<p class="p1">
	解决方法：
</p>
<p class="p1">
	# cd ruby-2.0.0-p247
</p>
<p class="p1">
	# wget --no-check-certificate&nbsp;<a href="https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/41808/raw/ext/openssl/ossl_pkey_ec.c" rel="nofollow">https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/41808/raw/ext/openssl/ossl_pkey_ec.c</a>
</p>
<p class="p1">
	# wget --no-check-certificate&nbsp;<a href="https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/41808/raw/test/openssl/test_pkey_ec.rb" rel="nofollow">https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/41808/raw/test/openssl/test_pkey_ec.rb</a>
</p>
<p class="p1">
	# mv ext/openssl/ossl_pkey_ec.c &nbsp;ext/openssl/ossl_pkey_ec.c.bak
</p>
<p class="p1">
	# cp ossl_pkey_ec.c ext/openssl/
</p>
<p class="p1">
	# mv test/openssl/test_pkey_ec.rb test/openssl/test_pkey_ec.rb.bak
</p>
<p class="p1">
	# cp test_pkey_ec.rb &nbsp;test/openssl/
</p>
<p class="p1">
	重新编译：
</p>
<p class="p1">
	# make &amp;&amp; make install
</p>
<p class="p2">
	
</p>
<p class="p1">
	四.将ruby命令集加入系统环境变量
</p>
<p class="p1">
	# echo "PATH=$PATH:/usr/local/ruby/bin;export PATH" &gt;&gt; /etc/profile
</p>
<p class="p1">
	# source /etc/profile
</p>
<p class="p2">
	
</p>
<p class="p1">
	五.检查ruby版本
</p>
<p class="p1">
	# ruby -v
</p>
<p class="p1">
	——————————————————————————
</p>
<p class="p1">
	ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
</p>
<p class="p1">
	——————————————————————————
</p>
<p class="p2">
	
</p>
<p class="p1">
	# gem --version
</p>
<p class="p1">
	——————————————————————————
</p>
<p class="p1">
	2.0.3
</p>
<p class="p1">
	——————————————————————————
</p>
<p class="p2">
	
</p>
<p class="p1">
	# irb
</p>
<p class="p1">
	——————————————————————————
</p>
<p class="p1">
	irb(main):001:0&gt; 3+5
</p>
<p class="p1">
	=&gt; 8
</p>
<p class="p1">
	irb(main):002:0&gt; puts "hello world!"
</p>
<p class="p1">
	hello world!
</p>
<p class="p1">
	——————————————————————————
</p>
<p class="p2">
	
</p>
<p class="p1">
	大功告成 O(∩_∩)O~</p>
<div>声明: 本文采用 <a rel="external" href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" title="署名-非商业性使用-相同方式共享 3.0 Unported">CC BY-NC-SA 3.0</a> 协议进行授权</div><div>转载请注明来源：<a rel="external" title="DevOps技术分享" href="http://www.showerlee.com/archives/1123">DevOps技术分享</a></div><div>本文链接地址：<a rel="external" title="CentOS 6.3下编译安装Ruby 2.0" href="http://www.showerlee.com/archives/1123">http://www.showerlee.com/archives/1123</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.showerlee.com/archives/1123/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
