根据业务定制自动安装CentOS
过几天机房要上架29台服务器,需要装系统。机器太多,想自动化安装,由于没测试机,实验都在虚拟机实现,为了能快点部署完,想了几套方案,毕竟早点部署完, 就可以回宿舍,不用去公司了。
[root@localhost ~]# mount /dev/cdrom /mnt
[root@localhost ~]# mkdir -p iso/CentOS [root@localhost CentOS]# pwd /root/iso/CentOS
[root@localhost ~]# awk '/Installing/{print $2}' install.log | sed 's/^[0-9]*://g' >package.txt
[root@localhost ~]# cat cp.sh #!/bin/bash DVD='/mnt/CentOS' #DVD镜像存放包路径 PACKDIR='/root/package.txt' #记录的是现在系统里安装的所有包名 NEW_DVD='/root/iso/CentOS/' # 新镜像需要包的存放路径 while read LINE do cp ${DVD}/${LINE}*.rpm /${NEW_DVD} || echo "$LINE don't cp......." done < package.txt
[root@localhost CentOS]# rsync -a --exclude=CentOS /mnt/ /root/iso
[root@localhost ~]# cat anaconda-ks.cfg | grep -v "^#" install cdrom lang en_US.UTF-8 keyboard us network --device eth0 --bootproto static --ip 192.168.0.45 --netmask 255.255.255.0 --gateway 192.168.0.1 rootpw --iscrypted $1$cT7w.PYF$autqNIf5WqO0P.3CW5nru. firewall --enabled --port=22:tcp authconfig --enableshadow --enablemd5 selinux --enforcing timezone --utc Asia/Shanghai bootloader --location=mbr --driveorder=sda clearpart --linux part /boot --fstype ext3 --size=100 part swap --size=2000 part / --fstype ext3 --size=100 --grow %packages @base @core @dialup @editors @text-internet keyutils trousers fipscheck device-mapper-multipath
[root@localhost ~]# cp anaconda-ks.cfg /root/iso
[root@localhost ~]# vim /root/iso/isolinux/isolinux.cfg Default linux 修改成default linux ks=cdrom:/anaconda-ks.cfg
[root@localhost ~]# cd /root/iso/ [root@localhost iso]# createrepo -g repodata/*comps.xml /root/iso/ 457/457 - CentOS/fbset-2.1-22.x86_64.rpm Saving Primary metadata Saving file lists metadata Saving other metadata [root@localhost iso]#
[root@localhost ~]# mkisofs -o MyCentOS.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -T /root/iso/
[root@localhost ~]# /usr/lib/anaconda-runtime/implantisomd5 MyCentOS.iso Inserting md5sum into iso p_w_picpath... md5 = 82cc70b16908bea468a2ce1c263dee9a Inserting fragment md5sums into iso p_w_picpath... fragmd5 = bdf4b332ccf4a6fafe883a4cff54527df985ac2ee71be3c6c66d51e3421c frags = 20 Setting supported flag to 0 [root@localhost ~]#