linux-centos-pxe批量安装
制作背景: 通过传统的方式安装和部署计算机时,都会要求通过交互的方式,回答各类问题,以完成安装和部署任务,过程繁琐,且无法实现自动化。因此,许多系统管理员都希望能够通过一种网络化的无人值守的自动安装方式将操作系统部署到目标计算机中。本次实验中所使用和安装的操作系统为CentOS 6。
上期跟大家分享了关于自动安装centos系统的iso的制作;
这一期小编跟大家分享linux-centos-pxe批量安装(和上一期大概步骤相同,只不过这一期不需要制作iso,而是通过服务器dhcp自动分配的地址然后自动链接服务器ftp下载相关的引导文件以及安装包 | 只要你的带宽和服务器好批量为几百台电脑安装系统不是问题)
一、制作环境(和上期一样)
实验环境:VMware、linux、centos系统 // 小编这里用的是centos 6.9,其他6之后的版本步骤应该差不多
相关软件: Xshell、Xmanager Enterprise 5 //这些软件在软件管家以及其他软件或网址可以下载,且都有免费版。
拓扑图:
二、菜鸟的坎坷经历:
1、代码
例如:编辑文件时代码打错、漏掉、多添加字符以及保存文件时没有保存成功等
错误体现:新建的虚拟机打开遇到找不到dhcp、ftp、linux等
建议:打完代码应检查几遍,保存退出时也要注意不要在切换编辑模式时添加多余字符,特别一文件的位置是否正确、是否保存成功;
2、编辑ks.cfg时
配置如小编下图这般应该就不会出错,
错误体现:若其他文件代码编辑正确,则在系统完成引导后重启时进度条卡住不动,大概就是ks.cfg配置错误,小编配置时安装包选择错误,scientific包没装,只需装base和scientifi应该就可没问题;
建议:若重启出现错误,可尝试安装基本系统中的所有包
三、为了节省同志们的时间下面出来给出代码,只在复杂的地方给予具体步骤:
IP地址可以根据自己的需要设置
[[email protected] ~]# mkdir /media/cdrom
[[email protected] ~]# mount /dev/cdrom /media/cdrom
[[email protected] ~]# yum --disablerepo=\* --enablerepo=c6-media install vim man -y
[[email protected] ~]# yum --disablerepo=\* --enablerepo=c6-media install ftp vsftpd tftp-server system-config-kickstart -y
[[email protected] ~]# service vsftpd start
[[email protected] ~]# netstat -tupln //21端口
[[email protected] ~]# iptables -F INPUT
[[email protected] ~]# iptables -F OUTPUT
在物理机上输入ftp://192.168.2.100/ 查看ftp连接是否正常
[[email protected] ~]# rpm -ql vsftpd |less
[[email protected] ~]# cd /var/ftp
[[email protected] ftp]# ll
[[email protected] ftp]# cp -rf /media/cdrom/. ./
[[email protected] ftp]# vim /etc/xinetd.d/tftp
将 disable=yes 改为 disable=no
[[email protected] ftp]# service xinetd start
正在启动 xinetd: [确定]
[[email protected] ftp]# netstat -tupln
//69端口开启则xinetd服务启动成功
[[email protected] ftp]# cd /var/lib/tftpboot
[[email protected] tftpboot]# cp /media/cdrom/isolinux/vmlinuz ./
[[email protected] tftpboot]# cp /media/cdrom/isolinux/initrd.img ./
[[email protected] tftpboot]# ll
总用量 44792
-r--r--r--. 1 root root 41587792 7月 9 08:02 initrd.img
-r-xr-xr-x. 1 root root 4274992 7月 9 08:01 vmlinuz
(-)[[email protected] tftpboot]# yum --disablerepo=\* --enablerepo=c6-media install syslinux system-config-kickstart -y
[[email protected] tftpboot]# cd /usr/share/syslinux
[[email protected] syslinux]# cp pxelinux.0 /var/lib/tftpboot
[[email protected] syslinux]# cd /var/lib/tftpboot
[[email protected] tftpboot]# ll
总用量 44820
-r--r--r--. 1 root root 41587792 7月 9 08:02 initrd.img
-rw-r--r--. 1 root root 26759 7月 9 08:07 pxelinux.0
-r-xr-xr-x. 1 root root 4274992 7月 9 08:01 vmlinuz
[[email protected] tftpboot]# mkdir pxelinux.cfg
[[email protected] tftpboot]# cd pxelinux.cfg
[[email protected] pxelinux.cfg]# cp /media/cdrom/isolinux/isolinux.cfg ./default
[[email protected] pxelinux.cfg]# ll
总用量 4
-r--r--r--. 1 root root 923 7月 9 08:11 default
[[email protected] pxelinux.cfg]# vim default
如图:
[[email protected] ~]# cp ks.cfg /var/ftp
[[email protected] ~]# vim /etc/dhcp/dhcpd.conf
//编辑dhcp作用域(例):
subnet 192.168.2.0 netmask 255.255.255.0 {
range 192.168.2.110 192.168.2.150;
option routers 192.168.2.254;
option domain-name-servers 1.1.1.1,2.2.2.2;
next-server 192.168.2.100;
filename "pxelinux.0";
[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# find . -exec mv {} {}.bak \;
[[email protected] yum.repos.d]# mv CentOS-Media.repo.bak CentOS-Media.repo
[[email protected] dir1]# ll
[[email protected] dir1]# cd ..
[[email protected] yum.repos.d]# pwd
[[email protected] yum.repos.d]# ll
[[email protected] yum.repos.d]# vim CentOS-Media.repo
将 enabled=0改为: enabled=1
[[email protected] ~]# vim 1.sh // 新建文件1.sh
[[email protected] ~]# chmod +x 1.sh //授权为可执行文件
[[email protected] ~]# vim 1.sh
#/bin/bash
#get host ip address
string=`ifconfig eth0 |grep 'inet\>' |awk '{print $2}'`
#get ip address last num
num=${string##*.}
#modify hostname
sed -e "s/HOSTNAME.*/HOSTNAME=station$num.a.com/" /etc/sysconfig/network
#modify host ip address
sed -e "s/BOOTPROTO.*/BOOTPROTO=static\nIPADDR=192.168.2.$num\nNETMASK=255.255.255.0\nGATEWAY=192.168.2.254\nDNS1=1.1.1.1/" /etc/sysconfig/network-scripts/ifcfg-eth0
[[email protected] ~]# vim ks.cfg
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --enforcing
# Do not configure the X Window System
logging --level=info
# System timezone
timezone --isUtc Asia/Shanghai
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --append="rhgb quiet" --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="ext4" --size=512
part / --fstype="ext4" --size=15000
part swap --fstype="swap" --size=512
poweroff //配置完成后自动关机
%post --interpreter=/bin/bash
#get host ip address
string=`ifconfig eth0 |grep 'inet\>' |awk '{print $2}'`
#get ip address last num
num=${string##*.}
#modify hostname
sed -e "s/HOSTNAME.*/HOSTNAME=station$num.a.com/" /etc/sysconfig/network
#modify host ip address
sed -e "s/BOOTPROTO.*/BOOTPROTO=static\nIPADDR=192.168.2.$num\nNETMASK=255.255.255.0\nGATEWAY=192.168.2.254\nDNS1=1.1.1.1/" /etc/sysconfig/network-scripts/ifcfg-eth0
%end
%packages
@base
@compat-libraries
@debugging
@directory-client
@hardware-monitoring
@mainframe-access
@network-file-system-client
@network-tools
@performance
@perl-runtime
@security-tools
@storage-client-multipath
:wq! //切换至末行模式,退出保存
[[email protected] ~]# system-config-kickstart // 用Xmanager配置 ks.cfg配置步骤
新建的虚拟机打开电源即可,虚拟机通过服务器dhcp自动分配的地址然后自动链接服务器ftp下载相关的引导文件以及安装包自动完成系统安装
欢迎大家评论和建议,小编会在大家的鼓励中努力成长的,谢谢大家
下期我会跟大家分享关于centos的日志系统搭建经验,期待你的再次光临