天天看点

如何在 Ubuntu 上安装配置管理系统 Chef (大厨)

下面是我们将要在本篇中要设置和配置chef的主要组件。

如何在 Ubuntu 上安装配置管理系统 Chef (大厨)

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

我们将在下面的基础环境下设置chef配置管理系统。

管理和配置工具:chef

基础操作系统

ubuntu 14.04.1 lts (x86_64)

chef server

version 12.1.0

chef manage

version 1.17.0

chef development kit

version 0.6.2

内存和cpu

4 gb  , 2.0+2.0 ghz

我使用下面的命令来下载和安装它。

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

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

现在运行下面的命令来启动所有的chef服务端服务,这一步也许会花费一些时间,因为它需要由许多不同一起工作的服务组成一个可正常运作的系统。

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

chef服务端启动命令'chef-server-ctl reconfigure'需要运行两次,这样就会在安装后看到这样的输出。

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

<code>opscode reconfigured!</code>

安装完成后重启系统使系统能最好的工作,不然我们或许会在创建用户的时候看到下面的ssl连接错误。

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

运行下面的命令来创建一个新的管理员账户及其配置。创建过程中,用户的rsa私钥会自动生成,它需要保存到一个安全的地方。--file选项会保存rsa私钥到指定的路径下。

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

chef manage是一个针对企业级chef用户的管理控制台,它提供了可视化的web用户界面,可以管理节点、数据包、规则、环境、cookbook 和基于角色的访问控制(rbac)。

从官网复制链接并下载chef manage的安装包。

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

使用下面的命令在root的家目录下安装它。

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

安装完成后我们需要运行下面的命令来重启chef manage和服务端。

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

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

我们可以使用localhost或它的域名来访问网页控制台,并用已经创建的管理员登录

如何在 Ubuntu 上安装配置管理系统 Chef (大厨)

chef amanage

你或许被要求创建新的组织,或者也可以接受其他组织的邀请。如下所示,使用缩写和全名来创建一个新的组织。

如何在 Ubuntu 上安装配置管理系统 Chef (大厨)

create org

我们同样也可以运行下面的命令来创建新的组织。

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

为了设置工作站,我们需要用命令行创建一个新的用户和组织。

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

<code></code>

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

在工作站的网页控制台中下载并保存入门套件,它用于与服务端协同工作

如何在 Ubuntu 上安装配置管理系统 Chef (大厨)

starter kit

如何在 Ubuntu 上安装配置管理系统 Chef (大厨)

chef开发套件是一款包含开发chef所需的所有工具的软件包。它捆绑了由chef开发的带chef客户端的工具。

我们可以从它的官网链接中下载开发包,并选择操作系统来下载chef开发包。

如何在 Ubuntu 上安装配置管理系统 Chef (大厨)

chef dk

复制链接并用wget下载

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

使用dpkg命令安装开发套件

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

使用下面的命令验证客户端是否已经正确安装。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

我们将创建 ~/.chef目录,并从chef服务端复制两个用户和组织的pem文件到该目录下。

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

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

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

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

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

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

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

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

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

<code>log_level :info</code>

<code>log_location stdout</code>

<code>node_name "kashi"</code>

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

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

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

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

<code>cache_type 'basicfile'</code>

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

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

创建knife.rb中指定的“~/cookbooks”文件夹。

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

运行“knife user list”和“knife client list”来验证knife是否工作。

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

第一次运行的时候可能会看到下面的错误,这是因为工作站上还没有chef服务端的ssl证书。

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

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

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

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

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

要解决上面的命令的错误,运行下面的命令来获取ssl证书,并重新运行knife user和client list,这时候应该就可以了。

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

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

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

knife没有办法验证这些是否是有效的证书。你应该在下载时验证这些证书的真实性。

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

在上面的命令取得ssl证书后,接着运行下面的命令。

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

<code>kashi-linux</code>

节点是执行所有基础设施自动化的chef客户端。因此,在配置完chef-server和knife工作站后,通过配置与chef-server交互的新节点,来将新的服务端添加到我们的chef环境下。

我们使用下面的命令来添加与chef服务端协同工作的新节点。

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

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

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

<code>connecting to 172.25.10.170</code>

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

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

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

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

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

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

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

<code>172.25.10.170</code>

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

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

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

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

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

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

之后我们可以在knife节点列表下看到创建的新节点,它也会在新节点下创建新的客户端。

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

<code>mydns</code>

类似地我们只要通过给上面的knife命令提供ssh证书,就可以在chef设施上创建多个节点。

本篇我们学习了chef管理工具,并通过安装和配置设置基本了解了它的组件。我希望你在学习安装和配置chef服务端以及它的工作站和客户端节点中获得乐趣。

本文来自云栖社区合作伙伴“linux中国”,原文发布日期:2015-08-10

继续阅读