Vagrant虚拟机供给

如何基于Vagrant与Virtualbox快速在本地拉起测试虚拟机

Vagrant Provision [DRAFT]

If you wish to run pigsty on your laptop, consider using vagrant and virtualbox as vm provisioner

  1. Install vagrant, virtualbox and ansible on your computer. for example:
brew install virtualbox vagrant ansible 	# MacOS, other may not work this way
  1. Use vagrant with Vagrantfile, it will provision 4 nodes (via virtualbox) for this project.
make up     # pull up vm nodes. alternative: cd vagrant && vagrant up
  1. Setup nopass ssh from your host to vm nodes
make ssh		# cd vagrant && vagrant ssh-config > ~/.ssh/pigsty_config
  1. There are some vagrant shortcuts defined in Makefile
make				# launch cluster
make new    # create a new pigsty cluster
make dns		# write pigsty dns record to your /etc/hosts (sudo required)
make ssh		# write ssh config to your ~/.ssh/config
make clean	# delete current cluster
make cache	# copy local yum repo packages to your pigsty/pkg

Vagrant provision scripts tested on MacOS 10.15 Catalina.

Vagrant使用教程

如果您希望在本地环境运行Pigsty示例,可以考虑使用 vagrantvirtualbox初始化本地虚拟机。

  1. 在宿主机上安装 vagrant, virtualboxansible(可选)

    具体安装方式因平台而异,请参照软件官网文档进行,以MacOS为例,可以使用homebrew一键安装:

brew install virtualbox vagrant ansible 	# MacOS命令行
  1. 在项目主目录执行make up,系统会使用 Vagrantfile中的定义拉起四台虚拟机。
make up     # 拉起所有节点,也可以通过进入vagrant目录执行vagrant up实现
  1. 配置宿主机到虚拟机的SSH免密访问
make ssh		# 等价于执行 cd vagrant && vagrant ssh-config > ~/.ssh/pigsty_config
  1. Makefile 中定义了一些vagrant快捷方式
make				# 启动集群
make new    # 销毁并创建新集群
make dns		# 将Pigsty域名记录写入本机/etc/hosts (需要sudo权限)
make ssh		# 将虚拟机SSH配置信息写入 ~/.ssh/config
make clean	# 销毁现有本地集群
make cache	# 制作离线安装包,并拷贝至宿主机本地,加速后续集群创建
make upload # 将离线安装缓存包 pkg.tgz 上传并解压至默认目录 /www/pigsty

附带的Vagrantfile在MacOS 10.15下测试

最后修改 January 4, 2021: update zh doc (d400d32)