プロジェクト

全般

プロフィール

001a_Ubuntu 20.04系にRedmine4.2(Redmine5.0)をインストール

バージョン 12 (手動人形, 2023/02/09 10:42) → バージョン 13/19 (手動人形, 2023/02/09 12:37)

{{TOC}}

## 本記事で実施すること

1. Redmineを動かすためのパッケージがインストールできるように準備をします。
1. Redmineを動かすためのパッケージ(Ruby/データベース/Webサービスなど)をインストールします。
1. データベースやWebサービスの基礎設定を行います。
1. Redmineの動作確認を行います。

## 想定している読者

- 「Redmine」をUbuntuにインストールしてみたい
- まずは動くところまで確認できればいい

## 前提

- Ubuntuサーバの初期設定が終わった直後の状態を想定します。
- DNSでドメインの名前が解決できることを前提としています
- 環境は以下の通りです。
- Apache系
- MySQL
- Ruby 2.7
- また、パッケージ管理としてaptitudeを用いています。aptが好みの方はこちらに読み替えてください。

### 特記事項

- インストールするRedmineのバージョンは4.2です。
- 5.x系にしないのは「筆者が使いたいプラグインが4.2系まででしか動作確認できなかった(2023年1月現在)」という単純にして重要な理由です。
- 同様に、Ubuntu22.04でインストールできるRedmineのバージョンは5.x以降となるため、インストールするUbuntuは20.04系になっています。
- 本記事のredmineの格納ディレクトリは/home/www-data/redmineです。一般的なディレクトリ(/var/lib/redmine)と異なることを最初に注記します。

## 手順

### 必要なパッケージをインストールします。

```bash
sudo aptitude update

sudo aptitude install build-essential zlib1g-dev libssl-dev libreadline-dev libyaml-dev libcurl4-openssl-dev libffi-dev mysql-server mysql-client apache2 apache2-dev libapr1-dev libaprutil1-dev imagemagick libmagick++-dev fonts-takao-pgothic subversion git ruby libruby ruby-dev libmysqlclient-dev

```

### apacheの追加モジュールをインストールします。

```bash
sudo aptitude install libapache2-mod-passenger
```

### rubyのパッケージ管理(gem)を用いて必要なライブラリをインストールします。

```bash
sudo gem install bundler racc mysql2
# 「3 gems installed」が表示されればインストール成功です。
```

### 必要に応じてmysqlの初期設定を行います。 mysqlの初期設定を行います。

mysql_secure_installationによる初期設定を行います。 #### mysql設定変更

うまくいかない場合は以下を参照してください。 ```bash
sudo mkdir /etc/old
# 各種設定ファイルのバックアップをここに格納します。


https://atelier.reisalin.com/projects/zettel/questions/5-mysql_secure_installation sudo cp -pi /etc/mysql/mysql.conf.d/mysqld.cnf /etc/old/mysqld.cnf.$(date +%Y%m%d)
# .$(date +%Y%m%d)をつけることで、バックアップファイルは当日日付(YYYYMMDD形式)で記録されます

diff -u /etc/mysql/mysql.conf.d/mysqld.cnf /etc/old/mysqld.cnf.$(date +%Y%m%d)
# バックアップが取れていることを「差分が存在しないこと」で確認します

echo -e "default_authentication_plugin=mysql_native_password" | sudo tee -a /etc/mysql/mysql.conf.d/mysqld.cnf
# mysqld.cnfに追記をします

```

#### 設定後の差分確認

```bash
diff -u /etc/old/mysqld.cnf.$(date +%Y%m%d) /etc/mysql/mysql.conf.d/mysqld.cnf
```

```diff
+default_authentication_plugin=mysql_native_password
```

#### 設定反映

```bash
sudo systemctl restart mysql.service
```

#### mysql rootパスワード変更

```bash
sudo mysql
```

```sql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
#''のpasswordは任意のものを入力ください

flush privileges;

exit

```

#### mysql_secure_installation

```bash
sudo mysql_secure_installation
```

#### 質問事項

```
Enter password for user root:
# 上記で設定したパスワードを入力します

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No:
# Yを入力してEnter

There are three levels of password validation policy:

LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:
# ポリシーに合わせて0/1/2を入力

Estimated strength of the password: 50
Change the password for root ? ((Press y|Y for Yes, any other key for No) :
# 既に設定しているのでn

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) :
# anonymousユーザーを削除するためY

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) :
# rootユーザのリモートログインを禁止するためY

Remove test database and access to it? (Press y|Y for Yes, any other key for No) :
# テストDBを削除するためY

Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
# 設定を反映するためy
```


### mysqlでDBとユーザーを設定します。

```bash
sudo mysql -u root -p
# 上記で設定した「mysqlのrootパスワード」を入力し、mysqlにログインします
```

```mysql
CREATE DATABASE redmine character set utf8mb4;
# DB "redmine" を作成します

CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'password';
# ユーザ "redmine"を作成し、パスワードを設定します
# この'password'は任意のパスワードに変更してください

GRANT ALL ON redmine.* TO 'redmine'@'localhost';
# DB "redmine"の権限をユーザ "redmine"に委譲します

flush privileges;
# 設定を反映させます

exit
```

### Redmineプログラムを配置します。

```bash
sudo mkdir -p /home/www-data/redmine

sudo chown -R www-data:www-data /home/www-data

sudo -u www-data svn co https://svn.redmine.org/redmine/branches/4.2-stable /home/www-data/redmine
```

### Redmineのコンフィグを設定します。

```bash
sudo cp -pi /home/www-data/redmine/config/database.yml.example /home/www-data/redmine/config/database.yml

sudo vi /home/www-data/redmine/config/database.yml
# 教義・信仰に従ったエディタで編集してください。
```

#### database.yml 編集内容

```yml
production:
adapter: mysql2
database: redmine
host: localhost
username: redmine
# rootからredmineに変更します
password: "redmine用のパスワード"
encoding: utf8mb4
# 本番環境(production)のみ設定を行います
```

### Redmineのマイグレーションを行います。

```bash
cd /home/www-data/redmine/ && pwd
# /home/www-data/redmine/ (Redmineを配置したディレクトリ)であることを確認します

sudo -u www-data bundle install --without development test --path vendor/bundle

sudo -u www-data bundle exec rake generate_secret_token

sudo -u www-data RAILS_ENV=production bundle exec rake db:migrate

sudo -u www-data RAILS_ENV=production REDMINE_LANG=ja bundle exec rake redmine:load_default_data
```

### Apacheの設定ファイルを作成します。

```bash
cat <<- __EOF__ | sudo tee -a /etc/apache2/sites-available/redmine.conf
<VirtualHost *:80>
ServerName hoge.example.com
# ServerNameは自身が設定したredmineに読み替えてください。
DocumentRoot /home/www-data/redmine/public
<Directory /home/www-data/redmine/public>
Options -MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
__EOF__
```

### 設定を反映させます。

```bash
ls -l /etc/apache2/sites-available/redmine.conf
# ファイルがあることを確認します。

sudo a2ensite redmine.conf
# 設定ファイルを有効化します

sudo a2dissite 000-default.conf
sudo a2dissite default-ssl.conf
# 初期サイト設定を無効化します

sudo apache2ctl configtest
# Syntax OK を確認します

sudo systemctl restart apache2.service

systemctl status apache2.service
```

### Webページの表示を確認します。

http://設定したRedmineドメイン

でRedmineのトップページが表示されれば成功です。

**直ちにadmin/adminでログインし、強固なパスワードを設定し直します。**

## 次のステップでやること

- SSL接続を有効化します。
- ログのローテーションを有効化し、適切なアクセスログを設定します。
トップへ
クリップボードから画像を追加 (サイズの上限: 50 MB)