Dev Env Made Easy with Vagrant

在英特尔NUC上面安装了Debian系统, 然后再安装VirtualBox及Vagrant. 使用Vagrant可以轻松搭建一个OpenVPN实验环境.

VPN客户端, 通过VPN安全隧道, 访问WEB服务.

$ vagrant init
$ vi Vagrantfile
$ vagrant up

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

############################# FIX CentOS SSH ###############################
# vagrant ssh -p vpn -- -o user=vagrant 'chmod 600 ~/.ssh/authorized_keys' #
############################################################################

$script_vpn = <<SCRIPT
yum install -y epel-release  
yum install -y openvpn easy-rsa haveged  
SCRIPT

$script_web = <<SCRIPT
apt update  
apt install -y nginx  
SCRIPT

Vagrant.configure("2") do |config|

  config.vm.define "vpn" do |vpn|
    vpn.vm.box = "centos/7"
    vpn.vm.network :public_network
    vpn.vm.network :private_network, ip: "192.168.2.100"
    vpn.vm.provision :shell, inline: $script_vpn
  end

  config.vm.define "web" do |web|
    web.vm.box = "debian/jessie64"
    web.vm.network :private_network, ip: "192.168.2.200"
    web.vm.provision :shell, inline: $script_web
  end

end  

Trouble Shooting

$ vagrant up
    vpn: Inserting generated public key within guest...
    vpn: Removing insecure key from the guest if it's present...
    vpn: Key inserted! Disconnecting and reconnecting using new SSH key...
    vpn: Warning: Authentication failure. Retrying...
    vpn: Warning: Authentication failure. Retrying...
    vpn: Warning: Authentication failure. Retrying...
    vpn: Warning: Authentication failure. Retrying...
    vpn: Warning: Authentication failure. Retrying...
    vpn: Warning: Authentication failure. Retrying...

# 644 => 600
$ vagrant ssh -p vpn -- -o user=vagrant 'chmod 600 ~/.ssh/authorized_keys'

$ vagrant ssh vpn -- 'curl 192.168.2.200'