サーバーをセキュリティ修正で最新の状態に保つことは、サーバーの約束を回避するのに役立ちます。パッケージの更新ですべてのセキュリティ侵害を防ぐことはできませんが、サーバーを最新の状態に保つことは、セキュリティ手順の重要な要素である必要があります。
この記事では、RedHat®EnterpriseLinux®(RHEL)およびCentOS®Rackspaceパブリッククラウドサーバーで自動更新を有効にして、重要な更新がインストールされ、最新であることを確認する方法について説明します。
RHEL6およびCentOS6
次の手順を使用して、RHEL6およびCentOS6Rackspaceパブリッククラウドサーバーで自動更新を有効にします。
-
サーバーに接続したら、
yum-cron
をインストールします 次のコマンドを実行します:$ yum -y install yum-cron
-
yum-cron
を表示するには 構成ファイルの場合は、次のコマンドを使用します。$ vi /etc/sysconfig/yum-cron
ファイルは任意のテキストエディタで開くこともできます。
次の例に示すように、デフォルトでは、構成は更新をダウンロードしてインストールするように設定されています。
# Pass any given parameter to yum, as run in all the scripts invoked # by this package. Be aware that this is global, and yum is invoked in # several modes by these scripts for which your own parameter might not # be appropriate YUM_PARAMETER= # Don't install, just check (valid: yes|no) CHECK_ONLY=no # Check to see if you can reach the repos before updating (valid: yes|no) CHECK_FIRST=no # Don't install, just check and download (valid: yes|no) # Implies CHECK_ONLY=yes (gotta check first to see what to download) DOWNLOAD_ONLY=no
-
(オプション) インストール時間、インストールされたパッケージ、インストールエラーなど、パッケージの自動更新の通知を設定するには、
MAILTO=
で始まる行を編集します。 次の例に示すように、通知を受信するためのメールアドレスを追加するには:# if MAILTO is set and the mail command is available, the mail command # is used to deliver yum output # by default MAILTO is unset, so crond mails the output by itself # example: MAILTO=root [email protected]
-
ファイルを保存します。
vim
を使用している場合 構成ファイルを編集するには、 escを押します。 次に、:wqと入力します 変更を保存します。ファイルを保存すると、ファイルが正しく書き込まれたことを示す次のメッセージが表示されます。
APT::Periodic::Update-Package_Lists "1"; APT::Periodic::Download-Upgradable-Packages "1"; APT::Periodic::Unattended-Upgrade "1"; APT::Periodic::AutocleanInterval "14";
-
yum-cron
を開始します 次のコマンドを実行してサービスを提供します:$ /etc/inid.d/yum-cron start
-
サーバーの再起動時にサービスを自動的に開始するには、次のコマンドを実行します。
$ chkconfig yum-cron on
RHEL7およびCentOS7
次の手順を使用して、RHEL7およびCentOS7Rackspaceパブリッククラウドサーバーで自動更新を有効にします。
-
RHEL7またはCentOS7サーバーに接続した後、
yum-cron
をインストールします 次のコマンドを実行します:$ yum -y install yum-cron
-
yum-cron
を表示するには 構成ファイルの場合は、次のコマンドを使用します。$ vi /etc/sysconfig/yum-cron
ファイルは任意のテキストエディタで開くこともできます。
次の例に示すように、デフォルトでは、更新は自動的にダウンロードされますが、インストールされません。
# Whether a message should be emitted when updates are available, # were downloaded, or applied. update_messages = yes # Whether updates should be downloaded when they are available. download_updates = yes # Whether updates should be applied when they are available. Note # that download_updates must also be yes for the update to be applied. apply_updates = no # Maximum amount of time to randomly sleep, in minutes. The program # will sleep for a random amount of time between 0 and random_sleep # minutes before running. This is useful for e.g. staggering the # times that multiple systems will access update servers. If # random_sleep is 0 or negative, the program will run immediately. # 6x60 = 360 random_sleep = 360
-
自動更新をダウンロードしてインストールするには、
download_updates
を確認してください。 およびapply_updates
yes
に設定されています 。 -
(オプション)
yum
の出力が次のようになるように、構成ファイルで通知を設定できます。 何が完了したか、問題がある場合は何が失敗したかを通知するために、更新が電子メールで送信されます。次のセクションを編集します:-
[emitters]
構成ファイルのセクションで、emit_via
を確認しますstdio
に設定されています 、次の例に示すように:[emitters] # Name to use for this system in messages that are emitted. If # system_name is None, the hostname will be used. system_name = None # How to send messages. Valid options are stdio and email. If # emit_via includes stdio, messages will be sent to stdout; this is useful # to have cron send the messages. If email_via includes email, this # program will send email itself according to the configured options. # If emit_via is None or left blank, no message will be sent. emit_via = stdio
-
[email]
で 構成ファイルのセクションで、email_to
を編集します 次の例に示すように、出力の送信先となる電子メールアドレスを追加するフィールド:[email] # The address to send email messages from. # NOTE: 'localhost' will be replaced with the value of system_name. email_from = root@localhost # List of addresses to send messages to. email_to = [email protected] # Name of the host to connect to to send email messages. email_host = localhost
-
-
ファイルを保存します。
vim
を使用している場合 構成ファイルを編集するには、 escを押します。 次に、:wqと入力します 変更を保存します。ファイルを保存すると、ファイルが正しく書き込まれたことを示す次のメッセージが表示されます。
"/etc/yum/yum-cron.conf" 81L, 2620C written
-
yum-cron
かどうかを確認します 次のコマンドを実行すると、サービスが開始されます。$ systemctl status yum-cron
サービスが実行されていない(非アクティブ)場合は、次のコマンドを実行してサービスを開始します。
$ systemctl start yum-cron
-
サービスが実行されているので、サーバーの再起動後にサービスが自動的に開始されることを確認する必要があります。次のコマンドを実行して、
yum-cron
かどうかを確認します 有効になっている:$ systemctl list-unit-files –type=service
yum-cron.service
を見つけます リスト内のプロセス。有効にすると、サーバーの起動時にサービスが開始されます。無効になっている場合は、次のコマンドを使用して有効にします。$ systemctl enable yum-cron