ひじりんのひつまむしブログ

現役システムエンジニアのゲームやら映画やら技術やら・・

AlmaLinux 9 に getssl を用いて、Let's Enciptを入れる

 

Apacheのインストール

AlmaLinux構築直後では、apache が入っていない場合がある

その場合

dnf install httpd

で、インストール。

systemctl start httpd

で、起動。

 

ファイアーウォールの設定

次いでに、ファイアーウォールも起動しておいた方がよい

systemctl start firewalld

ファイアウォールの初期は、httpが許可されていない場合もあるので、追加

firewall-cmd --add-service=http --permanent

firewall-cmd --reload

設定されているかは、

firewall-cmd --list-all

で確認できる。サービスの行に http があればよい

 

また、クラウド業者によっては、パケットフィルターを設定している

ところもあるので、フィルタに Web (http/https) を追加が必要

 

次に進む前に、http にて、ドメインでアクセスできるか確認しておく

(※Google Chrome では、http アクセスを https へ切り替えるという

 事もあるようなので、他のブラウザの方がよいかも・・)

 

getssl の設定

getssl は、certbot の代替としてあるものの一つ

root のホーム等で、下記を実行する

curl --silent https://raw.githubusercontent.com/srvrco/getssl/latest/getssl > getssl

chmod 700 getssl

 

ドメインSSL取得

./getssl -c ドメイン

そうすると、~/.getssl/ドメイン/getssl.cfg

ファイルができる

 

もし、./getssl コマンドが下記のエラーが発生した場合

getssl: this script requires one of: dig nslookup drill host

下記をインストールする

dnf install bind-utils

 

getssl.cfg を書き換える

# The staging server is best for testing
#CA="https://acme-staging-v02.api.letsencrypt.org"
# This server issues full certificates, however has rate limits
#CA="https://acme-v02.api.letsencrypt.org"

この部分は、下の CA の方をコメントアウトを解除する

(上のCAは、テスト用)

# Note: this is Additional domains - so should not include the primary domain.
SANS="別ドメイン"

このドメインは、元々 getssl -c で作成しようとしてるドメインとは

異なるドメインを指定する必要があります

どちらも、自身のサーバを指している必要があり

複数個ドメインを登録する場合は、認証済のドメインでも可能です

# Multiple locations can be defined for a file by separating the locations with a semi-colon.
#ACL=('/var/www/dev.innate-ss.co.jp/web/.well-known/acme-challenge'

こちらは、既存 apache を経由するため、実パスでよい

ACL=('/var/www/html/.well-known/acme-challenge'
     '/var/www/html/.well-known/acme-challenge')

このパスの、/var/www/html は、apache のデフォルトドキュメントルート

と一致するはず

ファイルが更新できれば、保存し getssl のあるディレクトリに戻って

getssl ドメイン

を実行する

正常終了すれば、~/.getssl/ドメイン に

ができていると思います

 

apache を更新

sslモジュールをインストール

dnf install mod_ssl

apache に 証明書を設定。/etc/httpd/conf.d/ssl.conf ファイルの

SSLCertificateFile /etc/pki/tls/certs/localhost.crt

SSLCertificateKeyFile /etc/pki/tls/private/localhost.key

を、先程作成したファイルに変更

 

apacheを再起動

systemctl restart httpd

 

ファイアウォールも追加しておく

firewall-cmd --add-service=https --permanent

firewall-cmd --reload

 

Let's Encriptの更新

更新は、下記を cron 登録しておくとよい

5 0 1 * * /root/getssl -u -a -q
5 0 5 * * /root/getssl -u -a -q

期限まで、30日未満になると更新できるので

月1回程度で、実施して。ただし、31日の月もあるので

毎月1日と5日などの、2回を実施しておけば、どちらかで更新できる

 

不要になったドメインの更新対象外

更新対象外とする場合は、下記を実行する

# getssl -r ドメイン

 

PVアクセスランキング にほんブログ村