CentOSにNoto Sans CJK JPをインストール

Noto Sans CJK JPはGoogleとAdobe(Adobe側の名称は源ノ角ゴシック/Source Han Sans JP)が共同開発したオープンソースのフォントです。視認性が高く、無料で使えるため、多くのWebサイトで利用されています。(当サイトも利用しています。)

https://fonts.google.com/specimen/Noto+Sans+JP

https://www.google.com/get/noto/help/cjk/

Webサイトで利用する場合は、HTMLかCSSにWebフォントとして利用するための設定を行えば表示されますが、サーバー側の処理で作成するPDF等で利用するには、フォントをサーバーにインストールする必要があります。

ここではCentOSにNoto Sans CJK JPをインストールする手順についてご説明します。

フォントのダウンロード

$ wget https://noto-website-2.storage.googleapis.com/pkgs/NotoSansCJKjp-hinted.zip
$ unzip NotoSansCJKjp-hinted.zip -d NotoSansCJKjp

フォントディレクトリに移動

$ sudo mv NotoSansCJKjp /usr/share/fonts/NotoSansCJKjp
$ sudo chmod 644 /usr/share/fonts/NotoSansCJKjp/*

キャッシュを更新

$ sudo fc-cache -fv

sudo: fc-cache: command not foundと表示が出た場合、フォント管理のためのライブラリFontconfigがインストールされていない可能性があります。その場合は、yumを利用してインストールします。

$ sudo yum install fontconfig -y

インストールの確認

$ fc-list | grep NotoSansCJKjp
/usr/share/fonts/NotoSansCJKjp/NotoSansCJKjp-DemiLight.otf: Noto Sans CJK JP,Noto Sans CJK JP DemiLight:style=DemiLight,Regular
/usr/share/fonts/NotoSansCJKjp/NotoSansMonoCJKjp-Bold.otf: Noto Sans Mono CJK JP,Noto Sans Mono CJK JP Bold:style=Bold,Regular
/usr/share/fonts/NotoSansCJKjp/NotoSansCJKjp-Black.otf: Noto Sans CJK JP,Noto Sans CJK JP Black:style=Black,Regular
/usr/share/fonts/NotoSansCJKjp/NotoSansCJKjp-Light.otf: Noto Sans CJK JP,Noto Sans CJK JP Light:style=Light,Regular
/usr/share/fonts/NotoSansCJKjp/NotoSansCJKjp-Thin.otf: Noto Sans CJK JP,Noto Sans CJK JP Thin:style=Thin,Regular
/usr/share/fonts/NotoSansCJKjp/NotoSansCJKjp-Bold.otf: Noto Sans CJK JP,Noto Sans CJK JP Bold:style=Bold,Regular
/usr/share/fonts/NotoSansCJKjp/NotoSansCJKjp-Medium.otf: Noto Sans CJK JP,Noto Sans CJK JP Medium:style=Medium,Regular
/usr/share/fonts/NotoSansCJKjp/NotoSansCJKjp-Regular.otf: Noto Sans CJK JP,Noto Sans CJK JP Regular:style=Regular
/usr/share/fonts/NotoSansCJKjp/NotoSansMonoCJKjp-Regular.otf: Noto Sans Mono CJK JP,Noto Sans Mono CJK JP Regular:style=Regular

以上でインストールは完了です。

Let’s Encryptでワイルドカードを利用する

証明書の作成

Let’s Encryptでドメインにワイルドカードを使用するには、次のコマンドを実行します。

※例として*.example.comを設定しています。以下、example.comのところを、お使いのドメインに置き換えていただければと思います。

$ certbot certonly --manual --preferred-challenges dns-01 -d *.example.com -m info@example.com

コマンドを実行すると、次のようなメッセージが出力されます。xxxx…のところには、実際には英数字およびアンダースコア等で構成された文字列が表示されます。

Performing the following challenges:
dns-01 challenge for example.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.example.com with the following value:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue

xxxx…の文字列を、DNSのTXTレコード(キーは_acme-challenge.example.com)として設定します。設定前に、勢い余ってEnterを押さないことに注意します。

TXTレコードの設定が反映されたら、Enterを押して完了です。

TXTレコードを確認するには次のコマンドが便利です。

$ host -t txt _acme-challenge.example.com

証明書の更新

ワイルドカードを使用しない場合、証明書の更新は次のコマンドで行うことができます。

$ certbot renew

ただ、上記手順で証明書を作成した場合、このコマンドでは次のエラーが発生します。

$ certbot renew

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/example.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert is due for renewal, auto-renewing...
Could not choose appropriate plugin: The manual plugin is not working; there may be problems with your existing configuration.
The error was: PluginError('An authentication script must be provided with --manual-auth-hook when using the manual plugin non-interactively.',)
Failed to renew certificate racks.jp with error: The manual plugin is not working; there may be problems with your existing configuration.
The error was: PluginError('An authentication script must be provided with --manual-auth-hook when using the manual plugin non-interactively.',)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
All renewals failed. The following certificates could not be renewed:
  /etc/letsencrypt/live/example.com/fullchain.pem (failure)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1 renew failure(s), 0 parse failure(s)

現在のところ、証明書の更新の際も作成と同じコマンドを使用して、DNS設定を再度行う必要があるようです。

$ certbot certonly --manual --preferred-challenges dns-01 -d *.example.com -m info@example.com

CentOSでLet’s Encryptを自動更新

Let’s Encryptは無料で利用できるSSL証明書です。ただ、90日間で期限が切れてしまうため、定期的に更新する必要があります。

証明書の更新はコマンドのみで実行できるため簡単ですが、それでも手動で行うのは手間が掛かりますし、更新を忘れてしまいがちですので、Cronを利用して自動実行するのが良いと思います。

$ sudo crontab -e
00 04 01 * * certbot renew && systemctl reload nginx

上記の例では、毎月1日早朝4時に証明書の更新を行っています。また、Webサーバーは更新済みの証明書を再度読み込む必要があるため、Nginxサービスに対してreloadコマンドを実行しています。


追記

CentOSでyumでインストールした場合、自動更新用のサービス(certbot-renew)が用意されているので、そちらを利用した方が良いと思われます。

$ sudo systemctl enable --now certbot-renew.timer

更新後にNginxをリロードする場合は、次のファイルに設定します。

$ sudo vi /etc/sysconfig/certbot
POST_HOOK="--post-hook 'systemctl reload nginx'"

Top