在Linux上安装Chef工作站
导读 | Chef是一个IT基础设施自动化软件,它可以管理你组织中所有的服务器和网络设备。当我们想与Chef服务器、任何物理节点(服务器、网络设备等)的基础设施进行交互时,我们需要一个Chef工作站。本教程解释如何安装和配置Linux服务器上Chef工作站。 |
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
使用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
执行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,显示验证成功。
执行 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相关的环境变量,如: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服务器上的Chef Manage GUI,添加以下firewalld规则,开放Chef服务器上的相应端口。
firewall-cmd --direct --add-rule ipv4 \ filter INPUT_direct 0 -i eth0 -p tcp \--dport 443 -j ACCEPTfirewall-cmd --direct --add-rule ipv4 \ filter INPUT_direct 0 -i eth0 -p tcp \--dport 80 -j ACCEPTfirewall-cmd --direct --add-rule ipv4 \ filter INPUT_direct 0 -i eth0 -p tcp \--dport 9683 -j ACCEPTfirewall-cmd --reload
登录到Chef Manage GUI,单击“Administration”选项,从列表中选择“organization”。此例中,“organization”为“example”,选中organization之后,点击左侧菜单中的“Starter Kit”。
按下“Download(下载)”按钮之后,会跳出一个警告信息,按下“Proceed”,它会将chef-starter.zip文件下载到本地机器。
将chef-starter.zip文件传输到Chef工作站并解压到root的home目录下
# cd ~ # unzip chef-starter.zip Archive: chef-starter.zipcreating: 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)到上面显示的目录中。
在这个阶段如果执行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工作站工作正常,当你执行“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工作站相关推荐
- 如何在Red Hat Enterprise Linux上安装Python 3
如何在Red Hat Enterprise Linux上安装Python 3. 本文介绍如何安装Python 3, ,pip,venv,virtualenv和pipenv在企业Linux 7.按照本文 ...
- linux上安装mysql,tomcat,jdk
Linux 上安装 1 安装jdk 检测是否安装了jdk 运行 java –version 若有 需要将其卸载 a) 查看安装哪些jdk rmp –qa |grep java b) ...
- linux下安装sbt_如何在Linux上安装SBT
linux下安装sbt 介绍 (Introduction) Hi! I am Sanjula, and in this guide I hope to teach you how to install ...
- 在Linux上安装QT4
比起在Windows上安装QT,在Linux上安装QT要容易多了,这都得意于Linux系统的autoconf和automake工具. 1. 将QT的源码包放至到一个目录下,笔者的目录是:/home/k ...
- 明明安装了模块,还是出现 错误 ImportError: No module named ‘pandas‘ 原因LINUX上安装了多个python环境,将脚本中python 改为python3问题解
明明安装了模块,还是出现 错误 ImportError: No module named 'pandas' 原因LINUX上安装了多个python环境,将脚本中python 改为python3问题解 ...
- linux上安装redis
Redis Redis在linux上安装 将redis-3.0.7.tar.gz上传到linux虚拟机上 编译: a) 因为redis是C语言开发,所以需要先编译,在linux上编译需要依 ...
- Linux上安装paramiko模块
Linux上安装paramiko模块 一.paramiko模块作用 paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接.由于使用的是pyt ...
- 在linux上安装Filezilla文件传输FTP软件
在linux上安装Filezilla文件传输FTP软件 1 Filezilla安装方法一:使用apt-get安装 2 Filezilla安装方法二:使用filezilla安装包进行安装 1 Filez ...
- 如何在 Linux 上安装服务器管理软件 Cockpit
如何在 Linux 上安装服务器管理软件 Cockpit Cockpit 是一个自由开源的服务器管理软件,它使得我们可以通过它好看的 web 前端界面轻松地管理我们的 GNU/Linux 服务器.Co ...
最新文章
- python猜年龄代码_python入门教程NO.7用python来写一个猜数字游戏
- mfc程序转化为qt_工控编程,Qt 学习之路
- oracle中怎样查询用户权限
- docker-compose 安装方法
- 案例 | 易快报:解放“客户成功”的背后故事
- 第四范式获批工信部工业和信息化人才培养工程培训基地
- linux内核组件分析之--设备驱动模型之bus
- docker 添加端口映射_Docker快速搭建PHP开发环境详细教程
- Neo4j导入:java.lang.IllegalStateException:不支持在单个导入中混合指定和未指定的组所有物...
- 自定义的plot函数参数date坐标模型[x,y]的使用建议
- ionic3-android打包完美解决
- css alpha滤镜
- Windows下使用TeamViewer连接远程服务器,以及解决“远程桌面关闭后TeamViewer不能连接”的问题
- mysql 5.5 主从_Mysql5.5常用命令及主从配置
- python第三库安装方法记录
- UNIX/Linux RHEL6.3 root密码破解,GRUB加密(图文并茂)
- python列表去重_python列表的去重
- 【转载】C# WinForm程序中使用Unity3D控件
- [渝粤教育] 四川农业大学 农业气象学 参考 资料
- 生产排程系统_APS(高级计划排产)系统该如何选型,主要从哪些方面考虑?
热门文章
- css设置子盒子水平垂直居中(四种方式)
- Android的SharedPreferences存取String和List<String>类型(在Activity和Fragment内使用)
- Python得到n个从start到end的不重复随机数(set实现)
- php怎样空格分开输入三个数,php函数在每一空行拆分一个数组?
- KM、流程、风险管理的关系分析
- ubuntu全局配置文件
- Windows网络命令行程序
- 心情随笔(六):金秋十月备考之路亦别有一番风味
- 2018中国年度AI评选揭晓!10大领航企业,50家明星公司,10佳投资机构
- 雷军振臂一呼:1亿小爱同学激活是不是中国第一?百度硬刚:我才是