每次都自己調 server 太煩了,用 chef-solo 調一次以後一直套用比較方便,可以用 Vagrant 練習會快一點
先安裝 VirtualBox 和 Vagrant
https://www.virtualbox.org/wiki/Downloads
https://www.vagrantup.com/downloads.html
Ubuntu 16.04 的 Vagrant box (Vagrant box 就是包好的環境的意思)
https://app.vagrantup.com/ubuntu/boxes/xenial64
```
➜ Codes mkdir vagrant-test
➜ Codes cd vagrant-test
➜ vagrant-test vagrant init
```
在 Vagrantfile 裡設定
```
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
end
```
然後開啟 Vagrant
```
vagrant up
```
然後就可以 ssh 進去玩了
vagrant ssh
//關閉VM
$ vagrant halt
//暫停VM
$ vagrant suspend
//恢復暫停的VM
$ vagrant resume
//重啓VM
$ vagrant reload
## Chef solo
首先要 init 一個 chef-solo 的 project
檢查 vagrant 的 ssh-config
```
➜ vagrant-test git:(master) ✗ vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/wayne/Codes/vagrant-test/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
```
PasswordAuthentication 被設為 no 了所以要嘛去把 local 的 ssh key 加到 vagrant 裡要嘛就把 password 設成 yes,預設 password 是 vagrant
我個人是很懶所以就這樣:
```
ssh-copy-id -i ~/.ssh/id_rsa.pub -p 2222 vagrant@localhost
```
但其實還是有一些其他做法可以參考:
https://github.com/puphpet/puphpet/issues/1253
https://blog.vvtitan.com/2015/10/%E4%BD%BF%E7%94%A8vagrant%E7%B7%B4%E7%BF%92%E4%BD%88%E7%BD%B2%E4%BC%BA%E6%9C%8D%E5%99%A8/
https://medium.com/@brianmayrose/using-vagrant-on-ubuntu-16-04-to-create-a-virtual-machine-c767f6e2d876
https://gist.github.com/nicholasklick/af98d5814d5b8ba6d844
沒有留言:
張貼留言