0
点赞
收藏
分享

微信扫一扫

pxe安装centos系统

alanwhy 2023-12-20 阅读 15

pxe安装centos系统


一 环境基本配置

1.关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

2.selinux设置#

将selinux设置为disabled

3.网卡设置静态IP

#修改网卡配置文件,配置固定IP地址;

4.配置yum源

cd /etc/yum.repos.d/ && mkdir backup && mv *repo backup/

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo

sed -i -e "s|mirrors.cloud.aliyuncs.com|mirrors.aliyun.com|g " /etc/yum.repos.d/CentOS-*

sed -i -e "s|releasever|releasever-stream|g" /etc/yum.repos.d/CentOS-*

yum clean all && yum makecache

二  安装软件依赖

#安装依赖包

yum -y install dhcp-server tftp-server httpd syslinux-nonlinux

#服务开机自启

systemctl enable --now httpd tftp dhcpd

三 配置DHCP服务

#注意事项:IP地址网段与主机网段一致,否则服务无法启动

[root@localhost ~]# vi /etc/dhcp/dhcpd.conf
#

# DHCP Server Configuration file.

#   see /usr/share/doc/dhcp-server/dhcpd.conf.example

see dhcpd.conf(5) man page

#

subnet 192.168.160.0 netmask 255.255.255.0 {
range 192.168.160.150 192.168.160.200;
option routers 192.168.160.137;
option domain-name-servers 180.76.76.76, 114.114.114.114;
next-server 192.168.160.137;
filename "pxelinux.0";
}

四  pxe安装源配置

#创建镜像目录

mkdir -pv /var/www/html/centos/{7,8}/os/x86_64/

#挂载镜像

mount CentOS-8.3.2011-x86_64-dvd1.iso /mnt/
mount CentOS-7.6-x86_64-DVD-1810.iso /mnt/

#进入挂载目录,将镜像中内容拷贝到创建目录下

cp -a * /var/www/html/Centos/8/os/x86_64/
cp -a * /var/www/html/Centos/7/os/x86_64/

#网页访问

http://192.168.160.137/centos/

Index of /centos
[ICO]	Name	Last modified	Size	Description
[PARENTDIR]	Parent Directory 	 	- 	 
[DIR]	7/ 	2022-06-18 18:10 	- 	 
[DIR]	8/ 	2022-06-18 18:10 	-

五 安装应答文件

#创建应答文件放置目录

mkdir /var/www/html/ks/

#将centos8系统root目录下的anaconda-ks.cfg文件拷贝到目录下,并编辑;

cp anaconda-ks.cfg /var/www/html/ks/centos8.cfg

#centos8应答文件

#version=RHEL8

# Use graphical install

#graphical
ignoredisk --only-use=sda

#repo --name="AppStream" --baseurl=http://192.168.160.137/centos8/os/x86_64/AppStream

%packages
@^graphical-server-environment
@container-management
@debugging
@development
@dotnet-core
@file-server
@ftp-server
@graphical-admin-tools
@guest-agents
@headless-management
@infiniband
@legacy-unix
@mail-server
@network-file-system-client
@network-server
@performance
@remote-desktop-clients
@remote-system-management
@rpm-development-tools
@scientific
@security-tools
@smart-card
@smb-server
@system-tools
@virtualization-client
@virtualization-hypervisor
@virtualization-tools
@web-server
kexec-tools

%end

# Keyboard layouts

keyboard --xlayouts='us'

# System language

lang en_US.UTF-8

# Network information

network  --bootproto=dhcp --device=ens33 --ipv6=auto --activate
network  --hostname=localhost.localdomain
#bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda

# Use CDROM installation media

url --url="http://192.168.160.137/centos/8/os/x86_64/"

# Run the Setup Agent on first boot

firstboot --enable

selinux --disabled
firewall --disabled

ignoredisk --only-use=sda

# Partition clearing information

clearpart --all --initlabel

# Disk partitioning information

part /boot --fstype="xfs" --ondisk=sda --size=1024
part pv.116 --fstype="lvmpv" --ondisk=sda --size=80895
volgroup cl --pesize=4096 pv.116
logvol / --fstype="xfs" --size=78811 --name=root --vgname=cl
logvol swap --fstype="swap" --size=2077 --name=swap --vgname=cl

# System timezone

timezone Asia/Shanghai --isUtc

# Root password

rootpw --iscrypted $6$2mrQBYDbWkM9Caex$LlFHoivTRlkYLy1O8x/g8pcr.mjPBTqRpcjRyofW5x6A/.S5evuWvD6koXKe3KlVUBG8LaxTIsjsh976L5c26.

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end

reboot

#找一台centos7系统,将anaconda-ks.cfg文件拷贝到目录下,并编辑;

#centos7应答文件

#version=DEVEL

# System authorization information

auth --enableshadow --passalgo=sha512

# Use CDROM installation media

url --url=http://192.168.160.137/centos/7/os/x86_64/

# Use graphical install

graphical

# Run the Setup Agent on first boot

firstboot --enable
ignoredisk --only-use=sda

# Keyboard layouts

keyboard --vckeymap=us --xlayouts='us'

# System language

lang en_US.UTF-8

# Network information

network  --bootproto=dhcp --device=ens33 --ipv6=auto --activate
network  --hostname=localhost.localdomain

# Root password

rootpw --iscrypted $6$IKmH6BAC5VbuhO5H$0Tgrknd8lTUZbVoaZl2W3nD04VkgMKGEE16LtgwgGeQaJrFjMYE.QCjcUkbiigMcdCHZgOcq6VMvYfG4HALTJ0

# System services

services --enabled="chronyd"

# System timezone

timezone Asia/Shanghai --isUtc

# X Window System configuration information

xconfig  --startxonboot

# System bootloader configuration

bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda

# Partition clearing information

clearpart --all --initlabel

# Disk partitioning information

part /boot --fstype="xfs" --ondisk=sda --size=1024
part pv.157 --fstype="lvmpv" --ondisk=sda --size=80895
volgroup centos --pesize=4096 pv.157
logvol swap  --fstype="swap" --size=2048 --name=swap --vgname=centos
logvol /  --fstype="xfs" --size=78840 --name=root --vgname=centos

%packages
@^graphical-server-environment
@backup-server
@base
@compat-libraries
@core
@desktop-debugging
@development
@dial-up
@dns-server
@file-server
@fonts
@ftp-server
@gnome-desktop
@guest-agents
@guest-desktop-agents
@ha
@hardware-monitoring
@identity-management-server
@infiniband
@input-methods
@internet-browser
@java-platform
@kde-desktop
@large-systems
@load-balancer
@mail-server
@mainframe-access
@mariadb
@multimedia
@network-file-system-client
@performance
@print-client
@print-server
@remote-system-management
@resilient-storage
@security-tools
@smart-card
@system-admin-tools
@virtualization-client
@virtualization-hypervisor
@virtualization-tools
@x11
chrony
kexec-tools

%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end

#修改应答文件权限;

chmod 644 * 
[root@localhost ks]# ls -lh
total 8.0K
-rw-r--r--. 1 root root 2.3K Jun 18 18:53 centos7.cfg
-rw-r--r--  1 root root 2.0K Jun 19 12:14 centos8.cfg

六 pxe启动文件

#创建启动目录

mkdir /var/lib/tftpboot/centos{7,8}

拷贝centos7启动文件

cp /var/www/html/centos/7/os/x86_64/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos7

#拷贝centos8启动文件

cp /var/www/html/centos/8/os/x86_64/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos8

#拷贝文件到tftpboot目录下

cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/

#以下三个文件是centos8安装所必须文件,centos6,7则不需要

cp /var/www/html/centos/8/os/x86_64/isolinux/{ldlinux.c32,libcom32.c32,libutil.c32} /var/lib/tftpboot/

#生成安装菜单文件

mkdir /var/lib/tftpboot/pxelinux.cfg/

 cp /var/www/html/centos/8/os/x86_64/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

#查看目录结构

[root@localhost ks]# tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── centos7
│   ├── initrd.img
│   └── vmlinuz
├── centos8
│   ├── initrd.img
│   └── vmlinuz
├── ldlinux.c32
├── libcom32.c32
├── libutil.c32
├── menu.c32
├── pxelinux.0
└── pxelinux.cfg
    └── default

3 directories, 10 files

七.启动菜单文件

[root@localhost ks]# cat /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
timeout 600

menu title Install CentOS Linux
label linux8
menu label Auto Install CentOS Linux ^8
kernel centos8/vmlinuz
append initrd=centos8/initrd.img ks=http://192.168.160.137/ks/centos8.cfg

#label linux7
#menu label Auto Install CentOS Linux ^7
#kernel centos7/vmlinuz
#append initrd=centos7/initrd.img ks=http://192.168.160.137/ks/centos7.cfg

label manual
menu label ^Manual Install CentOS Linux 8.0
kernel centos8/vmlinuz
append initrd=centos8/initrd.img
inst.repo=http://192.168.160.137/centos/8/os/x86_64/

label rescue
menu label ^Rescue a CentOS Linux system 8
kernel centos8/vmlinuz
append initrd=centos8/initrd.img
inst.repo=http://192.168.160.137/centos/8/os/x86_64/ rescue

#label local
#menu default
#menu label Boot from ^local drive
#localboot 0xffff

八 启动机器测试pxe安装

#我的环境在vmvare环境下,只需要安装centos8,所以将centos7部分注释掉了;

  • centos7/8自动应答文件中,磁盘分区大小已经写好,创建机器磁盘大小与文件中一致;
  • centos8的cfg文件,网卡选项一定要做安装源前面,要不然安装会显示 error setting up base repository


举报

相关推荐

0 条评论