CentOS7 使用PXE+kickstar批量安装
kickstar可实现批量无人值守的方式安装系统,批量部署前可以生成一个设置好各种参数的脚本ks.cfg文件,然后自动化安装
流程为
服务端192.168.10.11 DHCP范围192.168.10.100-192.168.10.110
安装组件
yum -y install dnsmasq tftp-server xinetd syslinux httpd pykickstart system-config-kickstart
配置dhcp
mv /etc/dnsmasq.conf /etc/dnsmasq.conf.backup vim /etc/dnsmasq.conf 改为 interface=ens34 dhcp-range=192.168.10.100,192.168.10.110,255.255.255.0,1h dhcp-boot=pxelinux.0 enable-tftp tftp-root=/var/lib/tftpboot #执行 systemctl enable dnsmasq systemctl start dnsmasq systemctl status dnsmasq
配置tftp
sed -i '/disable\>/s/\<yes\>/no/' /etc/xinetd.d/tftp #执行 systemctl enable tftp systemctl restart tftp.service systemctl status tftp.service
配置httpd
rm -rf /etc/httpd/conf.d/welcome.conf sed -i 's#\#ServerName www.example.com:80#ServerName 127.0.0.1:80#g' /etc/httpd/conf/httpd.conf mkdir -p /var/www/html/centos7 mount -o loop /dev/cdrom /var/www/html/centos7 #执行 systemctl enable httpd systemctl start httpd systemctl status httpd
配置pxe
cp -r /usr/share/syslinux/* /var/lib/tftpboot cp -a /var/www/html/centos7/isolinux/* /var/lib/tftpboot/ mkdir /var/lib/tftpboot/pxelinux.cfg vim /var/lib/tftpboot/pxelinux.cfg/default 改为 default ks prompt 0 label ks kernel vmlinuz append initrd=initrd.img ks=http://192.168.10.11/ks.cfg
生成ks
#避免Package selection is disabled due to problems downloading package informatio错误两种方式 #方法1 vim /etc/yum.repos.d/development.repo 改为 [development] name=development baseurl=file:///var/www/html/centos7 gpgcheck=0 #方法2 #或者vim /usr/share/system-config-kickstart/packages.py #164行后添加"base"
#执行 system-config-kickstart
左上角File--Open File
选择本机安装过系统自动生成的anaconda-ks.cfg
设置语言、键盘布局、时区、密码
安装方式选择http,填写http服务器地址以及yum仓库路径
安装新boot loader,改为MBR
清除主分区记录,移除所有存在的分区,初始化分区,根据需求自定义分区
配置网卡
验证默认
关闭SELinux和防火墙
反勾选安装图形界面环境
选择需要安装的包
安装前脚本,根据需求在右边白框内编写脚本,这里默认
安装后脚本,根据需求在右边白框内编写脚本
点击左上角File,保存
选择保存到/root目录下
#验证 cp /root/ks.cfg /var/www/html/ ksvalidator /var/www/html/ks.cfg
新建一个和服务器同一个网段的虚拟机,测试启动后一切自动安装
附上ks.cfg
#platform=x86, AMD64, or Intel EM64T #version=DEVEL # Install OS instead of upgrade install # Keyboard layouts keyboard 'us' # Root password rootpw --iscrypted $1$mgFXptMu$u3fP3Gbq5b49HqIPYMvS71 # System language lang en_US # System authorization information auth --useshadow --passalgo=sha512 # Use graphical install graphical # SELinux configuration selinux --disabled # Do not configure the X Window System skipx # Firewall configuration firewall --disabled # Network information network --bootproto=static --device=ens33 --gateway=192.168.10.2 --ip=192.168.10.15 --nameserver=8.8.8.8 --netmask=255.255.255.0 # Reboot after installation reboot # System timezone timezone Asia/Hong_Kong # Use network installation url --url="http://192.168.10.11/centos7" # System bootloader configuration bootloader --location=mbr # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all --initlabel # Disk partitioning information part /boot --fstype="xfs" --size=512 part / --fstype="xfs" --grow --size=1 part swap --fstype="swap" --size=4096 %post mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.bak adduser vos echo "vos":"voscn" | chpasswd %end %packages @^minimal @compat-libraries @core @debugging @development @system-admin-tools tree nmap sysstat lrzsz dos2unix telnet %end
本站所有文章均可随意转载,转载时请保留原文链接及作者。