はじめに
プリザンターではWEBサーバーに「nginx」を使用しているが、「Apache」を使用したいという要望がありました。マニュアルをもとに下記環境でプリザンターのWEBサーバーに「Apache」を使用する手順を記載します。Linux初心者ですので、至らない点がありましたらコメントよろしくお願いいたします。私が作業していてつまずいたところを「つまずきポイント」としてご紹介します。
OS: RHEL9
EC2: プリザンターサーバ
RDS: PostgreSQL14
OSの構築
今回は60日間のトライアル版を使って、isoファイルからRHEL9で検証します
- こちらにアクセスする。
- isoファイルをダウンロードする(今回は「rhel-baseos-9.1-x86_64-dvd.iso」をダウンロード)。
- ダウンロードしたisoファイルををマシンにセットして、起動する。
- Install Red Hat Enterprise Linuxを選択してEnterを押下する。
- 言語の選択する(今回は日本語を選択)。
- インストール概要画面にて、インストール先を確認する(今回は特に変更なし)。
- アカウント情報を登録する(ユーザー名:root パスワード:XXXX(任意))。
- インストール開始
- システムの再起動
プリザンターをRed Hat Enterprise Linuxにインストールする
caution
特権ユーザーである「root」で操作するのは基本的にNG!そのため、他の一般ユーザーでログインし、下記2つの方法で実施。
- それぞれのコマンドの頭に「sudo」をつける。
- 「su - 」コマンドで「root」ユーザーに切り替える。
ここから下は下記マニュアルをもとに「Apache」をインストールした手順になります。
プリザンターをRed Hat Enterprise Linuxにインストールする
.NET6.0 のインストール
.NET SDKのインストール
Binariesをダウンロードして(今回は「dotnet-sdk-6.0.406-linux-x64.tar.gz」をダウンロード)、下記コマンドを入力してください。
# cd
# mkdir -p $HOME/dotnet && tar zxf dotnet-sdk-6.0.406-linux-x64.tar.gz -C $HOME/dotnet
# echo 'export DOTNET_ROOT=$HOME/dotnet' >> .bash_profile
# echo 'export PATH=$PATH:$HOME/dotnet' >> .bash_profile
# sh .bash_profile
つまずきポイント
- 「dotnet」フォルダがあると「mkdir」コマンド実行後エラーが発生します。
→「dotnet」フォルダを削除することで解決済み。
GDI+のインストール
# dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
# dnf install -y libgdiplus
PostgreSQLのセットアップ
リポジトリのインストール
# dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
PostgreSQLのインストール
# dnf module -y disable postgresql
# dnf install -y postgresql14-server postgresql14-contrib
データベースの初期化
# /usr/pgsql-14/bin/postgresql-14-setup initdb
サービス有効化
# systemctl enable postgresql-14
認証方式の設定
/var/lib/pgsql/14/data/pg_hba.conf を開き、METHOD列の設定を以下のように変更します。
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
ログの出力設定
/var/lib/pgsql/14/data/postgresql.confを開き、以下を設定します。
log_destination = 'stderr'
logging_collector = on
log_line_prefix = '[%t]%u %d %p[%l]'
※ ログファイルは "/var/lib/pgsql/data/log" に保存されます。
PostgreSQLのサービス再起動
# systemctl restart postgresql-14
PostgreSQLユーザー設定
- PostgreSQL管理用のユーザー"postgres"(OSのユーザー)にパスワードを設定します。
# passwd postgres
- ユーザー"postgres"に切り替え、PostgreSQLへ接続します。
# su - postgres
# psql -U postgres
- PostgreSQLの管理ユーザー "postgres" のパスワードを設定します(「new password」には任意のパスワードを入力)。
postgres=# alter role postgres with password '<new password>';
プリザンター用のデータベース作成
- データベース "Implem.Pleasanter" を作成します。
postgres=# create database "Implem.Pleasanter";
- 以下のコマンドで作成したDBの確認を行います。
postgres=# ¥l
全⽂検索⽤モジュール(pg_trgm)のインストール
テキストの全⽂検索に必要なモジュール(pg_trgm)をインストールします。
データベース"Implem.Pleasanter"に接続し、pg_trgm をインストール
postgres=# ¥c "Implem.Pleasanter";
Implem.Preasanter=# create extension pg_trgm;
外部からDBへのアクセスを許可する場合の設定
- /var/lib/pgsql/14/data/postgresql.conf の以下の2行のコメントを解除します。
# - Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
port = 5432 # (change requires restart)
/var/lib/pgsql/14/data/pg_hba.conf に以下の行を追加します。Address欄にはアクセスを許可するIPアドレスの範囲を指定します。
# TYPE DATABASE USER ADDRESS METHOD
host all all 192.168.1.0/24 md5
設定後、PostgreSQLのサービスを再起動します。
# systemctl restart postgresql-14
プリザンターの導入
アプリケーションの準備
プリザンターをダウンロードします。
ルートディレクトリ("/")に"/web"フォルダーを作成し、そこに"pleasanter" フォルダーを配置するものとして記述します。
/web/pleasanter/Implem.Pleasanter
/web/pleasanter/Implem.CodeDefiner
/web/pleasanter/Tools
データベースの構成
/web/pleasanter/Implem.Pleasanter/App_Data/Parameters/Rds.json を以下のように設定します。
{
"Dbms": "PostgreSQL",
"Provider": "Local",
"SaConnectionString":"Server=localhost;Port=5432;Database=postgres;UID=postgres;PWD=<設定したパスワード>",
"OwnerConnectionString":"Server=localhost;Port=5432;Database=#ServiceName#;UID=#ServiceName#_Owner;PWD=SetAdminsPWD",
"UserConnectionString":"Server=localhost;Port=5432;Database=#ServiceName#;UID=#ServiceName#_User;PWD=SetUsersPWD",
"SqlCommandTimeOut": 0,
"MinimumTime": 3,
"DeadlockRetryCount": 4,
"DeadlockRetryInterval": 1000
}
CodeDefinerを実行
# cd /web/pleasanter/Implem.CodeDefiner
# dotnet Implem.CodeDefiner.dll _rds
つまずきポイント
- 「dotnet」は「.NET SDKのインストール」項目でhomeディレクトリ配下のdotnetフォルダを設定しているため、フォルダ構成が異なる場合は絶対パスで入力します。
→「/home/implem/dotnet/dotnet Implem.Pleasanter.dll _rds」にて実行することで解決済み。
Pleasnterの起動確認
# cd ../Implem.Pleasanter
# dotnet Implem.Pleasanter.dll
つまずきポイント
- 「dotnet」のパスには「.NET SDKのインストール」項目でhomeディレクトリ配下のdotnetフォルダを設定しているため、フォルダ構成が異なる場合は絶対パスで入力します。
→「/home/implem/dotnet/dotnet Implem.Pleasanter.dll _rds」にて実行することで解決済み。
別のターミナルで "http://localhost:5000/" にアクセスし、正常なレスポンスが帰ってくることを確認します。
# curl -v http://localhost:5000/
* About to connect() to localhost port 5000 (#0)
* Trying ::1...
* Connected to localhost (::1) port 5000 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:5000
> Accept: */*
>
< HTTP/1.1 302 Found
< Date: Mon, 25 May 2020 15:13:08 GMT
< Server: Kestrel
< Content-Length: 0
< Location: http://localhost:5000/users/login?ReturnUrl=%2F
確認できたらCtrl+Cで終了します。
Pleasanterサービス用スクリプトの作成
/etc/systemd/system/pleasanter.service を以下の内容で作成します。
[Unit]
Description = Pleasanter
Documentation =
Wants=network.target
After=network.target
[Service]
ExecStart = /home/implem/dotnet/dotnet Implem.Pleasanter.dll
WorkingDirectory = /web/pleasanter/Implem.Pleasanter
Restart = always
RestartSec = 10
KillSignal=SIGINT
SyslogIdentifier=dotnet-pleasanter
User = root
Group = root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy = multi-user.target
サービスとして登録・サービスの起動
# systemctl daemon-reload
# systemctl enable pleasanter
# systemctl start pleasanter
リバースプロキシ(Apache)の設定
通常のwebサーバと同じ Port80 でアクセスできるようにリバースプロキシの設定を行います。
Apacheのインストール
次のコマンドでApacheをインストールします。
# dnf install -y httpd
# systemctl enable httpd
リバースプロキシの設定
/etc/httpd/conf/httpd.conf の最終行に以下の内容を追記します。
ProxyRequests Off
ProxyPass / http://localhost:5000/
ProxyPassReverse / http://localhost:5000/
ファイルを追記後、Apacheを再起動します。
# systemctl restart httpd
Http へのアクセス許可
クライアントからWebサービスへアクセスさせるため、 Http(port:80)へのアクセス許可の設定を行って下さい。
# firewall-cmd --permanent --add-service=http
さいごに
上記設定でプリザンターをインストールし、アクセスできることを確認しました。今回、初めてのLinuxということでコマンド入力での操作やユーザーごとの権限など色々なことを勉強させてもらいました。Linuxやネットについてはまだまだ知識不足ではありますが、これからも勉強は欠かさず実施していこうと思っています。
マニュアル