DUICUO

Kickstart に基づく CentOS の自動インストールの実践

[[134901]]

序文

Hadoopベースのビッグデータプラットフォームを構築するために、Inspurのx86サーバーにCentOSを集中的に導入する必要があり、SLES(SuSE Linux Enterprise Server)の豊富な経験があり、Autoyastを用いてCDまたはPXEネットワーク経由の自動インストールを既に実装済み(具体的な実装方法については後ほど説明します)であるため、この記事では主にKickstartを学習し、最もシンプルなCentOSのCD-ROM自動インストールを実現することに焦点を当てます。ただし、ほとんどのオンラインチュートリアルは私の環境に完全には適合していないため、この記事ではKickstart関連の概念については詳しく説明しません。詳細は拡張資料をご覧ください。

Kickstart は、Linux のインストールを自動化する最も一般的な方法の 1 つです。

環境整備

カスタマイズされたシステム

CentOS-6.4-x86_64

公式ダウンロードリンク - http://wiki.centos.org/Download

ソフトウェアパッケージをインストールする

インターネットプロキシのヒント: export http_proxy=ip:port

  1. yum - y install createrepo mkisofs

生産工程

ディレクトリ構造

元の CentOS イメージの内容を、簡略化せずにコピーします。

  1. mkdir / mnt / centos
  2. mount / dev / sr0 / mnt / centos
  3. mkdir / tmp / iso
  4. cp - r / mnt / centos /* /tmp/iso

キックスタート設定ファイルを追加する

ファイルパスやインストール方法を自由に定義できます。

  1. cd / tmp / iso / isolinux
  2. #修改引导,注意ks=部分
  3. vi isolinux . cfg
  4. label linux
  5. menu label ^ Install or upgrade an existing system
  6. menu default
  7. kernel vmlinuz
  8. append initrd = initrd . img ks = cdrom : /isolinux/ ks . cfg
  9. #手动增加Kickstart配置文件
  10. vi ks . cfg
  1. #Kickstart file automatically generated by anaconda.
  2. #version=DEVEL
  3. #Install OS instead of upgrade
  4. #表示是安装,而不是升级
  5. install
  6. #Use text mode install
  7. #文本方式安装
  8. text
  9. #Use network installation
  10. #使用网络安装
  11. #url --url=ftp://ip/centos
  12. #Local installation Use CDROM installation media
  13. #使用光盘安装
  14. cdrom
  15. #Installation Number configuration
  16. #如果是RedHat的系统,会要求输入key,这里配置为跳过,如果不配置安装时会停在那里要求用户输入key
  17. #key –skip
  18. #System language
  19. #语言环境
  20. #lang en_US.UTF-8
  21. lang zh_CN . UTF - 8
  22. #System keyboard
  23. #键盘类型
  24. keyboard us
  25. #Network information
  26. #网络配置
  27. #network --device eth0 --bootproto dhcp --onboot yes
  28. #Root password
  29. #root密码
  30. rootpw chinaums
  31. #Firewall configuration
  32. #禁用防火墙
  33. firewall -- disabled
  34. #SELinux configuration
  35. #禁用selinux
  36. selinux -- disabled
  37. #Run the Setup Agent on first boot
  38. #禁用第一次启动时设置系统的向导
  39. firstboot -- disable
  40. #System authorization information
  41. #用户认证配置,useshadow表示使用本地认证,--passalgo表示密码加密算法
  42. authconfig -- enableshadow -- passalgo = sha512
  43. #System timezone
  44. #设置时区为上海
  45. timezone -- isUtc Asia / Shanghai
  46. #System bootloader configuration
  47. #指明bootloader的安装位置,指明驱动器的排序,指明操作系统安装完成之后,向内核传递的参数
  48. bootloader -- location = mbr -- driveorder = sda -- append = "crashkernel=auto rhgb quiet"
  49. #Clear the Master Boot Record
  50. #清除MBR引导记录
  51. zerombr yes
  52. #Partition clearing information
  53. #清除硬盘上的所有数据
  54. clearpart -- all -- initlabel
  55. #Disk partitioning information
  56. #自定义分区
  57. #创建一个200M大小的分区挂载/boot类型为ext4
  58. part / boot -- fstype = ext4 -- size = 200 -- ondisk = sda
  59. #创建一个20000M大小的SWAP分区
  60. part swap -- size = 20000 -- ondisk = sda
  61. #创建/目录
  62. part / -- fstype = ext4 -- grow -- size = 1 -- ondisk = sda
  63. #Reboot after installation
  64. #设置完成之后重启
  65. reboot -- eject
  66. #This packages is for CentOS 6.4
  67. #为CentOS 6.4定制的软件包
  68. % packages
  69. @base
  70. @core
  71. @chinese - support
  72. #增加安装后运行脚本
  73. % post
  74. #config service
  75. #自定义服务
  76. service NetworkManager stop
  77. chkconfig NetworkManager off
  78. #eject cdrom
  79. #安装完成弹出光碟
  80. #eject
  81. #reboot
  82. #执行完毕后重启
  83. #reboot -f
  84. #结束自动化部署
  85. % end

依存関係とISOファイルを生成する

パスとコマンドの正確さに注意してください。

  1. cd / tmp / iso
  2. createrepo - g repodata /*comps.xml .
  3. mkisofs -o /tmp/CentOS-6.4_64_auto.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -joliet-long -R -J -v -T /tmp/iso/

テストと提案

2つの参考資料をお勧めします。物理マシンに導入する前に、まず仮想マシンでテクノロジを繰り返しテストし、検証することをお勧めします。

  • Linux Kickstart 自動インストール - http://liaoph.com/linux-kickstart/
  • CentOS 6.4 カスタム自動インストールディスク - http://www.wpython.com/444.html

更新履歴

2015年5月20日 - 初稿

元の記事を読む - http://wsgzao.github.io/post/kickstart/

さらに読む

  • CentOS - http://wiki.centos.org/en/TipsAndTricks/KickStart
  • Fedora - https://fedoraproject.org/wiki/Anaconda/Kickstart/zh-cn