[置顶] [4] DevOps 自动化运维工具Chef----在Ubuntu上安装最新的Chef Client 12.13.37 并和Chef server关联起来

标签: Chef自动化运维devopsubuntu
1181人阅读 评论(0) 收藏 举报
分类:

上一节分享了在Ubuntu上安装最新的Chef WorkStation 12.13.37,现在这一节给大家分享一下,Ubuntu上安装最新的Chef Client 12.13.37 并和Chef server关联起来。Client的安装相对来说简单一点。首先到下面的地址下载Ubuntu的 Chef Client最新版本,https://downloads.chef.io/chef-client/ubuntu/ 。下载完成后,假设我们在VMWare workstations里面已经安装了一台Ubunt 14的机器,2 台 Chef Client的计算机名为chef-client-01-rodney和chef-client-02-rodney, 用户名为ubuntu,IP地址为192.168.80.7和192.168.80.8,咱们文章以chef-client-01-rodney为例子,chef-client-02-rodney的步骤是一样的,则相应的安装步骤如下。

1. 配置/etc/hosts
sudo vi /etc/hosts
在hosts文件里面,加入下面的配置
127.0.0.1 localhost localhost.example.com
192.168.80.5 chef-master-rodney.example.com chef-master-rodney
192.168.80.6 chef-workstation-rodney.example.com chef-workstation-rodney
192.168.80.7 chef-client-01-rodney.example.com chef-client-01-rodney
192.168.80.8 chef-client-02-rodney.example.com chef-client-02-rodney
2. 在Client机器上安装chef client
sudodpkg -ichef_12.13.37-1_amd64.deb
ubuntu@chef-client-02-rodney:~/software$ sudo dpkg -i chef_12.13.37-1_amd64.deb Selecting previously unselected package chef.
(Reading database ... 51147 files and directories currently installed.)
Preparing to unpack chef_12.13.37-1_amd64.deb ...
Unpacking chef (12.13.37-1) ...
Setting up chef (12.13.37-1) ...
Thank you for installing Chef!
3. 安装完成后,运行下面的命令 sudo chef-client -v
如果运行成功。则完成安装
ubuntu@chef-client-02-rodney:~/software$ sudo chef-client -v
Chef: 12.13.37
4. 登陆到 chef-workstation的机器
因为我当前的客户端配置的是用私钥登陆,所以需要把chef client node的
私钥拷贝到,chef workstation机器上来
然后在,/home/ubuntu/chef-repo 目录下运行
sudo knife bootstrap chef-client-01-rodney -N chef-client-01-rodney -x ubuntu -p 22 -i .chef/keypaire4salt.pem
注意,client node的私钥 存放在,/home/ubuntu/chef-repo/.chef/keypaire4salt.pem 目录下

如果客户机器用的是,用户名和密码登陆的话,则需要用下面的命令
sudo knife bootstrap chef-client-01-rodney -N chef-client-01-rodney -x ubuntu -p 22 -P password
在我的环境里面出现了下面的错误,
ubuntu@chef-workstation-rodney:~/chef-repo$ sudo knife bootstrap chef-client-01-rodney -N chef-client-02-rodney -x ubuntu -p 22 -i .chef/keypaire4salt.pem
Creating new client for chef-client-021-rodney
Creating new node for chef-client-01-rodney
Connecting to chef-client-01-rodney
chef-client-01-rodney -----> Existing Chef installation detected
chef-client-01-rodney mkdir: cannot create directory ‘/etc/chef’: Permission denied
chef-client-01-rodney sh: 179: cannot create /etc/chef/client.pem: Directory nonexistent
chef-client-01-rodney chmod: cannot access ‘/etc/chef/client.pem’: No such file or directory
chef-client-01-rodney mkdir: cannot create directory ‘/etc/chef’: Permission denied
chef-client-01-rodney sh: 214: cannot create /etc/chef/trusted_certs/chef-master-rodney_objectiva_com.crt: Directory nonexistent
chef-client-01-rodney sh: 244: cannot create /etc/chef/client.rb: Directory nonexistent
chef-client-01-rodney sh: 253: cannot create /etc/chef/first-boot.json: Directory nonexistent
chef-client-01-rodney Starting the first Chef Client run...
chef-client-01-rodney [2016-09-15T15:27:13+00:00] WARN:*****************************************
chef-client-01-rodney [2016-09-15T15:27:13+00:00] WARN: Did not find config file: /etc/chef/client.rb, using command line options.
chef-client-01-rodney [2016-09-15T15:27:13+00:00] WARN: *****************************************
chef-client-01-rodney [2016-09-15T15:27:13+00:00] FATAL: Cannot load configuration from /etc/chef/first-boot.json
解决的办法有两个:
#1 解决方法
这个时候,登陆到client node,然后创建/etc/chef 文件夹并把权限设置成 777
sudo mkdir -p /etc/chef
sudo chmod 777 /etc/chef
#2 解决方法
sudo chown -R ubuntu:ubuntu /etc
其中ubuntu:unbuntu 为需要登录的client 节点的用户名和用户组
做了上面的任何一种设置之后,再次执行上面的命令,可以其输出类似如下:
ubuntu@chef-workstation:~/chef-repo$ sudo knife bootstrap chef-client-ubuntu -N chef-client-ubuntu -x ubuntu -p 22 -P ubuntu
Node chef-client-ubuntu exists, overwrite it? (Y/N) Y
Client chef-client-ubuntu exists, overwrite it? (Y/N) Y
Creating new client for chef-client-ubuntu
Creating new node for chef-client-ubuntu
Connecting to chef-client-ubuntu
chef-client-ubuntu -----> Existing Chef installation detected
chef-client-ubuntu Starting the first Chef Client run...
chef-client-ubuntu Starting Chef Client, version 12.13.37
chef-client-ubuntu resolving cookbooks for run list: []
chef-client-ubuntu Synchronizing Cookbooks:
chef-client-ubuntu Installing Cookbook Gems:
chef-client-ubuntu Compiling Cookbooks...
chef-client-ubuntu [2016-11-24T07:24:22+00:00] WARN: Node chef-client-ubuntu has an empty run list.
chef-client-ubuntu Converging 0 resources
chef-client-ubuntu
chef-client-ubuntu Running handlers:
chef-client-ubuntu Running handlers complete
chef-client-ubuntu Chef Client finished, 0/0 resources updated in 01 seconds

那么sudo knife bootstrap这个命令真正对客户端做了些什么事情呢?
其实从其日志的输出中可以看出来,其默认在客户端的/etc目录下,新建了一个chef的文件夹(/etc/chef)
其生成了3个文件(/etc/chef/client.pem,/etc/chef/client.rb,  /etc/chef/first-boot.json)和一个保存服务器网站的公钥证书( /etc/chef/trusted_certs在这个文件夹下
#1 client.pem
这个保存的是这个client 节点的私钥,公钥保存在Chef服务上
#2 client.rb文件内容如下,保存的是如何和服务器进行交互的配置信息
log_location     STDOUT
chef_server_url  "https://chef-server/organizations/example"
validation_client_name "chef-validator"
node_name "chef-client-ubuntu"
trusted_certs_dir "/etc/chef/trusted_certs"
#3 first-boot.json 保存的是run_list清单
{"run_list":[]}
5. 登陆到Chef server管理网站验证
然后,如果运行成功,则安装就完成了。剩下的另外一台也一样。安装完成后登陆到服务器的管理界面,则可以看到下面的图片




1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:384515次
    • 积分:6321
    • 等级:
    • 排名:第4065名
    • 原创:227篇
    • 转载:0篇
    • 译文:5篇
    • 评论:157条
    博客专栏