Ming-der Wang
ming@log4analytics.com
TurboTeam 集先鋒科技
chef solo 跟 chef server 比較
用 Git 來管理 chef-repo
用 Git 來管理
但基本上, 我們不再手動安裝任何東西, 改用自動部署
chef gem install knife-solo
或
gem install knife-solo
安裝 docker toolbox (click image)
$ git clone https://github.com/mingderwang/TaipeiDevOpsMeetup-chef.git
$ cd TaipeiDevOpsMeetup-chef
$ git checkout v2.0.1-log4-chef-server
$ git checkout -b chef-server
$ cat Berksfile
source "https://api.berkshelf.com"
cookbook 'chef-server', '= 2.1.6'
$ berks install
$ cat nodes/hogege.json
{
"run_list": [
"recipe[chef-server]",
"recipe[log4-chef-server]"
]
}
$ cd TaipeiDevOpsMeetup-chef/chef-repo
$ knife solo prepare username@nodenameorip
$ knife solo cook username@nodenameorip
$ cat .chef/knife.rb
cookbook_path ["cookbooks", "site-cookbooks"]
node_path "nodes"
role_path "roles"
environment_path "environments"
data_bag_path "data_bags"
#encrypted_data_bag_secret "data_bag_key"
knife[:berkshelf_path] = "cookbooks"
Chef::Config[:ssl_verify_mode] = :verify_peer if defined? ::Chef
.chef
├── cache
├── client.pem
├── knife.rb
├── mwang.pem
└── syntax_check_cache
log_level :info
log_location STDOUT
node_name 'mwang'
client_key '/Users/mingderwang/.chef/mwang.pem'
validation_client_name 'chef-validator'
validation_key '/Users/mingderwang/.chef/client.pem'
chef_server_url 'https://chef-server.log4analytics.com:443'
syntax_check_cache_path '/Users/mingderwang/.chef/syntax_check_cache'
cookbook_path [
"/Users/mingderwang/src/chef-repo3/cookbooks"
]
接下來大家實作看看
30 mins
$ knife bootstrap 104.236.11.146 -N do1 -x mwang --sudo
knife bootstrap 目的是幫你 node 安裝 chef-client,
跟 chef solo 的 prepare 功能類似
// 這裡 mwang user 必須有 sudo 能力.
大家挑自己 node 的名字, 不要跟別人重複 (例如 mingdo1)
$ chef generate repo chef-repo
$ cd chef-repo
$ git init
$ git add -A
$ git commit -m 'init from chef-repo create'
// git push to your git server.
// to share with your IT admins.
{ "name": "do1",
"chef_type": "node",
"json_class": "Chef::Node",
"chef_environment": "_default",
"run_list": [
"recipe[ntp]"
]
}
do1.json 範例
大家挑自己 node 的名字, 不要跟別人重複 (例如 mingdo1.json)
接下來大家實作看看
30 mins
大家挑自己 node 的名字, 不要跟別人重複 (例如 mingdo1)
註解: cookbook 更新 server, 指令為
$ knife cookbook upload log4-chef-server
ming@log4analytics.com
DevOpsTaiwan.slack.com
(進入 slack 方法 -> devopstaiwan.com)