今更かもしれないけれども Vagrant を触ったので備忘録としてメモ
前提情報
母艦OS macOS Mojave
バージョン情報
CentOS 7.6-1810
VirtualBox 6.0.6
vagrant 2.2.4
マスタにするVM名(テキトー)
- centos76master
マスタにするOSのインストール時の作業
OSインストール時に作成するユーザ一覧
- root: vagrant
- vagrant: vagrant
設定するNAT用interface(よしなに)
- enp0s3: 10.0.2.15/24
マスタにするOSインストール後の作業
ファイルバックアップ用ディレクトリの作成
# mkdir /root/backup
OS最新化およびwgetとbzip2のインストール
# yum update
# yum install wget
# yum install bzip2
yum repositoryの設定
EPEL
# yum install epel-release
Remi
# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# wget https://rpms.remirepo.net/enterprise/remi-release-7.rpm
# rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm
sshの設定
# su - vagrant
$ mkdir .ssh
$ chmod 700 .ssh
$ cd .ssh
$ curl -k -L -o authorized_keys 'https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub'
$ chmod 600 authorized_keys
$ ..
$ chown -R vagrant.vagrant .ssh
$ exit
sudoの設定
# cp /etc/sudoers ./backup/sudoers.old
# visudo
# cp /etc/sudoers ./backup/sudoers.new
# diff .//backup/sudoers ./backup/sudoers.new
110a111
> vagrant ALL=(ALL) NOPASSWD: ALL
vagrant用の追加パッケージのインストール
# yum install kernel kernel-devel perl gcc
selinuxの無効化(許して・・・)
# cp /etc/selinux/config ./backup/selinux_config.old
# vi /etc/selinux/config
# cp /etc/selinux/config ./backup/selinux_config.new
# diff ./backup/selinux_config.old ./backup/selinux_config.new
7c7
< SELINUX=enforcing
---
> SELINUX=disabled
firewalldの停止と無効化(許して・・・)
# systemctl stop firewalld
# systemctl disable firewalld
virtualbox guest additionalsのインストール
# wget https://download.virtualbox.org/virtualbox/6.0.6/VBoxGuestAdditions_6.0.6.iso
# mount -t iso9660 VBoxGuestAdditions_6.0.6.iso /mnt
# /mnt/VBoxLinuxAdditions.run
おそらく以下のエラーが出力されるはず・・・
# sh /mnt/VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 6.0.6 Guest Additions for Linux........
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules. This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Kernel headers not found for target kernel
3.10.0-957.el7.x86_64. Please install them and execute
/sbin/rcvboxadd setup
modprobe vboxguest failed
The log file /var/log/vboxadd-setup.log may contain further information.
エラーの対処(のはず・・・)
# yum -y install kernel-3.10.0-957.10.1.el7
# yum -y install kernel-headers-3.10.0-957.10.1.el7
# yum -y install kernel-devel-3.10.0-957.10.1.el7
# reboot
# /sbin/rcvboxadd setup
# /sbin/rcvboxadd quicksetup all
マスタ用の最適化
余計なファイルの削除等実施
# yum clean all
# dd if=/dev/zero of=/EMPTY bs=1M
# rm -f /EMPTY
# shutdown -h now
母艦(macOS)での作業
$ cd /Users/sfukumura/Downloads/working
$ vagrant package --base centos76master
$ vagrant box add --name centos76minimal package.box
$ vagrant box list
$ vagrant init centos76minimal
$ vi Vagrantfile
$ vagrant up
$ vagrant ssh
vagrant up時に以下のエラーが出るかも
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:
mount -t vboxsf -o uid=1001,gid=1001 vagrant /vagrant
The error output from the command was:
/sbin/mount.vboxsf: mounting failed with the error: No such device
エラーの対処(のはず・・・)
$ vagrant plugin install vagrant-vbguest
Vagrantファイルの内容(node01とnode02をプロビする)
$ cat Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "centos76minimal"
config.vbguest.auto_update = false
config.vm.define "node01" do |server|
server.vm.hostname = "node01"
server.vm.network "forwarded_port", guest: 22, host: 2222, auto_correct: true
server.vm.network "private_network", type: "dhcp", virtualbox__intnet: true
end
config.vm.define "node02" do |server|
server.vm.hostname = "node02"
server.vm.network "forwarded_port", guest: 22, host: 2222, auto_correct: true
server.vm.network "private_network", type: "dhcp", virtualbox__intnet: true
end
end