Chef-solo-2
- Category: 電腦相關
- Last Updated: Wednesday, 22 April 2015 16:28
- Published: Thursday, 26 March 2015 15:41
- Written by sam
安裝一下,操作chef的利器Knife-Solo
一切重新開始,下了新的IMAGE
開機後,連入
先從安裝RUBY開始(記得要2.0最少)
所以需要手動一下
sudo apt-get -y update
sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
wget http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p481.tar.gz
tar -xvzf ruby-2.0.0-p481.tar.gz
cd ruby-2.0.0-p481/
./configure --prefix=/usr/local
make && sudo make install
check version
ruby -v
ruby 2.0.0p481 (2014-05-08 revision 45883) [x86_64-linux]
sudo gem install knife-solo
44 gems installed
完成後,就可以開始,先初始化一個資料夾(這邊是0325)
knife solo init 0325
vagrant@packer-virtualbox-iso-1411922062:/tmp/0325$ tree
.
├── cookbooks
├── data_bags
├── environments
├── nodes
├── roles
└── site-cookbooks
6 directories, 0 files
自動的建立了必要的目錄
先抓一臺來試一下指令
vagrant@packer-virtualbox-iso-1411922062:/tmp/0325$ knife solo prepare This email address is being protected from spambots. You need JavaScript enabled to view it.
Installing Chef 12.1.2
installing with dpkg...
Selecting previously unselected package chef.
(Reading database ... 45941 files and directories currently installed.)
Unpacking chef (from .../chef_12.1.2-1_amd64.deb) ...
Setting up chef (12.1.2-1) ...
Thank you for installing Chef!
Generating node config 'nodes/192.168.1.85.json'...
看來是搞定了,看一下NODE資料夾
vagrant@packer-virtualbox-iso-1411922062:/tmp/0325/nodes$ cat 192.168.1.85.json
{
"run_list": [
],
"automatic": {
"ipaddress": "192.168.1.85"
}
順便五臺一起做一下,反正很快不需要再次SSH連線
vagrant@packer-virtualbox-iso-1411922062:/tmp/0325/nodes$ ls
192.168.1.81.json 192.168.1.82.json 192.168.1.83.json 192.168.1.84.json 192.168.1.85.json
再來就是看怎麼玩了…大架構的話,應該要改用chef-server......
參考之前的裝一下沒用的ZSH
安裝中
root pts/1 192.168.20.66 14:41 26.00s 3.48s 0.67s chef-solo worker: ppid=17507;start=14:41:58;
安裝前
root@debian1:~# dpkg --get-selections | sed -n 's/\t\+install//p' |grep zsh
安裝後
root@debian1:~# dpkg --get-selections | sed -n 's/\t\+install//p' |grep zsh
zsh
安裝設定檔案
vagrant@packer-virtualbox-iso-1411922062:/tmp/0325/cookbooks/zsh/recipes$ cat default.rb
package 'zsh'
再來要使用REMOVE
修改一下
vagrant@packer-virtualbox-iso-1411922062:/tmp/0325$ cat cookbooks/zsh/recipes/default.rb
package 'zsh' do
action :remove
end
以上就是基本的套件安裝
再來就是弄一下USERADD
一樣先建立一本食譜
vagrant@packer-virtualbox-iso-1411922062:/tmp/0325$ knife cookbook create user
先新加一下帳號及密碼(密碼不是明碼,採用openssl passwd -1 password)
vagrant@packer-virtualbox-iso-1411922062:/tmp/0325$ cat cookbooks/user/recipes/default.rb
user 'depo' do
password '$1$TpR6daQs$ovLS3bs0IBwLE4U93hATe1'
end
再修改一下
vagrant@packer-virtualbox-iso-1411922062:/tmp/0325$ cat nodes/192.168.1.85.json
{
"run_list": [
"recipe[zsh]",
"recipe[user]"
],
"automatic": {
"ipaddress": "192.168.1.85"
}
}
連線至192.168.1.85
cat /etc/passwd
果然有了
depo:x:1002:1002::/home/depo:/bin/sh
再來當然是試著移除使用者
vagrant@packer-virtualbox-iso-1411922062:/tmp/0325$ cat cookbooks/user/recipes/default.rb
user 'depo' do
action :remove
end
連線至192.168.1.85 看一下user "depo"還在不在
root@debian1:~# cat /etc/passwd |grep depo
以上…如果有使用ssh authorized_key作認證的話…就會省事很多
有KEY的話,可以使用以下連接方式
knife solo cook -i /root/id_rsa @192.168.1.85
記得使用
ssh-copy-id -i /root/id_rsa.pub 192.168.1.81
把KEY弄到每臺去
一次執行多臺
echo 192.168.1.83 192.168.1.82 |xargs -n 1 knife solo prepare -i /root/id_rsa
連線至EC2主機測試
knife solo prepare -i /root/id_rsa -P XXX This email address is being protected from spambots. You need JavaScript enabled to view it.