Azureの「ストレージ共有」使ってDockerでRedmineしてみた
Azureの仮想マシンを使って単純な構成でEC2のときの様に1台構成でRedmine鯖を構築してみたけれども、前回Dockerを使ってRedmineを構築して少し目覚めた。
AWSの場合はS3※にDBのストレージをマウントして運用しようとするととても実用に耐えないですがAzureの場合はAzureFilesとかいうのがあってなんかEFSより安そうに見えたのと速度試してみて、もしかしてDBのストレージ乗せれば小規模レベルなら格安でストレージ気にしなくてRedmine運用できんじゃねとか思ったので試してみました。
#2021/6/3:
添付ファイルとプラグインはAzureFilesに逃がせましたが、どうやってもDBの方は逃がせませんでした。どなたか、DBを逃がすよい手立てありましたらご教示くださると幸甚です。
ひとまずVMのB1sとAzureFilesという組み合わせです。むちゃくちゃ速度があれだったのでAWSではこういう組み合わせをしようという気すら起きない・・・。
◆構築手順
1.OSイメージ展開後の注意
①イメージギャラリーからイメージを選択
②VMの作成でVMを作成する
③VM展開後にsudo可能ユーザのパスワードのリセットを行う。
2.AzureDNS設定
①DNSゾーンを作成する
②該当ゾーンに仮想マシンのグローバルIPを設定したAレコードを作成する
3.Dockerインストール
#https経由のaptリポジトリ許可
$ cd
$ sudo apt update
$ sudo apt-get -y install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
#DockerCEインストール
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
OK
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
$ sudo apt update
$ sudo apt -y install docker-ce
#Docker-composeインストール
#最新バージョン確認 https://github.com/docker/compose/blob/master/CHANGELOG.md
#インストール
$ export compose='NewerVersion'
$ sudo curl -L https://github.com/docker/compose/releases/download/${compose}/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
$ sudo chmod 0755 /usr/local/bin/docker-compose
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
$ sudo systemctl enable docker4.BlobSotrageファイル共有
①ストレージアカウントを作成する
②データストレージから「ファイル共有」を作成する
5.BlobStorageファイル共有のマウント設定
$ export AZUREFILES_RGN="VirtualMachineExamination"
$ export AZUREFILES_SA="YOUR_STORAGE_ACCOUNT"
$ export AZUREFILES_FSN="YOUR_FILESTORAGE_NAME"
$ export AZUREFILES_MNT="/mnt/$AZUREFILES_SA/$AZUREFILES_FSN"
$ curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
$ az login
#AzureStorageFiles 接続用Shellスクリプト作成
$ vi azurefilesconnect.sh
---------------------------
#! /bin/bash
resourceGroupName=$AZUREFILES_RGN
storageAccountName=$AZUREFILES_SA
# This command assumes you have logged in with az login
httpEndpoint=$(az storage account show \
--resource-group $resourceGroupName \
--name $storageAccountName \
--query "primaryEndpoints.file" | tr -d '"')
smbPath=$(echo $httpEndpoint | cut -c7-$(expr length $httpEndpoint))
fileHost=$(echo $smbPath | tr -d "/")
nc -zvw3 $fileHost 445
---------------------------
$ chmod a+x azurefilesconnect.sh
$ ./azurefilesconnect.sh
Connection to YOUR_STORAGE_ACCOUNT.file.core.windows.net 445 port [tcp/microsoft-ds] succeeded!
#マウント用Shellスクリプト作成
$ vi azurefilesmount.sh
---------------------------
#! /bin/bash
resourceGroupName=$AZUREFILES_RGN
storageAccountName=$AZUREFILES_SA
fileShareName=$AZUREFILES_FSN
mntPath="/mnt/$storageAccountName/$fileShareName"
sudo mkdir -p $mntPath
if [ ! -d "/etc/smbcredentials" ]; then
sudo mkdir "/etc/smbcredentials"
fi
storageAccountKey=$(az storage account keys list \
--resource-group $resourceGroupName \
--account-name $storageAccountName \
--query "[0].value" | tr -d '"')
smbCredentialFile="/etc/smbcredentials/$storageAccountName.cred"
if [ ! -f $smbCredentialFile ]; then
echo "username=$storageAccountName" | sudo tee $smbCredentialFile > /dev/null
echo "password=$storageAccountKey" | sudo tee -a $smbCredentialFile > /dev/null
else
echo "The credential file $smbCredentialFile already exists, and was not modified."
fi
sudo chmod 600 $smbCredentialFile
# This command assumes you have logged in with az login
httpEndpoint=$(az storage account show \
--resource-group $resourceGroupName \
--name $storageAccountName \
--query "primaryEndpoints.file" | tr -d '"')
smbPath=$(echo $httpEndpoint | cut -c7-$(expr length $httpEndpoint))$fileShareName
if [ -z "$(grep $smbPath\ $mntPath /etc/fstab)" ]; then
echo "$smbPath $mntPath cifs nofail,vers=3.0,file_mode=0666,dir_mode=0777,uid=999,gid=999,credentials=$smbCredentialFile,serverino" | sudo tee -a /etc/fstab > /dev/null
else
echo "/etc/fstab was not modified to avoid conflicting entries as this Azure file share was already present. You may want to double check /etc/fstab to ensure the configuration is as desired."
fi
sudo mount -a
---------------------------
$ chmod a+x azurefilesmount.sh
$ ./azurefilesmount.sh6.Dockerファイル準備・起動
$ cd
$ mkdir redmine
$ cd redmine
$ vi docker-compose.yml
-------------------------------------
version: '3.8'
networks:
web_net:
name: redmine_net
services:
# nginx
web:
image: steveltn/https-portal:1
container_name: web
restart: always
volumes:
- ./web/ssl_certs:/var/lib/https-portal
networks:
web_net:
ports:
- '80:80'
- '443:443'
env_file:
- .env
environment:
DOMAINS: >-
${HOSTNAME_READMINE} -> http://redmine:${APP_DOCKER_PORT}/,
# STAGE: 'staging'
STAGE: 'production'
depends_on:
- redmine
- reddb
restart: always
# Redmine Apps
redmine:
image: redmine:latest
container_name: ${APP_CONTAINER_NAME}
restart: always
volumes:
- ./app/plugins:/usr/src/redmine/plugins
- ./app/themes:/usr/src/redmine/public/themes
- ./app/config/configuration.yml:/usr/src/redmine/config/configuration.yml
- /mnt/YOUR_STORAGE_ACCOUNT/YOUR_FILESTORAGE_NAME/log:/usr/src/redmine/log:z
- /mnt/YOUR_STORAGE_ACCOUNT/YOUR_FILESTORAGE_NAME/files:/usr/src/redmine/files:z
networks:
- web_net
expose:
- ${APP_DOCKER_PORT}
env_file:
- .env
environment:
- REDMINE_DB_POSTGRES=reddb
- REDMINE_DB_DATABASE=${DB_NAME}
- REDMINE_DB_USERNAME=${DB_USER}
- REDMINE_DB_PASSWORD=${DB_PASSWORD}
- TZ=${DB_TZ}
depends_on:
- reddb
restart: always
# postgreSQL
reddb:
image: postgres:latest
container_name: ${DB_CONTAINER_NAME}
restart: always
volumes:
- ./db/initdb:/docker-entrypoint-initdb.d
- ./db/dbdata:/var/lib/postgresql/data
networks:
- web_net
expose:
- ${DB_DOCKER_PORT}
env_file:
- .env
environment:
- POSTGRES_DB=${DB_NAME}
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- TZ=${DB_TZ}
command: --port=${DB_DOCKER_PORT}
restart: always
--------------------------------
$ vi .env
--------------------------------
HOSTNAME_READMINE=YOUR_DOMAIN
APP_CONTAINER_NAME=redmine
APP_DOCKER_PORT=3000
DB_CONTAINER_NAME=db_redmine
DB_DOCKER_PORT=5432
DB_USER=redmine
DB_PASSWORD=redmine
DB_NAME=REDMINE_DB
DB_TZ=asia/Tokyo
--------------------------------
$ mkdir app
$ mkdir app/config
$ vi app/config/configuration.yml
--------------------------------------------
default:
email_delivery:
delivery_method: :smtp
smtp_settings:
address: "smtp.sendgrid.net"
port: 587
domain: "smtp.sendgrid.net"
authentication: :login
user_name: apikey
password: YOUR_SENDGRID_TOKEN
--------------------------------------------7.ネットワークセキュリティグループ
仮想マシンのネットワークで「受信ポートの規則を追加する」からhttpとhttpsを追加
8.Docker-Compose起動
#動作確認取れたらCtrl+Cで終了 $ docker-compose up #↓バックグラウンド起動しておく $ docker-compose up -d
◆参考サイト
・AzureOSイメージ更新
https://docs.microsoft.com/ja-jp/azure/virtual-machines/windows/capture-image-resource
・AzureVMパスワードリセット
https://www.hitoriit.com/entry/2019/01/15/080200
・AzureDNS
https://azure-recipe.kc-cloud.jp/2016/03/azure_dns/
・Azure Storage ファイル共有
https://qiita.com/hashitomu/items/1c29ee8012e7cc9be12d
・RedmineのDocker(ほぼこのサイトまんま)
https://create-it-myself.com/know-how/launch-https-portal-redmine-postgresql-with-docker-compose/
・Azureのネットワークセキュリティーグループ
https://docs.microsoft.com/ja-jp/azure/virtual-network/network-security-groups-overview
https://qiita.com/yotan/items/d5e3e8dcc94a2099fa05
やってみると動きました。今のところデータ量少ないのでそこそこ動いているみたい。どれぐらいの量まで実用レベルで動くのかは試してみないと何とも言えないけれども今のところサクサク動いています。S3より割高ながらEFSほどではないのでもしかしたら結構、いい選択肢かもしれないと思いつつしばらく様子見です。
#2021/6/3:
データベースファイルが悔しいところです。ここさえクリアできればストレージのバックアップで悩む必要があまりなくなるのになぁというところだっただけに残念です。また何かあれば追記します。
コメント