2017年9月27日水曜日

VagrantでBaculaサーバー&Bacula-webとBaculaクライアントを2台の仮想マシン(Ubuntu16.04)にインストールする

Vagrantfileを使用して以下の2台の仮想マシンにBaculaとBacula-webをインストールします
1.baculasrv
  ・Baculaサーバー/クライアント
  ・Apache2+Bacula-web
  ・PostgreSQL
2.baculacli
  ・Baculaサーバー

Vagrantfile

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.define "baculacli" do |server|
    server.vm.box = "bento/ubuntu-16.04"
    server.vm.hostname = "baculacli"
    server.vm.network :public_network, ip:"192.168.1.102"
    server.vm.network "private_network", ip: "192.168.55.102", :netmask => "255.255.255.0"
    server.vm.provider :virtualbox do |vbox|
      vbox.name = "baculacli"
      vbox.cpus = 2
      vbox.memory = 4096
      vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
    end
    server.vm.provision "shell", inline: <<-SHELL
apt-get install -y bacula-client

sed -i -e "s/Name = baculacli-dir/Name = baculasrv-dir/" /etc/bacula/bacula-fd.conf
sed -i -e "s/127.0.0.1/192.168.55.102/" /etc/bacula/bacula-fd.conf
service bacula-fd restart

cp /etc/bacula/common_default_passwords /vagrant/passwords_baculacli

SHELL
  end
  #----------------------------------------------------------------------------------------


  config.vm.define "baculasrv" do |server|
    server.vm.box = "bento/ubuntu-16.04"
    server.vm.hostname = "baculasrv"
    server.vm.network :public_network, ip:"192.168.1.101"
    server.vm.network "private_network", ip: "192.168.55.101", :netmask => "255.255.255.0"
    server.vm.provider :virtualbox do |vbox|
      vbox.name = "baculasrv"
      vbox.cpus = 2
      vbox.memory = 4096
      vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
    end
    server.vm.provision "shell", inline: <<-SHELL
apt-get update
# install mysql
echo "mysql-server-5.7 mysql-server/root_password password root" | sudo debconf-set-selections
echo "mysql-server-5.7 mysql-server/root_password_again password root" | sudo debconf-set-selections
apt-get -y install mysql-server-5.7


# install bacula
apt-get install -y debconf-utils
echo "postfix postfix/main_mailer_type        select  Local only\n" \
"postfix postfix/mailname        string  baculasrv\n" \
"bacula-director-mysql   bacula-director-mysql/dbconfig-install  boolean true\n" \
"bacula-director-mysql   bacula-director-mysql/mysql/app-pass password bacula\n" \
"bacula-director-mysql   bacula-director-mysql/app-password-confirm password bacula" | debconf-set-selections
apt-get install -y --no-install-recommends bacula-server bacula-client bacula-common-mysql

# configure bacula
mkdir -p /opt/bacula/backup /opt/bacula/restore
chown -R bacula:bacula /opt/bacula
chmod -R 700 /opt/bacula

source /etc/bacula/common_default_passwords

# configure bacula storage daemon
cat << EOF >> /etc/bacula/bacula-sd.conf
Device {
  Name = FileStorage
  Media Type = File
  Archive Device = /opt/bacula/backup
  LabelMedia = yes;
  Random Access = Yes;
  AutomaticMount = yes;
  RemovableMedia = no;
  AlwaysOpen = no;
}
EOF
sed -i -e "s/SDAddress = 127.0.0.1/SDAddress = 192.168.55.101/" /etc/bacula/bacula-sd.conf

# configure bacula director
cat << EOF >> /etc/bacula/bacula-dir.conf
Storage {
  Name = File
  Address = 192.168.55.101
  SDPort = 9103
  Password = "$SDPASSWD"
  Device = FileStorage
  Media Type = File
}

Job {
  Name = "Backup-baculasrv"
  JobDefs = "DefaultJob"
  Storage = File
}

EOF


source /vagrant/passwords_baculacli

cat << EOF >> /etc/bacula/bacula-dir.conf
# Client (File Services) to backup
Client {
  Name = baculacli-fd
  Address = 192.168.55.102
  FDPort = 9102
  Catalog = MyCatalog
  Password = "$FDPASSWD"              # password for FileDaemon
  File Retention = 60 days            # 60 days
  Job Retention = 6 months            # six months
  AutoPrune = yes                     # Prune expired Jobs/Files
}

Job {
  Name = "Backup-baculacli"
  JobDefs = "DefaultJob"
  Storage = File
  Client = baculacli-fd
}

EOF

sed -i -e "s#/nonexistant/path/to/file/archive/dir/bacula-restores#/opt/bacula/restore/#" /etc/bacula/bacula-dir.conf
cat << EOF | sed -i -e '/File = \/usr\/sbin/r /dev/stdin' /etc/bacula/bacula-dir.conf
    File = /home
EOF

service bacula-director restart
service bacula-sd restart


# install apache2 & bacula-web
apt-get -y install php7.0 libapache2-mod-php7.0 apache2 php7.0-mbstring php7.0-gd php7.0-gettext php7.0-mysql php7.0-pdo

wget -O bacula-web-7.4.0.tgz http://www.bacula-web.org/download.html?file=files/bacula-web.org/downloads/7.4.0/bacula-web-7.4.0.tgz
mkdir -p /opt/bacula-web
mv bacula-web-7.4.0.tgz /opt/bacula-web
cd /opt/bacula-web
tar xvfz bacula-web-7.4.0.tgz

cp /opt/bacula-web/application/config/config.php.sample /opt/bacula-web/application/config/config.php
sed -i -e "s/'en_US';/'ja_JP';/" /opt/bacula-web/application/config/config.php
sed -i -e "s/\?>//" /opt/bacula-web/application/config/config.php
cat << EOF >> /opt/bacula-web/application/config/config.php
// bacula catalog (MySQL)
\\$config[0]['label'] = 'baculasrv';
\\$config[0]['host'] = 'localhost';
\\$config[0]['login'] = 'bacula';
\\$config[0]['password'] = 'bacula';
\\$config[0]['db_name'] = 'bacula';
\\$config[0]['db_type'] = 'mysql';
\\$config[0]['db_port'] = '3306';
?>
EOF
chown -R www-data:www-data /opt/bacula-web
sudo ln -s /opt/bacula-web/ /var/www/html/

systemctl restart apache2

SHELL
  end
  #----------------------------------------------------------------------------------------

end

0 件のコメント:

コメントを投稿