赞
踩
实验名称:PXE网络装机实验
实验要求:搭建PXE服务,对裸机进行自动化安装centos7操作系统
实验环境:centos7虚拟机一台,搭建pxe进行网络装机;一台裸机,用于验证
实验步骤:
1),准备环境
配置网络源yum
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@localhost yum.repos.d]# mkdir yum.repos.d.bak
[root@localhost yum.repos.d]# mv C* yum.repos.d.bak
[root@localhost yum.repos.d]# vim yum.repo
# CentOS-Base.repo # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-$releasever - Base baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/ # mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 # released updates [updates] name=CentOS-$releasever - Updates baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/ # mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 # additional packages that may be useful [extras] name=CentOS-$releasever - Extras baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/ # mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 # additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/ # mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
2),安装配置所需程序
清空yum缓存,重新加载数据,安装yum扩展包
[root@localhost yum.repos.d]# yum clean all #清空缓存 Loaded plugins: fastestmirror, langpacks Cleaning repos: base extras updates Cleaning up everything [root@localhost yum.repos.d]# yum makecache #加载数据 Loaded plugins: fastestmirror, langpacks base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/10): base/7/x86_64/group_gz | 153 kB 00:00:00 (2/10): base/7/x86_64/primary_db | 6.1 MB 00:00:00 (3/10): base/7/x86_64/other_db | 2.6 MB 00:00:00 (4/10): base/7/x86_64/filelists_db | 7.2 MB 00:00:06 (5/10): extras/7/x86_64/filelists_db | 224 kB 00:00:05 (6/10): extras/7/x86_64/other_db | 134 kB 00:00:00 (7/10): extras/7/x86_64/primary_db | 222 kB 00:00:06 (8/10): updates/7/x86_64/primary_db | 3.7 MB 00:00:01 (9/10): updates/7/x86_64/other_db | 227 kB 00:00:00 (10/10): updates/7/x86_64/filelists_db | 2.1 MB 00:00:01 Determining fastest mirrors Metadata Cache Created [root@localhost yum.repos.d]# yum -y install yum-utils #安装yum扩展程序
安装dhcp服务程序,编辑dhcp的配置文件
[root@localhost yum.repos.d]# yum -y install dhcp 安装dhcp服务程序 [root@localhost yum.repos.d]# cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf #复制文件,强行覆盖 cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y [root@localhost yum.repos.d]# vim /etc/dhcp/dhcpd.conf 配置dhcp subnet 192.168.22.0 netmask 255.255.255.0 { #网段和子网掩码 range 192.168.22.80 192.168.22.150; #IP地址池 option domain-name-servers ns1.internal.example.org; #DNS域名服务器 option domain-name "internal.example.org"; #域 option routers 192.168.22.254; #网关 option broadcast-address 192.168.22.255; #广播 default-lease-time 600; #默认组约时间,单位秒 max-lease-time 7200; #最大租约时间 next-server 192.168.22.100; #PXE服务器IP filename "pxelinux.0"; #制定引导文件 } [root@localhost yum.repos.d]# systemctl start dhcpd #开启dhcp服务
安装所需程序
[root@localhost yum.repos.d]# yum -y install syslinux xinetd tftp-server vsftpd #安装程序 [root@localhost yum.repos.d]# mkdir /var/ftp/centos7 #创建镜像存放目录 [root@localhost yum.repos.d]# cp -rf /media/* /var/ftp/centos7/ #复制镜像数据 [root@localhost yum.repos.d]# cd #切换工作目录 [root@localhost ~]# vim /etc/xinetd.d/tftp #进行编辑,关闭配置中自动关闭tftf-server服务,yes为默认关闭 disable = no #把此行yes改为no [root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux.cfg #创建pxelinux.cfg目录 [root@localhost ~]# cp /media/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default #复制模板 [root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ [root@localhost ~]# cp /media/isolinux/vmlinuz /var/lib/tftpboot/ [root@localhost ~]# cp /media/isolinux/initrd.img /var/lib/tftpboot/ [root@localhost ~]# cp /media/isolinux/vesamenu.c32 /var/lib/tftpboot/ [root@localhost ~]# cp /media/isolinux/boot.msg /var/lib/tftpboot/ [root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default 编辑配置,进行修改 label linux menu label ^Install CentOS Linux 7 kernel vmlinuz append initrd=initrd.img inst.repo=ftp://192.168.22.100/centos7 inst.ks=ftp://192.168.22.100/ks.cfg label check menu label Test this ^media & install CentOS Linux 7 menu default kernel vmlinuz append initrd=initrd.img inst.stage2=ftp://192.168.22.100/yum inst.ks=ftp://192.168.22.100/yum/ks.cfg quiet [root@localhost ~]# setenforce 0 #暂时关闭沙河 [root@localhost ~]# systemctl start vsftpd #开启服务 [root@localhost ~]# systemctl start xinetd #开启服务
安装使用自动化工具
[root@localhost ~]# yum -y install system-config-kickstart 安装kickstart自动化工具
[root@localhost ~]# system-config-kickstart 启动工具
保存后Ctrl+c退出
[root@localhost ~]# vim /root/anaconda-ks.cfg #进入复制内容
[root@localhost ~]# vim ks.cfg 添加复制的anaconda-ks.cfg文件中内容
[root@localhost ~]# mv ks.cfg /var/ftp/centos7/ #移动
设置防火墙规则
[root@localhost ~]# firewall-cmd --add-service=ftp --permanent
success
[root@localhost ~]# firewall-cmd --add-service=dhcp --permanent
success
[root@localhost ~]# firewall-cmd --add-port=69/udp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
3),使用裸机,进行装机
需注意运行内存至少2G,硬盘大小不小于kickstart设置的大小,裸机和PXE服务器位于同一物理网络
自动安装
【等安装完毕,至此PXE网络安装完成】
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。