vagrant init <IMAGE>
vagrant up [VM_NAME]
vagrant reload [VM_NAME]
vagrant halt [VM_NAME]
vagrant destroy [VM_NAME]
vagrant ssh [VM_NAME]
controllersudo yum install centos-release-ansible-29 -y
sudo yum install ansible -y
ansible --version
vi inventory.ini
inventory.ini
192.168.100.11
192.168.100.12
ansible 192.168.100.11 -i inventory.ini -m yum -a "name=httpd state=present" -b
ansible 192.168.100.11 -i inventory.ini -m service -a "name=httpd state=started enabled=yes" -b
apache_install.yaml
- hosts: 192.168.100.11
tasks:
- yum:
name: httpd
state: present
- service:
name: httpd
enabled: yes
state: started
ansible-playbook -i inventory.ini apache_install.yaml -b
~/vagrant/ansible/Vagrantfile
Vagrant.configure("2") do |config|
# Define VM
config.vm.define "controller" do |centos|
centos.vm.box = "centos/7"
centos.vm.hostname = "controller"
centos.vm.network "private_network", ip: "192.168.100.10"
centos.vm.provider "virtualbox" do |vb|
vb.name = "controller"
vb.cpus = 2
vb.memory = 2048
end
end
# Define VM
config.vm.define "node1" do |centos|
centos.vm.box = "centos/7"
centos.vm.hostname = "node1"
centos.vm.network "private_network", ip: "192.168.100.11"
centos.vm.provider "virtualbox" do |vb|
vb.name = "node1"
vb.cpus = 2
vb.memory = 2048
end
end
# Define VM
config.vm.define "node2" do |centos|
centos.vm.box = "centos/7"
centos.vm.hostname = "node2"
centos.vm.network "private_network", ip: "192.168.100.12"
centos.vm.provider "virtualbox" do |vb|
vb.name = "node2"
vb.cpus = 2
vb.memory = 2048
end
end
end
ํ์ผ์ ์ธ์ฝ๋ฉ
- UTF-8
- UTF-16
๋ผ์ธ์ ๋
- CRLF: Windows
- LF: Unix-like
vagrant up
node1
vagrant ssh node1
sudo vi /etc/ssh/sshd_config
PasswordAuthentication yes
sudo systemctl restart httpd
node2
vagrant ssh node2
sudo vi /etc/ssh/sshd_config
PasswordAuthentication yes
sudo systemctl restart httpd
controller
vagrant ssh controller
ssh-keygen
ssh-copy-id vagrant@192.168.100.11
ssh-copy-id vagrant@192.168.100.12
A(Client) ---SSH---> B(Server)
/etc/ssh/ssh_host_<Algorithm>.pub/etc/ssh/ssh_host_<Algorithm>~/.ssh/known_hosts ํ์ผ์ B์ ๊ณต๊ฐํค ๋ฑ๋กssh-keygen~/.ssh/id_rsa: ๊ฐ์ธํค~/.ssh/id_rsa.pub: ๊ณต๊ฐํค~/.ssh/authorized_keys : ํด๋ผ์ด์ธํธ์ ๊ณต๊ฐํค ๋ฑ๋กssh-copy-id ๋ช
๋ น์ผ๋ก ๋ฑ๋ก~/.ssh/known_hosts ํ์ผ์ B์ ๊ณต๊ฐํค ๋ฑ๋ก๊ธฐ๋ณธ ๋ก๊ทธ์ธ ์ฌ์ฉ์
ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key.pub
ssh-keyscan 192.168.100.11
ssh-keyscan -t <rsa|ecdsa> 192.168.100.11
ssh-keyscan -t ecdsa 192.168.100.11 | ssh-keygen -l -f -
ssh-keyscan -t ecdsa 192.168.100.11 >> ~/.ssh/known_hosts
/etc/ssh/ssh_config: ํด๋ผ์ด์ธํธ ์ค์ ํ์ผ/etc/ssh/sshd_config: ์๋ฒ์ ์ค์ ํ์ผ/etc/ssh/sshd_config
PasswordAuthentication no # ํจ์ค์๋ ์ธ์ฆ
GSSAPIAuthentication yes # ํค ์ธ์ฆ
ssh-keygen
๐ก ์ค์ ์์๋ ํจ์คํผ๋ ์ด์ฆ๋ฅผ ์ค์
ssh-keyscan -t ecdsa 192.168.100.11 >> ~/.ssh/known_hosts
ssh-keyscan -t ecdsa 192.168.100.12 >> ~/.ssh/known_hosts
ssh-copy-id vagrant@192.168.100.11
ssh-copy-id vagrant@192.168.100.12
vagrant ssh <VM_NAME>
ssh -i .\.vagrant\machines\controller\virtualbox\private_key 192.168.100.10
ssh -i .\.vagrant\machines\node1\virtualbox\private_key vagrant@192.168.100.11
ssh -i .\.vagrant\machines\node2\virtualbox\private_key vagrant@192.168.100.12
~/.ssh/config
Host controller
HostName 192.168.100.10
User vagrant
IdentityFile C:\Users\Playdata\vagrant\ansible\.vagrant\machines\controller\virtualbox\private_key
Host node1
HostName 192.168.100.11
User vagrant
IdentityFile C:\Users\Playdata\vagrant\ansible\.vagrant\machines\node1\virtualbox\private_key
Host node2
HostName 192.168.100.12
User vagrant
IdentityFile C:\Users\Playdata\vagrant\ansible\.vagrant\machines\node2\virtualbox\private_key