0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Ubuntu環境でFileMaker ServerにLet's Encryptを導入・自動更新する方法

Posted at

はじめに

業務にてFileMaker Cloudを使用していましたが、このたびオンプレ環境のFileMaker Serverに切り替えることになりました。
そしてなぜか私が、Linux完全初心者にもかかわらず、FileMaker ServerのインストールからSSL証明書(Let's Encrypt)の導入・自動更新まで担当することに…。

調べても公式は商用証明書の手順のみで、Let's Encryptを使った自動更新手順はほぼ情報がありません。

運用しながら試行錯誤した結果、安定して動く手順を確立できたので、この記事にまとめます。

環境

OS:Ubuntu 22.04
FileMaker Server 2024 (21.x系)

1. 証明書の手動取得手順(初回のみ)

まずは、Let’s EncryptのSSL証明書を取得します。
FileMaker Serverは標準でNginxを内包しているため、webroot オプションを使って取得します。

手順1:snapd と certbot のインストール

sudo apt update
sudo apt install snapd
sudo snap install --classic certbot

certbotコマンドを使いやすくするため、シンボリックリンクを作成

sudo ln -s /snap/bin/certbot /usr/bin/certbot

手順2:証明書の取得

sudo certbot certonly --webroot -w "/opt/FileMaker/FileMaker\ Server/NginxServer/htdocs/httpsRoot/" -d your-domain.example.com

your-domain.example.comは、SSL証明書を取得したい実際のドメイン名に置き換えてください。

実行すると、以下の質問が順番に表示されます。

  • メールアドレスを入力
  • 規約への同意
  • メーリングリストに載せていいか(任意)

それぞれ回答すると、証明書の取得が始まり、成功すると以下のメッセージが表示されます。

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/your-domain.example.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/your-domain.example.com/privkey.pem
This certificate expires on 2024-03-03.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

手順3:証明書ファイルをFileMaker ServerのCStoreへコピー

sudo cp /etc/letsencrypt/live/your-domain.example.com/cert.pem /opt/FileMaker/FileMaker\ Server/CStore/
sudo cp /etc/letsencrypt/live/your-domain.example.com/chain.pem /opt/FileMaker/FileMaker\ Server/CStore/
sudo cp /etc/letsencrypt/live/your-domain.example.com/privkey.pem /opt/FileMaker/FileMaker\ Server/CStore/

手順4:FileMaker Serverへ証明書をインポート

sudo /opt/FileMaker/FileMaker\ Server/Database\ Server/bin/fmsadmin certificate import \
/opt/FileMaker/FileMaker\ Server/CStore/cert.pem \
--keyfile /opt/FileMaker/FileMaker\ Server/CStore/privkey.pem \
--intermediateCA /opt/FileMaker/FileMaker\ Server/CStore/chain.pem

usernameとpasswordを聞かれるので、FileMaker Serverをインストールしたときに作った管理者アカウントの情報を入力。

注意ポイント
fullchain.pem は 使わないでください!
→ これを使うと以下のエラーが出ます:

The certificate file [/tmp/0DA54B95-C7D0-4D1D-A402-FA3E503A08F3/D12AAA9C-2725-4BFB-A897-57873F3B87C7] does not match the private key [ /opt/FileMaker/FileMaker Server/CStore/serverKey.pem].
Error: 20621 (Key doesn't match certificate)

正しくは chain.pem を指定!

手順5:FileMaker Server再起動

sudo service fmshelper restart

ここまででSSL証明書のインポートが完了です。
ブラウザでコンソール画面(https://your-domain.example.com/admin-console/signin)を開いて、エラーが出なければOK!

2. 自動化スクリプト・cron設定

Let’s Encryptの証明書は有効期限が90日なので、自動更新スクリプト+cron設定で運用します。
FileMaker Serverの仕様上、証明書の入れ替えにはコツが必要だったので、構成から説明します。

自動化用ディレクトリ作成

スクリプトは /opt/fms_scripts/ 配下にまとめて管理します。

sudo mkdir -p /opt/fms_scripts
cd /opt/fms_scripts

スクリプト構成

スクリプト名 役割
fms_cert_delete.sh 期限切れ証明書を削除(expect使用)
fms_cert_import.sh 新しい証明書をインポート(expect使用)
fms_restart.sh FileMaker Server再起動
fms_cert_renew.sh 全体制御(更新チェック・分岐・実行)

重要ポイント
FileMaker Serverは証明書のdelete必須
運用中の検証で、古い証明書を削除しないと反映されないケースがありました。
そのため delete → import → restart の順番で処理します。

スクリプトの作成

まずは、シェルスクリプトを作成します。

sudo touch fms_cert_delete.sh fms_cert_import.sh fms_restart.sh fms_cert_renew.sh && sudo chmod +x fms_cert_*.sh

次にそれぞれのスクリプトの中身を記入します。
途中に出てくるxxxxはFileMaker Serverをインストールしたときに作った管理者アカウントのusername、passwordをそれぞれ入力してください。

fms_cert_delete.sh
#!/usr/bin/expect -f

set timeout 60
spawn sudo "/opt/FileMaker/FileMaker Server/Database Server/bin/fmsadmin" certificate delete
expect "really delete certificate? (y, n)"
send "y\r"
expect "username"
send "xxxx\r"
expect "password:"
send "xxxx\r"
expect eof
fms_cert_import.sh
#!/usr/bin/expect -f

set timeout 60
spawn sudo "/opt/FileMaker/FileMaker Server/Database Server/bin/fmsadmin" certificate import /opt/FileMaker/FileMaker\ Server/CStore/cert.pem --keyfile /opt/FileMaker/FileMaker\ Server/CStore/privkey.pem --intermediateCA /opt/FileMaker/FileMaker\ Server/CStore/chain.pem
expect "really import certificate? (y, n)"
send "y\r"
expect "username"
send "xxxx\r"
expect "password:"
send "xxxx\r"
expect eof
fms_restart.sh
#!/bin/bash
sudo service fmshelper restart
fms_cert_renew.sh
#!/bin/bash

# 1. fmshelper起動
sudo service fmshelper start

# 2. certbot更新チェック
RENEW_LOG=$(sudo certbot renew)
echo "$RENEW_LOG"

# 3. 更新がなかったら終了
if echo "$RENEW_LOG" | grep -q "No renewals were attempted."; then
        echo "$(date) No certificate renewal. Skipping FileMaker update."
        exit 0
fi

echo "$(date) Certificate renewed. Proceeding with FileMaker update."

# 4. 証明書コピー
sudo cp /etc/letsencrypt/live/your-domain.example.com/cert.pem /opt/FileMaker/FileMaker\ Server/CStore/
sudo cp /etc/letsencrypt/live/your-domain.example.com/chain.pem /opt/FileMaker/FileMaker\ Server/CStore/
sudo cp /etc/letsencrypt/live/your-domain.example.com/privkey.pem /opt/FileMaker/FileMaker\ Server/CStore/

# 5. FileMaker 証明書削除・インポート・再起動
/opt/fms_scripts/fms_cert_delete.sh
/opt/fms_scripts/fms_cert_import.sh
/opt/fms_scripts/fms_restart.sh

echo "$(date) FileMaker certificate update completed."

cronの登録

毎日1時に実行するようにしました。

sudo vi /etc/cron.d/certbot
certbot
SHELL=/bin/bash
# You can also override PATH, but by default, newer versions inherit it from the environment
#PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed
00 1 * * * ubuntu /opt/fms_scripts/fms_cert_renew.sh >> /tmp/fms_cert_update.log 2>&1

visudo設定(パスワードなし実行許可)

ubuntuユーザにroot権限がないので、実行の度にパスワードを聞かれてしまいます。
そこで、visudo設定を行って、パスワードなしで実行できるようにします。

sudo visudo

一番下に(rootよりも下)以下を追加します。

ubuntu ALL=(ALL) NOPASSWD: /opt/FileMaker/FileMaker\ Server/Database\ Server/bin/fmsadmin, /bin/cp, /usr/bin/cp, /usr/sbin/service

そのまま保存(Ctrl+O ➔ Enter ➔ Ctrl+X)

以上で自動更新の設定が完了です!
以降はcronが更新タイミングを監視し、更新があれば自動でFileMakerへ反映されます。

参考にしたページ

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?