自动化安装centos7 centos6
实验:实现基于PXE的系统自动化安装centos
初始化:iptables|firewalld 关闭,selinux 关闭, ntp|chrony时间同步
环境:两台主机
一台主机A:DHCP,TFTP,HTTP,ks,yum 源 vmnet 192.168.38.100 可以连接互联网
一台主机B:客户端pxe
1 在A上实现
实现http服务
yum install httpd
systemctl start httpd
systemctl enable httpd
2 yum源(centos7,6) 把需要安装的镜像文件挂载到http网页上
ls /root/CentOS-6.10-x86_64-bin-DVD1.iso CentOS-7-x86_64-Everything-1810.iso
mkdir /var/www/html/centos{7,6}/os/x86_64/ -pv
vim /etc/fstab
/root/CentOS-6.10-x86_64-bin-DVD1.iso /var/www/html/centos/6/os/x86_64 iso9660 defaults 0 0
/root/CentOS-7-x86_64-Everything-1810.iso /var/www/html/centos/7/os/x86_64 iso9660 defaults 0 0
mount -a
3 应答文件
system-config-kickstart 基于图形化界面创造应答文件
vim /root/anaconda-ks.cfg
ls /var/www/html/ksdir/ 准备centos6 和 centos7 应答文件
ks6_desktop.cfg ks7_mini.cfg
下面是我写的centos7应答文件 仅供参考
url --url="http://192.168.38.100/centos/7/os/x86_64/"
text
reboot
selinux --disabled
firewall --disabled
zerombr
clearpart --all --initlabel
rootpw --plaintext magedu
bootloader --append="net.ifnames=0" --location=mbr
part / --fstype="xfs" --size=100000
part /boot --fstype="xfs" --size=1000
part swap --fstype="swap" --size=2048
%packages
@^minimal
autofs
%end
%post
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
cat > /etc/yum.repos.d/test.repo <<EOF
[base]
Baseurl=file:///misc/cd
gpgcheck=0
EOF
%end
ks7_mini.cfg
url --url=“http://192.168.38.100/centos/7/os/x86_64/”
ks6_desktop.cfg
url --url=“http://192.168.38.100/centos/6/os/x86_64/”
4 dhcp
yum install dhcp
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
vim /etc/dhcp/dhcpd.conf
subnet 192.168.38.0 netmask 255.255.255.0 {
range 192.168.38.101 192.168.38.254;
option routers 192.168.38.1;
option domain-name-servers 180.76.76.76;
next-server 192.168.38.100;
filename "pxelinux.0";
}
systemctl start dhcpd
systemctl enable dhcpd
5 tftp
yum install tftp-server
systemctl start tftp
systemctl enable tftp
6 相关PXE相关文件
yum install syslinux
cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/
mkdir /var/lib/tftpboot/centos{6,7},
cp /var/www/html/centos/7/os/x86_64/isolinux/{vmlinux,initrd.img} /var/lib/tftpboot/centos7
cp /var/www/html/centos/6/os/x86_64/isolinux/{vmlinux,initrd.img} /var/lib/tftpboot/centos6
7 准备安装菜单
mkdir /var/lib/tftpboot/pxelinux.cfg/
cp /var/www/html/centos/7/os/x86_64/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
这里必须把isolinux.cfg改名为default 不然客户端找不到 安装菜单不会显示 会报错
vim /var/lib/tftpboot/pxelinux.cfg/default 注意文件严格按照自己的对应
default menu.c32
timeout 600
menu title Auto Install CentOS for M38
label linux7
menu label Install ^Mini CentOS 7
menu default
kernel centos7/vmlinuz
append initrd=centos7/initrd.img ks=http://192.168.38.100 /ksdir/ks7_mini.cfg
label linux6
menu label Install ^Desktop CentOS 6
kernel centos6/vmlinuz
append initrd=centos6/initrd.img ks=http://192.168.38.100/ksdir/ks6_desktop.cfg
label local
menu label Boot from ^local drive
localboot 0xffff
在机器b上开启自动使用dhcp获取地址 然后是以下界面
tree /var/lib/tftpboot/ 我的文件树状图 经供参考
/var/lib/tftpboot/
├── centos6
│ ├── initrd.img
│ └── vmlinuz
├── centos7
│ ├── initrd.img
│ └── vmlinuz
├── menu.c32
├── pxelinux.0
└── pxelinux.cfg
└── default
3 directories, 7 files
8 在B上测试安装 注意B机器如果安装centos7 必须最小内存为1.5G 不然会报错 和服务器A机器必须在同一模式 不然获取不了dhcp地址