2018年8月16日木曜日

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

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

〇Rundeckの画面

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

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

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/centos-7.5"
  config.vm.hostname = "co75rundeckmysql"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "co75rundeckmysql"
     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
localectl set-locale LANG=ja_JP.UTF-8

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

# install mysql
sudo yum -y remove mariadb-libs
yum -y localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
yum -y install yum-utils
yum -y install mysql mysql-devel mysql-server mysql-utilities
sudo systemctl enable mysqld.service
sudo systemctl start mysqld.service
# change password and create users and databases.
chkconfig mysqld on
service mysqld start
export MYSQL_ROOTPWD='Root123#'
export MYSQL_PWD=`cat /var/log/mysqld.log | awk '/temporary password/ {print $NF}'`
mysql -uroot --connect-expired-password -e "UNINSTALL PLUGIN validate_password;"
mysql -uroot --connect-expired-password -e "SET PASSWORD = PASSWORD('root'); FLUSH PRIVILEGES;"
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
yum -y install java-1.8.0-openjdk

# 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://co75rundeckmysql: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 件のコメント:

コメントを投稿