さくらのVPSでCentos8LAMP環境構築1 OS初期設定とLet’s Encrypt

 個人的な開発案件でさくらのVPSを借りてみた。

プランは1Gのストレージ100Gオプション付き。
今回はサーバーサイドに手間をあまりかけたくないのでCentos8+LAMP環境Scriptで構築した。サーバー契約後に管理画面のサーバーから作成したサーバーを選択

OSインストールを開きCentos8、使用スクリプトをLAMP、ファイアーウォールを22/80/443を許可、公開鍵をputtygenで作って設定してputtyからrootに鍵認証で入れるように初期設定して作成した。秘密鍵も作成してローカルに保存しておくこと。

SSL通信関係Let’s Encrypt


を参考に組み込んでみようとしたがCentos7ようなのでうまくいかない。DNSの設定などは参考にしてサーバー側の設定を行う。

サーバー管理画面のVNCコンソール、あるいはputtyでrootログイン。接続→SSH→認証で接続のためのプライベートキーファイルに上記で作成した秘密鍵を指定すると公開鍵認証でリモートからsshできます。

ちなみにスクリプトを使ったLAMP環境のAPACHEでもssl用基本設定はできているようだ。もちろん証明書エラーになるが
#httpd -M | grep ssl_module
 ssl_module (shared)
とsslモジュールはOK。
続いて必要なパッケージのインストール
Centos8はyumは廃止なのでdnfコマンドを使うそうだ。
#  dnf -y install scl-utils python27 wget nano

設定コマンドをダウンロード

#wget https://dl.eff.org/certbot-auto
ダウンロードしたものを移動してパーミッション設定
# mv certbot-auto /usr/local/bin/certbot-auto
# chown root /usr/local/bin/certbot-auto
# chmod 0755 /usr/local/bin/certbot-auto

ドメインとメールアドレスを入れ替えて下記を実行
#  /usr/local/bin/certbot-auto certonly --webroot -w /var/www/html -d {取得したドメイン} --email {メールアドレス}

これでパッケージのインストールが始まる。インストールが終わると同意確認があるのでyをタイプ。

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y
Account registered.
Requesting a certificate for orderwaiting.info
Performing the following challenges:
http-01 challenge for orderwaiting.info
Using the webroot path /var/www/html for all unmatched domains.
Waiting for verification...
Cleaning up challenges
Subscribe to the EFF mailing list (email: dokoka@orderwaiting.info).

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/orderwaiting.info/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/orderwaiting.info/privkey.pem
   Your cert will expire on 2021-03-28. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again. To non-interactively renew *all* of your certificates, run
   "certbot-auto renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

/etc/letsencrypt/live/{ドメイン}に証明書ができているはず。
続いてアパッチの設定変更と再起動
nano -w /etc/httpd/conf.d/ssl.conf
-----------------------------変更
SSLCertificateFile /etc/letsencrypt/live/{ドメイン}/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/{ドメイン}/privkey.pem
-----------------------------
systemctl restart httpd

これで有効なSSLの設定が完了したはず。
一度ブラウザを立ち上げなおすか(設定前にクロームでアクセスしてると問題ありのままになります)、シークレットモードを立ち上げてhttps://{ドメイン}にアクセスして確認する。

続いて自動更新設定

# crontab -e
-----------------------------追加
30 2 * * * /usr/local/bin/certbot-auto renew -q --deploy-hook "systemctl restart httpd"
-----------------------------
 
有効期限が30日切ると更新作業が走ります。 --force-renewal オプションをつけると有効期限にかかわらず更新しますが、Let’s Encryptに負担がかかるのでテスト時のみにします。

次回myPHPadminを組み込みます。








コメント

このブログの人気の投稿

ネットギア WiFi6 無線lan 法人向け メッシュ アクセスポイント WAX610の初期設定

Raspberry Pi 4 でデュアルディスプレイの拡張・複製

【更新】福祉施設向け事務用PC選定