利用Kickstart自動化安裝CentOS的教程

來源:互聯網
上載者:User

   前言

  因為需要在浪潮的x86伺服器中集中式部署CentOS搭建基於Hadoop的大資料平台,平時接觸SLES(SuSE Linux Enterprise Server)較多並且已經實現基於Autoyast方式使用光碟片或者PXE網路自動化安裝(後續會分享具體實現方法)。這次主要通過學習Kisckstart實現最簡單的光碟片方式自動化安裝CentOS,而網上的大多數教程並不完全適用於自身的環境,本文將不再贅述Kickstart相關概念,細節可參考擴充閱讀。

  Kickstart是最為通用的Linux自動化安裝方法之一

  環境準備

  定製系統

  CentOS-6.4-x86_64

  官方下載地址 - http://wiki.centos.org/Download

  安裝軟體包

  代理上網小技巧,export http_proxy=ip:port

  代碼如下:

  yum -y install createrepo mkisofs

  製作流程

  目錄結構

  拷貝CentOS原始鏡像內容,不做任何精簡

  代碼如下:

  mkdir /mnt/centos

  mount /dev/sr0 /mnt/centos

  mkdir /tmp/iso

  cp -r /mnt/centos/* /tmp/iso

  增加Kickstart設定檔

  檔案路徑和安裝方式可自由定義

  複製代碼

  代碼如下:

  cd /tmp/iso/isolinux

  #修改引導,注意ks=部分

  vi isolinux.cfg

  label linux

  menu label ^Install or upgrade an existing system

  menu default

  kernel vmlinuz

  append initrd=initrd.img ks=cdrom:/isolinux/ks.cfg

  #手動增加Kickstart設定檔

  vi ks.cfg

< p> #Kickstart file automatically generated by anaconda.

 

  #version=DEVEL

  #Install OS instead of upgrade

  #表示是安裝,而不是升級

  install

  #Use text mode install

  #文本方式安裝

  text

  #Use network installation

  #使用網路安裝

  #url --url=ftp://ip/centos

  #Local installation Use CDROM installation media

  #使用光碟片安裝

  cdrom

  #Installation Number configuration

  #如果是RedHat的系統,會要求輸入key,這裡配置為跳過,如果不配置安裝時會停在那裡要求使用者輸入key

  #key –skip

  #System language

  #語言環境

  #lang en_US.UTF-8

  lang zh_CN.UTF-8

  #System keyboard

  #鍵盤類型

  keyboard us

  #Network information

  #網路設定

  #network --device eth0 --bootproto dhcp --onboot yes

  #Root password

  #root密碼

  rootpw chinaums

  #Firewall configuration

  #禁用防火牆

  firewall --disabled

  #SELinux configuration

  #禁用selinux

  selinux --disabled

  #Run the Setup Agent on first boot

  #禁用第一次啟動時設定系統的嚮導

  firstboot --disable

  #System authorization information

  #使用者認證配置,useshadow表示使用本地認證,--passalgo表示密碼密碼編譯演算法

  authconfig --enableshadow --passalgo=sha512

  #System timezone

  #設定時區為上海

  timezone --isUtc Asia/Shanghai

  #System bootloader configuration

  #指明bootloader的安裝位置,指明磁碟機的排序,指明作業系統安裝完成之後,向核心傳遞的參數

  bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"

  #Clear the Master Boot Record

  #清除MBR引導記錄

  zerombr yes

  #Partition clearing information

  #清除硬碟上的所有資料

  clearpart --all --initlabel

  #Disk partitioning information

  #自訂分區

  #建立一個200M大小的分區掛載/boot類型為ext4

  part /boot --fstype=ext4 --size=200 --ondisk=sda

  #建立一個20000M大小的SWAP分區

  part swap --size=20000 --ondisk=sda

  #建立/目錄

  part / --fstype=ext4 --grow --size=1 --ondisk=sda

  #Reboot after installation

  #設定完成之後重啟

  reboot --eject

  #This packages is for CentOS 6.4

  #為CentOS 6.4定製的軟體包

  %packages

  @base

  @core

  @chinese-support

  #增加安裝後運行指令碼

  %post

  #config service

  #自訂服務

  service NetworkManager stop

  chkconfig NetworkManager off

  #eject cdrom

  #安裝完成彈出光碟

  #eject

  #reboot

  #執行完畢後重啟

  #reboot -f

  #結束自動化部署

  %end

  產生依賴關係和ISO檔案

  注意路徑和命令的準確性

  代碼如下:

  cd /tmp/iso

  createrepo -g repodata/*comps.xml .

  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/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.