使用官方托管chef server入门

测试环境为ubuntu 16.04,能连公网,不需要外网ip,域名等

首先chef官网注册账号,比如叫A,用户名是a,公司是b
登录官方chef manage
https://manage.chef.io/login
可以看到组织b和用户a
点击组织右边设置下载config.rb
在这里插入图片描述
然后点击用户a右边设置
在这里插入图片描述
保存私钥,之后会用到
安装chef client

curl -L https://www.opscode.com/chef/install.sh | sudo bash

之后会在root目录下生成.chef文件夹,这里存放我们刚才保存的私钥,比如是a.pem
然后修改下config.rb的内容,同样放到这个文件夹

# See http://docs.chef.io/config_rb.html for more information on knife configuration options

current_dir = File.dirname(__FILE__)
log_level                :info
log_location             STDOUT
node_name                "testnode"
client_key               "#{current_dir}/a.pem"
chef_server_url          "https://api.chef.io/organizations/b"
cookbook_path            ["#{current_dir}/../nodes/cookbooks"]

修改保存完毕,将当前节点通知给chef server
机器上执行

knife bootstrap 节点ip或主机名 --sudo -x 节点用户名 -P 密码 -N testnode

添加成功后就可以在manage的控制台看到节点信息了,下面是我的节点信息供读者参考
在这里插入图片描述
我们在安装chef client的时候root目录已经为我们生成了nodes目录,里边有当前节点的attributes信息的json
我们在config.rb中配置的目录是/root/nodes/cookbooks,所以我们要创建这个文件夹并创建一个简单的cookbook,这里我们从超市下载一个示例,然后修改

mkdir /root/nodes/cookbooks
knife supermarket install example

修改示例cookbook
vim example/recipes/default.rb

execute 'repo_test' do
        command 'netstat -nltp>> /tmp/netstat.txt'
        ignore_failure true
end

上传到chef server

knife upload cookbook example
knife upload cookbook example_resources
knife cookbook list

manage上可以看到已经上传了
在这里插入图片描述
然后在manage的node下边编辑run_list
在这里插入图片描述
把cookbook拖过来
在这里插入图片描述
chef client运行并查看文件,成功

root@ubuntu:~/nodes/cookbooks# chef-client 
Starting Chef Infra Client, version 16.7.61
Patents: https://www.chef.io/patents
resolving cookbooks for run list: ["example"]
Synchronizing Cookbooks:
  - example (0.1.14)
  - example_resources (1.0.14)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 1 resources
Recipe: example::default
  * execute[repo_test] action run
    - execute netstat -nltp>> /tmp/netstat.txt

Running handlers:
Running handlers complete
Chef Infra Client finished, 1/1 resources updated in 24 seconds
root@ubuntu:~/nodes/cookbooks# cat /tmp/netstat.txt 
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      52064/sshd      
tcp6       0      0 :::22                   :::*                    LISTEN      52064/sshd      
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值