2018年7月26日木曜日

VagrantでRundeckとMySQLをインストールした仮想マシン(Ubuntu18.04)を構築する

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

〇Rundeckの画面

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

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

Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/ubuntu-18.04"
  config.vm.hostname = "ub1804rundeckmysql"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "ub1804rundeckmysql"
     vbox.cpus = 2
     vbox.memory = 2048
     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
sed -i -e 's/# ja_JP.UTF-8 UTF-8/ja_JP.UTF-8 UTF-8/' /etc/locale.gen
locale-gen
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
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
mysql -uroot -proot -e "CREATE DATABASE rundeck DEFAULT CHARACTER SET utf8;"
mysql -uroot -proot -e "CREATE USER rundeck@localhost IDENTIFIED BY 'rundeck';"
mysql -uroot -proot -e "GRANT ALL PRIVILEGES ON rundeck.* TO 'rundeck'@'localhost';"
mysql -uroot -proot -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://ub1804rundeckmysql: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 件のコメント:

コメントを投稿