基于Kickstart自动化安装CentOS实践

来源:互联网 发布:c语言做贪吃蛇 编辑:程序博客网 时间:2024/05/22 14:06

前言

因为需要在浪潮的x86服务器中集中部署CentOS搭建基于Hadoop的大数据平台,平时接触SLES(SuSE Linux Enterprise Server)较多并且已经实现基于Autoyast方式使用光盘或者PXE网络自动化安装(后续会分享具体实现方法)。这次主要通过学习Kisckstart实现最简单的光盘方式自动化安装CentOS,而网上的大多数教程并不完全适用于自身的环境,本文将不再赘述Kickstart相关概念,细节可参考扩展阅读。

Kickstart是最为通用的Linux自动化安装方法之一


更新历史

2015年05月20日 - 初稿

阅读原文 - http://wsgzao.github.io/post/kickstart/

扩展阅读

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

环境准备

定制系统

CentOS-6.4-x86_64

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

安装软件包

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

yum -y install createrepo mkisofs

制作流程

目录结构

拷贝CentOS原始镜像内容,不做任何精简

mkdir /mnt/centosmount /dev/sr0 /mnt/centosmkdir /tmp/isocp -r /mnt/centos/* /tmp/iso

增加Kickstart配置文件

文件路径和安装方式可自由定义

cd /tmp/iso/isolinux#修改引导,注意ks=部分vi isolinux.cfglabel 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
#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-8lang 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#禁用selinuxselinux --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类型为ext4part /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 stopchkconfig NetworkManager off#eject cdrom#安装完成弹出光碟 #eject#reboot#执行完毕后重启 #reboot -f #结束自动化部署%end

生成依赖关系和ISO文件

注意路径和命令的准确性

cd /tmp/isocreaterepo -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/

测试和建议

推荐两篇参考文献,建议先在虚拟机上反复测试验证再到物理机部署

Linux Kickstart 自动安装 - http://liaoph.com/linux-kickstart/
Centos6.4定制自动化安装盘 - http://www.wpython.com/444.html

0 0