當前位置:學問谷 >

行業範例 >工業 >

利用Kickstart自動化安裝CentOS的方法

利用Kickstart自動化安裝CentOS的方法

前言

利用Kickstart自動化安裝CentOS的方法

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

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

環境準備

定製系統

CentOS-6.4-x86_64

官方下載地址 -

安裝軟件

代理上網小技巧,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

label linux

menu label ^Install or upgrade an existing system

menu default

kernel vmlinuz

append initrd= ks=cdrom:/isolinux/

#手動增加Kickstart配置文件

vi

#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_-8

lang zh_-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/* .

mkisofs -o /tmp/CentOS-6.4_64_ -b isolinux/ -c isolinux/ -no-emul-boot -boot-load-size 4 -boot-info-table -joliet-long -R -J -v -T /tmp/iso/

  • 文章版權屬於文章作者所有,轉載請註明 https://xuewengu.com/flhy/gongye/kkv50g.html