kickstart自动化安装--tftp+nfs+dhcp

时间:2021-09-08 15:58:26

使用kickstart实现Centos 自动化安装

Kickstart自动化安装简介:

规模化:同时装配多台 服务器

自动化 :安装系统,配置各种服务

远程实现:不需要光盘,U盘等安装介质

优势:

(1)流线自动化的安装

(2)快速大量的裸机部署

(3)强制建立的一致性(软件包,分区,配置,监控,安全性)

(4)减少人为的部署失误

使用Kickstart方法安装的过程:
(1). 创建一个kickstart文件
(2). 创建有kickstart文件的引导介质或者使这个文件在网络上可用;
(3). 筹备一个安装树
(4). 开始ks安装:anconda自身启动 –>选取ks安装模式–> 从ks文件读取配置 –> 最后安装
创建kickstart配置文件的方式:
(1). 文本编辑器(vim)等
(2). 用图形化界面配置:system-config-kickstat(需要安装system-config-kickstart.noarch包

PXE(preboot execute environment, )是由Intel公司开发的最新技术,工作client/server的网络 模式,支持工作通过网络从远端服务器 下载映像,并由此支持  通过网络启动操作系统 ,在启动过程中,终端要求服务器 分配IP地址,在用TFTP或MTFTP协议下载一个启动软件包到本机内存中执行,更有这个启动软件 包完成终端基本软件设置,从而引导预先安装在服务器终端 操作系统,PXE可以引导 多种操作系统.

  1. 预启动执行环境,在操作系统之前运行
  2. 可用于远程安装,构建无盘工作站

服务端:远程DHCP服务,用来分配地址,定位引导程序;

运行TFTP服务器,提供引导程序下载

客户端 :网卡支持PXE协议

主板支持 网络启动

基本部署过程:

  1. 准备rhel/centOS安装源(YUM仓库)
  2. 启动TFTP服务,并提供内核,引导程序
  3. 启动 DHCP服务,用来分配地址,指出引导程序位置
  4. 配置启动菜单

一.DHCP,TFTP安装

[root@kickstart-server ~]# yum install -y dhcp* tftp*

首先配置tftp服务:

[root@kickstart-server ~]# vim /etc/xinetd.d/tftp

kickstart自动化安装--tftp+nfs+dhcp

2)TFTP+PXE配置

要实现远程安装系统,首先需要在tftpboot目录指定相关PXE相关内核模块机相关参数,配置步骤如下:

Ps:如果系统 是5.x,默认tftpboot目录已经自动创建到/根目录下

如果系统是6.x,则默认tftpboot目录在/var/lib/目录下,所以centos6.x需要做软链接到/目录下

[root@localhost ~]# yum install -y syslinux

[root@kickstart-server ~]# find / -name "pxelinux.0"

/usr/share/syslinux/pxelinux.0

[root@kickstart-server ~]# ln -s /var/lib/tftpboot/ /

[root@kickstart-server ~]# cd /tftpboot/

[root@kickstart-server tftpboot]# cp /usr/share/syslinux/pxelinux.0 .

[root@kickstart-server tftpboot]# ls

pxelinux.0

[root@localhost tftpboot]# cp /media/cdrom/images/pxeboot/* .[A1]

[root@localhost tftpboot]# ls

initrd.img  pxelinux.0  TRANS.TBL  vmlinuz

[root@localhost tftpboot]# rm -rf TRANS.TBL

[root@localhost tftpboot]# ls

initrd.img  pxelinux.0  vmlinuz

[root@localhost tftpboot]# mkdir -p pxelinux.cfg

[root@localhost tftpboot]# ls

initrd.img  pxelinux.0  pxelinux.cfg  vmlinuz

[root@localhost tftpboot]# cp /media/cdrom/isolinux/isolinux.cfg pxelinux.cfg/default

[root@localhost tftpboot]# vim pxelinux.cfg/default


ps:注解[A1]拷贝tftpboot目录下,也就是当前目录,也tftpboot目录

kickstart自动化安装--tftp+nfs+dhcp

解析:192.168.20.150是kickstart服务器,/centosinstall是nfs共享 linux镜像 的目录,也就是linux存放安装文件的路径;ks.cfg是kickstart主配置文件;设置timeout 60 /*超时时间为10s */;

Ksdevel-etho代表当我们有多块网卡 的时候,要实现自动化需要设置从etho安装

TFTP配置完毕,由于 是tftp是非独立服务,需要依赖xinetd服务来启动

启动命令为

[root@localhost tftpboot]# chkconfig tftp  --level 35  on

[root@localhost tftpboot]# service xinetd restart

二.NFS+kickstart配置

3NFS+kickstart配置

远程系统安装 ,客户端需要下载系统所需的软件包,所以需要使用NFS或HTTPD把镜像文件共享出来

[root@kickstart-server ~]# yum install nfs

[root@kickstart-server ~]# echo "/centosinstall   * (rw,sync)" >>/etc/exports

3NFS+kickstart配置

远程系统安装 ,客户端需要下载系统所需的软件包,所以需要使用NFS或HTTPD把镜像文件共享出来

[root@kickstart-server ~]# yum install nfs

[root@kickstart-server ~]# echo "/centosinstall   * (rw,sync)" >>/etc/exports

可以直接拷贝/root目录下anaconda-ks.cfg。重命名为ks.cfg,并把ks.cf拷贝到刚共享的/centosinstall目录下,赋予权限为chmod 777 ks.cfg

[root@kickstart-server ~]# mkdir /centosinstall

[root@kickstart-server ~]# cd /centosinstall/

[root@kickstart-server centosinstall]# nohup  cp /media/cdrom/*  . -a &[A1]


ps:注解 [A1]后台复制

[root@localhost ~]# vim /centosinstall/ks.cfg

#kickstart file automatically generated  by anaconda.

install

text

nfs --server=192.168.20.150 --dir=/centosinstall

key --skip

lang zh_CN,UTF-8

keyboard us

network --device eth0 --bootproto=dhcp --noipv6

rootpw 123456

firewall --disabled

authconfig --enableshadow --enablemd5

selinux --disabled

timezone Asia/shanghai

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

clearpart --all --initlabel

part /boot --fstype ext3 --size=200

part swap --size=1000

part / --fstype ext3 --size=10000

part /data --fstype ext3 --size=1 --grow

%packages

@base

@development-libs

@development-tools

mtools

pax

libxmu

%end

kickstart自动化安装--tftp+nfs+dhcp

kickstart自动化安装--tftp+nfs+dhcp

[root@kickstart-server ~]# service xinetd restart

[root@kickstart-server centosinstall]# service nfs restart

三.安装dhcp服务

[root@localhost ~]# yum install -y dhcp

[root@localhost ~]# vim /etc/dhcp/dhcpd.conf

kickstart自动化安装--tftp+nfs+dhcp

OK到目前为止,kickstart服务端的配置已经全部配置完成!为了保证服务正常生效,我们最后一次重启一下三个服务!

[root@localhost ~]# /etc/init.d/dhcpd restart

[root@localhost ~]# /etc/init.d/xinetd restart

[root@localhost ~]# /etc/init.d/nfs restart

客户端验证,是否自动化安装部署系统

新建rheld虚拟机(ps:要保证系统和服务属于同一个网段)

kickstart自动化安装--tftp+nfs+dhcp

kickstart自动化安装--tftp+nfs+dhcp

kickstart自动化安装--tftp+nfs+dhcp

kickstart自动化安装--tftp+nfs+dhcp

kickstart自动化安装--tftp+nfs+dhcp

kickstart自动化安装--tftp+nfs+dhcp

输入用户名和密码(123456)即可登录系统

kickstart自动化安装--tftp+nfs+dhcp

Ps:kickstart所有配置就此告一段落,真实环境需要注意,新服务器跟kickstart最后独立在一个网络,不要跟办公环境或者服务器机房混在一起,如果其他机器以网卡就会把它的系统重新装成linux系统,

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

kickstart多系统安装部署centos

Ps:因为之前在上述实验当中环境已经部署完成,本次只需要将其修改和添加多个系统即可

创建多个目录

[root@localhost tftpboot]# mkdir centos65_64

[root@localhost tftpboot]# mkdir centos67_64

[root@localhost tftpboot]# uname -r   #查看linux版本号

2.6.32-431.el6.x86_64

[root@localhost tftpboot]# uname -a   #显示系统名、节点名称、操作系统的发行版号、操作系统版本、运行系统的机器 ID 号。

Linux localhost.localdomain 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

拷贝不同的安装引导文件到各自对应的目录/centos65_64/

[root@localhost tftpboot]# mv initrd.img vmlinuz centos65_64/      #我们先把之前的引导文件拷贝到新建的centos65_64目录

[root@localhost tftpboot]# ls

centos65_64  centos67_64  pxelinux.0  pxelinux.cfg

接下来 我们先将6.5光盘卸载,替换成6.7光盘,并将其挂在到/medir/cdrom目录

[root@localhost ~]# umount /media/cdrom/       #将新挂在的6.7镜像引导文件内容拷贝新建的centos67_64目录

[root@localhost ~]# mount /dev/cdrom /media/cdrom/

[root@localhost ~]# cp /media/cdrom/images/pxeboot/* /var/lib/tftpboot/centos67_64/    #光盘挂之后,将内容全部拷贝到/centos67_64/下

[root@localhost ~]# cd /var/lib/tftpboot/centos67_64/

[root@localhost centos67_64]# ls

initrd.img  TRANS.TBL  vmlinuz

[root@localhost centos67_64]# rm -rf TRANS.TBL

[root@localhost tftpboot]# vim  pxelinux.cfg/default

kickstart自动化安装--tftp+nfs+dhcp

[root@localhost tftpboot]# cd /

将之前拷贝到 centosinstall目录下内容重新拷贝到新的系统目录/centos65_64

[root@localhost /]# mv centosinstall/* centos65_64/

[root@localhost centosinstall]# cd /centos65_64/

[root@localhost centos65_64]# ls

CentOS_BuildTag  images     Packages                  RPM-GPG-KEY-CentOS-Debug-6

EFI              isolinux   RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-Security-6

EULA             ks.cfg     repodata                  RPM-GPG-KEY-CentOS-Testing-6

GPL              nohup.out  RPM-GPG-KEY-CentOS-6      TRANS.TBL

[root@localhost centos65_64]# vim ks.cfg                      #这是存在centos65_64目录下ks.cfg

kickstart自动化安装--tftp+nfs+dhcp

将当前centos6.7版本挂在的/medir/cdrom/目录的内容拷贝到新建的centos67_64目录下

[root@localhost centos67_64]# nohup cp -a /media/cdrom/* . &

因为没有ks.cfg,为了快捷的方便,我们借用centos65_64目录下的ks.cfg,并稍加修改

[root@localhost centos67_64]# cp /centos65_64/ks.cfg /centos67_64/ks.cfg

[root@localhost ~]# vim /centos67_64/ks.cfg

kickstart自动化安装--tftp+nfs+dhcp

设置NFS共享

[root@localhost ~]# vim /etc/exports

kickstart自动化安装--tftp+nfs+dhcp

配置安装系统时,界面提示消息

[root@localhost centos67_64]# vim /tftpboot/boot.msg

kickstart自动化安装--tftp+nfs+dhcp

重启生效

[root@localhost tftpboot]# /etc/init.d/nfs restart

root@localhost tftpboot]# /etc/init.d/xinetd restart

验证:

  1. 1.     安装centos6.5版本

kickstart自动化安装--tftp+nfs+dhcp

kickstart自动化安装--tftp+nfs+dhcp

安装centos6.7版本系统

kickstart自动化安装--tftp+nfs+dhcp

kickstart自动化安装--tftp+nfs+dhcp

多系统安装实验完成!!!!!!!!!!!!!!!!

由于时间的关系,以下安装步骤省略~~~~~~~~如有疑问,请参照上述界面安装操作