vagrant file을 지정하기 위해서는 VAGRANT_VAGRANTFILE 환경변수에 해당 파일 경로를 설정하면 된다.
cd /d/github/cloud-space/infra/virutalbox
cat <<EOF > /assets/Vagrantfile-Mgmt
VAGRANTFILE_API_VERSION = "2"
IMAGE_NAME = "generic/ubuntu2004"
$script = <<SCRIPT
sudo mkdir /root/.ssh
sudo chmod 600 /root/.ssh
sudo cp /vagrant/id_rsa.pub /root/.ssh/authorized_keys
#sudo sed -i 's/dhcp4: .*/dhcp4: no/g' /etc/netplan/01-netcfg.yaml
#sudo sed -i 's/dhcp6: .*/dhcp4: no/g' /etc/netplan/01-netcfg.yaml
#sudo echo ' gateway4: 192.168.77.1' >> /etc/netplan/50-vagrant.yaml
#sudo sed -i 's/^#DNS.*/DNS=8.8.8.8/g' /etc/systemd/resolved.conf
sudo reboot
SCRIPT
$override_disk_size ||= false
$disk_size ||= "30GB"
CLUSTER = {
"node-61" => { :ip => "192.168.0.61", :cpus => 8, :memory => 8192, :script => $script },
"node-62" => { :ip => "192.168.0.62", :cpus => 8, :memory => 8192, :script => $script },
}
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
CLUSTER.each_with_index do |(hostname, info), index|
if ($override_disk_size)
unless Vagrant.has_plugin?("vagrant-disksize")
system "vagrant plugin install vagrant-disksize"
end
config.disksize.size = $disk_size
end
config.vm.synced_folder "assets/", "/vagrant", disabled: false
config.vm.define hostname do |cfg|
cfg.vm.provider :virtualbox do |vb, override|
config.vm.box = IMAGE_NAME
override.vm.network :public_network, bridge: "Realtek PCIe GBE Family Controller", ip: "#{info[:ip]}"
override.vm.hostname = hostname
vb.name = hostname
vb.customize ["modifyvm", :id, "--memory", info[:memory], "--cpus", info[:cpus], "--hwvirtex", "on"]
end # end provider
# inline shell scripts
cfg.vm.provision :shell do |s|
s.inline = info[:script]
end # end inline shell scripts
end # end config
end # end cluster
end
EOF
# 생성시
VAGRANT_VAGRANTFILE=./assets/Vagrantfile-Mgmt vagrant up
# 삭제시
VAGRANT_VAGRANTFILE=./assets/Vagrantfile-Mgmt vagrant destroy -f
NAT interface 삭제, yum repo 조정 및 시간 동기화
rm -f /etc/netplan/01-netcfg.yaml
cat <<EOF > /etc/netplan/50-vagrant.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses:
- 192.168.0.61/24
gateway4: 192.168.0.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
EOF
rm /etc/resolv.conf
cat <<EOF > /etc/resolv.conf
nameserver 8.8.8.8
EOF
sed -i 's/us.archive.ubuntu.com/mirror.kakao.com/g' /etc/apt/sources.list
apt update; apt -y upgrade
apt-get install -y chrony
sed -i '/pool/ s/^/#/' /etc/chrony/chrony.conf
cat <<EOF > /etc/chrony/chrony.conf
server 0.kr.pool.ntp.org iburst
server 3.asia.pool.ntp.org iburst
server 1.asia.pool.ntp.org iburst
EOF
systemctl restart chronyd
chronyc sources -v
timedatectl set-timezone Asia/Seoul; date
rm -f /etc/netplan/01-netcfg.yaml
cat <<EOF > /etc/netplan/50-vagrant.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses:
- 172.30.1.13/24
gateway4: 172.30.1.254
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
EOF
apt 저장소 변경(mirror.kakao.com)
// kr.archive.ubuntu.com -> mirror.kakao.com
// us.archive.ubuntu.com -> mirror.kakao.com
$ sudo sed -i 's/us.archive.ubuntu.com/mirror.kakao.com/g' /etc/apt/sources.list
// 확인
$ apt-get update
시긴동기화 설정, Timezone 설정
// chronyd 설치
$ apt update; apt -y upgrade
$ apt-get install -y chrony
// 한국 NTP server pool 및 접속 CIDR 설정
$ vi /etc/chrony/chrony.conf
...
#pool ntp.ubuntu.com iburst maxsources 4 // 주석 처리
#pool 0.ubuntu.pool.ntp.org iburst maxsources 1 // 주석 처리
#pool 1.ubuntu.pool.ntp.org iburst maxsources 1 // 주석 처리
#pool 2.ubuntu.pool.ntp.org iburst maxsources 2 // 주석 처리
# Korea public time server
server 0.kr.pool.ntp.org iburst
server 3.asia.pool.ntp.org iburst
server 1.asia.pool.ntp.org iburst
allow 10.0.0.0/24
...
$ systemctl restart chronyd
$ chronyc sources -v
$ timedatectl set-timezone Asia/Seoul
$ cat /etc/resolv.conf
nameserver 127.0.0.53
options edns0 trust-ad