今までは手動でウィルスの定義ファイル、ウィルスのチェック、パッケージの更新、電子証明書の更新を行っていた。
それを今回は自動化した。
まずやったのはウィルス定義ファイルの自動更新
crontabに以下のように記述をした。
00 00 */1 * * root freshclam
毎日ウィルスの定義ファイルが更新される
次ぎにウィルスの自動チェックを設定
00 03 * * 0 root clamdscan –fdpass /
–fdpassオプションを付けないと権限の関係でエラーが出る。
これで毎週日曜日の午前3時頃にウィルスのチェックが入る。
後はパッケージの更新だが、これはcronを使うのでは無く、dnf-automaticと言うパッケージを使った。
パッケージをインストールして設定ファイル(/etc/dnf/automatic.conf)に以下を記述
upgrade_type = default
download_updates = yes
apply_updates = yes
reboot = when-needed
reboot_command = “shutdown -r +5 ‘Rebooting after applying package updates’”
emit_via = command_email
command_format = “mail -Ssendwait -s {subject} -r {email_from} {email_to}”
stdin_format = “{body}”
後はsystemctl enable –now dnf-automatic.timerをしてタイマーを動作させ、
/etc/systemd/system/timers.target.wants/dnf-automatic.timerファイルに
OnCalendar=Mon –-* 6:00
を記述した。これで毎週月曜日の午前6時頃にパッケージの更新が行われるはずだ。
サーバの電子証明書関係も自動更新にした。
これはcrontabに以下を記述
00 05 01 * * root /bin/certbot renew –force-renewal && /bin/systemctl restart httpd && /bin/systemctl restart vsftpd && /bin/systemctl restart postfix && /bin/systemctl restart dovecot
これで毎回手動で行っていた作業を自動化することが出来たよ。
コメント