Vagrant でつくる Rancher HA 構成

# Vagrant で作る Rancher HA 構成

Rancher Meetup #4 で解説する Rancher HA構成をつくるVagrantの解説ページです。

Work in progress....

2017/02/15 14:48時点でこんな感じです。

個別の解説は、別途追加予定

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

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  config.vm.define "rancher_mariadb" do |v|
     v.vm.box = "ubuntu/xenial64"
     v.vm.network :public_network, ip: "172.16.202.130", bridge: "eno2"

     # delete default gw on eth0
     v.vm.provision "shell",
       run: "always",
       inline: "eval `route -n | awk '{ if ($8 ==\"enp0s3\" && $2 != \"0.0.0.0\") print \"route del default gw \" $2; }'`"

     # default router
     v.vm.provision "shell",
       run: "always",
       inline: "route add default gw 172.16.202.10"

     v.vm.provision "shell", inline: <<-SHELL
        apt-get update
        sudo apt-get install -y software-properties-common
        sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
        sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/repo/10.0/ubuntu xenial main'
        export DEBIAN_FRONTEND=noninteractive
        sudo apt update
        sudo -E apt install -y -qq mariadb-server
        sudo -E apt install -y -qq mariadb-client
        sudo -E apt upgrade -y
        echo "CREATE DATABASE IF NOT EXISTS cattle COLLATE = 'utf8_general_ci' CHARACTER SET = 'utf8';" | mysql -uroot
        echo "GRANT ALL ON cattle.* TO 'cattle'@'%' IDENTIFIED BY 'cattle';" | mysql -uroot
        echo "GRANT ALL ON cattle.* TO 'cattle'@'localhost' IDENTIFIED BY 'cattle';" | mysql -uroot
        sudo sed -i -e 's/bind-address/#bind-address/g' /etc/mysql/my.cnf
        sudo service mysql restart
     SHELL
  end


  config.vm.define "rancher_serverha_01" do |v|
     v.vm.box = "ubuntu/xenial64"
     v.vm.network :public_network, ip: "172.16.202.131", bridge: "eno2"

     # delete default gw on eth0
     v.vm.provision "shell",
       run: "always",
       inline: "eval `route -n | awk '{ if ($8 ==\"enp0s3\" && $2 != \"0.0.0.0\") print \"route del default gw \" $2; }'`"

     # default router
     v.vm.provision "shell",
       run: "always",
       inline: "route add default gw 172.16.202.10"

     v.vm.provision "shell", inline: <<-SHELL
        export DEBIAN_FRONTEND=noninteractive
        sudo -E apt update
        sudo -E apt install -y
        sudo apt-get install -y --no-install-recommends \
            apt-transport-https \
            ca-certificates \
            curl \
            software-properties-common
        curl -fsSL https://apt.dockerproject.org/gpg | sudo apt-key add -
        apt-key fingerprint 58118E89F3A912897C070ADBF76221572C52609D
        sudo add-apt-repository \
            "deb https://apt.dockerproject.org/repo/ \
            ubuntu-$(lsb_release -cs) \
            main"
        sudo apt-get update
        sudo apt-get -y install docker-engine
        sudo docker run -d \
          --restart=unless-stopped \
          -p 8080:8080 \
          -p 9345:9345 \
          rancher/server \
          --db-host 172.16.202.130 \
          --db-port 3306 \
          --db-user cattle \
          --db-pass cattle \
          --db-name cattle \
          --advertise-address 172.16.202.131
     SHELL
  end

  config.vm.define "rancher_serverha_02" do |v|
     v.vm.box = "ubuntu/xenial64"
     v.vm.network :public_network, ip: "172.16.202.132", bridge: "eno2"

     # delete default gw on eth0
     v.vm.provision "shell",
       run: "always",
       inline: "eval `route -n | awk '{ if ($8 ==\"enp0s3\" && $2 != \"0.0.0.0\") print \"route del default gw \" $2; }'`"

     # default router
     v.vm.provision "shell",
       run: "always",
       inline: "route add default gw 172.16.202.10"

     v.vm.provision "shell", inline: <<-SHELL
        export DEBIAN_FRONTEND=noninteractive
        sudo -E apt update
        sudo -E apt install -y
        sudo apt-get install -y --no-install-recommends \
            apt-transport-https \
            ca-certificates \
            curl \
            software-properties-common
        curl -fsSL https://apt.dockerproject.org/gpg | sudo apt-key add -
        apt-key fingerprint 58118E89F3A912897C070ADBF76221572C52609D
        sudo add-apt-repository \
            "deb https://apt.dockerproject.org/repo/ \
            ubuntu-$(lsb_release -cs) \
            main"
        sudo apt-get update
        sudo apt-get -y install docker-engine
        sudo docker run -d \
          --restart=unless-stopped \
          -p 8080:8080 \
          -p 9345:9345 \
          rancher/server \
          --db-host 172.16.202.130 \
          --db-port 3306 \
          --db-user cattle \
          --db-pass cattle \
          --db-name cattle \
          --advertise-address 172.16.202.131
     SHELL
  end
end
```