# 永久配置yum源
setenforce 0
sed -i'/^SELINUX=/{s#enforcing#disabled#}' /etc/selinux/config
systemctlstop firewalld
systemctldisable firewalld
systemctlstop NetworkManager
systemctldisable NetworkManager
systemctlrestart network
mkdir/mnt/yum
mount/dev/sr0 /mnt/yum
rm -rf/etc/yum.repos.d/*
cat >/etc/yum.repos.d/LBXyum.repo << ok
[LBXyum]
name=LBXyum
baseurl=file:///mnt/yum
gpgcheck=0
enabled=1
ok
echo"mount /dev/sr0 /mnt/yum" >> /etc/rc.d/rc.local
chmod +x/etc/rc.d/rc.local
echo "永久yum源配置成功!"
# 设置vim行距
cat >~/.vimrc << ok
set nu
set ts=4
set sw=4
set ai
set si
set ci
ok
echo "设置vim行距成功!"
# PXE无人值守自动装机(第一部分)
yum install-y dhcp
echo"dhcp安装成功!"
wangduan=`ifconfigens33 | grep netmask | tr -s " " | cut -d " " -f3 | cut -d"." -f1,2,3`
hostIP=`ifconfigens33 | grep netmask | tr -s " " | cut -d " " -f3 | cut -d"." -f1,2,3,4`
cat >/etc/dhcp/dhcpd.conf << ok
subnet${wangduan}.0 netmask 255.255.255.0 {
range ${wangduan}.101 ${wangduan}.254;
next-server ${hostIP};
filename "pxelinux.0";
}
ok
echo"dhcp配置成功!"
sed -i'/^BOOTPROTO=/{s#dhcp#static#}' /etc/sysconfig/network-scripts/ifcfg-ens33
echo "设置为静态ip成功!"
yum install-y tftp-server
echo"tftp安装成功!"
sed -i'/disable/{s#yes#no#}' /etc/xinetd.d/tftp
echo"tftp取消禁用成功!"
yum install-y syslinux
echo"syslinux安装成功!已发现pxelinux.0引导文件!"
cp/usr/share/syslinux/pxelinux.0 /var/lib/tftpboot
echo"pxelinux.0引导文件拷贝到/var/lib/tftpboot成功!"
neiheDir=`find/ -name "isolinux" | grep -v "proc"`
\cp${neiheDir}/vmlinuz /var/lib/tftpboot
\cp${neiheDir}/initrd.img /var/lib/tftpboot
\cp${neiheDir}/isolinux.cfg /var/lib/tftpboot
echo "3个内核文件拷贝到/var/lib/tftpboot成功!"
mkdir/var/lib/tftpboot/pxelinux.cfg
echo "创建/var/lib/tftpboot/pxelinux.cfg目录成功!"
mv/var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
echo "将其中一个内核文件isolinux.cfg移动到pxelinux.cfg并改名叫default成功!"
sed -i'1c\default linux' /var/lib/tftpboot/pxelinux.cfg/default
sed -i'64c\ append initrd=initrd.imgks=http:// '${hostIP}'/ks/ks.cfg' /var/lib/tftpboot/pxelinux.cfg/default
echo "配置内核文件default成功(tftp配置成功)!"
yum install-y httpd
echo"httpd安装成功!"
mkdir/var/www/html/ks
echo "创建/var/www/html/ks目录成功!"
mkdir/var/www/html/cdrom
echo "创建/var/www/html/cdrom目录成功!"
mount/dev/sr0 /var/www/html/cdrom
echo "挂载镜像sr0到挂载点cdrom成功!"
yum -yinstall system-config-kickstart
echo"kickstart安装成功!"
sed -i'1c\[development]' /etc/yum.repos.d/LBXyum.repo
echo "修改为development成功!"
system-config-kickstart
# PXE无人值守自动装机(第二部分,分两个.sh运行)
mv /root/桌面/ks.cfg/var/www/html/ks
echo "桌面生成的ks.cfg移动到/var/www/html/ks成功!"
systemctlrestart dhcpd
echo"dfcpd启动成功!"
systemctlrestart tftp
echo"tftp启动成功!"
systemctlrestart httpd
echo"httpd启动成功!"
echo "接下来请新建的一个虚拟机,将内存设置为1500M,网卡NAT模式,开机即可,注意本虚拟机需要调为NAT模式,而且网络编辑器的NAT要设置为对应的网段"
感悟:看起来很完美的脚本,实际上有很多错误,只有在实验之后,才能算是完美。