2018年7月6日金曜日

VagrantでRundeckとMySQLをインストールした仮想マシン(Debian Stretch/9.4)を構築する

Rundeckはオープンソースのジョブスケジューラです。

〇Rundeckの画面

ブラウザからhttp://192.168.1.107:4440にアクセスする。デフォルトのユーザ名/パスワードはadmin/adminです。

〇構築方法
以下のVagrantfileを使用して、RundeckとMySQLをインストールした仮想マシン(Debian Stretch/9.4)を構築する事ができます。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/debian-9.4"
  config.vm.hostname = "db94rundeckmysql"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "db94rundeckmysql"
     vbox.cpus = 2
     vbox.memory = 4096
     vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
  end
config.vm.network "private_network", ip: "192.168.55.107", :netmask => "255.255.255.0"
config.vm.network "public_network", ip:"192.168.1.107", :netmask => "255.255.255.0"
  config.vm.provision "shell", inline: <<-SHELL
apt-get -y install task-japanese
sed -i -e 's/# ja_JP.UTF-8 UTF-8/ja_JP.UTF-8 UTF-8/' /etc/locale.gen
locale-gen
update-locale LANG=ja_JP.UTF-8
localectl set-locale LANG=ja_JP.UTF-8
localectl set-keymap jp106
apt-get update
#DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade

cd /root
mkdir ./.ssh
ssh-keygen -f ./.ssh/id_rsa -t rsa -N ''

# install mysql
wget https://dev.mysql.com/get/mysql-apt-config_0.8.9-1_all.deb
export DEBIAN_FRONTEND=noninteractive
echo mysql-apt-config mysql-apt-config/enable-repo select mysql-5.7-dmr | sudo debconf-set-selections
dpkg -i mysql-apt-config_0.8.9-1_all.deb
apt-get update
apt-get -y install mysql-server
mysql -uroot -e "CREATE DATABASE rundeck DEFAULT CHARACTER SET utf8;"
mysql -uroot -e "CREATE USER rundeck@localhost IDENTIFIED BY 'rundeck';"
mysql -uroot -e "GRANT ALL PRIVILEGES ON rundeck.* TO 'rundeck'@'localhost';"
mysql -uroot -e "FLUSH PRIVILEGES;"

# install java
apt-get -y install openjdk-8-jdk

# download and install rundeck
mkdir -p /opt/rundeck
cd /opt/rundeck
wget http://dl.bintray.com/rundeck/rundeck-maven/rundeck-launcher-2.11.4.jar
/usr/bin/java -Xmx1024m -jar rundeck-launcher-2.11.4.jar --installonly


# setup config files
sed -i -e 's#grails.serverURL=http://db94rundeckmysql:4440#grails.serverURL=http://192.168.1.107:4440#' /opt/rundeck/server/config/rundeck-config.properties
sed -i -e 's#dataSource.url = jdbc:h2:file:/opt/rundeck/server/data/grailsdb;MVCC=true#dataSource.url = jdbc:mysql://localhost/rundeck?autoReconnect=true#' /opt/rundeck/server/config/rundeck-config.properties
echo 'dataSource.username = rundeck' >> /opt/rundeck/server/config/rundeck-config.properties
echo 'dataSource.password = rundeck' >> /opt/rundeck/server/config/rundeck-config.properties


cat << EOF > /etc/systemd/system/rundeck.service
[Unit]
Description=rundeck
[Service]
Type=simple
ExecStart=/usr/bin/java -Xmx2048m -jar rundeck-launcher-2.11.4.jar -b /opt/rundeck
WorkingDirectory=/opt/rundeck
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
systemctl enable rundeck.service
systemctl start rundeck.service

echo 'id_rsa.pub'
echo '------------------'
cat /root/.ssh/id_rsa.pub
echo '------------------'
echo ''
echo 'access -> http://192.168.1.107:4440'
echo 'user: admin    password:admin'

SHELL
end

0 件のコメント:

コメントを投稿