导读 Chef是一个IT基础设施自动化软件,它可以管理你组织中所有的服务器和网络设备。当我们想与Chef服务器、任何物理节点(服务器、网络设备等)的基础设施进行交互时,我们需要一个Chef工作站。本教程解释如何安装和配置Linux服务器上Chef工作站。

下载 ChefDK

ChefDK是Chef Development Kit的缩写,它几乎用于所有的平台,包括基于Debian发行版、Ubuntu、RedHat、CentOS、Mac OS X和Windows。当前ChefDK的稳定版本是0.11.2,对于基于RHEL的系统,它可用于版本 6 和 7(如: CentOS 6 和 CentOS 7),RPM版本只有64位版本。

使用以下命令下载ChefDK

在CentOS 7上

cd ~
wget https://packages.chef.io/stable/el/7/chefdk-0.11.2-1.el7.x86_64.rpm

在CentOS 6上

cd ~
wget https://packages.chef.io/stable/el/6/chefdk-0.11.2-1.el6.x86_64.rpm
安装 ChefDK

使用RPM安装刚刚下载的ChefDK

# rpm -ivh chefdk-0.11.2-1.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:chefdk-0.11.2-1.el7 ################################# [100%]
Thank you for installing Chef Development Kit!

ChefDK默认安装到/opt/chefdk目录下,如下所示

# ls -l /opt/chefdk/
drwxr-xr-x. 2 root root 4096 Mar 3 13:50 bin
drwxr-xr-x. 7 root root 62 Mar 3 13:50 embedded
-rw-r--r--. 1 root root 13249 Feb 22 14:26 version-manifest.json
-rw-r--r--. 1 root root 8233 Feb 22 14:26 version-manifest.txt
验证ChefDK的安装

执行chef verify,验证所有来自ChefDK的不同组件,确保他们都工作正常,没有任何问题

# chef verify
Running verification for component 'berkshelf'
Running verification for component 'test-kitchen'
Running verification for component 'tk-policyfile-provisioner'
Running verification for component 'chef-client'
Running verification for component 'chef-dk'
Running verification for component 'chef-provisioning'
Running verification for component 'chefspec'
Running verification for component 'generated-cookbooks-pass-chefspec'
Running verification for component 'rubocop'
Running verification for component 'fauxhai'
Running verification for component 'knife-spork'
Running verification for component 'kitchen-vagrant'
Running verification for component 'package installation'
Running verification for component 'openssl'
Running verification for component 'inspec'
.......
---------------------------------------------
Verification of component 'test-kitchen' succeeded.
Verification of component 'chef-dk' succeeded.
Verification of component 'chefspec' succeeded.
Verification of component 'rubocop' succeeded.
Verification of component 'knife-spork' succeeded.
Verification of component 'openssl' succeeded.
Verification of component 'berkshelf' succeeded.
Verification of component 'chef-client' succeeded.
Verification of component 'fauxhai' succeeded.
Verification of component 'inspec' succeeded.
Verification of component 'tk-policyfile-provisioner' succeeded.
Verification of component 'kitchen-vagrant' succeeded.
Verification of component 'chef-provisioning' succeeded.
Verification of component 'package installation' succeeded.
Verification of component 'generated-cookbooks-pass-chefspec' succeeded.

下面是chef verify失败的案例。注意:Ruby在Chef中是必须的,它被嵌入在了ChefDK中。

# chef verify
..
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/mixlib-shellout-2.2.6/lib/mixlib/shellout.rb:289:in `invalid!': Expected process to exit with [0], but received '1' (Mixlib::ShellOut::ShellCommandFailed)
---- Begin output of /usr/bin/ohai -v ----
STDOUT:
STDERR: /opt/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems/dependency.rb:319:in `to_specs': Could not find 'chef-config' (= 12.8.0) - did find: [chef-config-12.7.2] (Gem::LoadError)

以上错误信息显示:“Could not find ‘chef-config’ (= 12.8.0) – did find: [chef-config-12.7.2] (Gem::LoadError)”,在安装的ChefDK中chef-config的版本是12.7.2的旧版本,在手动安装chef-confg 12.8.0版本后再执行chef verify,显示验证成功。

验证ChefDK版本

执行 chef -version命令,显示ChefDK的版本号以及所有附带组件

# chef --version
Chef Development Kit Version: 0.11.2
chef-client version: 12.7.2
berks version: 4.2.0
kitchen version: 1.5.0
设置Chef 环境变量

设置Chef相关的环境变量,如:GEM_ROOT GEM_HOME GEM_PATH。

export GEM_ROOT="/opt/chefdk/embedded/lib/ruby/gems/2.1.0"
export GEM_HOME="/root/.chefdk/gem/ruby/2.1.0"
export GEM_PATH="/root/.chefdk/gem/ruby/2.1.0:/opt/chefdk/embedded/lib/ruby/gems/2.1.0"

此外,如果你的系统上已经安装了ruby,你需要更新与ruby相关的PATH变量,如下所示

export PATH="/opt/chefdk/bin:/root/.chefdk/gem/ruby/2.1.0/bin:/opt/chefdk/embedded/bin:/opt/chefdk/bin:/root/.chefdk/gem/ruby/2.1.0/bin:/opt/chefdk/embedded/bin:/opt/chefdk/bin:/root/.chefdk/gem/ruby/2.1.0/bin:/opt/chefdk/embedded/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin"

显示所有Chef设置的环境变量。

chef shell-init bash

想要快速设置这些环境变量,可以将其添加到bash_profile文件中,如下所示。

echo 'eval "$(chef shell-init bash)"' >> ~/.bash_profile
访问Chef的Firewalld规则

为了访问Chef服务器上的Chef Manage GUI,添加以下firewalld规则,开放Chef服务器上的相应端口。

firewall-cmd --direct  --add-rule ipv4 \
filter INPUT_direct 0 -i eth0 -p tcp \
--dport 443 -j ACCEPT firewall-cmd --direct --add-rule ipv4 \
filter INPUT_direct 0 -i eth0 -p tcp \
--dport 80 -j ACCEPT firewall-cmd --direct --add-rule ipv4 \
filter INPUT_direct 0 -i eth0 -p tcp \
--dport 9683 -j ACCEPT firewall-cmd --reload
从Chef Manage GUI下载Starter Kit

登录到Chef Manage GUI,单击“Administration”选项,从列表中选择“organization”。此例中,“organization”为“example”,选中organization之后,点击左侧菜单中的“Starter Kit”。
按下“Download(下载)”按钮之后,会跳出一个警告信息,按下“Proceed”,它会将chef-starter.zip文件下载到本地机器。

解压缩 Starter Kit

将chef-starter.zip文件传输到Chef工作站并解压到root的home目录下

# cd ~
# unzip chef-starter.zip
Archive: chef-starter.zip
creating: chef-repo/cookbooks/
creating: chef-repo/cookbooks/starter/
creating: chef-repo/cookbooks/starter/templates/
creating: chef-repo/cookbooks/starter/templates/default/
inflating: chef-repo/cookbooks/starter/templates/default/sample.erb
creating: chef-repo/cookbooks/starter/files/
creating: chef-repo/cookbooks/starter/files/default/
inflating: chef-repo/cookbooks/starter/files/default/sample.txt
creating: chef-repo/cookbooks/starter/recipes/
inflating: chef-repo/cookbooks/starter/recipes/default.rb
creating: chef-repo/cookbooks/starter/attributes/
inflating: chef-repo/cookbooks/starter/attributes/default.rb
inflating: chef-repo/cookbooks/starter/metadata.rb
inflating: chef-repo/cookbooks/chefignore
inflating: chef-repo/README.md
inflating: chef-repo/.gitignore
creating: chef-repo/.chef/
creating: chef-repo/roles/
inflating: chef-repo/.chef/knife.rb
inflating: chef-repo/roles/starter.rb
inflating: chef-repo/.chef/ramesh.pem
inflating: chef-repo/.chef/example-validator.pem

如果你手动创建了chef-repo文件夹,那你就需要手动创建上述的子目录,复制knife.rb文件、organization-validator.pem文件(如:example-validator.pem)、username.pem文件(如:ramesh.pem)到上面显示的目录中。

Chef服务器的SSL证书

在这个阶段如果执行knife client list会得到以下错误信息

# cd ~/chef-repo
# knife client list
ERROR: SSL Validation failure connecting to host: centos.example.com - SSL_connect returned=1 errno=0 state=error: certificate verify failed
ERROR: Could not establish a secure connection to the server.
Use `knife ssl check` to troubleshoot your SSL configuration.
If your Chef Server uses a self-signed certificate, you can use
`knife ssl fetch` to make knife trust the server's certificates. Original Exception: OpenSSL::SSL::SSLError: SSL Error connecting to https://centos.example.com/organizations/example/clients - SSL_connect returned=1 errno=0 state=error: certificate verify failed

证书验证失败,因为我们没有从Chef服务器下载SSL证书,此时可以执行以下“knife ssl fetch”。

# cd ~/chef-repo
# knife ssl fetch
WARNING: Certificates from centos.example.com will be fetched and placed in your trusted_cert
directory (/root/chef-repo/.chef/trusted_certs). Knife has no means to verify these are the correct certificates. You should
verify the authenticity of these certificates after downloading.

证书将会下载到以下truster_certs目录中

# ls -l /root/chef-repo/.chef/trusted_certs
-rw-r--r--. 1 root root 1379 Mar 20 20:17 centos_example_com.crt # cat /root/chef-repo/.chef/trusted_certs/centos_example_com.crt
-----BEGIN CERTIFICATE-----
MIIDzDCCArSgAwIBAgIBADANBgkqhkiG9w0BAQsFADBRMQswCQYDVQQGEwJVUzEQ
MA4GA1UECgwHWW91Q29ycDETMBEGA1UECwwKT3BlcmF0aW9uczEbMBkGA1UEAwwS
ZXJhdGlvbnMxGzAZBgNVBAMMEmNlbnRvcy5leGFtcGxlLmNvbTCCASIwDQYJKoZI
..
..
WLyr2ORLMcck/OGsubabO/koMNTqhl2JJPECNiDJh06MeZ/2+BOwGZSpXDbw+vFE
NJAsLfsTzihGWZ58einMFA==
-----END CERTIFICATE-----
Chef工作站的最终确认

如果Chef工作站工作正常,当你执行“knife client list”时,它会显示所有连接工作站的客户端。由于我们刚刚安装它,因此只能看到刚刚我们创建的组织(organization)

# cd ~/chef-repo

# knife client list
example-validator

如果你现有的Chef工作站机器上已经有5个服务器连接到它了,你会看到以下信息

# knife client list
example-validator
node1
node2
node3
node4
node5

免费提供最新Linux技术教程书籍,为开源技术爱好者努力做得更多更好:https://www.linuxprobe.com/

在Linux上安装Chef工作站的更多相关文章

  1. 在Windows和Linux上安装paramiko模块以及easy_install的安装方法

    一.paramiko模块有什么用? paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接.由于使用的是python这样的能够跨平台运行的语言 ...

  2. 在Linux上安装Oracle RAC 12 c(12.1) 虚拟机,一步一步向导

    Oracle RAC 12 c(12.1)在Linux上安装虚拟机,一步一步向导 今天我们将看到如何安装 12 c版本1 RAC(真正的应用程序集群)数据库2 Linux 64位的虚拟机 使用VMWa ...

  3. WINDOWS和Linux上安装php7 alpha 并安装 yaf

    WINDOWS和Linux上安装php7 alpha 并安装 yaf PHP技术  widuu  2个月前 (06-15)  126浏览  0评论 windows 1.windows上安装 php7 ...

  4. 在Windows和Linux上安装paramiko模块

    一.paramiko模块有什么用? paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接.由于使用的是python这样的能够跨平台运行的语言 ...

  5. Linux上安装使用boost入门指导

    Data Mining Linux上安装使用boost入门指导 获得boost boost分布 只需要头文件的库 使用boost建立一个简单的程序 准备使用boost二进制文件库 把你的程序链接到bo ...

  6. 如何在Linux上安装Storm

    Storm是开源的分布式实时计算系统,能够让数据流处理变得简单.可靠,也因此在大数据领域有广泛的实际 应用.下面介绍一下如何在Linux系统上安装Storm.根据Storm官网介绍,安装Storm软件 ...

  7. linux上安装Drupal

    linux上安装Drupal 前言:国内用drupal的并不太多,网上资料也很少.要注意的是drupal尽量别使用apt来安装,特别是ubuntu平台的drupal做出了一定的更改,会妨碍后期的学习和 ...

  8. 在Linux上安装Hadoop

    先决条件: Hadoop是用JAVA写的,所以首先要安装Java.在Ubuntu上安装JDK见:http://blog.csdn.net/microfhu/article/details/766739 ...

  9. linux上安装配置samba服务器

    linux上安装配置samba服务器 在linux上安装配置samba服务器 在这给大家介绍一个不错的家伙,samba服务.如果您正在犯愁,如何在Windows和Linux之间实现资源共享,就请看看这 ...

随机推荐

  1. 使用Python发送HTML格式的邮件(收到的邮件有发送方才是正解)

    发送html格式的和普通文本格式差不多,只是MIMEText(content,"html","utf-8"))与MIMEText(content,"p ...

  2. The Pragmatic Programmer 读书笔记

    --在所有的弱点中,最大的弱点就是害怕暴露弱点. --责任是你主动担负的东西.你承诺确保某件事情正确完成,但你不一定能直接控制事情的每一个方面.除了尽你所能以外,你必须分析风险是否超出了你的控制.对于 ...

  3. python装饰器原理

    妙处在于装饰器的两个return 1.装饰器 # 使用闭包 def wrap(fun): def check(): print("正在检查用户权限!") fun() return ...

  4. bzoj 4408: [Fjoi 2016]神秘数 数学 可持久化线段树 主席树

    https://www.lydsy.com/JudgeOnline/problem.php?id=4299 一个可重复数字集合S的神秘数定义为最小的不能被S的子集的和表示的正整数.例如S={1,1,1 ...

  5. [CodeChef-QUERY]Observing the Tree

    题目大意: 给你一棵树,一开始每个点的权值都是0,要求支持一下三种操作: 1.路径加等差数列. 2.路径求和. 3.回到以前的某次操作. 强制在线. 思路: 树链剖分+主席树. 最坏情况下,n个点的树 ...

  6. Loj10166 数字游戏2

    题目描述 由于科协里最近真的很流行数字游戏,某人又命名了一种取模数,这种数字必须满足各位数字之和 modN 为 000.现在大家又要玩游戏了,指定一个整数闭区间 [a,b][a,b][a,b],问这个 ...

  7. 华为S5300系列升级固件S5300SI-V100R006C00SPC800.cc

    这个固件附带了web,V100R005可以直接升级到这个版本,但没什么必要,因为V100R005本身可以直接升级到V200. 升级小插曲: 1.升级的使用使用Windows,不要用Mac或者Linux ...

  8. Spring源码解析 – @Configuration配置类及注解Bean的解析

    在分析Spring 容器创建过程时,我们知道容器默认会加载一些后置处理器PostPRocessor,以AnnotationConfigApplicationContext为例,在构造函数中初始化rea ...

  9. [Windows核心编程]32bit程序在64bit操作系统下处理重定向细节[1]

    这段时间,都在做Ring3层的普通32bit程序兼容64bit操作系统的代码修改,在此记录修改和学习心德.编程领域太广, 任何人经历有限,本人不是专家,所以我一贯原则是: 用到的时候,才去研究,在去记 ...

  10. Send custom commands to Mass Storage device

    http://stackoverflow.com/questions/14363152/send-custom-commands-to-mass-storage-device I have devel ...