阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Chef简介及在Linux下的安装

135次阅读
没有评论

共计 5207 个字符,预计需要花费 14 分钟才能阅读完成。

Chef 简介及在 Linux 下的安装

Chef 有三个重要的概念:(如上图所示)
它们的合作关系大致是这样的,Workstation 把资源或者说是一些要被运行的命令上传到 Chef-Server 上,Nodes 自动通过 Chef-Server 拿到属于自己的执行任务到本地执行,这样可达到一个将军指挥千军万马的效果:smirk:。

  1. Chef Server
    存放所有通过 Workstation 上传的资源,和用户等公共数据(用 PostgreSQL)。可以干脆叫它为资源服务器,大家都可以与它通讯(用 RabbitMQ),本身提供一个在线管理工具叫 chef-server-webui(用 Nginx,包括它的 rest-api)。
    Chef Server 只能安装在 linux 系统上。
  2. Workstation
    简单理解为管理员操作机,通过安装的工具 knife 远程操作 Chef-Server 上的资源,或者注册 Nodes 等
    这个可以安装在任意系统上,包括 windows
  3. Nodes
    一些客户端的机子,它们是内部装有一个工具叫做 Chef-Client,这东西会自动到 Chef-Server 上获取自己的要执行命令清单
    可以安装在任意系统上,包括 windows

Chef 安装

安装环境为 3 台 Ubuntu13 的虚拟机(应该看出来为什么是 3 台了吧)和 Chef11。

注意,在开始之前先把所有机器的时间更新一下,sudo ntpdate ntp.ubuntu.com,不然无法通过登录认证:worried:。

Chef 提供两个安装包,一个是 Server,一个是 Client,其中 Client 包括 Chef-Client 和 Workstation 用到的 knife,也就是说 Nodes 和 Workstation 上的安装都是这个包。

下载 Chef

Chef-11 的安装特别简单,官方下载(传送门:http://www.getchef.com/chef/install/),里面包括 Server 和 Client 的下载,注意 Server 在第二个选项卡里,选择相应的操作系统和版本就会出现下载链接。

安装命令:

//ChefServer安装// 在第一台虚拟机上运行
dpkg -i chef-server_11.1.1-1_amd64.deb
//Chef-Client安装 // 在第二台和第三台虚拟机上运行,也就是WorkstationNode
dpkg -i chef_11.12.8-2_amd64.deb

Chef Server 安装官方参考:http://docs.opscode.com/open_source/install_server.html
Chef-Client 安装官方参考:http://docs.opscode.com/chef/install_workstation.html

运行和配置 Chef

怎么让这三个东西一起工作起来呢,其实也很简单,只是开始有些概念上的东西比较模糊导致无从下手。

让 Chef-Server 跑起来

在第一台 Ubuntu 虚拟机上进行。

执行完上面的安装过程以后,运行一个配置初始化命令 sudo chef-server-ctl reconfigure,然后所有服务就会自动运行了,所生成的配置文件,包括前面提到的 postgresqlrabbitmq 等,放在 /etc/chef-server/chef-server-running.json

如果你需要自定义其中的某些配置 ,需要创建文件 /etc/chef-server/chef-server.rb,一个基于 ruby 语法的配置文件
官方参考:http://docs.opscode.com/open_source/config_rb_chef_server.html
所有配置说明和实例:http://docs.opscode.com/config_rb_chef_server_optional_settings.html
修改完成后通过 sudo chef-server-ctl reconfigure 命令重新生成配置文件,并自动重启有变化的服务。

更多 Chef-Server 操作命令请运行 chef-server-ctl -h 查看
官方参考:http://docs.opscode.com/open_source/ctl_chef_server.html。

现在可以通过这台机器的 ip 访问 chef-server-webui,用户名:admin,密码:p@ssw0rd1
远程 REST API 请参考:http://docs.opscode.com/open_source/api_chef_server.html

运行 Chef Workstation

在第二台 Ubuntu 虚拟机上进行。

克隆 Workstation 的目录结构:chef-repo
方法:git clone git://github.com/opscode/chef-repo.git,当然你要安装 git
sudo apt-get update && sudo apt-get install git

生成认证文件:
chef-repo 目录下创建一个目录 .chef 来存储 workstation 与 server 的交互认证和一些 server 的配置信息。
主要有三个文件:knife.rbvalidator.pem USER.pem,通过命令 knife configure --initial 生成!

在 chef-server 机器的 /etc/chef-server 目录下找到 chef-validator.pemadmin.pem 两个私钥拷贝到刚才创建的 .chef 目录下,然后在 chef-repo 目录下执行 knife configure --initial,请参考以下交互信息:

admin1@localhost:~/chef-repo$ knife configure --initial
WARNING:No knife configuration file found
Where should I put the config file?[/home/admin1/.chef/knife.rb]/home/admin1/chef-repo/.chef/knife.rb
Please enter the chef server URL:[https://localhost:443] https://ubuntu:443Please enter a name for the new user:[admin1] chefuser5
Please enter the existing admin name:[admin]Please enter the location of the existing admin's private key: [/etc/chef-server/admin.pem] /home/admin1/chef-repo/.chef/admin.pem
Please enter the validation clientname: [chef-validator] 
Please enter the location of the validation key: [/etc/chef-server/chef-validator.pem] /home/admin1/chef-repo/.chef/chef-validator.pem
Please enter the path to a chef repository (or leave blank): /home/admin1/chef-repo/cookbooks
Creating initial API user...
Please enter a password for the new user: 
Created user[chefuser5]
Configuration file written to /home/admin1/chef-repo/.chef/knife.rb

没什么问题的话就成功了,通过命令 knife client list 来测试是否安装成功:v:!

启动一个 Chef Node

在第二台 Ubuntu 虚拟机也就是 Workstation 上进行,并假设第三台虚拟机的 IP 为 192.168.0.3
通过 Workstation 注册这台 Node,命令:(在 chef-repo 目录下)
knife bootstrap 192.168.0.3 -x username -P password --sudo
其中 usernamepassword 是虚拟机 192.168.0.3SSH 登录的用户名及密码。
参考交互信息:

admin1@localhost:~/chef-repo$ knife bootstrap 192.168.0.3-x admin1 -P 111111--sudoConnecting to 192.168.0.3192.168.0.3 knife sudo password:Enter your password:192.168.0.3192.168.0.3Starting first ChefClient run...192.168.0.3[2014-06-13T10:14:07+08:00] WARN:192.168.0.3****************************************192.168.0.3 SSL validation of HTTPS requests is disabled. HTTPS connections are still
192.168.0.3 encrypted, but chef is not able to detect forged replies or man in the middle
192.168.0.3 attacks.192.168.0.3192.168.0.3To fix this issue add an entry like this to your configuration file:192.168.0.3192.168.0.3```
192.168.0.3   # Verify all HTTPS connections (recommended)
192.168.0.3   ssl_verify_mode :verify_peer
192.168.0.3 
192.168.0.3   # OR, Verify only connections to chef-server
192.168.0.3   verify_api_cert true
192.168.0.3 ```192.168.0.3192.168.0.3To check your SSL configuration, or troubleshoot errors, you can use the
192.168.0.3`knife ssl check` command like so:192.168.0.3192.168.0.3```
192.168.0.3   knife ssl check -c /etc/chef/client.rb
192.168.0.3 ```192.168.0.3192.168.0.3****************************************192.168.0.3192.168.0.3StartingChefClient, version 11.12.8192.168.0.3 resolving cookbooks for run list:[]192.168.0.3SynchronizingCookbooks:192.168.0.3CompilingCookbooks...192.168.0.3[2014-06-13T10:15:13+08:00] WARN:Node localhost has an empty run list.192.168.0.3Converging0 resources
192.168.0.3192.168.0.3Running handlers:192.168.0.3Running handlers complete
192.168.0.3192.168.0.3ChefClient finished,0/0 resources updated in66.508732206 seconds

官方参考:http://docs.opscode.com/open_source/knife_bootstrap.html

其它参考

官方资料:http://docs.opscode.com/open_source/
安装参考:https://www.digitalocean.com/community/tutorials/how-to-install-a-chef-server-workstation-and-client-on-ubuntu-vps-instances 第二个链接讲解了管理员私钥(admin.pem)和校验私钥(chef-validator.pem)是如何产生的。

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-04/130639.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计5207字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中