kickstart+http+dhcp+tftp实现centos7的无人值守安装

环境:
IP: 172.16.0.11 centos 7.2

一. tftp

安装tftp服务端和客户端
[root@localhost ~]# yum -y install tftp tftp-server
启动tftp
[root@localhost ~]# systemctl start tftp.socket
[root@localhost ~]# systemctl enable tftp.socket

[root@localhost ~]# ss -unl | grep :69
UNCONN     0      0           :::69                      :::*

在tftp工作目录下准备一个文件,进行测试
[root@localhost ~]# ls /var/lib/tftpboot/
[root@localhost ~]# cp /etc/grub2.cfg /var/lib/tftpboot/
先切换到本地/tmp目录, 因为tftp不支持lcd命令
[root@localhost ~]# cd /tmp
下载grub2.cfg文件
[root@localhost tmp]# tftp 172.16.0.11
tftp> get grub2.cfg
tftp> quit

查看本地目录: 
[root@localhost tmp]# ls
fstab  grub2.cfg  nginx.conf

删除测试文件
[root@localhost tmp]# rm /var/lib/tftpboot/grub2.cfg

二. dhcp

[root@localhost tmp]# cd /etc/dhcp
[root@localhost dhcp]# vim dhcpd.conf
注释掉host配置项
#host hostname {       #名称标识  和客户端hostname可以不同
# hardware ethernet 00:0c:29:f9:98:20;   #客户端mac
# fixed-address  172.16.100.10;          #给上面的mac固定ip地址
#}


option domain-name "magedu.com";    #搜索后缀
option routers 172.16.0.254;        #网关, 配置成实际的网关
option domain-name-servers 202.106.0.20;   #dns地址



subnet 172.16.0.0 netmask 255.255.0.0 {            #子网
    range 172.16.100.101 172.16.100.130;           #地址池
    filename "pxelinux.0";
    next-server 172.16.0.11;
}


[root@localhost dhcp]# systemctl restart dhcpd.service
[root@localhost dhcp]# ss -unl | grep :67
UNCONN     0      0            *:67                       *:*

三. yum 仓库

使用光盘做yum仓库, 最好拷贝到某个目录,而不是直接挂载光盘, 此处直接挂载
[root@localhost dhcp]# mkdir -pv /var/www/html/centos/7/x86_64
[root@localhost dhcp]# mount -r /dev/cdrom /var/www/html/centos/7/x86_64
[root@localhost dhcp]# ls /var/www/html/centos/7/x86_64/
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL

[root@localhost dhcp]# systemctl start httpd.service

mark

四. kickstart

制作kickstart文件
mark
mark
mark
mark
mark
mark
mark
mark
mark
mark
mark
mark

[root@localhost ~]# ksvalidator centos7.cfg

[root@localhost dhcp]# mkdir /var/www/html/kickstarts
[root@localhost dhcp]# vim /var/www/html/kickstarts/centos7.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
# old format: keyboard us
# new format:
keyboard --vckeymap=us --xlayouts='us'
# Root password
rootpw --iscrypted $1$hgfvQffN$tXNj5mQldgQt4ziW1QhNF0
# Use network installation
url --url="http://172.16.0.11/centos/7/x86_64"
# System language
lang en_US
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx

# System services
services --disabled="chronyd"
ignoredisk --only-use=sda
# Network information
network  --bootproto=dhcp --device=eno16777984
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai --ntpservers=3.centos.pool.ntp.org,0.centos.pool.ntp.org,2.centos.pool.ntp.org,1.centos.pool.ntp.org
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --asprimary --fstype="xfs" --size=1000
part swap --fstype="swap" --size=8000
part / --fstype="xfs" --grow --size=1

%packages
@^minimal
@core

%end

五. pxeliunx

配置yum仓库, 使用公网yum仓库亦可
[root@localhost ~]# vim /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=file:///var/www/html/centos/7/x86_64/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[root@localhost Packages]# yum -y install syslinux

[root@localhost Packages]# rpm -ql syslinux | grep "pxelinux.0"
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/pxelinux.0
拷贝pxelinux到tftp工作目录
[root@localhost Packages]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
拷贝内核和initrd文件
[root@localhost ~]# cp /var/www/html/centos/7/x86_64/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/

准备字符界面需要的文件
[root@localhost ~]# cp /usr/share/syslinux/{chain.c32,menu.c32,memdisk,mboot.c32} /var/lib/tftpboot/
准备引导界面目录
[root@localhost tftpboot]# cd
[root@localhost ~]# cd /var/lib/tftpboot/
[root@localhost tftpboot]# ls
chain.c32  initrd.img  mboot.c32  memdisk  menu.c32  pxelinux.0  vmlinuz
[root@localhost tftpboot]# mkdir pxelinux.cfg
[root@localhost tftpboot]# cd pxelinux.cfg/
[root@localhost pxelinux.cfg]# vim default
default menu.c32
        prompt 5
        timeout 30
        MENU TITLE CentOS 7 PXE Menu

        LABEL linux
        MENU LABEL Install CentOS 7 x86_64
        KERNEL vmlinuz
        APPEND initrd=initrd.img inst.repo=http://172.16.0.11/centos/7/x86_64
        LABEL linux_autoinst
        MENU LABEL Install CentOS 7 x86_64 auto
        KERNEL vmlinuz
        APPEND initrd=initrd.img inst.repo=http://172.16.0.11/centos/7/x86_64 ks=http://172.16.0
.11/kickstarts/centos7.cfg



启动httpd服务(之前启动过,此处应不需要重启)
[root@localhost pxelinux.cfg]# systemctl start httpd.service

六. 验证

创建虚拟机并启动
mark
mark
mark
mark
mark
mark

注意: 此处网关设置得不太合理, 并不是pxe服务器作为网关,导致无法上网, 签名配置文件中已改成正确的网关

问题: yum -y install syslinux时,报Error downloading packages:

syslinux-4.05-13.el7.x86_64: [Errno 256] No more mirrors to try.

解决方法:

[root@localhost Packages]# rm -fr /var/cache/yum/*
[root@localhost Packages]# yum clean all

原创文章,作者:hansj,如若转载,请注明出处:http://www.178linux.com/77410

(0)
hansjhansj
上一篇 2017-06-03 11:14
下一篇 2017-06-03 14:17

相关推荐

  • 如何安装CentOS 6.9

    1、打开VMware,点击“创建新的虚拟机”   2、刚开始用的话,一般就选择推荐的典型类型来安装,所以直接点击“下一步”   3、此处选择稍后安装操作系统,这里我们先进行配置,点击“下一步”   4、因为我需要用里面的linux系统,所以选择客户机操作系统为Linux,选择版本为CentOS 64位,单击“下一步”。 &nbs…

    2017-07-11
  • 第二周总结(文件操作命令、用户及组权限管理、BASH命令行展开与执行命令返回值、命令别名使用、执行结果引用、通配符使用)

    1、常见文件管理命令分类         1)文件内容查看(cat、tca、more、less、head、tail)         2)文件字符替换(tr、sed、awk等)         3)文…

    Linux干货 2017-01-31
  • Linux文件类型及颜色标识

    文件类型(共7种): – :普通文件 d:目录文件 (directory) c:字符设备文件 (char) b:块设备文件 (block) s:本地域套接口 (socket) p:有名管道 (pipeline) l:符号连接 (link) 关于硬链接、软连接、复制之间的区别说明: 上图中,我为photo.png这个图片文件建立了一个拷贝(phot…

    Linux干货 2016-10-16
  • lvm基本应用

    前言 一种技术要知其然,还要知其所以然 lvm简介 LVM是 Logical Volume Manager(逻辑卷管理)的简写,它是Linux环境下对磁盘分区进行管理的一种机制。普通的磁盘分区管理方式在逻辑分区划分好之后就无法改变其大小,当一个逻辑分区存放不下某个文件时,这个文件因为受上层文件系统的限制,也不能跨越多个分区来存放,所以也不能同时放到别的磁盘上…

    Linux干货 2016-05-21
  • 小练习题。【第四周】

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其他用户均没有任何访问权限。 home]# chmod g-rwx,o-rwx -R tuser1 2、编辑/etc/group文件,添加组hadoop。 /]# vim /etc/group …

    Linux干货 2016-11-26
  • nfs与samba实现文件共享服务的流程

    nfs与samba实现文件共享服务的流程     nfs与samba都是能够实现文件共享的服务应用,其用法大致相同,但是挂载选项与配置文件的设置机制不同,下面介绍这两种文件共享服务的内容。     一.nfs服务的安装与配置     服务端主机的配置:   &…

    Linux干货 2016-10-23