您的位置:首页 > 运维架构 > Linux

CentOS 基于Kickstart自动化安装

2016-06-01 19:59 519 查看

环境准备

定制系统

CentOS-6.4-x86_64

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

安装软件包

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

1

yum -y install createrepo mkisofs

制作流程

目录结构

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

12
3
4

mkdir /mnt/centos
mount /dev/sr0 /mnt/centos
mkdir /tmp/iso
cp -r /mnt/centos/* /tmp/iso

增加Kickstart配置文件

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

12
3
4
5
6
7
8
9
10
1112

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

12
3
4
5
6
7
8
9
10
1112
13
14
15
16
17
18
19
20
2122
23
24
25
26
27
28
29
30
3132
33
34
35
36
37
38
39
40
4142
43
44
45
46
47
48
49
50
5152
53
54
55
56
57
58
59
60
6162
63
64
65
66
67
68
69
70
7172
73
74
75
76
77
78
79
80
8182
83
84
85
86
87
88
89
90
9192
93
94
95
96
97
98
99
100
101102
103
104
105
106
107
108
109
110
111112
113
114
115

#基于Kickstart自动化安装CentOS实践 - http://wsgzao.github.io/post/kickstart/ #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
@server-policy
telnet

#增加安装后运行脚本
%post
#config service
#自定义服务
service NetworkManager stop
chkconfig NetworkManager off
service network restart

#eject cdrom
#安装完成弹出光碟
#eject

#reboot
#执行完毕后重启
#reboot -f

#结束自动化部署
%end

生成依赖关系和ISO文件

注意路径和命令的准确性

12
3

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/

测试和建议

推荐两篇参考文献,建议先在虚拟机上反复测试验证再到物理机部署
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: