Vagrant.configure("2") do |config| ############## yum repos variable ############## base_repo = <<~BASE [base] name=CentOS-$releasever - Base baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/ gpgcheck=0 [updates] name=CentOS-$releasever - Updates baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/updates/$basearch/ gpgcheck=0 [extras] name=CentOS-$releasever - Extras baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/ gpgcheck=0 BASE epel_repo =<<~EPEL [epel] name=Extra Packages for Enterprise Linux 7 - $basearch baseurl=https://mirrors.ustc.edu.cn/epel/7/$basearch enabled=1 gpgcheck=0 EPEL php_repo = <<~PHP [remi] name=remirepo baseurl=http://mirrors.ustc.edu.cn/remi/enterprise/7/php74/x86_64/ enable=1 gpgcheck=0 [remisafe] name=remisaferepo baseurl=http://mirrors.ustc.edu.cn/remi/enterprise/7/safe/x86_64/ enable=1 gpgcheck=0 PHP mysql_repo = <<~MYSQL [mysql57] name=MySQL baseurl=https://mirrors.cloud.tencent.com/mysql/yum/mysql57-community-el7/ enabled=1 gpgcheck=0 MYSQL ########## base repo and epel repo for all vm ########### config.vm.provision "shell", inline:<<-SHELL sudo bash mkdir /etc/yum.repos.d/bak mv /etc/yum.repos.d/CentOS-*.repo /etc/yum.repos.d/bak # yum base repo cat <<'EOF' >/etc/yum.repos.d/base.repo #{base_repo} EOF # yum epel repo cat <<'EOF' >/etc/yum.repos.d/epel.repo #{epel_repo} EOF SHELL # all vm: centos7 config.vm.box = "generic/centos7" ######### nginx node ########## config.vm.define "nginx"do |ngx| ngx.vm.hostname = "nginx-vm" ngx.vm.provider :virtualboxdo |vb| vb.name = "nginx_centos7" end ngx.vm.provider :hypervdo |v| v.vmname = "nginx_centos7" end ngx.vm.provision "shell", inline:"sudo yum install -y nginx" end
######### php node ########## config.vm.define "php"do |php| php.vm.hostname = "php-vm" php.vm.provider :virtualboxdo |vb| vb.name = "php_centos7" end php.vm.provider :hypervdo |v| v.vmname = "php_centos7" end php.vm.provision "shell", inline:<<-SHELL sudo bash cat <<'END' >/etc/yum.repos.d/remi.repo #{php_repo} END yum install -y php php-fpm SHELL end ########### mysql master ########### config.vm.define "mysql-master"do |mysql| mysql.vm.hostname = "mysql-master-vm" mysql.vm.provider "virtualbox"do |vb| vb.name = "mysql-master_centos7" end
mysql.vm.provider :hypervdo |v| v.vmname = "mysql-master_centos7" end mysql.vm.provision "shell", inline:<<-SHELL sudo bash cat <<'END' >/etc/yum.repos.d/mysql.repo #{mysql_repo} END yum install -y mysql-community-{server,client} SHELL end
########## mysql slaves ############ 2.times do |i| config.vm.define "mysql-slave-#{i}"do |mysql| mysql.vm.hostname = "mysql-slave-#{i}-vm"
mysql.vm.provider :virtualboxdo |vb| vb.name = "mysql-slave-#{i}_centos7" end
mysql.vm.provider :hypervdo |v| v.vmname = "mysql-slave-#{i}_centos7" end mysql.vm.provision "shell", inline:<<-SHELL sudo bash cat <<'END' >/etc/yum.repos.d/mysql.repo #{mysql_repo} END yum install -y mysql-community-{server,client} SHELL end end end