iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >如何在CentOS 6.3系统中部署一个CHEF环境
  • 745
分享到

如何在CentOS 6.3系统中部署一个CHEF环境

2023-06-10 09:06:29 745人浏览 安东尼
摘要

今天就跟大家聊聊有关如何在Centos 6.3系统中部署一个CHEF环境,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。安装前的准备:(chef.example.com,node1.e

今天就跟大家聊聊有关如何在Centos 6.3系统中部署一个CHEF环境,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

安装前的准备:(chef.example.com,node1.example.com)

关闭iptables

代码如下:


# service iptables stop


2.关闭SElinux

代码如下:


# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled
---------------


3.同步时间(重要)

代码如下:


# ntpdate asia.pool.ntp.org
# hwclock -w


4.安装ruby环境:
详见: https://www.yisu.com/article/54981.htm

三.chef-server安装:(chef.example.com)

下载chef-server安装包

进入页面Http://www.opscode.com/chef/install,点击Chef Server标签,选择要下载的版本
或在终端下用以下命令下载11.0.12版本:

代码如下:


# wget -c --no-check-certificate
<a href="https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-server-11.0.12-1.el6.x86_64.rpm">https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-server-11.0.12-1.el6.x86_64.rpm</a>



2.安装chef-server

终端内进入chef-server软件包所在目录,执行以下命令:

代码如下:


# rpm -ivh chef-server-11.0.12-1.el6.x86_64.rpm


注:请使用下载的软件包名称替换上面命令中的软件包名称.

3.修改本地FQDN名:

1).首先修改主机的hostname

代码如下:


# vi /etc/sysconfig/network
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-
HOSTNAME=chef.example.com
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-


2).修改本地host,添加server与node的FNDN


代码如下:


# echo "10.107.91.251 chef.example.com" >> /etc/hosts
# echo "10.107.91.252 node1.example.com" >> /etc/hosts


重启系统. 登录后验证:

代码如下:


# hostname -f
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-
chef.example.com
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-

配置chef-server

执行以下命令配置chef-server

代码如下:


# chef-server-ctl reconfigure


注:chef-server 10.x版本默认监听4000端口,chef-server 11.x监听443端口
SO若线上开启防火墙,需执行以下命令防火墙开启443端口

代码如下:


# iptables -I INPUT -p tcp --dport 443 -j ACCEPT
# service iptables save


现在浏览器打开https://10.107.91.251
输入:

代码如下:


username: admin
passWord: p@ssw0rd1


即可访问chef-server WEB页面.


四.chef-workstation安装:(chef.example.com)


1.安装chef-Client
进入页面http://www.opscode.com/chef/install,点击Chef Client标签,选择要下载的版本.
本例使用11.12.4-1版本:

代码如下:


# wget -c --no-check-certificate https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-11.12.4-1.el6.x86_64.rpm
# rpm -ivh chef-11.12.4-1.el6.x86_64.rpm



2.安装配置git

1).yum安装git:


代码如下:


# yum -y install git



2).进入root主目录,git克隆chef repository


代码如下:

# su -
# cd ~
# git clone git://GitHub.com/opscode/chef-repo.git
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
Initialized empty Git repository in /root/chef-repo/.git/
remote: Reusing existing pack: 223, done.
remote: Total 223 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (223/223), 45.77 KiB | 37 KiB/s, done.
Resolving deltas: 100% (57/57), done.
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;



2.配置chef-workstation

运行命令 knife configure -i ,配置过程如下所示(只需填写chef repository一项:/root/chef-repo,其他项使用默认值):

代码如下:


# knife configure --initial
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
WARNING: No knife configuration file found
Where should I put the config file? [/root/.chef/knife.rb]
Please enter the chef server URL: [https://chef.example.com:443]
Please enter a name for the new user: [root]
Please enter the existing admin name: [admin]
Please enter the location of the existing admin's private key: [/etc/chef-server/admin.pem]
Please enter the validation clientname: [chef-validator]
Please enter the location of the validation key: [/etc/chef-server/chef-validator.pem]
Please enter the path to a chef repository (or leave blank): /root/chef-repo
Creating initial api user...
Please enter a password for the new user: 123456
注:这里输入API user密码(后面要使用)
Created user[root]
Configuration file written to /root/.chef/knife.rb
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;


注: 没有出现Please enter a name for the new user: [root] 检查chef-server的443端口是否可以访问.

五.chef-workstation与chef-server不在同一服务器上的配置方法

(本例server与workstation在同一服务器,如无特殊需可略过这部分)

1.将chef-server的域名解析添加至chef-workstation的hosts文件


代码如下:


# echo "10.107.91.251 chef.example.com" >>/etc/hosts



2.在chef-workstation先创建/root/.chef目录,并将chef服务器上的/etc/chef-server/admin.pem和/etc/chef-server/chef-validator.pem文件拷贝到此目录

代码如下:


# mkdir ~/.chef
# scp chef.example.com:/etc/chef-server/admin.pem ~/.chef
# scp chef.example.com:/etc/chef-server/chef-validator.pem ~/.chef



3.执行knife configure -i命令进行初始化, 然后删除~/.chef/admin.pem

代码如下:


# knife configure --initial
# rm ~/.chef/admin.pem



4.knife configure配置过程:
1).server URL修改为chef服务器的地址https://chef.example.com:443,
2).admin's private key路径改为/root/.chef/admin.pem
3).validation key路径改为/root/.chef/chef-validation.pem
4).chef repository地址输入/root/chef-repo,其余项保持默认值.

代码如下:


# knife configure --initial
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
Overwrite /root/.chef/knife.rb? (Y/N) Y
Please enter the chef server URL: [https://workstation:443] https://chef.example.com:443
Please enter a name for the new user: [root]
Please enter the existing admin name: [admin]  
Please enter the location of the existing admin's private key: [/etc/chef-server/admin.pem] /root/.chef/admin.pem
Please enter the validation clientname: [chef-validator]
Please enter the location of the validation key: [/etc/chef-server/chef-validator.pem] /root/.chef/chef-validator.pem
Please enter the path to a chef repository (or leave blank): /root/chef-repo
Creating initial API user...
Please enter a password for the new user: 123456
注:这里输入API user密码(后面要使用)
Created user[root]
Configuration file written to /root/.chef/knife.rb
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;



5.配置ruby路径(之前已安装RUBY,这里可以略过)

chef默认集成了一个ruby的稳定版本,需修改PATH变量,保证chef集成的ruby被优先使用.

代码如下:

# echo 'export PATH="/opt/chef/embedded/bin:$PATH"' >> ~/.bash_profile && source ~/.bash_profile

六.验证chef-workstation

执行knife client list命令返回client列表则配置成功.

代码如下:


# knife client list
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
chef-validator
chef-webui
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;



七.chef-node配置 (node1.example.com)

node即为被chef-server配置管理的服务器

安装chef-Client

进入页面http://www.opscode.com/chef/install,点击Chef Client标签,选择要下载的版本.
本例使用11.12.4-1版本:

代码如下:


# wget -c --no-check-certificate https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-11.12.4-1.el6.x86_64.rpm
# rpm -ivh chef-11.12.4-1.el6.x86_64.rpm



2.修改本地FQDN名:

1).首先修改主机的hostname

代码如下:


# vi /etc/sysconfig/network
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-
HOSTNAME=node1.example.com
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-



2).修改本地host,添加本机和server的FNDN


代码如下:


# echo "10.107.91.251 chef.example.com" >> /etc/hosts
# echo "10.107.91.252 node1.example.com" >> /etc/hosts


重启系统. 登录后验证:

代码如下:


# hostname -f
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-
node1.example.com
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-



3.在chef-worksation执行下面命令添加并配置node


代码如下:


# knife bootstrap node1.example.com -x root -P 123456


注: 这里的密码是node1系统root账号的密码
chef-workstation通过ssh连接到node1(10.107.91.252)上执行bootstrap脚本(chef-workstation /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef11.6.0/lib/chef/knife/bootstrap/chef-full.erb)可以使用自定义的bootstrap脚本对node进行初始化配置.
node1会下载https://www.opscode.com/chef/install.sh脚本.脚本检查操作系统类型并在网络上下载符合此系统的chef版本进行安装(下载安装较慢).可以在node上预安装chef(见workstation安装chef部分)跳过此脚本.

代码如下:


&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-
Connecting to node1.example.com
node1.example.com Starting first Chef Client run...
node1.example.com [2014-05-08T15:53:22+08:00] WARN:
node1.example.com * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
node1.example.com SSL validation of HTTPS requests is disabled. HTTPS connections are still
node1.example.com encrypted, but chef is not able to detect forged replies or man in the middle
node1.example.com attacks.
node1.example.com
node1.example.com To fix this issue add an entry like this to your configuration file:
node1.example.com
node1.example.com ```
node1.example.com   # Verify all HTTPS connections (recommended)
node1.example.com   ssl_verify_mode :verify_peer
node1.example.com
node1.example.com   # OR, Verify only connections to chef-server
node1.example.com   verify_api_cert true
node1.example.com ```
node1.example.com
node1.example.com To check your SSL configuration, or troubleshoot errors, you can use the
node1.example.com `knife ssl check` command like so:
node1.example.com
node1.example.com ```
node1.example.com   knife ssl check -c /etc/chef/client.rb
node1.example.com ```
node1.example.com
node1.example.com * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
node1.example.com
node1.example.com Starting Chef Client, version 11.12.4
node1.example.com Creating a new client identity for node1.example.com using the validator key.
node1.example.com resolving cookbooks for run list: []
node1.example.com Synchronizing Cookbooks:
node1.example.com Compiling Cookbooks...
node1.example.com [2014-05-08T15:53:25+08:00] WARN: Node node1.example.com has an empty run list.
node1.example.com Converging 0 resources
node1.example.com
node1.example.com Running handlers:
node1.example.com Running handlers complete
node1.example.com
node1.example.com Chef Client finished, 0/0 resources updated in 2.393659851 seconds
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-


查看是否连接node1成功:

代码如下:


# knife node list
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
node1
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;


从上面可以看出node1已经成功注册到了chef-server中,整个环境 chef-workstation => chef-server => chef-client-1 已经搭建成功。

八.登陆server web后台

1.修改浏览器本机HOST,这里笔者使用的是Mac系统

代码如下:

# vi /etc/hosts
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
10.107.91.251 chef.example.com
10.107.91.252 node1.example.com
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;-&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;


2.访问https://chef.example.com
如图:

如何在CentOS 6.3系统中部署一个CHEF环境

如何在CentOS 6.3系统中部署一个CHEF环境

如何在CentOS 6.3系统中部署一个CHEF环境

如何在CentOS 6.3系统中部署一个CHEF环境

九.创建一个cookbook实例

git克隆chef repository (chef.example.com)
注: chef repository 是一个存储cookbooks和其他文件的目录结构,初次使用需要从github克隆

代码如下:


# su -
# cd ~
# git clone git://github.com/opscode/chef-repo.git
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
Initialized empty Git repository in /root/chef-repo/.git/
remote: Reusing existing pack: 223, done.
remote: Total 223 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (223/223), 45.77 KiB | 37 KiB/s, done.
Resolving deltas: 100% (57/57), done.
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;


获取到的目录如下:

代码如下:


# ls
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
Desktop    Downloads  Pictures  Templates  anaconda-ks.cfg  install.log         src
Documents  Music      Public    Videos     chef-repo        install.log.syslog
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
# cd chef-repo/
# ls
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
LICENSE    Rakefile      chefignore  cookbooks  environments
README.md  certificates  config      data_bags  roles
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;


2.创建一个cookbook,取名quick_start (chef.example.com)
注:需要切换到之前clone获取到的目录的cookbooks目录下

代码如下:


# cd ~/chef-repo/cookbooks
# knife cookbook create quick_start -o ./
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
** Creating cookbook quick_start
** Creating README for cookbook: quick_start
** Creating CHANGELOG for cookbook: quick_start
** Creating metadata for cookbook: quick_start
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;


创建的cookbooks目录如下

代码如下:


# # ls -1p quick_start
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
CHANGELOG.md
README.md
attributes/
definitions/
files/
libraries/
metadata.rb
providers/
recipes/
resources/
templates/
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;


注: cookbooks用来在chef中分布共享,大多数你创建基础实例都需要cookbooks.
此cookbook实例是创建一个简单的recipe,用来传递给node1一个简单的带有一些已经定义好的变量属性的文本.

创建一个属性文件,取名"quick_start.rb" (chef.example.com)

代码如下:


# vi ~/chef-repo/cookbooks/quick_start/attributes/quick_start.rb
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
nORMal[:deep_thought] = "If a tree falls in the forest ..."
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;


注: 在cookbook中属性文件用来在node中创建一些配置,从而你可以从recipe中调用这些属性.

对default recipe创建一个source template源模板 (chef.example.com)

代码如下:


# vi ~/chef-repo/cookbooks/quick_start/recipes/default.rb
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
template "/tmp/deep_thought.txt" do
 source "deep_thought.txt.erb"
 variables :deep_thought => node[:deep_thought]
 action :create
end
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;


注: recipes允许你对具体的源进行管理,这个例子中,你创建了一个叫quick_start的recipe,内容包括一个单独的源模板名叫template "/tmp/deep_thought.txt"

创建一个template模板文件 (chef.example.com)

注:这个文件调用源模板的具体属性,而后被chef传送给具体的node客户端

代码如下:

# vi ~/chef-repo/cookbooks/quick_start/templates/default/deep_thought.txt.erb
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
Today's deep thought: <%= @deep_thought %>
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;


6.将cookbook上传到Server (chef.example.com)

代码如下:


# cd ~/chef-repo/cookbooks/
# ls
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
README.md  quick_start
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
# knife cookbook upload -a -o ./
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
Uploading quick_start  [0.1.0]
Uploaded all cookbooks.
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;


确认你刚上传的cookbook

代码如下:


# knife cookbook list
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
quick_start   0.1.0
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;


6.将quick_start recipe添加到你的node中 (chef.example.com)

代码如下:


# knife node run_list add node1.example.com 'recipe[quick_start]'
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
node1.example.com:
run_list: recipe[quick_start]
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;


查看添加好的recipe

代码如下:


# knife  node show node1.example.com -r
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
node1.example.com:
run_list: recipe[quick_start]
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;


6.在node客户端注册,从而获取server上recipe的具体实例 (node1.example.com)
注:保证/etc/chef下有client.pem与validation.pem证书文件,如果没有检查之前的配置.

代码如下:

# chef-client
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
[2014-05-08T23:55:33+08:00] WARN:
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
SSL validation of HTTPS requests is disabled. HTTPS connections are still
encrypted, but chef is not able to detect forged replies or man in the middle
attacks.
To fix this issue add an entry like this to your configuration file:
```
# Verify all HTTPS connections (recommended)
ssl_verify_mode :verify_peer
# OR, Verify only connections to chef-server
verify_api_cert true
```
To check your SSL configuration, or troubleshoot errors, you can use the
`knife ssl check` command like so:
```
knife ssl check -c /etc/chef/client.rb
```
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Starting Chef Client, version 11.12.4
resolving cookbooks for run list: ["quick_start"]
Synchronizing Cookbooks:
- quick_start
Compiling Cookbooks...
Converging 1 resources
Recipe: quick_start::default
* template[/tmp/deep_thought.txt] action create
   - create new file /tmp/deep_thought.txt
   - update content in file /tmp/deep_thought.txt from none to feb62f
      --- /tmp/deep_thought.txt    2014-05-08 23:55:43.098408727 +0800
      +++ /tmp/chef-rendered-template20140508-8171-11cxwpb    2014-05-08 23:55:43.099454345 +0800
      @@ -1 +1,2 @@
      +Today's deep thought: If a tree falls in the forest ...
Running handlers:
Running handlers complete
Chef Client finished, 1/1 resources updated in 9.915108372 seconds
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;


最终执行后,创建 /tmp/deep_thought.txt文件,即实现了server向node的文件分发

代码如下:

# vi  /tmp/deep_thought.txt
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;
Today's deep thought: If a tree falls in the forest ...
&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;

看完上述内容,你们对如何在CentOS 6.3系统中部署一个CHEF环境有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注编程网精选频道,感谢大家的支持。

--结束END--

本文标题: 如何在CentOS 6.3系统中部署一个CHEF环境

本文链接: https://www.lsjlt.com/news/260066.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 如何在CentOS 6.3系统中部署一个CHEF环境
    今天就跟大家聊聊有关如何在CentOS 6.3系统中部署一个CHEF环境,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。安装前的准备:(chef.example.com,node1.e...
    99+
    2023-06-10
  • 如何在Kubernetes环境中部署Prometheus系统
    在Kubernetes环境中部署Prometheus系统通常需要以下步骤: 创建Prometheus配置文件:在配置文件中定义P...
    99+
    2024-03-04
    Prometheus
  • 如何进行centos卸载系统与环境部署
    这篇文章将为大家详细讲解有关如何进行centos卸载系统与环境部署,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。centos卸载系统已被广泛应用但是也在不断的更新。centos安装好之后ce...
    99+
    2023-06-16
  • centos如何部署php环境
    这篇“centos如何部署php环境”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“centos如何部署php环境”文章吧。c...
    99+
    2023-07-04
  • 如何在docker中部署一个.NET 5 运行环境
    如何在docker中部署一个.NET 5 运行环境?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。1、创建站点创建一个ASP.NET Core Web应用程序,选中启用Docke...
    99+
    2023-06-07
  • 关于如何使用docker部署centos系统测试环境
    目录一、检查本地服务器系统版本二、检查docker版本三、检查docker状态四、下载centos镜像五、创建centos容器1.运行cnentos容器2.进入容器内六、centos...
    99+
    2023-05-14
    docker docker部署centos centos系统环境
  • 怎么使用docker部署centos系统测试环境
    今天小编给大家分享一下怎么使用docker部署centos系统测试环境的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。一、检查...
    99+
    2023-07-05
  • Node.js环境在linux上如何部署
    本篇内容介绍了“Node.js环境在linux上如何部署”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!一 打开centos,然后开始下载no...
    99+
    2023-06-17
  • Docker在混合云环境中如何部署
    在混合云环境中部署Docker,可以采用以下步骤: 确保混合云环境的基础设施已经搭建好,包括私有云和公有云的资源。 在私有云...
    99+
    2024-05-07
    Docker
  • Linux中怎么部署一个Vue项目环境
    这篇文章将为大家详细讲解有关Linux中怎么部署一个Vue项目环境,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。安装要将Vuei .js集成到一个项目中,您可以使用CDN包、NPM或CLI。...
    99+
    2023-06-15
  • PostgreSQL在云环境中如何部署与管理
    在云环境中部署和管理PostgreSQL通常有两种方式:使用云服务提供商的托管服务或者自行部署和管理PostgreSQL实例。 使...
    99+
    2024-04-09
    PostgreSQL
  • centos系统上如何安装golang环境
    这篇文章主要讲解了“centos系统上如何安装golang环境”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“centos系统上如何安装golang环境”吧!一、Golang简介Golang是...
    99+
    2023-07-05
  • 如何在Kubernetes容器环境下部署Spinnaker ?
    如果你关注Docker,想了解基于Kubernetes的CD实践。那么,Spinnaker可能是多云平台部署工具的最佳选择。本文重点介绍spinnaker的概念、安装与踩过的坑,spinnaker在kubernetes的持续部署,以及线上容...
    99+
    2023-06-04
  • 如何在centos中安装java环境
    如何在centos中安装java环境?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。安装jdk(介绍三种方法)查看java版本:java -version方法一:利用yum源...
    99+
    2023-06-15
  • Grafana在容器化环境中如何部署和管理
    在容器化环境中部署和管理Grafana可以通过以下步骤实现: 使用Docker部署Grafana容器:首先,可以使用Docker...
    99+
    2024-04-02
  • 如何在不同环境中部署Golang应用程序
    引言Golang是一个开源的编程语言,由于其简洁、高效和并发性能好等特点,逐渐成为后端开发中备受关注的语言之一。在本文中,我们将讨论如何在不同的环境中部署Golang应用程序。安装Golang要在你的计算机中部署Golang应用程序,首先需...
    99+
    2023-05-14
  • Kubernetes在混合云环境中如何部署与管理
    在混合云环境中部署和管理Kubernetes可以通过以下步骤实现: 确保在所有云服务提供商上都安装了Kubernetes,并且版本...
    99+
    2024-05-08
    Kubernetes
  • 在Linux上搭建一个Java部署环境的详细步骤
    目录在Linux上搭建一个Java部署环境1. 安装jdk2.操作步骤:3. 安装mysql小结上篇介绍了如何在 Linux 上搭建 java ...
    99+
    2023-01-13
    linux搭建java部署环境 linux搭建java环境 linux部署java环境
  • 如何在 Unix 系统中部署 ASP 容器?
    在 Unix 系统中,如果想要部署一个 ASP 容器,需要做哪些事情呢?这里,我们将为您详细介绍一下如何在 Unix 系统中部署 ASP 容器。 ASP(Active Server Pages)是一种由微软公司开发的服务器端脚本语言,用于在...
    99+
    2023-09-16
    容器 unix 数组
  • 怎么在CentOS 7.3.1611中搭建一个Nginx1.10.3+MySQL5.7.16+PHP7.1.2环境
    本篇文章给大家分享的是有关怎么在CentOS 7.3.1611中搭建一个Nginx1.10.3+MySQL5.7.16+PHP7.1.2环境,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起...
    99+
    2023-06-08
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作