<?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; chef</title>
	<atom:link href="http://www.showerlee.com/archives/tag/chef-2/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批量部署APACHE</title>
		<link>http://www.showerlee.com/archives/1145</link>
		<comments>http://www.showerlee.com/archives/1145#comments</comments>
		<pubDate>Thu, 29 May 2014 04:23:53 +0000</pubDate>
		<dc:creator>showerlee</dc:creator>
				<category><![CDATA[CHEF]]></category>
		<category><![CDATA[APACHE]]></category>
		<category><![CDATA[chef]]></category>

		<guid isPermaLink="false">http://www.showerlee.com/?p=1145</guid>
		<description><![CDATA[之前的博文我介绍了如何搭建CHEF环境以及创建编写cookbook,resipes用来批量将cookbook下 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>
	之前的博文我介绍了如何搭建CHEF环境以及创建编写cookbook,resipes用来批量将cookbook下发到客户端执行相应的部署操作.
</p>
<p>
	NOW,本篇文档我们会详细介绍如何利用CHEF独有的框架语言来批量部署安装<a href="http://www.showerlee.com/archives/tag/apache" title="查看APACHE中的全部文章" class="tag_link">APACHE</a>,并加载其HTTPS模块等功能.
</p>
<p>
	相信如果你看了本篇文档,利用CHEF实现一个批量自动化部署将不是什么难事.
</p>
<p>
	
</p>
<p>
	CHEF环境部署详见:&nbsp;<a href="http://showerlee.blog.51cto.com/2047005/1408467" target="_blank">http://showerlee.blog.51cto.com/2047005/1408467</a>
</p>
<p>
	
</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>
	<span style="line-height:1.5;">Server : &nbsp; &nbsp; &nbsp; &nbsp; &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)</span>
</p>
<p>
	<span style="line-height:1.5;">Workstation: &nbsp; &nbsp; 10.107.91.251 (chef.example.com)</span>
</p>
<p>
	<span style="line-height:1.5;">node: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;10.107.91.252 (node1.example.com)</span>
</p>
<p>
	
</p>
<p>
	一. 创建一个空的cookbook实例,并命名为apache&nbsp;(chef.example.com)
</p>
<p>
	# su -
</p>
<p>
	# cd ~/chef-repo/cookbooks/
</p>
<p>
	# knife cookbook create apache
</p>
<p>
	# ls
</p>
<p>
	------------------------------------------------------------------------------------------------
</p>
<p>
	README.md &nbsp;apache &nbsp;quick_start
</p>
<p>
	------------------------------------------------------------------------------------------------
</p>
<p>
	# cd apache
</p>
<p>
	# ls&nbsp;
</p>
<p>
	------------------------------------------------------------------------------------------------
</p>
<p>
	CHANGELOG.md &nbsp;attributes &nbsp; files &nbsp; &nbsp; &nbsp;metadata.rb &nbsp;recipes &nbsp; &nbsp;templates
</p>
<p>
	README.md &nbsp; &nbsp; definitions &nbsp;libraries &nbsp;providers &nbsp; &nbsp;resources
</p>
<p>
	------------------------------------------------------------------------------------------------
</p>
<p>
	
</p>
<p>
	二. 创建SSL秘钥证书并复制到apache的cookbook对应文件夹&nbsp;(chef.example.com)
</p>
<p>
	1.证书配置:
</p>
<p>
	1).下载并解压ssl证书生成压缩包:
</p>
<p>
	# cd ~/chef-repo/cookbooks/apache/files/default
</p>
<p>
	# mkdir certificates
</p>
<p>
	# cd certificates
</p>
<p>
	# wget <a href="http://www.openssl.org/contrib/ssl.ca-0.1.tar.gz" rel="nofollow">http://www.openssl.org/contrib/ssl.ca-0.1.tar.gz</a>
</p>
<p>
	# tar zxvf ssl.ca-0.1.tar.gz
</p>
<p>
	# cd ssl.ca-0.1
</p>
<p>
	
</p>
<p>
	2).利用ssl内脚本生成根证书:
</p>
<p>
	# ./new-root-ca.sh &nbsp;
</p>
<p>
	----------------------------------------------------------------------------------------------
</p>
<p>
	No Root CA key round. Generating one
</p>
<p>
	Generating RSA private key, 1024 bit &nbsp;long modulus
</p>
<p>
	………………………++++++
</p>
<p>
	….++++++
</p>
<p>
	e is 65537 (0×10001)
</p>
<p>
	Enter &nbsp;pass phrase for ca.key:&nbsp;(输入一个密码)
</p>
<p>
	Verifying – Enter pass phrase for ca.key: &nbsp;(再输入一次密码)
</p>
<p>
	……
</p>
<p>
	Self-sign the root CA… (签署根证书)
</p>
<p>
	Enter pass phrase for &nbsp;ca.key:&nbsp;(输入刚刚设置的密码)
</p>
<p>
	……..
</p>
<p>
	……..&nbsp;(下面开始签署)
</p>
<p>
	Country Name (2 letter code) &nbsp;[MY]:CN
</p>
<p>
	State or Province Name (full name) [Perak]:JiangSu
</p>
<p>
	Locality Name &nbsp;(eg, city) [Sitiawan]:NanJing
</p>
<p>
	Organization Name (eg, company) [My Directory &nbsp;Sdn Bhd]:example Co.,Ltd
</p>
<p>
	Organizational Unit Name (eg, section) &nbsp;[Certification Services Division]:example
</p>
<p>
	Common Name (eg, MD Root CA) &nbsp;[]:example
</p>
<p>
	Email Address []:info@example.com
</p>
<p>
	---------------------------------------------------------------------------------------------
</p>
<p>
	这样就生成了ca.key和ca.crt两个文件
</p>
<p>
	
</p>
<p>
	3).生成服务端证书:
</p>
<p>
	# ./new-server-cert.sh server &nbsp;
</p>
<p>
	<span style="color:#E53333;">注:证书名为server</span>
</p>
<p>
	-----------------------------------------------------------------------------------------------
</p>
<p>
	……
</p>
<p>
	……
</p>
<p>
	Country Name (2 letter code) [MY]:CN
</p>
<p>
	State or &nbsp;Province Name (full name) [Perak]:JiangSu
</p>
<p>
	Locality Name (eg, city) &nbsp;[Sitiawan]:NanJing
</p>
<p>
	Organization Name (eg, company) [My Directory Sdn &nbsp;Bhd]:example Co.,Ltd
</p>
<p>
	Organizational Unit Name (eg, section) [Secure Web &nbsp;Server]:example
</p>
<p>
	Common Name (eg, <a href="http://www.domain.com" rel="nofollow">http://www.domain.com</a>) &nbsp;[]:www.example.com
</p>
<p>
	Email Address &nbsp;[]:info@example.com
</p>
<p>
	------------------------------------------------------------------------------------------------
</p>
<p>
	这样就生成了server.csr和server.key这两个文件。
</p>
<p>
	
</p>
<p>
	4).签署服务端证书:
</p>
<p>
	# &nbsp;./sign-server-cert.sh server
</p>
<p>
	--------------------------------------------------------------------------------------------
</p>
<p>
	CA signing: server.csr -&gt; &nbsp;server.crt:
</p>
<p>
	Using configuration from ca.config
</p>
<p>
	Enter pass phrase for &nbsp;./ca.key:&nbsp;(输入上面设置的根证书密码)
</p>
<p>
	Check that the request matches the &nbsp;signature
</p>
<p>
	Signature ok
</p>
<p>
	The Subject’s Distinguished Name is as &nbsp;follows
</p>
<p>
	countryName &nbsp; RINTABLE:’CN’
</p>
<p>
	stateOrProvinceName &nbsp; RINTABLE:’JiangSu’
</p>
<p>
	localityName &nbsp; RINTABLE:’NanJing’
</p>
<p>
	organizationName &nbsp; RINTABLE:’example Co.,Ltd’
</p>
<p>
	organizationalUnitName:PRINTABLE:’example’
</p>
<p>
	commonName &nbsp; RINTABLE:’www.example.com’
</p>
<p>
	emailAddress &nbsp;:IA5STRING:’info@example.com’
</p>
<p>
	Certificate is to be certified until Jul 16 &nbsp;12:55:34 2005 GMT (365 days)
</p>
<p>
	Sign the certificate? [y/n]:y
</p>
<p>
	1 out of 1 &nbsp;certificate requests certified, commit? [y/n]y
</p>
<p>
	Write out database with 1 new &nbsp;entries
</p>
<p>
	Data Base Updated
</p>
<p>
	CA verifying: server.crt &lt;-&gt; CA &nbsp;cert
</p>
<p>
	server.crt: OK
</p>
<p>
	--------------------------------------------------------------------------------------
</p>
<p>
	
</p>
<p>
	2.复制证书到cookbook相应位置
</p>
<p>
	# pwd
</p>
<p>
	--------------------------------------------------------------------------------------
</p>
<p>
	/root/chef-repo/cookbooks/apache/files/default/certificates/ssl.ca-0.1
</p>
<p>
	--------------------------------------------------------------------------------------
</p>
<p>
	# cp server.crt server.key ca.crt ..
</p>
<p>
	# cd ..
</p>
<p>
	# ls
</p>
<p>
	--------------------------------------------------------------------------------------
</p>
<p>
	ca.crt &nbsp;server.crt &nbsp;server.key &nbsp;ssl.ca-0.1 &nbsp;ssl.ca-0.1.tar.gz
</p>
<p>
	--------------------------------------------------------------------------------------
</p>
<p>
	
</p>
<p>
	
</p>
<p>
	三. 定义cookbook变量属性&nbsp;(chef.example.com)
</p>
<p>
	# cd ~/chef-repo/cookbooks/apache/attributes
</p>
<p>
	# vi default.rb
</p>
<p>
	--------------------------------------------------------------------------------------
</p>
<p>
	default['apache']['dir'] &nbsp; &nbsp; = "/etc/httpd"
</p>
<p>
	default['apache']['sslpath'] &nbsp; &nbsp;= "/etc/httpd/ssl"
</p>
<p>
	default['apache']['servername'] = "node1.example.com"
</p>
<p>
	--------------------------------------------------------------------------------------
</p>
<p>
	
</p>
<p>
	四.编写recipes(可按照实际部署需求修改)&nbsp;(chef.example.com)
</p>
<p>
	# cd ~/chef-repo/cookbooks/apache/recipes
</p>
<p>
	# vi default.rb
</p>
<p>
	--------------------------------------------------------------------------------------
</p>
<p>
	# Cookbook Name:: apache
</p>
<p>
	# Recipe:: default
</p>
<p>
	#
</p>
<p>
	# Copyright 2013, YOUR_COMPANY_NAME
</p>
<p>
	#
</p>
<p>
	# All rights reserved - Do Not Redistribute
</p>
<p>
	#
</p>
<p>
	
</p>
<p>
	# Install httpd package but don't start it
</p>
<p>
	package "httpd" do
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp;action [:install]
</p>
<p>
	end
</p>
<p>
	
</p>
<p>
	# Install mod_ssl package to enable ssl module in apache
</p>
<p>
	package "mod_ssl" do
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp;action [:install]
</p>
<p>
	end
</p>
<p>
	
</p>
<p>
	# Stop iptables service permanently
</p>
<p>
	service "iptables" do
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp;action [:disable,:stop]
</p>
<p>
	end
</p>
<p>
	
</p>
<p>
	# Stop ip6tables service permanently&nbsp;
</p>
<p>
	service "ip6tables" do
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp;action [:disable,:stop]
</p>
<p>
	end
</p>
<p>
	
</p>
<p>
	# Create /etc/httpd/ssl directory on chef client
</p>
<p>
	directory "#{node['apache']['dir']}/ssl" do<br />
<span style="line-height:1.5;">&nbsp; &nbsp; &nbsp; action :create</span>
</p>
<p>
	<span style="line-height:1.5;">&nbsp; &nbsp; &nbsp; recursive true</span>
</p>
<p>
	<span style="line-height:1.5;">&nbsp; &nbsp; &nbsp; mode 0755</span>
</p>
<p>
	<span style="line-height:1.5;">end</span>
</p>
<p>
	
</p>
<p>
	# Copy ssl certificates from certificates folder to client's /etc/httpd/ssl folder
</p>
<p>
	remote_directory "#{node['apache']['dir']}/ssl" do
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp;source "certificates"
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp;files_owner "root"
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp;files_group "root"
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp;files_mode 00644
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp;owner "root"
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp;group "root"
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp;mode 0755
</p>
<p>
	end
</p>
<p>
	
</p>
<p>
	# This will make changes to ssl.conf&nbsp;
</p>
<p>
	template "/etc/httpd/conf.d/ssl.conf" do
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp;source "ssl.conf.erb"
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp;mode 0644
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp;owner "root"
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp;group "root"
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp;variables(
</p>
<p>
	:sslcertificate =&gt; "#{node['apache']['sslpath']}/server.crt",
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:sslkey =&gt; "#{node['apache']['sslpath']}/server.key",
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:sslcacertificate =&gt; "#{node['apache']['sslpath']}/ca.crt",
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:servername =&gt; "#{node['apache']['servername']}"
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp;)
</p>
<p>
	end
</p>
<p>
	# start httpd service
</p>
<p>
	service "httpd" do
</p>
<p>
	&nbsp; &nbsp;action [:enable,:start]
</p>
<p>
	end
</p>
<p>
	<span style="line-height:1.5;">--------------------------------------------------------------------------------------</span>
</p>
<p>
	
</p>
<p>
	
</p>
<p>
	五.定义templates&nbsp;(chef.example.com)
</p>
<p>
	
</p>
<p>
	<span style="color:#E53333;">注:这里实际上就是将apache原有的配置文件中需要修改的参数添加chef自有的变量属性,部署到client端,实现apache的自定义配置.</span>
</p>
<p>
	<span style="color:#E53333;">此处仅仅更改了SSL证书的具体路径,如果有其他需要可按此语法格式进行修改.</span>
</p>
<p>
	# cd ~/chef-repo/cookbooks/apache/templates/default
</p>
<p>
	# vi ssl.conf.erb
</p>
<p>
	--------------------------------------------------------------------------------------
</p>
<p>
	#
</p>
<p>
	# This is the Apache server configuration file providing SSL support.
</p>
<p>
	# It contains the configuration directives to instruct the server how to
</p>
<p>
	# serve pages over an https connection. For detailing information about these
</p>
<p>
	# directives see &lt;URL:<a href="http://httpd.apache.org/docs/2.2/mod/mod_ssl.html&#038;gt" rel="nofollow">http://httpd.apache.org/docs/2.2/mod/mod_ssl.html&#038;gt</a>;
</p>
<p>
	#
</p>
<p>
	# Do NOT simply read the instructions in here without understanding
</p>
<p>
	# what they do. &nbsp;They're here only as hints or reminders. &nbsp;If you are unsure
</p>
<p>
	# consult the online docs. You have been warned.
</p>
<p>
	#
</p>
<p>
	LoadModule ssl_module modules/mod_ssl.so
</p>
<p>
	#
</p>
<p>
	# When we also provide SSL we have to listen to the
</p>
<p>
	# the HTTPS port in addition.
</p>
<p>
	#
</p>
<p>
	Listen 443
</p>
<p>
	##
</p>
<p>
	## &nbsp;SSL Global Context
</p>
<p>
	##
</p>
<p>
	## &nbsp;All SSL configuration in this context applies both to
</p>
<p>
	## &nbsp;the main server and all SSL-enabled virtual hosts.
</p>
<p>
	##
</p>
<p>
	# &nbsp; Pass Phrase Dialog:
</p>
<p>
	# &nbsp; Configure the pass phrase gathering process.
</p>
<p>
	# &nbsp; The filtering dialog program (`builtin' is a internal
</p>
<p>
	# &nbsp; terminal dialog) has to provide the pass phrase on stdout.
</p>
<p>
	SSLPassPhraseDialog &nbsp;builtin
</p>
<p>
	# &nbsp; Inter-Process Session Cache:
</p>
<p>
	# &nbsp; Configure the SSL Session Cache: First the mechanism
</p>
<p>
	# &nbsp; to use and second the expiring timeout (in seconds).
</p>
<p>
	SSLSessionCache &nbsp; &nbsp; &nbsp; &nbsp; shmcb:/var/cache/mod_ssl/scache(512000)
</p>
<p>
	SSLSessionCacheTimeout &nbsp;300
</p>
<p>
	# &nbsp; Semaphore:
</p>
<p>
	# &nbsp; Configure the path to the mutual exclusion semaphore the
</p>
<p>
	# &nbsp; SSL engine uses internally for inter-process synchronization.
</p>
<p>
	SSLMutex default
</p>
<p>
	# &nbsp; Pseudo Random Number Generator (PRNG):
</p>
<p>
	# &nbsp; Configure one or more sources to seed the PRNG of the
</p>
<p>
	# &nbsp; SSL library. The seed data should be of good random quality.
</p>
<p>
	# &nbsp; WARNING! On some platforms /dev/random blocks if not enough entropy
</p>
<p>
	# &nbsp; is available. This means you then cannot use the /dev/random device
</p>
<p>
	# &nbsp; because it would lead to very long connection times (as long as
</p>
<p>
	# &nbsp; it requires to make more entropy available). But usually those
</p>
<p>
	# &nbsp; platforms additionally provide a /dev/urandom device which doesn't
</p>
<p>
	# &nbsp; block. So, if available, use this one instead. Read the mod_ssl User
</p>
<p>
	# &nbsp; Manual for more details.
</p>
<p>
	SSLRandomSeed startup file:/dev/urandom &nbsp;256
</p>
<p>
	SSLRandomSeed connect builtin
</p>
<p>
	#SSLRandomSeed startup file:/dev/random &nbsp;512
</p>
<p>
	#SSLRandomSeed connect file:/dev/random &nbsp;512
</p>
<p>
	#SSLRandomSeed connect file:/dev/urandom 512
</p>
<p>
	#
</p>
<p>
	# Use "SSLCryptoDevice" to enable any supported hardware
</p>
<p>
	# accelerators. Use "openssl engine -v" to list supported
</p>
<p>
	# engine names. &nbsp;NOTE: If you enable an accelerator and the
</p>
<p>
	# server does not start, consult the error logs and ensure
</p>
<p>
	# your accelerator is functioning properly.
</p>
<p>
	#
</p>
<p>
	SSLCryptoDevice builtin
</p>
<p>
	#SSLCryptoDevice ubsec
</p>
<p>
	##
</p>
<p>
	## SSL Virtual Host Context
</p>
<p>
	##
</p>
<p>
	&lt;VirtualHost _default_:443&gt;
</p>
<p>
	# General setup for the virtual host, inherited from global configuration
</p>
<p>
	#DocumentRoot "/var/www/html"
</p>
<p>
	ServerName <span style="color:#E53333;">&lt;%= @servername %&gt;:443</span>
</p>
<p>
	# Use separate log files for the SSL virtual host; note that LogLevel
</p>
<p>
	# is not inherited from httpd.conf.
</p>
<p>
	ErrorLog logs/ssl_error_log
</p>
<p>
	TransferLog logs/ssl_access_log
</p>
<p>
	LogLevel warn
</p>
<p>
	# &nbsp; SSL Engine Switch:
</p>
<p>
	# &nbsp; Enable/Disable SSL for this virtual host.
</p>
<p>
	SSLEngine on
</p>
<p>
	# &nbsp; SSL Protocol support:
</p>
<p>
	# List the enable protocol levels with which clients will be able to
</p>
<p>
	# connect. &nbsp;Disable SSLv2 access by default:
</p>
<p>
	SSLProtocol all -SSLv2
</p>
<p>
	# &nbsp; SSL Cipher Suite:
</p>
<p>
	# List the ciphers that the client is permitted to negotiate.
</p>
<p>
	# See the mod_ssl documentation for a complete list.
</p>
<p>
	SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
</p>
<p>
	# &nbsp; Server Certificate:
</p>
<p>
	# Point SSLCertificateFile at a PEM encoded certificate. &nbsp;If
</p>
<p>
	# the certificate is encrypted, then you will be prompted for a
</p>
<p>
	# pass phrase. &nbsp;Note that a kill -HUP will prompt again. &nbsp;A new
</p>
<p>
	# certificate can be generated using the genkey(1) command.
</p>
<p>
	SSLCertificateFile&nbsp;<span style="color:#E53333;">&lt;%= @sslcertificate %&gt;</span>
</p>
<p>
	# &nbsp; Server Private Key:
</p>
<p>
	# &nbsp; If the key is not combined with the certificate, use this
</p>
<p>
	# &nbsp; directive to point at the key file. &nbsp;Keep in mind that if
</p>
<p>
	# &nbsp; you've both a RSA and a DSA private key you can configure
</p>
<p>
	# &nbsp; both in parallel (to also allow the use of DSA ciphers, etc.)
</p>
<p>
	SSLCertificateKeyFile&nbsp;<span style="color:#E53333;">&lt;%= @sslkey %&gt;</span>
</p>
<p>
	# &nbsp; Server Certificate Chain:
</p>
<p>
	# &nbsp; Point SSLCertificateChainFile at a file containing the
</p>
<p>
	# &nbsp; concatenation of PEM encoded CA certificates which form the
</p>
<p>
	# &nbsp; certificate chain for the server certificate. Alternatively
</p>
<p>
	# &nbsp; the referenced file can be the same as SSLCertificateFile
</p>
<p>
	# &nbsp; when the CA certificates are directly appended to the server
</p>
<p>
	# &nbsp; certificate for convinience.
</p>
<p>
	#SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt
</p>
<p>
	# &nbsp; Certificate Authority (CA):
</p>
<p>
	# &nbsp; Set the CA certificate verification path where to find CA
</p>
<p>
	# &nbsp; certificates for client authentication or alternatively one
</p>
<p>
	# &nbsp; huge file containing all of them (file must be PEM encoded)
</p>
<p>
	SSLCACertificateFile&nbsp;<span style="color:#E53333;">&lt;%= @sslcacertificate %&gt;</span>
</p>
<p>
	# &nbsp; Client Authentication (Type):
</p>
<p>
	# &nbsp; Client certificate verification type and depth. &nbsp;Types are
</p>
<p>
	# &nbsp; none, optional, require and optional_no_ca. &nbsp;Depth is a
</p>
<p>
	# &nbsp; number which specifies how deeply to verify the certificate
</p>
<p>
	# &nbsp; issuer chain before deciding the certificate is not valid.
</p>
<p>
	#SSLVerifyClient require
</p>
<p>
	#SSLVerifyDepth &nbsp;10
</p>
<p>
	# &nbsp; Access Control:
</p>
<p>
	# &nbsp; With SSLRequire you can do per-directory access control based
</p>
<p>
	# &nbsp; on arbitrary complex boolean expressions containing server
</p>
<p>
	# &nbsp; variable checks and other lookup directives. &nbsp;The syntax is a
</p>
<p>
	# &nbsp; mixture between C and Perl. &nbsp;See the mod_ssl documentation
</p>
<p>
	# &nbsp; for more details.
</p>
<p>
	#&lt;Location /&gt;
</p>
<p>
	#SSLRequire ( &nbsp; &nbsp;%{SSL_CIPHER} !~ m/^(EXP|NULL)/ \
</p>
<p>
	# &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd." \
</p>
<p>
	# &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"} \
</p>
<p>
	# &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and %{TIME_WDAY} &gt;= 1 and %{TIME_WDAY} &lt;= 5 \
</p>
<p>
	# &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and %{TIME_HOUR} &gt;= 8 and %{TIME_HOUR} &lt;= 20 &nbsp; &nbsp; &nbsp; ) \
</p>
<p>
	# &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; or %{REMOTE_ADDR} =~ m/^192\.76\.162\.[0-9]+$/
</p>
<p>
	#&lt;/Location&gt;
</p>
<p>
	# &nbsp; SSL Engine Options:
</p>
<p>
	# &nbsp; Set various options for the SSL engine.
</p>
<p>
	# &nbsp; o FakeBasicAuth:
</p>
<p>
	# &nbsp; &nbsp; Translate the client X.509 into a Basic Authorisation. &nbsp;This means that
</p>
<p>
	# &nbsp; &nbsp; the standard Auth/DBMAuth methods can be used for access control. &nbsp;The
</p>
<p>
	# &nbsp; &nbsp; user name is the `one line' version of the client's X.509 certificate.
</p>
<p>
	# &nbsp; &nbsp; Note that no password is obtained from the user. Every entry in the user
</p>
<p>
	# &nbsp; &nbsp; file needs this password: `xxj31ZMTZzkVA'.
</p>
<p>
	# &nbsp; o ExportCertData:
</p>
<p>
	# &nbsp; &nbsp; This exports two additional environment variables: SSL_CLIENT_CERT and
</p>
<p>
	# &nbsp; &nbsp; SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
</p>
<p>
	# &nbsp; &nbsp; server (always existing) and the client (only existing when client
</p>
<p>
	# &nbsp; &nbsp; authentication is used). This can be used to import the certificates
</p>
<p>
	# &nbsp; &nbsp; into CGI scripts.
</p>
<p>
	# &nbsp; o StdEnvVars:
</p>
<p>
	# &nbsp; &nbsp; This exports the standard SSL/TLS related `SSL_*' environment variables.
</p>
<p>
	# &nbsp; &nbsp; Per default this exportation is switched off for performance reasons,
</p>
<p>
	# &nbsp; &nbsp; because the extraction step is an expensive operation and is usually
</p>
<p>
	# &nbsp; &nbsp; useless for serving static content. So one usually enables the
</p>
<p>
	# &nbsp; &nbsp; exportation for CGI and SSI requests only.
</p>
<p>
	# &nbsp; o StrictRequire:
</p>
<p>
	# &nbsp; &nbsp; This denies access when "SSLRequireSSL" or "SSLRequire" applied even
</p>
<p>
	# &nbsp; &nbsp; under a "Satisfy any" situation, i.e. when it applies access is denied
</p>
<p>
	# &nbsp; &nbsp; and no other module can change it.
</p>
<p>
	# &nbsp; o OptRenegotiate:
</p>
<p>
	# &nbsp; &nbsp; This enables optimized SSL connection renegotiation handling when SSL
</p>
<p>
	# &nbsp; &nbsp; directives are used in per-directory context.
</p>
<p>
	#SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
</p>
<p>
	&lt;Files ~ "\.(cgi|shtml|phtml|php3?)$"&gt;
</p>
<p>
	&nbsp; &nbsp;SSLOptions +StdEnvVars
</p>
<p>
	&lt;/Files&gt;
</p>
<p>
	&lt;Directory "/var/www/cgi-bin"&gt;
</p>
<p>
	&nbsp; &nbsp;SSLOptions +StdEnvVars
</p>
<p>
	&lt;/Directory&gt;
</p>
<p>
	# &nbsp; SSL Protocol Adjustments:
</p>
<p>
	# &nbsp; The safe and default but still SSL/TLS standard compliant shutdown
</p>
<p>
	# &nbsp; approach is that mod_ssl sends the close notify alert but doesn't wait for
</p>
<p>
	# &nbsp; the close notify alert from client. When you need a different shutdown
</p>
<p>
	# &nbsp; approach you can use one of the following variables:
</p>
<p>
	# &nbsp; o ssl-unclean-shutdown:
</p>
<p>
	# &nbsp; &nbsp; This forces an unclean shutdown when the connection is closed, i.e. no
</p>
<p>
	# &nbsp; &nbsp; SSL close notify alert is send or allowed to received. &nbsp;This violates
</p>
<p>
	# &nbsp; &nbsp; the SSL/TLS standard but is needed for some brain-dead browsers. Use
</p>
<p>
	# &nbsp; &nbsp; this when you receive I/O errors because of the standard approach where
</p>
<p>
	# &nbsp; &nbsp; mod_ssl sends the close notify alert.
</p>
<p>
	# &nbsp; o ssl-accurate-shutdown:
</p>
<p>
	<span style="line-height:1.5;"># &nbsp; &nbsp; This forces an accurate shutdown when the connection is closed, i.e. a</span>
</p>
<p>
	# &nbsp; &nbsp; SSL close notify alert is send and mod_ssl waits for the close notify
</p>
<p>
	# &nbsp; &nbsp; alert of the client. This is 100% SSL/TLS standard compliant, but in
</p>
<p>
	# &nbsp; &nbsp; practice often causes hanging connections with brain-dead browsers. Use
</p>
<p>
	<span style="line-height:1.5;"># &nbsp; &nbsp; this only for browsers where you know that their SSL implementation</span>
</p>
<p>
	<span style="line-height:1.5;"># &nbsp; &nbsp; works correctly.</span>
</p>
<p>
	<span style="line-height:1.5;"># &nbsp; Notice: Most problems of broken clients are also related to the HTTP</span>
</p>
<p>
	<span style="line-height:1.5;"># &nbsp; keep-alive facility, so you usually additionally want to disable</span>
</p>
<p>
	<span style="line-height:1.5;"># &nbsp; keep-alive for those clients, too. Use variable "nokeepalive" for this.</span>
</p>
<p>
	# &nbsp; Similarly, one has to force some clients to use HTTP/1.0 to workaround
</p>
<p>
	# &nbsp; their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
</p>
<p>
	# &nbsp; "force-response-1.0" for this.
</p>
<p>
	SetEnvIf User-Agent ".*MSIE.*" \
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp; nokeepalive ssl-unclean-shutdown \
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp; downgrade-1.0 force-response-1.0
</p>
<p>
	# &nbsp; Per-Server Logging:
</p>
<p>
	# &nbsp; The home of a custom SSL log file. Use this when you want a
</p>
<p>
	# &nbsp; compact non-error SSL logfile on a virtual host basis.
</p>
<p>
	CustomLog logs/ssl_request_log \
</p>
<p>
	&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</p>
<p>
	
</p>
<p>
	&lt;/VirtualHost&gt;
</p>
<p>
	--------------------------------------------------------------------------------------
</p>
<p>
	
</p>
<p>
	六.上传cookbook&nbsp;(chef.example.com)
</p>
<p>
	# cd /root/chef-repo/cookbooks
</p>
<p>
	# knife cookbook upload apache
</p>
<p>
	--------------------------------------------------------------------------------------
</p>
<p>
	Uploading apache &nbsp; &nbsp; &nbsp; &nbsp; [0.1.0]
</p>
<p>
	Uploaded 1 cookbook.
</p>
<p>
	--------------------------------------------------------------------------------------
</p>
<p>
	
</p>
<p>
	七.创建Role&nbsp;(chef.example.com)
</p>
<p>
	<span style="color:#E53333;">注:简单来说Role就是实现一个能在Server端批量下发cookbook并自动开始对所有client的部署,此前的方法部署client端需要登录其SHELL执行chef-client,方能开始部署,少量部署无所谓,但批量的话执行效率会大大降低.</span>
</p>
<p>
	1). 设置editor环境变量
</p>
<p>
	# echo 'export EDITOR=$(which vi)' &gt;&gt; ~/.bashrc
</p>
<p>
	# source ~/.bashrc
</p>
<p>
	
</p>
<p>
	2). 编写Role,将默认替换成如下内容.
</p>
<p>
	# knife role create webserver
</p>
<p>
	--------------------------------------------------------------------------------------
</p>
<p>
	{
</p>
<p>
	&nbsp;"run_list": [
</p>
<p>
	&nbsp; &nbsp;"recipe[apache]"
</p>
<p>
	&nbsp;],
</p>
<p>
	&nbsp;"chef_type": "role",
</p>
<p>
	&nbsp;"env_run_lists": {
</p>
<p>
	&nbsp;},
</p>
<p>
	&nbsp;"description": "apache webserver",
</p>
<p>
	&nbsp;"override_attributes": {
</p>
<p>
	&nbsp;},
</p>
<p>
	&nbsp;"json_class": "Chef::Role",
</p>
<p>
	&nbsp;"default_attributes": {
</p>
<p>
	&nbsp;},
</p>
<p>
	&nbsp;"name": "webserver"
</p>
<p>
	}
</p>
<p>
	--------------------------------------------------------------------------------------
</p>
<p>
	
</p>
<p>
	八. Bootstrap客户端.
</p>
<p>
	<span style="color:#E53333;">注: bootstrap是一个将CHEF具体的cookbook实例部署到目标客户端的程序,因此他可以在server端实现client本地执行最后部署命令chef-client的功能</span>
</p>
<p>
	1. 首先需要做一个CHEF的server端到client端的SSH秘钥认证,实现server端无需输入SSH密码即可登录client执行部署.
</p>
<p>
	1) .在CHEF的Server端(SSH客户端)创建秘钥对：(chef.example.com)
</p>
<p>
	# su - root
</p>
<p>
	# ssh-keygen -t dsa
</p>
<p>
	一路回车即可
</p>
<p>
	----------------------
</p>
<p>
	Generating public/private dsa key pair.
</p>
<p>
	<span style="line-height:1.5;">Enter file in which to save the key (/root/.ssh/id_dsa):</span>
</p>
<p>
	<span style="line-height:1.5;">Created directory '/root/.ssh'.</span>
</p>
<p>
	<span style="line-height:1.5;">Enter passphrase (empty for no passphrase):</span>
</p>
<p>
	<span style="line-height:1.5;">Enter same passphrase again:</span>
</p>
<p>
	Your identification has been saved in /root/.ssh/id_dsa.
</p>
<p>
	Your public key has been saved in /root/.ssh/id_dsa.pub.
</p>
<p>
	The key fingerprint is:
</p>
<p>
	e9:5e:4a:7f:79:64:c5:ae:f2:06:a7:26:e4:41:5c:0e <a href="mailto:root@chef.example.com">root@chef.example.com</a>
</p>
<p>
	The key's randomart image is:
</p>
<p>
	+--[ DSA 1024]----+
</p>
<p>
	| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |
</p>
<p>
	| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;E . &nbsp; &nbsp;|
</p>
<p>
	| &nbsp; &nbsp; &nbsp; &nbsp; . + &nbsp; . |
</p>
<p>
	| &nbsp; &nbsp; &nbsp; &nbsp; .o . &nbsp; o|
</p>
<p>
	| &nbsp; &nbsp; &nbsp; &nbsp;S. &nbsp; &nbsp; o |
</p>
<p>
	| &nbsp; &nbsp; &nbsp; . &nbsp;o . + .|
</p>
<p>
	| &nbsp; &nbsp; &nbsp; &nbsp;oo.. B . |
</p>
<p>
	| &nbsp; &nbsp; &nbsp; o +o * + &nbsp;|
</p>
<p>
	| &nbsp; &nbsp; &nbsp; &nbsp;o .+ =. &nbsp;|
</p>
<p>
	+-----------------+
</p>
<p>
	----------------------
</p>
<p>
	
</p>
<p>
	2). 查看生成的秘钥对：(chef.example.com)
</p>
<p>
	# ls -lda ~/.ssh
</p>
<p>
	-----------------
</p>
<p>
	drwx------ 2 root root 4096 6月 &nbsp; 6 23:03 .ssh
</p>
<p>
	-----------------
</p>
<p>
	# cd .ssh
</p>
<p>
	# ls -la
</p>
<p>
	------------------
</p>
<p>
	总用量 16
</p>
<p>
	drwx------ &nbsp; 2 root root 4096 6月 &nbsp; 6 23:03 .
</p>
<p>
	dr-xr-x---. 26 root root 4096 6月 &nbsp; 6 23:03 ..
</p>
<p>
	-rw------- &nbsp; 1 root root &nbsp;668 6月 &nbsp; 6 23:03 id_dsa
</p>
<p>
	-rw-r--r-- &nbsp; 1 root root &nbsp;613 6月 &nbsp; 6 23:03 id_dsa.pub
</p>
<p>
	------------------
</p>
<p>
	秘钥生成完毕
</p>
<p>
	
</p>
<p>
	3) .将公钥（锁）分发到SSH服务端(CHEF客户端)：(chef.example.com)
</p>
<p>
	# ssh-copy-id -i .ssh/id_dsa.pub node1.example.com
</p>
<p>
	<span style="color:#E53333;">注：若非root用户，以及自定义SSH端口，则格式为：</span>
</p>
<p>
	# ssh-copy-id -i .ssh/id_rsa.pub "-p 22 user@server"
</p>
<p>
	输入yes,然后密码后回车：
</p>
<p>
	----------------------------
</p>
<p>
	The authenticity of host 'node1.example.com (10.107.91.252)' can't be established.
</p>
<p>
	RSA key fingerprint is fc:9b:2e:38:3b:04:18:67:16:8f:dd:94:a8:bd:08:03.
</p>
<p>
	Are you sure you want to continue connecting (yes/no)? yes
</p>
<p>
	Warning: Permanently added 'node1.example.com' (RSA) to the list of known hosts.
</p>
<p>
	Address node1.example.com maps to bogon, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
</p>
<p>
	<a href="mailto:root@node1.example.com">root@node1.example.com</a>'s password: &nbsp;输入密码
</p>
<p>
	Now try logging into the machine, with "ssh 'node1.example.com'", and check in:</p>
<p>&nbsp;.ssh/authorized_keys</p>
<p>to make sure we haven't added extra keys that you weren't expecting.
</p>
<p>
	-----------------------------
</p>
<p>
	公钥分发完毕
</p>
<p>
	
</p>
<p>
	
</p>
<p>
	4) .SSH服务端(CHEF客户端)查看收到的分发文件：(node1.example.com)
</p>
<p>
	
</p>
<p>
	# ll /root/.ssh
</p>
<p>
	-------------
</p>
<p>
	总用量 4
</p>
<p>
	-rw------- 1 root root 613 6月 &nbsp; 6 23:29 authorized_keys
</p>
<p>
	-------------
</p>
<p>
	成功收到
</p>
<p>
	
</p>
<p>
	2.执行bootstrap部署&nbsp;(chef.example.com)
</p>
<p>
	# knife bootstrap node1.example.com -x root --sudo -r "role[webserver]"
</p>
<p>
	-------------------------------------------------------------------------------------------------------------- &nbsp;
</p>
<p>
	Connecting to node1.example.com
</p>
<p>
	node1.example.com Starting first Chef Client run...
</p>
<p>
	node1.example.com [2014-05-09T06:08:53+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>
	<span style="line-height:1.5;">node1.example.com&nbsp;</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com ```</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com &nbsp; # Verify all HTTPS connections (recommended)</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com &nbsp; ssl_verify_mode :verify_peer</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com&nbsp;</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com &nbsp; # OR, Verify only connections to chef-server</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com &nbsp; verify_api_cert true</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com ```</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com&nbsp;</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com To check your SSL configuration, or troubleshoot errors, you can use the</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com `knife ssl check` command like so:</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com&nbsp;</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com ```</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com &nbsp; knife ssl check -c /etc/chef/client.rb</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com ```</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com&nbsp;</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *&nbsp;</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com&nbsp;</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com Starting Chef Client, version 11.12.4</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com resolving cookbooks for run list: ["apache"]</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com Synchronizing Cookbooks:</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com &nbsp; - apache</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com Compiling Cookbooks...</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com Converging 8 resources</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com Recipe: apache::default</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com &nbsp; * package[httpd] action install (up to date)</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com &nbsp; * package[mod_ssl] action install (up to date)</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com &nbsp; * service[iptables] action disable (up to date)</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com &nbsp; * service[iptables] action stop (up to date)</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com &nbsp; * service[ip6tables] action disable (up to date)</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com &nbsp; * service[ip6tables] action stop (up to date)</span>
</p>
<p>
	<span style="line-height:1.5;">node1.example.com &nbsp; * directory[/etc/httpd/ssl] action create (up to date)</span>
</p>
<p>
	node1.example.com &nbsp; * remote_directory[/etc/httpd/ssl] action createRecipe: &lt;Dynamically Defined Resource&gt;
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ssl.ca-0.1/sign-user-cert.sh] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ssl.ca-0.1/sign-server-cert.sh] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ssl.ca-0.1/server.key] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ssl.ca-0.1/server.csr] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ssl.ca-0.1/server.crt] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ssl.ca-0.1/random-bits] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ssl.ca-0.1/p12.sh] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ssl.ca-0.1/new-user-cert.sh] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ssl.ca-0.1/new-server-cert.sh] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ssl.ca-0.1/new-root-ca.sh] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ssl.ca-0.1/ca.key] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ssl.ca-0.1/ca.db.serial] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ssl.ca-0.1/ca.db.index.attr] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ssl.ca-0.1/ca.db.index] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ssl.ca-0.1/ca.db.certs/01.pem] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ssl.ca-0.1/ca.crt] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ssl.ca-0.1/VERSION] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ssl.ca-0.1/README] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ssl.ca-0.1/COPYING] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ssl.ca-0.1.tar.gz] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/server.key] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/server.crt] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * cookbook_file[/etc/httpd/ssl/ca.crt] action create (up to date)
</p>
<p>
	node1.example.com &nbsp;(up to date)
</p>
<p>
	node1.example.com Recipe: apache::default
</p>
<p>
	node1.example.com &nbsp; * template[/etc/httpd/conf.d/ssl.conf] action create (up to date)
</p>
<p>
	node1.example.com &nbsp; * service[httpd] action enable (up to date)
</p>
<p>
	node1.example.com &nbsp; * service[httpd] action start (up to date)
</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/34 resources updated in 9.1690343 seconds
</p>
<p>
	-------------------------------------------------------------------------------------------------------------- &nbsp;
</p>
<p>
	部署成功....
</p>
<p>
	
</p>
<p>
	九.验证&nbsp;(node1.example.com)
</p>
<p>
	<span style="line-height:1.5;"># cd /etc/httpd/</span>
</p>
<p>
	<span style="line-height:1.5;"># ls</span>
</p>
<p>
	<span style="line-height:1.5;">-------------------------------------------------------------------------------------------------------------- &nbsp;</span>
</p>
<p>
	<span style="line-height:1.5;">conf &nbsp;conf.d &nbsp;logs &nbsp;modules &nbsp;run &nbsp;ssl</span>
</p>
<p>
	<span style="line-height:1.5;">-------------------------------------------------------------------------------------------------------------- &nbsp;</span>
</p>
<p>
	<span style="line-height:1.5;"># service httpd status</span>
</p>
<p>
	<span style="line-height:1.5;">-------------------------------------------------------------------------------------------------------------- &nbsp;</span>
</p>
<p>
	<span style="line-height:1.5;">httpd (pid &nbsp;10492) is running...</span>
</p>
<p>
	<span style="line-height:1.5;">-------------------------------------------------------------------------------------------------------------- &nbsp;</span>
</p>
<p>
	<span style="line-height:1.5;"># lsof -i:80</span>
</p>
<p>
	<span style="line-height:1.5;">--------------------------------------------------------------------------------------------------------------</span>
</p>
<p>
	COMMAND &nbsp; PID &nbsp; USER &nbsp; FD &nbsp; TYPE DEVICE SIZE/OFF NODE NAME
</p>
<p>
	<span style="line-height:1.5;">httpd &nbsp; 10492 &nbsp; root &nbsp; &nbsp;4u &nbsp;IPv6 &nbsp;48097 &nbsp; &nbsp; &nbsp;0t0 &nbsp;TCP *:http (LISTEN)</span>
</p>
<p>
	httpd &nbsp; 10494 apache &nbsp; &nbsp;4u &nbsp;IPv6 &nbsp;48097 &nbsp; &nbsp; &nbsp;0t0 &nbsp;TCP *:http (LISTEN)
</p>
<p>
	httpd &nbsp; 10495 apache &nbsp; &nbsp;4u &nbsp;IPv6 &nbsp;48097 &nbsp; &nbsp; &nbsp;0t0 &nbsp;TCP *:http (LISTEN)
</p>
<p>
	httpd &nbsp; 10496 apache &nbsp; &nbsp;4u &nbsp;IPv6 &nbsp;48097 &nbsp; &nbsp; &nbsp;0t0 &nbsp;TCP *:http (LISTEN)
</p>
<p>
	httpd &nbsp; 10497 apache &nbsp; &nbsp;4u &nbsp;IPv6 &nbsp;48097 &nbsp; &nbsp; &nbsp;0t0 &nbsp;TCP *:http (LISTEN)
</p>
<p>
	httpd &nbsp; 10498 apache &nbsp; &nbsp;4u &nbsp;IPv6 &nbsp;48097 &nbsp; &nbsp; &nbsp;0t0 &nbsp;TCP *:http (LISTEN)
</p>
<p>
	httpd &nbsp; 10499 apache &nbsp; &nbsp;4u &nbsp;IPv6 &nbsp;48097 &nbsp; &nbsp; &nbsp;0t0 &nbsp;TCP *:http (LISTEN)
</p>
<p>
	<span style="line-height:1.5;">httpd &nbsp; 10500 apache &nbsp; &nbsp;4u &nbsp;IPv6 &nbsp;48097 &nbsp; &nbsp; &nbsp;0t0 &nbsp;TCP *:http (LISTEN)</span>
</p>
<p>
	<span style="line-height:1.5;">httpd &nbsp; 10501 apache &nbsp; &nbsp;4u &nbsp;IPv6 &nbsp;48097 &nbsp; &nbsp; &nbsp;0t0 &nbsp;TCP *:http (LISTEN)</span>
</p>
<p>
	# lsof -i:443
</p>
<p>
	--------------------------------------------------------------------------------------------------------------
</p>
<p>
	COMMAND &nbsp; PID &nbsp; USER &nbsp; FD &nbsp; TYPE DEVICE SIZE/OFF NODE NAME
</p>
<p>
	httpd &nbsp; 10492 &nbsp; root &nbsp; &nbsp;6u &nbsp;IPv6 &nbsp;48101 &nbsp; &nbsp; &nbsp;0t0 &nbsp;TCP *:https (LISTEN)
</p>
<p>
	httpd &nbsp; 10494 apache &nbsp; &nbsp;6u &nbsp;IPv6 &nbsp;48101 &nbsp; &nbsp; &nbsp;0t0 &nbsp;TCP *:https (LISTEN)
</p>
<p>
	httpd &nbsp; 10495 apache &nbsp; &nbsp;6u &nbsp;IPv6 &nbsp;48101 &nbsp; &nbsp; &nbsp;0t0 &nbsp;TCP *:https (LISTEN)
</p>
<p>
	httpd &nbsp; 10496 apache &nbsp; &nbsp;6u &nbsp;IPv6 &nbsp;48101 &nbsp; &nbsp; &nbsp;0t0 &nbsp;TCP *:https (LISTEN)
</p>
<p>
	httpd &nbsp; 10497 apache &nbsp; &nbsp;6u &nbsp;IPv6 &nbsp;48101 &nbsp; &nbsp; &nbsp;0t0 &nbsp;TCP *:https (LISTEN)
</p>
<p>
	httpd &nbsp; 10498 apache &nbsp; &nbsp;6u &nbsp;IPv6 &nbsp;48101 &nbsp; &nbsp; &nbsp;0t0 &nbsp;TCP *:https (LISTEN)
</p>
<p>
	httpd &nbsp; 10499 apache &nbsp; &nbsp;6u &nbsp;IPv6 &nbsp;48101 &nbsp; &nbsp; &nbsp;0t0 &nbsp;TCP *:https (LISTEN)
</p>
<p>
	httpd &nbsp; 10500 apache &nbsp; &nbsp;6u &nbsp;IPv6 &nbsp;48101 &nbsp; &nbsp; &nbsp;0t0 &nbsp;TCP *:https (LISTEN)
</p>
<p>
	httpd &nbsp; 10501 apache &nbsp; &nbsp;6u &nbsp;IPv6 &nbsp;48101 &nbsp; &nbsp; &nbsp;0t0 &nbsp;TCP *:https (LISTEN)
</p>
<p>
	--------------------------------------------------------------------------------------------------------------
</p>
<p>
	如图:
</p>
<p>
	<a href="http://www.showerlee.com/wp-content/uploads/2014/05/5.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/5-1024x749.jpg" alt="5" width="1024" height="749" /></a>
</p>
<p>
	
</p>
<p>
	
</p>
<p>
	大功告成。。。。
</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/1145">DevOps技术分享</a></div><div>本文链接地址：<a rel="external" title="CentOS 6.3下CHEF批量部署APACHE" href="http://www.showerlee.com/archives/1145">http://www.showerlee.com/archives/1145</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.showerlee.com/archives/1145/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<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 (chef.example.com)
</p>
<p>
	node: &nbsp; &nbsp; &nbsp; &nbsp; 10.107.91.252 (node1.example.com) &nbsp; &nbsp;
</p>
<p>
	二.安装前的准备:(chef.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>
	三.chef-server安装:(chef.example.com)
</p>
<p>
	1.下载chef-server安装包
</p>
<p>
	进入页面http://www.opscode.com/chef/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>
	</channel>
</rss>
