CentOS 7
    • PDF

    CentOS 7

    • PDF

    Article Summary

    VPC環境で利用できます。

    NAVERクラウドプラットフォーム CentOS 7サーバのカーネルアップデート方法について説明します。

    このガイドは、NAVERクラウドプラットフォームで新規作成したサーバを基準に作成したため、ユーザーのサーバ環境とは異なる場合があります。ユーザーのサーバ環境はセキュリティハードニングや複数の設定などの様々な理由で、カーネルアップデートやサーバの再起動に影響を及ぼすことがあります。したがって、以下の事項を確認した後、カーネルアップデートを実行してください。

    • 実際のサーバのカーネルを更新する前に、サーバイメージを使用してレプリカサーバを作成します。作成したレプリカサーバでカーネルアップデートを実行し、正常に再起動できるか確認します。再起動後に運用状態に切り替わったら、サービスに問題がないか確認します。十分に検証した後、問題がない場合のみ、サーバカーネルのアップデートを実行してください。
    • GPUサーバの場合、カーネルバージョンに合う GPUドライバがインストールされている場合のみ正常に動作します。更新したカーネルが GPUドライバと互換性がない場合、GPUサーバが正常に動作しない場合があります。したがって、GPUドライバの互換性を確認した後、カーネルアップデートを実行してください。関連情報は、GPUドライバガイドをご確認ください。
    • NCP Repoは、VPC Private Subnetなどの外部アクセスに支障が生じるユーザー環境をサポートするために、NAVERクラウドプラットフォームが提供するリポジトリです。NCP Repoは最新のパッケージを提供しない場合があります。
    参考

    NAVERクラウドプラットフォームですべてのカーネルバージョンの更新をテストしたわけではありません。2024年1月1日基準に CentOS 7でカーネルアップデート適用テストしたバージョンは、3.10.0-1160.102.1.el7.x86_64です。

    注意
    • ユーザーサーバのカーネルアップデートはユーザーの責任で行う必要があり、カーネルアップデートにより発生するトラブルに対して NAVERクラウドプラットフォームは責任を負いません。
    • カーネルアップデートや再起動中はサーバの正常な使用が不可な場合があり、これによる復旧はサポートしていません。また、カーネルアップデートの失敗時のサーバ復旧はサポートしていません。
    • カーネルを更新する前にマイサーバイメージで作成したバックアップは、バックアップが不要になるまで保存してください。
    • このガイドと関連したトラブルに対しては、別途サポートは提供されません。

    カーネルアップデート

    CentOS 7.3、CentOS 7.8サーバのカーネルを更新する方法は、次の通りです。

    1. カーネルアップデートを適用するサーバにリモートアクセスします。

    2. サーバのカーネルバージョンを確認します。

      • CentOS 7.3
      [root@centos73 ~]# uname -r
      3.10.0-514.2.2.el7.x86_64
      
      • CentOS 7.8
      [root@centos78 ~]# uname -r
      3.10.0-1127.10.1.el7.x86_64
      
    3. サーバに接続されたリポジトリ情報を確認します。

      [root@centos78 ~]# grep ^baseurl /etc/yum.repos.d/CentOS-Base.repo
      baseurl=http://mirror.ncloud.com/centos/$releasever/os/$basearch
      baseurl=http://mirror.ncloud.com/centos/$releasever/updates/$basearch/
      baseurl=http://mirror.ncloud.com/centos/$releasever/extras/$basearch/
      baseurl=http://mirror.ncloud.com/centos/$releasever/centosplus/$basearch/
      baseurl=http://mirror.ncloud.com/centos/$releasever/contrib/$basearch/
      
    4. yum-config-managerを使用して Repoファイルをダウンロードします。

      • CentOS 7.3
        yum-config-managerを使用するには、yum-utilsパッケージをインストールしてから Repoファイルをダウンロードします。
      [root@centos73 ~]# rpm -qa | grep yum-utils | wc -l
      0
      
      [root@centos73 ~]# yum install yum-utils
      Loaded plugins: fastestmirror
      Determining fastest mirrors
      Resolving Dependencies
      --> Running transaction check
      ---> Package yum-utils.noarch 0:1.1.31-54.el7_8 will be installed
      --> Processing Dependency: python-kitchen for package: yum-utils-1.1.31-54.el7_8.noarch
      --> Running transaction check
      ---> Package python-kitchen.noarch 0:1.1.1-5.el7 will be installed
      --> Processing Dependency: python-chardet for package: python-kitchen-1.1.1-5.el7.noarch
      --> Running transaction check
      ---> Package python-chardet.noarch 0:2.2.1-3.el7 will be installed
      --> Finished Dependency Resolution
      
      Dependencies Resolved
      
      =================================================================================================================================================================================================
       Package                                           Arch                                      Version                                               Repository                               Size
      =================================================================================================================================================================================================
      Installing:
       yum-utils                                         noarch                                    1.1.31-54.el7_8                                       base                                    122 k
      Installing for dependencies:
       python-chardet                                    noarch                                    2.2.1-3.el7                                           base                                    227 k
       python-kitchen                                    noarch                                    1.1.1-5.el7                                           base                                    267 k
      
      Transaction Summary
      =================================================================================================================================================================================================
      Install  1 Package (+2 Dependent packages)
      
      Total download size: 616 k
      Installed size: 2.8 M
      Is this ok [y/d/N]: y
      
      ... 省略...
      
      Installed:
        yum-utils.noarch 0:1.1.31-54.el7_8                                                                                                                                                            
      
      Dependency Installed:
        python-chardet.noarch 0:2.2.1-3.el7                                                             python-kitchen.noarch 0:1.1.1-5.el7                                                           
      
      Complete!
      
      [root@centos73 ~ ]# yum-config-manager --add-repo http://init.ncloud.com/server/linux/repo/centos7/CentOS-Base.repo
      Loaded plugins: fastestmirror
      adding repo from: http://init.ncloud.com/server/linux/repo/centos7/CentOS-Base.repo
      grabbing file http://init.ncloud.com/server/linux/repo/centos7/CentOS-Base.repo to /etc/yum.repos.d/CentOS-Base.repo
      repo saved to /etc/yum.repos.d/CentOS-Base.repo
      
      • CentOS 7.8
      [root@centos78 ~ ]# yum-config-manager --add-repo http://init.ncloud.com/server/linux/repo/centos7/CentOS-Base.repo
      Loaded plugins: fastestmirror, langpacks
      adding repo from: http://init.ncloud.com/server/linux/repo/centos7/CentOS-Base.repo
      grabbing file http://init.ncloud.com/server/linux/repo/centos7/CentOS-Base.repo to /etc/yum.repos.d/CentOS-Base.repo
      repo saved to /etc/yum.repos.d/CentOS-Base.repo
      
    5. 変更されたリポジトリ情報を確認します。

      [root@centos78 ~ ]# grep ^baseurl /etc/yum.repos.d/CentOS-Base.repo
      baseurl=http://repo.ncloud.com/centos/$releasever/os/$basearch
      baseurl=http://repo.ncloud.com/centos/$releasever/updates/$basearch/
      baseurl=http://repo.ncloud.com/centos/$releasever/extras/$basearch/
      baseurl=http://repo.ncloud.com/centos/$releasever/centosplus/$basearch/
      baseurl=http://repo.ncloud.com/centos/$releasever/contrib/$basearch/
      
    6. リポジトリで提供するカーネルバージョンを確認します。

      [root@centos78 ~ ]# rm -rf /var/cache/yum/*
      
      [root@centos78 ~ ]# yum list kernel-3.10.0-1160.102.1.el7
      Loaded plugins: fastestmirror, langpacks
      Loading mirror speeds from cached hostfile
      Available Packages
      kernel.x86_64                                                                  3.10.0-1160.102.1.el7                                                                  update    
      
    7. 最新バージョンのカーネルをインストールします。
      新規インストールパッケージ、アップデートパッケージ、削除パッケージのリストを詳細に確認した後、異常がない場合 yを入力してインストールを完了します。

      • CentOS 7.3
      [root@centos73 ~ ]# yum install kernel-3.10.0-1160.102.1.el7
      Loaded plugins: fastestmirror
      Loading mirror speeds from cached hostfile
      Resolving Dependencies
      --> Running transaction check
      ---> Package kernel.x86_64 0:3.10.0-1160.102.1.el7 will be installed
      --> Processing Dependency: linux-firmware >= 20190429-72 for package: kernel-3.10.0-1160.102.1.el7.x86_64
      --> Running transaction check
      
      ... 省略...
      
      Dependencies Resolved
      
      ============================================================================================================================================================================
       Package                                         Arch                           Version                                                Repository                      Size
      ============================================================================================================================================================================
      Installing:
       kernel                                          x86_64                         3.10.0-1160.102.1.el7                                  update                          52 M
      Updating:
       kexec-tools                                     x86_64                         2.0.15-51.el7_9.3                                      update                         351 k
       selinux-policy-targeted                         noarch                         3.13.1-268.el7_9.2                                     update                         7.0 M
      Updating for dependencies:
       libselinux                                      x86_64                         2.5-15.el7                                             base                           162 k
       libselinux-devel                                x86_64                         2.5-15.el7                                             base                           187 k
       libselinux-python                               x86_64                         2.5-15.el7                                             base                           236 k
       libselinux-utils                                x86_64                         2.5-15.el7                                             base                           151 k
       libsemanage                                     x86_64                         2.5-14.el7                                             base                           151 k
       libsepol                                        x86_64                         2.5-10.el7                                             base                           297 k
       libsepol-devel                                  x86_64                         2.5-10.el7                                             base                            77 k
       linux-firmware                                  noarch                         20200421-80.git78c0348.el7_9                           update                          80 M
       policycoreutils                                 x86_64                         2.5-34.el7                                             base                           917 k
       selinux-policy                                  noarch                         3.13.1-268.el7_9.2                                     update                         498 k
      
      Transaction Summary
      ============================================================================================================================================================================
      Install  1 Package
      Upgrade  2 Packages (+10 Dependent packages)
      
      Total download size: 142 M
      Is this ok [y/d/N]: y
      
      ... 省略...
      
      Installed:
        kernel.x86_64 0:3.10.0-1160.102.1.el7                                                                                                                                    
      
      Updated:
        kexec-tools.x86_64 0:2.0.15-51.el7_9.3                                         selinux-policy-targeted.noarch 0:3.13.1-268.el7_9.2                                       
      
      Dependency Updated:
        libselinux.x86_64 0:2.5-15.el7      libselinux-devel.x86_64 0:2.5-15.el7       libselinux-python.x86_64 0:2.5-15.el7 libselinux-utils.x86_64 0:2.5-15.el7               
        libsemanage.x86_64 0:2.5-14.el7     libsepol.x86_64 0:2.5-10.el7               libsepol-devel.x86_64 0:2.5-10.el7    linux-firmware.noarch 0:20200421-80.git78c0348.el7_9
        policycoreutils.x86_64 0:2.5-34.el7 selinux-policy.noarch 0:3.13.1-268.el7_9.2
      
      Complete!
      
      • CentOS 7.8
      [root@centos78 ~ ]# yum install kernel-3.10.0-1160.102.1.el7
      Loaded plugins: fastestmirror, langpacks
      Loading mirror speeds from cached hostfile
      Resolving Dependencies
      --> Running transaction check
      ---> Package kernel.x86_64 0:3.10.0-1160.102.1.el7 will be installed
      --> Finished Dependency Resolution
      
      Dependencies Resolved
      
      ============================================================================================================================================================================
       Package                              Arch                                 Version                                               Repository                            Size
      ============================================================================================================================================================================
      Installing:
       kernel                               x86_64                               3.10.0-1160.102.1.el7                                 update                                52 M
      
      Transaction Summary
      ============================================================================================================================================================================
      Install  1 Package
      
      Total download size: 52 M
      Installed size: 66 M
      Is this ok [y/d/N]: y
      
      ... 省略...
      
      Installed:
        kernel.x86_64 0:3.10.0-1160.102.1.el7                                                                                                                                    
      
      Complete!
      
    8. インストールが完了してから起動可能なカーネルバージョンとデフォルトのブートカーネルバージョンを確認します。

      • CentOS 7.3
      [root@centos73 ~ ]# grep ^menuentry /boot/grub2/grub.cfg | cut -d "'" -f2
      CentOS Linux (3.10.0-1160.102.1.el7.x86_64) 7 (Core)
      CentOS Linux (3.10.0-514.2.2.el7.x86_64) 7 (Core)
      CentOS Linux (0-rescue-7b63677441464f9a89b04041488122e0) 7 (Core)
      
      [root@centos73 ~ ]# grub2-editenv list
      saved_entry=CentOS Linux (3.10.0-1160.102.1.el7.x86_64) 7 (Core)
      
      • CentOS 7.8
      [root@centos78 ~ ]# grep ^menuentry /boot/grub2/grub.cfg | cut -d "'" -f2
      CentOS Linux (3.10.0-1160.102.1.el7.x86_64) 7 (Core)
      CentOS Linux (3.10.0-1127.10.1.el7.x86_64) 7 (Core)
      CentOS Linux (3.10.0-1127.el7.x86_64) 7 (Core)
      CentOS Linux (0-rescue-aaaeb22f90c34b3e90e68880b8553310) 7 (Core)
      
      [root@centos78 ~ ]# grub2-editenv list
      saved_entry=CentOS Linux (3.10.0-1160.102.1.el7.x86_64) 7 (Core)
      
    参考

    インストールしたカーネルバージョンが表示されない場合、grub2-mkconfigコマンドを使用して grub.cfgを再作成します。
    # grub2-mkconfig -o /boot/grub2/grub.cfg

    1. デフォルトのブートカーネルバージョンがインストールしたカーネルバージョンと一致しない場合、デフォルトのブートカーネルを変更してください。

      [root@centos78 ~ ]# ls -ld /etc/grub2*
      lrwxrwxrwx. 1 root root 22 Aug 31  2020 /etc/grub2.cfg -> ../boot/grub2/grub.cfg
      
      [root@centos78 ~ ]# grub2-mkconfig -o /etc/grub2.cfg
      Generating grub configuration file ...
      Found linux image: /boot/vmlinuz-3.10.0-1160.102.1.el7.x86_64
      Found initrd image: /boot/initramfs-3.10.0-1160.102.1.el7.x86_64.img
      Found linux image: /boot/vmlinuz-3.10.0-1127.10.1.el7.x86_64
      Found initrd image: /boot/initramfs-3.10.0-1127.10.1.el7.x86_64.img
      Found linux image: /boot/vmlinuz-3.10.0-1127.el7.x86_64
      Found initrd image: /boot/initramfs-3.10.0-1127.el7.x86_64.img
      Found linux image: /boot/vmlinuz-0-rescue-aaaeb22f90c34b3e90e68880b8553310
      Found initrd image: /boot/initramfs-0-rescue-aaaeb22f90c34b3e90e68880b8553310.img
      done
      
      [root@centos78 ~ ]# grub2-set-default "CentOS Linux (3.10.0-1160.102.1.el7.x86_64) 7 (Core)"
      
      [root@centos78 ~ ]# grub2-editenv list
      saved_entry=CentOS Linux (3.10.0-1160.102.1.el7.x86_64) 7 (Core)
      
    参考

    デフォルトのブートカーネル以外のカーネルで起動したい場合は、起動時に grub画面でカーネルを変更できます。CentOS 7.3 grub画面の待機時間が短い場合は、CentOS 7.3 grub画面の待機時間延長を参照して待機時間を延長してください。

    1. インストールしたカーネルバージョンを有効にするには、サーバを再起動します。

      [root@centos78 ~ ]# reboot
      
    参考
    サーバの再起動に失敗した場合、カーネルアップデートが正常に行われなかったことを意味します。この場合は、[カーネルアップデートの復元](#커널업데이트원복)を参照して以前のカーネルバージョンに戻してください。
    
    1. サーバに再ログインして新しいカーネルが有効になっているか確認します。

      • CentOS 7.3
      [root@centos73 ~ ]# uname -r
      3.10.0-1160.102.1.el7.x86_64
      
      • CentOS 7.8
      [root@centos78 ~ ]# uname -r
      3.10.0-1160.102.1.el7.x86_64
      
    参考
    アップデートしたカーネルが正常に適用されたか確認するには、[カーネルアップデートの確認](#커널업데이트확인)を参照してカーネルのインストール状況をご確認ください。
    

    CentOS 7.3 grub画面の待機時間延長

    CentOS 7.3 grub画面の待機時間を延長する方法は、次の通りです。

    1. サーバの起動前に grub設定ファイルをご確認ください。
      [root@centos73 ~ ]# grep GRUB_TIMEOUT /etc/default/grub
      GRUB_TIMEOUT=5
      
    2. grub default設定ファイルを変更し、grub.cfgファイルを再作成します。
      [root@centos73 ~ ]# sed -i "s/GRUB_TIMEOUT=5/GRUB_TIMEOUT=30/" /etc/default/grub
      
      [root@centos73 ~ ]# grep GRUB_TIMEOUT /etc/default/grub
      GRUB_TIMEOUT=30
      
      [root@centos73 ~ ]# grub2-mkconfig -o /etc/grub2.cfg
      Generating grub configuration file ...
      Found linux image: /boot/vmlinuz-3.10.0-1160.102.1.el7.x86_64
      Found initrd image: /boot/initramfs-3.10.0-1160.102.1.el7.x86_64.img
      Found linux image: /boot/vmlinuz-3.10.0-514.2.2.el7.x86_64
      Found initrd image: /boot/initramfs-3.10.0-514.2.2.el7.x86_64.img
      Found linux image: /boot/vmlinuz-0-rescue-7b63677441464f9a89b04041488122e0
      Found initrd image: /boot/initramfs-0-rescue-7b63677441464f9a89b04041488122e0.img
      done    
      

    カーネルアップデートの確認

    アップデートしたカーネルが正常に適用されたか確認する方法は、次の通りです。

    1. サーバへリモートアクセスします。
    2. カーネルパッケージがインストールされているか確認します。
      [root@centos78 ~ ]# rpm -qa | grep kernel-3.10.0-1160.102.1.el7.x86_64
      kernel-3.10.0-1160.102.1.el7.x86_64
      
    3. /bootディレクトリに initramfsファイルと vmlinuzファイルが作成されているか確認します。
      [root@centos78 ~ ]# ls -l /boot/initramfs-3.10.0-1160.102.1.el7.x86_64.img
      -rw------- 1 root root 21897039 Dec  4 11:00 /boot/initramfs-3.10.0-1160.102.1.el7.x86_64.img
      
      [root@centos78 ~ ]# ls -l /boot/initramfs-3.10.0-1160.102.1.el7.x86_64kdump.img
      -rw------- 1 root root 20211564 Dec  4 11:10 /boot/initramfs-3.10.0-1160.102.1.el7.x86_64kdump.img
      
      [root@centos78 ~ ]# ls -l /boot/vmlinuz-3.10.0-1160.102.1.el7.x86_64
      -rwxr-xr-x 1 root root 7051880 Oct 18 00:46 /boot/vmlinuz-3.10.0-1160.102.1.el7.x86_64
      
    4. grub.cfgファイルに最新カーネル設定が登録されているか確認します。
      [root@centos78 ~ ]# grep ^menuentry /boot/grub2/grub.cfg | cut -d "'" -f2
      CentOS Linux (3.10.0-1160.102.1.el7.x86_64) 7 (Core)
      CentOS Linux (3.10.0-1127.10.1.el7.x86_64) 7 (Core)
      CentOS Linux (3.10.0-1127.el7.x86_64) 7 (Core)
      CentOS Linux (0-rescue-aaaeb22f90c34b3e90e68880b8553310) 7 (Core)
      
    5. grub設定を確認します。
      [root@centos78 ~ ]# grep GRUB_DEFAULT /etc/default/grub
      GRUB_DEFAULT=saved
      
      [root@centos78 ~ ]# cat /boot/grub2/grubenv
      # GRUB Environment Block
      saved_entry=CentOS Linux (3.10.0-1160.102.1.el7.x86_64) 7 (Core)
      ... 省略...
      

    カーネルアップデートの復元

    カーネルのアップデート後にサーバの再起動が正常に行われない場合、更新する前のカーネルに戻す必要があります。インストールされたカーネルの中から、複数のバージョンに復元できます。このガイドでは、カーネルを更新する直前に使用したカーネルバージョンに復元する方法を使っています。

    カーネルバージョンを復元する方法は、次の通りです。

    参考

    サーバの再起動問題を解決するために Single modeに入り、サーバの復旧を試行することもできます。Single modeの起動方法は、サーバ復旧ガイドをご参照ください。

    1. NAVERクラウドプラットフォームコンソールの Region メニューや Platform メニューから利用中の環境をクリックします。

    2. Services > Compute > Server メニューを順にクリックします。

    3. Server メニューをクリックします。

    4. サーバリストから復旧するサーバを選択した後、 [サーバアクセスコンソール] ボタンを選択します。

    5. grub起動画面でブートカーネルを以前のバージョンに選択して再起動します。

      • CentOS 7.3 grub起動画面
        kernel-update-centos73_console01

      • CentOS 7.8 grub起動画面
        kernel-update-centos78_console01

    6. 起動が完了したら、サーバのカーネルバージョンを確認します。

      • CentOS 7.3
      [root@centos73 ~ ]# uname -r
      3.10.0-514.2.2.el7.x86_64
      
      • CentOS 7.8
      [root@centos78 ~ ]# uname -r
      3.10.0-1127.10.1.el7.x86_64
      
    7. 現在有効になっているカーネルバージョンを確認します。

      • CentOS 7.3
      [root@centos73 ~ ]# grub2-editenv list
      saved_entry=CentOS Linux (3.10.0-1160.102.1.el7.x86_64) 7 (Core)
      
      [root@centos73 ~ ]# grep ^menuentry /boot/grub2/grub.cfg | cut -d "'" -f2
      CentOS Linux (3.10.0-1160.102.1.el7.x86_64) 7 (Core)
      CentOS Linux (3.10.0-514.2.2.el7.x86_64) 7 (Core)
      CentOS Linux (0-rescue-7b63677441464f9a89b04041488122e0) 7 (Core)
      
      • CentOS 7.8
      [root@centos78 ~ ]# grub2-editenv list
      saved_entry=CentOS Linux (3.10.0-1160.102.1.el7.x86_64) 7 (Core)
      
      [root@centos78 ~ ]# grep ^menuentry /boot/grub2/grub.cfg | cut -d "'" -f2
      CentOS Linux (3.10.0-1160.102.1.el7.x86_64) 7 (Core)
      CentOS Linux (3.10.0-1127.10.1.el7.x86_64) 7 (Core)
      CentOS Linux (3.10.0-1127.el7.x86_64) 7 (Core)
      CentOS Linux (0-rescue-aaaeb22f90c34b3e90e68880b8553310) 7 (Core)
      
    8. 起動時にデフォルトのカーネルバージョンを以前のバージョンのカーネルバージョンにリセットします。

      • CentOS 7.3
      [root@centos73 ~ ]# grub2-set-default "CentOS Linux (3.10.0-514.2.2.el7.x86_64) 7 (Core)"
      
      [root@centos73 ~ ]# grub2-editenv list
      saved_entry=CentOS Linux (3.10.0-514.2.2.el7.x86_64) 7 (Core)
      
      • CentOS 7.8
      [root@centos78 ~ ]# grub2-set-default "CentOS Linux (3.10.0-1127.10.1.el7.x86_64) 7 (Core)"
      
      [root@centos78 ~ ]# grub2-editenv list
      saved_entry=CentOS Linux (3.10.0-1127.10.1.el7.x86_64) 7 (Core)
      
    参考

    最新バージョンのカーネルアップデート時にデフォルトのブートカーネル設定を変更したので、カーネル復元時にブートカーネルのデフォルト値も一緒に変更する必要があります。そうしない場合、次の起動時に問題バージョンのカーネルで起動されます。

    1. (選択事項)変更されたカーネルバージョンが正常に起動するか確認するために、サーバを再起動します。

      [root@centos78 ~ ]# reboot
      
    2. (選択事項)サーバに再ログインして起動有無とカーネルバージョンを確認します。

      • CentOS 7.3
      [root@centos73 ~ ]# uname -r
      3.10.0-514.2.2.el7.x86_64
      
      • CentOS 7.8
      [root@centos78 ~ ]# uname -r
      3.10.0-1127.10.1.el7.x86_64
      

    この記事は役に立ちましたか?

    What's Next
    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.