PXE+Kickstart搭建无人值守网络安装服务器

本文详细描述了在CentOS7服务器上配置yum源、挂载镜像、设置DHCP和TFTP服务、SYSLinux引导以及vsftpd文件传输,还包括禁用防火墙和selinux,以及创建Kickstart安装脚本的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

实验环境

镜像:CentOS-7-x86_64-Minimal-2009.iso

镜像下载地址:https://mirrors.tuna.tsinghua.edu.cn/

Centos7镜像:https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo

服务端:server IP:192.168.110.11 网卡模式:NAT  内存:2048MB

客户端:client IP: 网卡模式:NAT  内存:2048MB

 实验过程:

1.配置yum源

[root@server ~]# mv /etc/yum.repos.d/C* /media/
[root@server ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo

2.挂载镜像

[root@server ~]# mkdir /media/cdrom
[root@server ~]# mount /dev/sr0 /media/cdrom
mount: /dev/sr0 写保护,将以只读方式挂载

3.配置DHCP

[root@server ~]# yum install -y dhcp
[root@server ~]# vim /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
allow booting;
allow bootp;
subnet 192.168.110.0 netmask 255.255.255.0{
 option subnet-mask 255.255.255.0;
 range 192.168.110.100 192.168.110.200;
 default-lease-time 21600;
 max-lease-time 43200;
 next-server 192.168.110.11;
 filename "pxelinux.0"; # 引导文件位置,这边表示TFTP根目录(/var/lib/tftpboot/)下的pxelinux.0文件
}
[root@server ~]# systemctl start dhcpd
[root@server ~]# systemctl enable dhcpd
[root@server ~]# ss -nulp | grep dhcp
UNCONN     0      0            *:67                       *:*                   users:(("dhcpd",pid=1452,fd=7))

4.配置TFTP

[root@server ~]# yum install -y xinetd tftp-server
[root@server ~]# vi /etc/xinetd.d/tftp 
# default: off
# description: The tftp server serves files using the trivial file transfer \
#       protocol.  The tftp protocol is often used to boot diskless \
#       workstations, download configuration files to network-aware printers, \
#       and to start the installation process for some operating systems.
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot -c
        disable                 = no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}
​
[root@server ~]# systemctl restart xinetd
[root@server ~]# systemctl restart tftp
[root@server ~]# ss -nulp | grep 69
UNCONN     0      0            *:69                       *:*                   users:(("xinetd",pid=1468,fd=5))

​

5.SYSLinux服务程序

[root@server ~]#yum install syslinux -y
[root@server ~]#cd /var/lib/tftpboot/
[root@server tftpboot]# cp /usr/share/syslinux/pxelinux.0 .
[root@server tftpboot]# cp /media/cdrom/images/pxeboot/{vmlinuz,initrd.img} .
[root@server tftpboot]# mkdir pxelinux.cfg
[root@server tftpboot]# cp /media/cdrom/isolinux/isolinux.cfg pxelinux.cfg/default
[root@server tftpboot]# vi pxelinux.cfg/default

 6.vsftpd服务

[root@server ~]# yum install -y vsftpd
[root@server ~]# systemctl start vsftpd
[root@server ~]# cp -r /media/* /var/ftp/

 7.关闭防火墙&&临时禁用selinux

[root@server ~]# systemctl disable firewalld
[root@server ~]# systemctl stop firewalld
[root@server ~]# setenforce 0

8.Kickstart应答文件

这里你可以按需求自己去安装

[root@server ~]# cp ~/anaconda-ks.cfg /var/ftp/pub/ks.cfg
[root@server ~]# chmod 777 /var/ftp/pub/ks.cfg 
[root@server ~]# vim /var/ftp/pub/ks.cfg

  1 #version=DEVEL
  2 # System authorization information
  3 auth --enableshadow --passalgo=sha512
  4 # Use CDROM installation media
  5 #cdrom
  6 url --url=ftp://192.168.110.11/cdrom
  7 # Use graphical install
  8 #graphical
  9 text
 10 # Run the Setup Agent on first boot
 11 firstboot --enable
 12 ignoredisk --only-use=sda
 13 # Keyboard layouts
 14 keyboard --vckeymap=us --xlayouts='us'
 15 # System language
 16 lang en_US.UTF-8
 17 
 18 # Network information
 19 network  --bootproto=dhcp --device=ens32 --onboot=yes --ipv6=auto --no-activate
 20 network  --hostname=server1
 21 
 22 # Root password
 23 rootpw --iscrypted $6$zYGvbEuQ7XhWzs7/$KvjfF.5csk53KTxYd4Hh0m/2mI/0XE9MmbXmL7T1IdiSd8lji1bH2oeZRBn0e06L5Mz9MvFGALI3e0TneTOgE0
 24 # System services
 25 services --enabled="chronyd"
 26 # System timezone
 27 timezone Asia/Shanghai --isUtc --nontp
 28 # System bootloader configuration
 29 bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
 30 autopart --type=lvm
 31 # Partition clearing information
 32 clearpart --none --initlabel
 33 
 34 reboot
 35 %packages
 36 @^minimal
 37 @core
 38 
 39 
 40 %end
 41 
 42 %post
 43 
 44 useradd server1
 45 echo 123456 | passwd --sdtin server1
 46 
 47 %end
 48 
 49 %anaconda
 50 pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
 51 pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
 52 pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
 53 %end

9.结果

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值