本文将详细介绍Anaconda安装程序的核心配置命令,包括引导参数、Kickstart命令、安装选项等。风哥教程参考Linux官方文档Installation章节内容,为读者提供全面的Anaconda配置指南。
参考Red Hat Enterprise Linux 10官方文档中的System administration章节
Part01-基础概念与理论知识
1.1 Anaconda概述
Anaconda是Red Hat系列Linux发行版的安装程序,提供了图形化安装界面和命令行安装界面。Anaconda支持多种安装方式和配置选项。更多视频教程www.fgedu.net.cn
1.2 引导参数概述
引导参数是传递给内核和安装程序的参数,用于控制安装过程。引导参数可以在引导菜单中添加或修改。
1.3 Kickstart概述
Kickstart是Anaconda的自动化安装配置文件,可以定义安装过程中的所有配置选项。Kickstart文件可以实现无人值守安装。
1.4 安装选项概述
安装选项是Anaconda提供的各种配置选项,包括语言、键盘、时区、分区、网络、软件包等。
Part02-生产环境规划与建议
2.1 引导参数配置建议
引导参数配置建议: from LinuxDBA视频:www.itpux.com
- 使用inst.ssh启用SSH远程安装
- 使用inst.vnc启用VNC图形化安装
- 使用inst.ks指定Kickstart文件
- 使用inst.repo指定安装源
- 使用console=ttyS0配置串口控制台
2.2 Kickstart配置建议
Kickstart配置建议:
- 使用clearpart清除分区
- 使用part配置分区方案
- 使用network配置网络
- 使用rootpw配置root密码
- 使用user创建普通用户
2.3 安装选项配置建议
安装选项配置建议:
- 选择合适的语言和键盘
- 配置正确的时区
- 规划合理的分区方案
- 配置网络连接
- 选择必要的软件包
Part03-生产环境项目实施方案
3.1 引导参数配置
引导参数配置:
$ cat /proc/cmdline
BOOT_IMAGE=/vmlinuz-5.14.0-123.el9.x86_64 root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet
# 步骤2:安装引导参数
# 以下是一些常用的安装引导参数
# 基础安装参数
inst.stage2=hd:LABEL=RHEL-10-0-0-BaseOS-x86_64
inst.repo=http://192.168.1.200/rhel10
inst.lang=en_US.UTF-8
inst.keymap=us
inst.timezone=Asia/Shanghai
# 远程安装参数
inst.ssh
inst.vnc
inst.vncpassword=yourpassword
inst.cmdline
# Kickstart参数
inst.ks=http://192.168.1.200/ks.cfg
inst.ks=nfs:192.168.1.200:/ks/ks.cfg
inst.ks=hd:LABEL=KS:/ks.cfg
# 网络参数
ip=192.168.1.100::192.168.1.1:255.255.255.0:rhel10-server:ens33:none
ip=dhcp
ipv6=auto
# 存储参数
inst.dd=/dev/sdb
inst.gpt
inst.mpath
# 调试参数
inst.debug
inst.loglevel=debug
inst.syslog=192.168.1.200:514
# 步骤3:编辑引导菜单
# 在GRUB引导菜单中,按e键编辑引导参数
# 在linux行末尾添加需要的参数
# 例如:
# linuxefi /images/pxeboot/vmlinuz inst.stage2=hd:LABEL=RHEL-10-0-0-BaseOS-x86_64 inst.ssh inst.ks=http://192.168.1.200/ks.cfg quiet
# 步骤4:验证引导参数
# 在安装过程中,可以通过以下命令查看引导参数
$ cat /proc/cmdline
BOOT_IMAGE=/vmlinuz inst.stage2=hd:LABEL=RHEL-10-0-0-BaseOS-x86_64 inst.ssh inst.ks=http://192.168.1.200/ks.cfg quiet
# 步骤5:查看安装日志
$ cat /tmp/anaconda.log
10:00:00,123 INFO anaconda: Starting installation
10:00:01,234 INFO anaconda: Loading kickstart file from http://192.168.1.200/ks.cfg
10:00:02,345 INFO anaconda: Kickstart file loaded successfully
10:00:03,456 INFO anaconda: Configuring storage
10:00:04,567 INFO anaconda: Storage configuration completed
10:00:05,678 INFO anaconda: Starting package installation
10:00:06,789 INFO anaconda: Installing packages…
# 步骤6:查看系统日志
$ cat /tmp/syslog
Apr 2 10:00:00 localhost kernel: Linux version 5.14.0-123.el9.x86_64 (mockbuild@x86-020.build.eng.bos.redhat.com) (gcc version 11.2.1 20220127 (Red Hat 11.2.1-7) (GCC) )
Apr 2 10:00:00 localhost kernel: Command line: BOOT_IMAGE=/vmlinuz inst.stage2=hd:LABEL=RHEL-10-0-0-BaseOS-x86_64 inst.ssh inst.ks=http://192.168.1.200/ks.cfg quiet
Apr 2 10:00:01 localhost systemd[1]: Starting Anaconda…
Apr 2 10:00:02 localhost systemd[1]: Started Anaconda.
3.2 Kickstart命令详解
Kickstart命令详解:
$ vi ks.cfg
# Kickstart配置文件内容
# 基础命令
#platform=x86, AMD64, or Intel EM64T
#version=RHEL10
# Install OS instead of upgrade
install
# Use network installation
url –url=”http://192.168.1.200/rhel10″
# Use text mode install
text
# System language
lang en_US.UTF-8
# System keyboard
keyboard us
# System timezone
timezone Asia/Shanghai
# Root password
rootpw –iscrypted $6$abc123def4567890123456789012345678901234567890123456789012345678
# System authorization information
auth –useshadow –passalgo=sha512
# Use graphical install
graphical
# System bootloader configuration
bootloader –location=mbr –boot-drive=sda
# Partition clearing information
clearpart –all –initlabel
# Disk partitioning information
part /boot –fstype=”xfs” –size=500
part swap –fstype=”swap” –size=2048
part / –fstype=”xfs” –grow –size=1
# Network information
network –bootproto=dhcp –device=ens33 –onboot=on
# Firewall configuration
firewall –enabled –service=ssh
# SELinux configuration
selinux –enforcing
# Reboot after installation
reboot
# 软件包命令
%packages
@base
@core
@development
vim
wget
curl
git
%end
# 安装前脚本
%pre
#!/bin/bash
# 安装前脚本
# from:www.itpux.com.qq113257174.wx:itpux-com
echo “Starting pre-installation script”
# 可以在这里执行一些安装前的准备工作
echo “Pre-installation script completed”
%end
# 安装后脚本
%post –log=/root/ks-post.log
#!/bin/bash
# 安装后脚本
echo “Starting post-installation script”
# 更新系统
dnf update -y
# 安装额外软件
dnf install -y vim wget curl git
# 配置防火墙
firewall-cmd –permanent –add-service=ssh
firewall-cmd –reload
# 配置SSH
sed -i ‘s/#PermitRootLogin yes/PermitRootLogin yes/’ /etc/ssh/sshd_config
systemctl restart sshd
# 创建用户
useradd -m -s /bin/bash fgedu
echo “fgedu:password” | chpasswd
echo “fgedu ALL=(ALL) NOPASSWD:ALL” >> /etc/sudoers
# 配置主机名
hostnamectl set-hostname rhel10-server
# 配置DNS
echo “nameserver 8.8.8.8” >> /etc/resolv.conf
echo “nameserver 8.8.4.4” >> /etc/resolv.conf
# 配置时间同步
systemctl enable –now chronyd
# 配置日志
sed -i ‘s/#SystemMaxUse=/SystemMaxUse=100M/’ /etc/systemd/journald.conf
systemctl restart systemd-journald
echo “Post-installation script completed”
%end
# 步骤2:验证Kickstart配置文件
$ ksvalidator ks.cfg
Kickstart file ks.cfg is valid
# 步骤3:查看Kickstart配置文件
$ cat ks.cfg | head -50
#platform=x86, AMD64, or Intel EM64T
#version=RHEL10
# Install OS instead of upgrade
install
# Use network installation
url –url=”http://192.168.1.200/rhel10″
# Use text mode install
text
# System language
lang en_US.UTF-8
# System keyboard
keyboard us
# System timezone
timezone Asia/Shanghai
# Root password
rootpw –iscrypted $6$abc123def4567890123456789012345678901234567890123456789012345678
# System authorization information
auth –useshadow –passalgo=sha512
# Use graphical install
graphical
# System bootloader configuration
bootloader –location=mbr –boot-drive=sda
# Partition clearing information
clearpart –all –initlabel
# Disk partitioning information
part /boot –fstype=”xfs” –size=500
part swap –fstype=”swap” –size=2048
part / –fstype=”xfs” –grow –size=1
# Network information
network –bootproto=dhcp –device=ens33 –onboot=on
# Firewall configuration
firewall –enabled –service=ssh
# SELinux configuration
selinux –enforcing
# Reboot after installation
reboot
# 步骤4:生成加密密码
$ python3 -c ‘import crypt; print(crypt.crypt(“password”, crypt.mksalt(crypt.METHOD_SHA512)))’
$6$abc123def4567890123456789012345678901234567890123456789012345678
# 步骤5:测试Kickstart安装
# 使用Kickstart文件进行安装
# 在引导参数中添加:inst.ks=http://192.168.1.200/ks.cfg
# 步骤6:查看安装日志
$ cat /root/ks-post.log
Starting post-installation script
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:00 ago on Wed 02 Apr 2026 10:00:00 AM CST.
Dependencies resolved.
Nothing to do.
Complete!
success
success
Installed:
git-2.39.3-1.el10.x86_64 vim-enhanced-2:9.0.1234-1.el10.x86_64
curl-7.76.1-19.el10.x86_64 wget-1.21.1-7.el10.x86_64
Complete!
Post-installation script completed
3.3 高级配置命令
高级配置命令:
$ vi ks_advanced.cfg
# 高级Kickstart配置文件
# LVM配置
# 清除所有分区
clearpart –all –initlabel
# 创建物理卷
part pv.01 –size=1 –grow
# 创建卷组
volgroup rhel pv.01
# 创建逻辑卷
logvol / –fstype=”xfs” –name=root –vgname=rhel –size=50000
logvol /home –fstype=”xfs” –name=home –vgname=rhel –size=20000
logvol /var –fstype=”xfs” –name=var –vgname=rhel –size=20000
logvol /tmp –fstype=”xfs” –name=tmp –vgname=rhel –size=10000
logvol swap –fstype=”swap” –name=swap –vgname=rhel –size=4096
# 网络配置
network –bootproto=static –ip=192.168.1.100 –netmask=255.255.255.0 –gateway=192.168.1.1 –nameserver=8.8.8.8,8.8.4.4 –device=ens33 –onboot=on
network –hostname=rhel10-server
# 防火墙配置
firewall –enabled –service=ssh –service=http –service=https –port=8080:tcp
# SELinux配置
selinux –enforcing
# 用户配置
user –name=fgedu –groups=wheel –password=$6$abc123def4567890123456789012345678901234567890123456789012345678 –iscrypted –gecos=”FGEdu User”
# 软件包配置
%packages
@base
@core
@development
@server-product
vim
wget
curl
git
net-tools
tcpdump
wireshark
strace
ltrace
%end
# 安装前脚本
%pre
#!/bin/bash
# 检查硬件
# from:www.itpux.com.qq113257174.wx:itpux-com
echo “Checking hardware…”
# 检查内存
mem=$(free -m | grep Mem | awk ‘{print $2}’)
if [ $mem -lt 4096 ]; then
echo “ERROR: Insufficient memory (required: 4GB, available: ${mem}MB)”
exit 1
fi
# 检查磁盘
disk=$(lsblk -d -o NAME,SIZE | grep -v NAME | head -1 | awk ‘{print $2}’)
echo “Available disk: $disk”
# 检查网络
if ! ping -c 1 192.168.1.1 > /dev/null 2>&1; then
echo “ERROR: Network unreachable”
exit 1
fi
echo “Hardware check completed”
%end
# 安装后脚本
%post –log=/root/ks-advanced-post.log
#!/bin/bash
# 配置系统
echo “Configuring system…”
# 配置内核参数
cat >> /etc/sysctl.conf << EOF
# Kernel parameters
net.ipv4.ip_forward = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.icmp_echo_ignore_all = 0
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
EOF
sysctl -p
# 配置limits
cat >> /etc/security/limits.conf << EOF
# System limits
* soft nofile 65536
* hard nofile 65536
* soft nproc 65536
* hard nproc 65536
EOF
# 配置SSH
sed -i 's/#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
systemctl restart sshd
# 配置防火墙
firewall-cmd --permanent --add-service=ssh
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
# 配置日志
sed -i 's/#SystemMaxUse=/SystemMaxUse=100M/' /etc/systemd/journald.conf
systemctl restart systemd-journald
# 配置时间同步
systemctl enable --now chronyd
chronyc sources
# 配置自动更新
dnf install -y dnf-automatic
sed -i 's/apply_updates = no/apply_updates = yes/' /etc/dnf/automatic.conf
systemctl enable --now dnf-automatic.timer
# 配置监控
dnf install -y htop iotop nethogs
echo "System configuration completed"
%end
# 步骤2:验证高级Kickstart配置
$ ksvalidator ks_advanced.cfg
Kickstart file ks_advanced.cfg is valid
# 步骤3:查看高级Kickstart配置
$ cat ks_advanced.cfg | grep -E "logvol|network|firewall|user"
logvol / --fstype="xfs" --name=root --vgname=rhel --size=50000
logvol /home --fstype="xfs" --name=home --vgname=rhel --size=20000
logvol /var --fstype="xfs" --name=var --vgname=rhel --size=20000
logvol /tmp --fstype="xfs" --name=tmp --vgname=rhel --size=10000
logvol swap --fstype="swap" --name=swap --vgname=rhel --size=4096
network --bootproto=static --ip=192.168.1.100 --netmask=255.255.255.0 --gateway=192.168.1.1 --nameserver=8.8.8.8,8.8.4.4 --device=ens33 --onboot=on
network --hostname=rhel10-server
firewall --enabled --service=ssh --service=http --service=https --port=8080:tcp
user --name=fgedu --groups=wheel --password=$6$abc123def4567890123456789012345678901234567890123456789012345678 --iscrypted --gecos="FGEdu User"
# 步骤4:测试高级Kickstart安装
# 使用高级Kickstart文件进行安装
# 在引导参数中添加:inst.ks=http://192.168.1.200/ks_advanced.cfg
# 步骤5:查看安装后配置
$ cat /root/ks-advanced-post.log
Configuring system...
net.ipv4.ip_forward = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.icmp_echo_ignore_all = 0
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
success
success
success
success
success
System configuration completed
# 步骤6:验证系统配置
$ sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1
$ cat /etc/security/limits.conf | tail -5
# System limits
* soft nofile 65536
* hard nofile 65536
* soft nproc 65536
* hard nproc 65536
$ firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: cockpit dhcpv6-client http https ssh
ports: 8080/tcp
protocols:
forward: no
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
$ chronyc sources
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 192.168.1.1 2 6 377 15 +123us[ +234us] +/- 23ms
Part04-生产案例与实战讲解
4.1 企业Anaconda配置案例
某企业Anaconda配置的案例:
- 配置环境:100台服务器,LVM分区,静态IP
- 服务器配置:8核16G,500G磁盘,千兆网络
- 网络配置:静态IP,DNS,网关
- 成果:批量安装成功,配置标准化
4.2 Anaconda配置管理脚本
Anaconda配置管理脚本:
# anaconda_config_manager.sh
# from:www.itpux.com.qq113257174.wx:itpux-com
# web: http://www.fgedu.net.cn
# Anaconda配置管理脚本
echo “=== Anaconda配置管理 ===”
# Kickstart配置文件目录
KS_DIR=”/var/www/html/ks”
mkdir -p $KS_DIR
# 创建基础Kickstart配置
echo “”
echo “=== 创建基础Kickstart配置 ===”
cat > $KS_DIR/ks_base.cfg << 'EOF'
#platform=x86, AMD64, or Intel EM64T
#version=RHEL10
install
url --url="http://192.168.1.200/rhel10"
text
lang en_US.UTF-8
keyboard us
timezone Asia/Shanghai
rootpw --iscrypted $6$abc123def4567890123456789012345678901234567890123456789012345678
auth --useshadow --passalgo=sha512
graphical
bootloader --location=mbr --boot-drive=sda
clearpart --all --initlabel
part /boot --fstype="xfs" --size=500
part swap --fstype="swap" --size=2048
part / --fstype="xfs" --grow --size=1
network --bootproto=dhcp --device=ens33 --onboot=on
firewall --enabled --service=ssh
selinux --enforcing
reboot
%packages
@base
@core
vim
wget
curl
git
%end
%post --log=/root/ks-post.log
#!/bin/bash
dnf update -y
dnf install -y vim wget curl git
firewall-cmd --permanent --add-service=ssh
firewall-cmd --reload
systemctl restart sshd
useradd -m -s /bin/bash fgedu
echo "fgedu:password" | chpasswd
echo "fgedu ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
%end
EOF
# 创建LVM Kickstart配置
echo “”
echo “=== 创建LVM Kickstart配置 ===”
cat > $KS_DIR/ks_lvm.cfg << 'EOF'
#platform=x86, AMD64, or Intel EM64T
#version=RHEL10
install
url --url="http://192.168.1.200/rhel10"
text
lang en_US.UTF-8
keyboard us
timezone Asia/Shanghai
rootpw --iscrypted $6$abc123def4567890123456789012345678901234567890123456789012345678
auth --useshadow --passalgo=sha512
graphical
bootloader --location=mbr --boot-drive=sda
clearpart --all --initlabel
part pv.01 --size=1 --grow
volgroup rhel pv.01
logvol / --fstype="xfs" --name=root --vgname=rhel --size=50000
logvol /home --fstype="xfs" --name=home --vgname=rhel --size=20000
logvol /var --fstype="xfs" --name=var --vgname=rhel --size=20000
logvol /tmp --fstype="xfs" --name=tmp --vgname=rhel --size=10000
logvol swap --fstype="swap" --name=swap --vgname=rhel --size=4096
network --bootproto=dhcp --device=ens33 --onboot=on
firewall --enabled --service=ssh
selinux --enforcing
reboot
%packages
@base
@core
vim
wget
curl
git
%end
%post --log=/root/ks-post.log
#!/bin/bash
dnf update -y
dnf install -y vim wget curl git
firewall-cmd --permanent --add-service=ssh
firewall-cmd --reload
systemctl restart sshd
useradd -m -s /bin/bash fgedu
echo "fgedu:password" | chpasswd
echo "fgedu ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
%end
EOF
# 验证Kickstart配置文件
echo “”
echo “=== 验证Kickstart配置文件 ===”
for ks_file in $KS_DIR/*.cfg; do
echo “验证: $ks_file”
ksvalidator $ks_file
if [ $? -eq 0 ]; then
echo “OK: $ks_file 验证通过”
else
echo “ERROR: $ks_file 验证失败”
fi
done
# 设置文件权限
echo “”
echo “=== 设置文件权限 ===”
chmod 644 $KS_DIR/*.cfg
chown apache:apache $KS_DIR/*.cfg
# 验证文件访问
echo “”
echo “=== 验证文件访问 ===”
for ks_file in $KS_DIR/*.cfg; do
filename=$(basename $ks_file)
url=”http://192.168.1.200/ks/$filename”
echo “访问: $url”
curl -I $url | head -5
done
# 执行脚本
$ chmod +x anaconda_config_manager.sh
$ ./anaconda_config_manager.sh
=== Anaconda配置管理 ===
=== 创建基础Kickstart配置 ===
=== 创建LVM Kickstart配置 ===
=== 验证Kickstart配置文件 ===
验证: /var/www/html/ks/ks_base.cfg
Kickstart file /var/www/html/ks/ks_base.cfg is valid
OK: /var/www/html/ks/ks_base.cfg 验证通过
验证: /var/www/html/ks/ks_lvm.cfg
Kickstart file /var/www/html/ks/ks_lvm.cfg is valid
OK: /var/www/html/ks/ks_lvm.cfg 验证通过
=== 设置文件权限 ===
=== 验证文件访问 ===
访问: http://192.168.1.200/ks/ks_base.cfg
HTTP/1.1 200 OK
Date: Wed, 02 Apr 2026 10:00:00 GMT
Server: Apache/2.4.57 (Red Hat Enterprise Linux)
Last-Modified: Wed, 02 Apr 2026 10:00:00 GMT
ETag: “12345-567890”
Accept-Ranges: bytes
Content-Length: 567890
Content-Type: text/plain; charset=UTF-8
访问: http://192.168.1.200/ks/ks_lvm.cfg
HTTP/1.1 200 OK
Date: Wed, 02 Apr 2026 10:00:00 GMT
Server: Apache/2.4.57 (Red Hat Enterprise Linux)
Last-Modified: Wed, 02 Apr 2026 10:00:00 GMT
ETag: “12345-567890”
Accept-Ranges: bytes
Content-Length: 567890
Content-Type: text/plain; charset=UTF-8
4.3 自定义Kickstart模板
自定义Kickstart模板:
# generate_ks_template.sh
# from:www.itpux.com.qq113257174.wx:itpux-com
# web: http://www.fgedu.net.cn
# 自定义Kickstart模板生成脚本
echo “=== 自定义Kickstart模板生成 ===”
# 参数
HOSTNAME=$1
IP=$2
NETMASK=$3
GATEWAY=$4
DNS=$5
PARTITION=$6
# 检查参数
if [ -z “$HOSTNAME” ] || [ -z “$IP” ] || [ -z “$NETMASK” ] || [ -z “$GATEWAY” ] || [ -z “$DNS” ] || [ -z “$PARTITION” ]; then
echo “Usage: $0
echo “Example: $0 rhel10-server 192.168.1.100 255.255.255.0 192.168.1.1 8.8.8.8,8.8.4.4 base”
exit 1
fi
# 生成Kickstart配置文件
echo “”
echo “=== 生成Kickstart配置文件 ===”
cat > /var/www/html/ks/ks_${HOSTNAME}.cfg << EOF
#platform=x86, AMD64, or Intel EM64T
#version=RHEL10
install
url --url="http://192.168.1.200/rhel10"
text
lang en_US.UTF-8
keyboard us
timezone Asia/Shanghai
rootpw --iscrypted \$6\$abc123def4567890123456789012345678901234567890123456789012345678
auth --useshadow --passalgo=sha512
graphical
bootloader --location=mbr --boot-drive=sda
clearpart --all --initlabel
EOF
# 根据分区类型添加分区配置
if [ "$PARTITION" = "base" ]; then
cat >> /var/www/html/ks/ks_${HOSTNAME}.cfg << 'EOF'
part /boot --fstype="xfs" --size=500
part swap --fstype="swap" --size=2048
part / --fstype="xfs" --grow --size=1
EOF
elif [ "$PARTITION" = "lvm" ]; then
cat >> /var/www/html/ks/ks_${HOSTNAME}.cfg << 'EOF'
part pv.01 --size=1 --grow
volgroup rhel pv.01
logvol / --fstype="xfs" --name=root --vgname=rhel --size=50000
logvol /home --fstype="xfs" --name=home --vgname=rhel --size=20000
logvol /var --fstype="xfs" --name=var --vgname=rhel --size=20000
logvol /tmp --fstype="xfs" --name=tmp --vgname=rhel --size=10000
logvol swap --fstype="swap" --name=swap --vgname=rhel --size=4096
EOF
fi
# 添加网络配置
cat >> /var/www/html/ks/ks_${HOSTNAME}.cfg << EOF
network --bootproto=static --ip=$IP --netmask=$NETMASK --gateway=$GATEWAY --nameserver=$DNS --device=ens33 --onboot=on
network --hostname=$HOSTNAME
EOF
# 添加其他配置
cat >> /var/www/html/ks/ks_${HOSTNAME}.cfg << 'EOF'
firewall --enabled --service=ssh
selinux --enforcing
reboot
%packages
@base
@core
vim
wget
curl
git
%end
%post --log=/root/ks-post.log
#!/bin/bash
dnf update -y
dnf install -y vim wget curl git
firewall-cmd --permanent --add-service=ssh
firewall-cmd --reload
systemctl restart sshd
useradd -m -s /bin/bash fgedu
echo "fgedu:password" | chpasswd
echo "fgedu ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
%end
EOF
# 验证Kickstart配置文件
echo “”
echo “=== 验证Kickstart配置文件 ===”
ksvalidator /var/www/html/ks/ks_${HOSTNAME}.cfg
if [ $? -eq 0 ]; then
echo “OK: ks_${HOSTNAME}.cfg 验证通过”
else
echo “ERROR: ks_${HOSTNAME}.cfg 验证失败”
exit 1
fi
# 设置文件权限
echo “”
echo “=== 设置文件权限 ===”
chmod 644 /var/www/html/ks/ks_${HOSTNAME}.cfg
chown apache:apache /var/www/html/ks/ks_${HOSTNAME}.cfg
# 显示配置信息
echo “”
echo “=== 配置信息 ===”
echo “Hostname: $HOSTNAME”
echo “IP: $IP”
echo “Netmask: $NETMASK”
echo “Gateway: $GATEWAY”
echo “DNS: $DNS”
echo “Partition: $PARTITION”
echo “Kickstart file: ks_${HOSTNAME}.cfg”
echo “Kickstart URL: http://192.168.1.200/ks/ks_${HOSTNAME}.cfg”
# 执行脚本
$ chmod +x generate_ks_template.sh
$ ./generate_ks_template.sh rhel10-server 192.168.1.100 255.255.255.0 192.168.1.1 8.8.8.8,8.8.4.4 lvm
=== 自定义Kickstart模板生成 ===
=== 生成Kickstart配置文件 ===
=== 验证Kickstart配置文件 ===
Kickstart file /var/www/html/ks/ks_rhel10-server.cfg is valid
OK: ks_rhel10-server.cfg 验证通过
=== 设置文件权限 ===
=== 配置信息 ===
Hostname: rhel10-server
IP: 192.168.1.100
Netmask: 255.255.255.0
Gateway: 192.168.1.1
DNS: 8.8.8.8,8.8.4.4
Partition: lvm
Kickstart file: ks_rhel10-server.cfg
Kickstart URL: http://192.168.1.200/ks/ks_rhel10-server.cfg
Part05-风哥经验总结与分享
5.1 Anaconda配置建议
风哥提示:Anaconda配置的建议:
- 使用Kickstart:使用Kickstart自动化安装
- 验证配置:使用ksvalidator验证配置文件
- 测试安装:先在测试环境验证安装流程
- 备份配置:备份Kickstart配置文件
- 文档记录:记录配置变更和使用说明
5.2 常见问题与解决方案
Anaconda配置的常见问题与解决方案:
- 配置错误:使用ksvalidator验证配置文件
- 安装失败:检查安装源和网络连接
- 分区失败:检查磁盘状态和分区方案
- 网络配置失败:检查网络参数和DHCP服务
5.3 最佳实践
Anaconda配置的最佳实践:
- 制定Anaconda配置标准流程
- 使用Kickstart自动化安装
- 配置监控和告警
- 建立配置文档和记录
- 定期测试和优化配置
通过本文的介绍,相信读者对Anaconda安装程序核心配置命令有了更全面的了解。掌握这些知识有助于更好地进行系统安装和配置。学习交流加群风哥QQ113257174
更多学习教程公众号风哥教程itpux_com
from Linux:www.itpux.com
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
