AWS (Amazon EC2) で Redmine サーバ作成

課題管理サーバを立てる必要が出てきたので、AWS (EC2) でお手軽に作ってみた。

1.仮想マシンデプロイ

AWS コンソールで EC2 のインスタンス追加画面に行き、AWS Marketplace から検索で「Redmine Certified by Bitnami」を探す。

この AMI を利用して、t1.micro の仮想マシンを作成する。

2. 初回ログイン

sshで仮想マシンにログインする。ユーザ名はbitnami、ssh鍵はデプロイ時に指定したものを使う。

bitnamiユーザのホームディレクトリに “bitnami_credentials”というテキストファイルがあるので、中を閲覧する。Redmine上のユーザ名とパスワードが記載されている。

Welcome to the Bitnami Redmine Stack

******************************************************************************
The default username and password is 'user' and 'TBLwnBpotZT3'.
******************************************************************************

You can also use this password to access the databases and any other component the stack includes.
Please refer to https://docs.bitnami.com/ for more details.

https://RedmineホストのグローバルIPアドレス/ にアクセスして、ユーザ名: user パスワード: 上記テキスト内のパスワード でログインする。

実際に使うユーザを作成してシステム管理者権限を割り当て、そのユーザで再ログインして元々の「user」ユーザを削除する(セキュリティを考慮して)。

3. ホスト名の付与と SSL 証明書の取得

自分の所有ドメインがある場合は、ホスト名を割り当て、Let’s Encryptで証明書を取得することで正規の https サイトにする。

所有ドメインのゾーンファイルに、以下のようなAレコードを追加してリロードする。例示アドレスの 203.0.113.100 は Redmine ホストのグローバル IP アドレスとする。

redmine.example.com.    IN A     203.0.113.100

Redmine サーバに ssh ログインして、/opt/bitnami 以下にインストール済みの letsencrypt クライアント (lego) を利用する。

$ sudo /opt/bitnami/letsencrypt/scripts/generate-certificate.sh -m root@example.com -d redmine.example.com
...
It will create a certificate for the domain "redmine.example.com" under the email "root@example.com"
Do you want to continue? [y/n]: y
...
You can now configure a cronjob to renew it every month.
Do you want to proceed? [y/n]: y

Apache の設定も自動で書き換わるので、これで作業完了でもよいが、httpでアクセスされたらhttpsに転送するようにしておく。

$ sudo vi /opt/bitnami/apache2/conf/bitnami/bitnami.conf

13行目付近に太字の3行を追加
<Directory "/opt/bitnami/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
<IfVersion < 2.3>
Order allow,deny
Allow from all

28行目をコメントアウト
#Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf"


$ sudo /etc/init.d/bitnami restart