PXE笔记整理

PXE笔记整理

1、开启主机图形,init5

2、去掉VMware使用本地DHCP将IP分配给虚拟机

3、配置网络可用

# 使用脚本进行一键编辑,在rhel7进行使用
[root@nginx ~]# vim /bin/vmset7.sh
#!/bin/bash
rm -rf /etc/sysconfig/network-scripts/ifcfg-$1
cat > /etc/sysconfig/network-scripts/ifcfg-$1 <<EOF
DEVICE=$1
ONBOOT=yes
BOOTPROTO=none
IPADDR=$2
PREFIX=24
GATEWAY=172.25.254.2
DNS1=114.114.114.114
NAME=$1
EOF

nmcli connection reload
nmcli connection up $1

hostnamectl set-hostname $3

cat > /etc/hosts <<EOF
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
$2      $3
EOF


[root@nginx ~]# vmset7.sh eth0 172.25.254.100 pxe.timinglee.org
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/4)

检查配置情况

[root@nginx ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.25.254.100	pxe.timinglee.org


[root@nginx ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.25.254.2    0.0.0.0         UG    100    0        0 eth0
172.25.254.0    0.0.0.0         255.255.255.0   U     100    0        0 eth0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

4、重要文件,在系统安装好后自动生成,记录系统在安装过程中所有设定

[root@pxe ~]# cat anaconda-ks.cfg 
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512		# 加密算法
# Use CDROM installation media
cdrom										# 安装源
# Use graphical install
graphical									# 图形化
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'		# 键盘
# System language
lang zh_CN.UTF-8

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

repo --name="Server-HighAvailability" --baseurl=file:///run/install/repo/addons/HighAvailability
repo --name="Server-ResilientStorage" --baseurl=file:///run/install/repo/addons/ResilientStorage
# Root password
rootpw --iscrypted $6$dvfzrDJk7LpHBS6X$nnI4Ve4QiQ9D6AVyhMpD/bzp0p.3O9J36F.onrzhi3EbwNW0RK./tP1qUtdYjzFWOGPpwmqtki8doru1uLz2h0
# 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
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel

%packages								# 安装包
@^graphical-server-environment			# @表示安装软件包组
@base
@core									
@desktop-debugging
@dial-up
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@hardware-monitoring
@input-methods
@internet-browser
@multimedia
@print-client
@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

5、使用kickstart工具生成

安装图形化生成kickstart自动安装脚本的工具

[root@pxe ~]# yum install system-config-kickstart -y

# 启动图形制作工具
[root@pxe ~]# system-config-kickstart 

# 安装httpd进行配置
[root@pxe ~]# yum install httpd -y
[root@pxe ~]# systemctl enable --now httpd

[root@pxe ~]# ln -s /rhel7/ /var/www/html/
[root@pxe ~]# ls /var/www/html/
rhel7


# 配置ks.cfg
[root@pxe ~]# cat /var/www/html/ks.cfg 
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$cq8heods$JT88ZtLSrZ58vQcEhH9O5.
# System language
lang zh_CN
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx


# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="http://172.25.254.100/rhel7"
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=1024
part swap --fstype="swap" --size=512
part / --fstype="xfs" --grow  --size=1

%packages
@base
httpd
%end

%post
mkdir -p /rhel7

echo mount /dev/cdrom  /rhel7 >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local


cat > /etc/yum.repos.d/rhel7.repo <<EOF
[rhel7]
name=rhel7
baseurl=file:///rhel7
gpgcheck=0
EOF

yum install gcc -y
%end



# 检查配置文件是否正确
[root@pxe ~]# ksvalidator ks.cfg 
kickstart文件的第45 行发生问题:

区域 %packages 未在 %end 结束。



图形化配置说明
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

6、搭建并配置DHCP服务测试kickstart脚本

# 寻找安装包
[root@pxe ~]# yum search dhcp

[root@pxe ~]# yum install dhcp -y

# 查看软件配置信息
[root@pxe ~]# rpm -qc dhcp
/etc/dhcp/dhcpd.conf
/etc/dhcp/dhcpd6.conf
/etc/openldap/schema/dhcp.schema
/etc/sysconfig/dhcpd
/var/lib/dhcpd/dhcpd.leases
/var/lib/dhcpd/dhcpd6.leases

# 复制默认模板
[root@pxe ~]# cat /etc/dhcp/dhcpd.conf 
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
[root@pxe ~]# \cp -f /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf

编辑配置文件

[root@pxe ~]# vim /etc/dhcp/dhcpd.conf
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
option domain-name "timinglee.org";
option domain-name-servers 114.114.114.114;

default-lease-time 600;
max-lease-time 7200;

# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# No service will be given on this subnet, but declaring it helps the 
# DHCP server to understand the network topology.

#subnet 10.152.187.0 netmask 255.255.255.0 {
#}

# This is a very basic subnet declaration.

subnet 172.25.254.0 netmask 255.255.255.0 {
  range 172.25.254.30 172.25.254.40;
  option routers 172.25.254.2;
}

[root@pxe ~]# systemctl enable --now dhcpd

开机选择
在这里插入图片描述

7、搭建pxe网络安装环境实现服务器自动部署

[root@pxe ~]# yum search pxelinux

[root@pxe ~]# yum install syslinux.x86_64 -y

[root@pxe ~]# rpm -ql syslinux.x86_64 | grep pxelinux.0
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/pxelinux.0

# 帮助信息
[root@pxe ~]# rpm -ql syslinux.x86_64 | grep pxelinux.txt
/usr/share/doc/syslinux-4.05/pxelinux.txt

安装tftp,可以共享pxelinux.0数据文件的网络服务

[root@pxe ~]# yum install -y tftp-server.x86_64

# 查询启动文件
[root@pxe ~]# rpm -ql tftp-server 
/etc/xinetd.d/tftp
/usr/lib/systemd/system/tftp.service

[root@pxe ~]# systemctl enable --now tftp

# 将启动数据加到数据目录文件
[root@pxe ~]# cp /rhel7/isolinux/* /var/lib/tftpboot/
[root@pxe ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

[root@pxe ~]# cd /var/lib/tftpboot/
[root@pxe tftpboot]# ls
boot.cat  grub.conf   isolinux.bin  memtest     splash.png  upgrade.img   vmlinuz
boot.msg  initrd.img  isolinux.cfg  pxelinux.0  TRANS.TBL   vesamenu.c32

[root@pxe tftpboot]# mkdir pxelinux.cfg
[root@pxe tftpboot]# cp isolinux.cfg pxelinux.cfg/default

修改dhcp配置文件

[root@pxe tftpboot]# vim /etc/dhcp/dhcpd.conf 
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
option domain-name "timinglee.org";
option domain-name-servers 114.114.114.114;

default-lease-time 600;
max-lease-time 7200;

# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# No service will be given on this subnet, but declaring it helps the 
# DHCP server to understand the network topology.

#subnet 10.152.187.0 netmask 255.255.255.0 {
#}

# This is a very basic subnet declaration.

subnet 172.25.254.0 netmask 255.255.255.0 {
  range 172.25.254.30 172.25.254.40;
  option routers 172.25.254.2;
  next-server 172.25.254.100;
  filename "pxelinux.0";
}


[root@pxe tftpboot]# systemctl restart dhcpd

修改default文件内容

[root@pxe tftpboot]# vim /var/lib/tftpboot/pxelinux.cfg/default
default vesamenu.c32
timeout 600

display boot.msg

# Clear the screen when exiting the menu, instead of leaving the menu displayed.
# For vesamenu, this means the graphical background is still displayed without
# the menu itself for as long as the screen remains in graphics mode.
menu clear
menu background splash.png
menu title Red Hat Enterprise Linux 7.9
menu vshift 8
menu rows 18
menu margin 8
#menu hidden
menu helpmsgrow 15
menu tabmsgrow 13

# Border Area
menu color border * #00000000 #00000000 none

# Selected item
menu color sel 0 #ffffffff #00000000 none

# Title bar
menu color title 0 #ff7ba3d0 #00000000 none

# Press [Tab] message
menu color tabmsg 0 #ff3a6496 #00000000 none

# Unselected menu item
menu color unsel 0 #84b8ffff #00000000 none

# Selected hotkey
menu color hotsel 0 #84b8ffff #00000000 none

# Unselected hotkey
menu color hotkey 0 #ffffffff #00000000 none

# Help text
menu color help 0 #ffffffff #00000000 none

# A scrollbar of some type? Not sure.
menu color scrollbar 0 #ffffffff #ff355594 none

# Timeout msg
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none

# Command prompt text
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none

# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.

menu tabmsg Press Tab for full configuration options on menu items.

menu separator # insert an empty line
menu separator # insert an empty line

label linux
  menu label ^Install Red Hat Enterprise Linux 7.9
  menu default			# 添加默认
  kernel vmlinuz
  append initrd=initrd.img repo=http://172.25.254.100/rhel7 ks=http://172.25.254.100/ks.cfg quiet	# 修改为自己的

label check
  menu label Test this ^media & install Red Hat Enterprise Linux 7.9
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.9\x20Server.x86_64 rd.live.check quiet

menu separator # insert an empty line

# utilities submenu
menu begin ^Troubleshooting
  menu title Troubleshooting

label vesa
  menu indent count 5
  menu label Install Red Hat Enterprise Linux 7.9 in ^basic graphics mode
  text help
	Try this option out if you're having trouble installing
	Red Hat Enterprise Linux 7.9.
  endtext
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.9\x20Server.x86_64 xdriver=vesa nomodeset quiet

label rescue
  menu indent count 5
  menu label ^Rescue a Red Hat Enterprise Linux system
  text help
	If the system will not boot, this lets you access files
	and edit config files to try to get it booting again.
  endtext
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.9\x20Server.x86_64 rescue quiet

label memtest
  menu label Run a ^memory test
  text help
	If your system is having issues, a problem with your
	system's memory may be the cause. Use this utility to
	see if the memory is working correctly.
  endtext
  kernel memtest

menu separator # insert an empty line

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

menu separator # insert an empty line
menu separator # insert an empty line

label returntomain
  menu label Return to ^main menu
  menu exit

menu end

选择从电源打开
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值