创建centos7.9虚机
最小化安装(略)
可参照本站之前写的workstation安装虚拟机
关闭防火墙和selinux
systemctl status firewalld
#查看防火墙状态
systemctl stop firewalld
#关闭防火墙
systemctl disable firewalld
#关闭selinux服务
sed -i.bak 's/=enforcing/=disabled/' /etc/sysconfig/selinuxsed -i 's/enforcing/disabled/' /etc/selinux/config setenforce 0
#重启后生效
安装vim、wget等工具
yum install vim
#安装wget
yum install wget
centos7更换阿里源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum repolist
centos更新和清除、卸载无用内核
yum update
yum clean all
#自动搜索无用内核及删除
yum remove $(rpm -qa | grep kernel | grep -v $(uname -r))
#查看/boot分区占用情况
df -h /boot
DHCP、TFTP、vsftpd、xinetd、HTTP等服务安装、设置开机启动
#dhcp服务安装
yum -y install dhcp yum install -y tftp-server xinetdyum -y install vsftpdyum -y install httpdyum install syslinux
##################################################
设置tftp开机启动systemctl start tftp && systemctl enable tftp
设置vsftpd开机启动systemctl start vsftpd && systemctl enable vsftpd
设置httpd开机启动systemctl start httpd && systemctl enable httpd
[root@localhost media]# ss -ntul
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
udp UNCONN 0 0 [fe80::29b2:d4ee:a5b:975f]%ens33:546 [::]:*
udp UNCONN 0 0 [::]:69 [::]:*
tcp LISTEN 0 128 *:22 *:*
tcp LISTEN 0 100 127.0.0.1:25 *:*
tcp LISTEN 0 128 [::]:80 [::]:*
tcp LISTEN 0 128 [::]:22 [::]:*
tcp LISTEN 0 100 [::1]:25
DHCP设置
从上面端口情况可得67端口未正常启动,接下来修改配置文件
dhcpd.conf 配置文件
:set paste 保持格式粘贴代码块
# 模板文件位于/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example
# #用法:
# #cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
# ## #根据实际地址修改编辑以下参数# ##
#ping www地址时,读取本服务器的设置信息的,作用不大
option domain-name "miao.its.com";
#公共域名服务器(阿里云DNS、百度云DNS、腾讯DNS)
option domain-name-servers 223.6.6.6, 180.76.76.76,119.29.29.29;
#续租时常设置项,3600*24=86400(一天)
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
option space pxelinux;
option pxelinux.magic code 208 = string;
option pxelinux.configfile code 209 = text;
option pxelinux.pathprefix code 210 = text;
option pxelinux.reboottime code 211 = unsigned integer 32;
option architecture-type code 93 = unsigned integer 16;
subnet 192.168.0.0 netmask 255.255.255.0 {
#指定为192.168.x.x网段分配网络参数 range 192.168.0.200 192.168.0.210;
#设置准备为客户端分配的IP地址 option domain-name-servers 223.6.6.6, 180.76.76.76,119.29.29.29;
#设置分配给客户端的DNS服务器地址。option routers 192.168.0.2;
#设置分配给客户端的网关地址。class "pxeclients" { match if substring (option vendor-class-identifier, 0, 9) = "PXEClient"; next-server 192.168.0.111;
# 提供引导文件的服务器IP地址,即tftp服务器地址 if option architecture-type = 00:07 { filename "uefi/shim.efi";
# 采用shim打包的EFI引导映象 } else { filename "pxelinux/pxelinux.0";
# SYSLINUX打包的BIOS引导映像 } } }
tftp配置文件
tftp配置文件
vim /etc/xinetd.d/tftpservice
tftp{ socket_type = dgram protocol = udp wait = yes
//yes是一台一台安装,no为一起多台安装 user = root server = /usr/sbin/in.tftpd server_args = -s /var/lib/tftpboot disable = yes
//改为no,表示开启TFTP服务 per_source = 11 cps = 100 2 flags = IPv4}
#此时检查端口应该ftp、dchp、http(67、69、80)都开启ss -ntul
上传CentOS-7-x86_64-Everything-2009.iso文件到/opt目录,挂载光盘
chmod -R 777 opt/
[root@localhost opt]# ls
CentOS-7-x86_64-Everything-2009.iso
挂载iso文件到/media
[root@localhost /]# mount -t iso9660 /opt/CentOS-7-x86_64-Everything-2009.iso /media/
mount: /dev/loop0 is write-protected, mounting read-only
[root@localhost /]# cd /media/
[root@localhost media]# ls
CentOS_BuildTag EFI EULA GPL images isolinux LiveOS Packages repodata RPM-GPG-KEY-CentOS-7 RPM-GPG-KEY-CentOS-Testing-7 TRANS.TBL
#复制光盘文件到http共享目录
mkdir -p /var/www/html/centos/7/os/x86/
cp -rv /media/* /var/www/html/centos/7/os/x86/
为使用BIOS(Legacy)的机器配置
在tftpboot中创建pxelinux目录,并将pxelinux.0复制到该目录中
mkdir /var/lib/tftpboot/pxelinuxcp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/pxelinux/
在 pxelinux/ 目录中创建目录 pxelinux.cfg,添加名为 default 的配置文件
mkdir /var/lib/tftpboot/pxelinux/pxelinux.cfgcp /var/www/html/centos/7/os/x86/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux/pxelinux.cfg/default
修改default文件(略)将引导映像复制到 pxelinux/ 目录下
cp /var/www/html/centos/7/os/x86/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/pxelinux/[root@localhost pxelinux.cfg]
# tree /var/lib/tftpboot/pxelinux//var/lib/tftpboot/pxelinux/├── initrd.img├── pxelinux.0├── pxelinux.cfg│ └── default└── vmlinuz
重新载入已运行服务 tftp、xinetd 和 dhcpsystemctl daemon-reloadsystemctl restart tftp httpd dhcpd
为使用UEFI的机器配置
需要软件包 shim 中的 shim.efi 文件,和软件包 grub2-efi 的 grubx64.efi 文件
yum install shim-x64yum install grub2-efi-x64
#在 tftpboot/ 目录中创建 uefi/ 目录,并将 EFI 引导映像复制到该目录下mkdir /var/lib/tftpboot/ueficp /boot/efi/EFI/centos/shim.efi /var/lib/tftpboot/uefi/cp /boot/efi/EFI/centos/grubx64.efi /var/lib/tftpboot/uefi/chmod 644 /var/lib/tftpboot/uefi/shim.efi grubx64.efi
#uefi/ 目录中添加名为 grub.cfg 的配置文件,可根据iso文件EFI/BOOT/grub.cfg修改vim /var/lib/tftpboot/uefi/grub.cfg修改grub.cfg(略)将 pxeboot 引导映像复制到 uefi/ 目录下cp /var/www/html/centos/7/os/x86/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/uefi/[root@localhost uefi]# tree /var/lib/tftpboot/uefi//var/lib/tftpboot/uefi/├── grub.cfg├── grubx64.efi├── initrd.img├── shim.efi└── vmlinuz重新载入已运行服务 tftp、xinetd 和 dhcpsystemctl daemon-reloadsystemctl restart tftp httpd dhcpd
将创建的应答文件拷贝到ks目录/var/www/html/ks
编辑centos7_ks.cfg(略)
[root@localhost ks]
# lscentos7_ks.cfg centos7_efi_ks.cfg