vag-docker
约 285 字小于 1 分钟
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
boxes = [
{
:name => "cfk1",
:eth1 => "192.168.2.121",
:mem => "8192",
:cpu => "2"
},
{
:name => "cfk2",
:eth1 => "192.168.2.122",
:mem => "8192",
:cpu => "2"
},
{
:name => "cfk3",
:eth1 => "192.168.2.123",
:mem => "8192",
:cpu => "2"
}
]
Vagrant.configure("2") do |config|
boxes.each do |opts|
config.vm.define opts[:name] do |config|
# 设置虚拟机的Box
config.vm.box = "centos719"
# 设置虚拟机的主机名
config.vm.hostname = opts[:name]
# 设置虚拟机的用户
# config.ssh.username = "root"
# # 设置虚拟机的密码
# config.ssh.password = "vagrant"
# 设置虚拟机的网络
# config.vm.network :private_network, ip: opts[:eth1]
config.vm.network :public_network, ip: opts[:eth1]
# 设置虚拟机的初始化脚本
config.vm.provision :shell, :path => "bootstrap.sh"
# 设置虚拟机的默认磁盘空间(需要安装 vagrant-disksize 插件)
config.vm.disk :disk, size: "50GB", primary: true
config.vm.provider "vmware_fusion" do |v|
v.vmx["memsize"] = opts[:mem]
v.vmx["numvcpus"] = opts[:cpu]
end
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--memory", opts[:mem]]
v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
v.customize ["modifyvm", :id, "--name", opts[:name]]
end
end
end
end
bootstrap
#!/usr/bin/env bash
# The output of all these installation steps is noisy. With this utility
# the progress report is nice and concise.
echo "Update /etc/hosts"
cat > /etc/hosts <<EOF
127.0.0.1 localhost
172.18.11.121 cfk1
172.18.11.122 cfk2
172.18.11.123 cfk3
EOF
echo "Disable iptables"
setenforce 0 >/dev/null 2>&1 && iptables -F
### Set env ###
echo "export LC_ALL=en_US.UTF-8" >> /etc/profile
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
### 允许登录
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/g' /etc/ssh/sshd_config
sudo -i
systemctl restart sshd