阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

自建DHCP TFTP服务 用PXE启动实现无人值守安装CentOS6

154次阅读
没有评论

共计 10316 个字符,预计需要花费 26 分钟才能阅读完成。

1、安装 DHCP TFTP

yum -y install dhcp tftp-server tftp

——————————————————————————–

2、配置 DHCP 文件

cat > /etc/dhcp/dhcpd.conf << EOF

#

option domain-name “dwhd.org”;

# 设置 DHCP 的 DNS

option domain-name-servers 172.16.0.1,114.114.114.114;

# 设置 DHCP 分配出去的 IP 超时时间 单位秒

default-lease-time 86440;

# 设置 DHCPlease-time 时间 单位秒

max-lease-time 100000;

 

log-facility local7;

# 设置 DHCP 的 IP 和掩码

subnet 192.168.1.0 netmask 255.255.255.0 {

# 设置 DHCP 对外分配 IP 段

    range 192.168.1.50 192.168.1.70;

# 设置路由 IP

    option routers 192.168.1.1;

# 下面的 4 行是根据 mac 分配指定 IP

    host CentOS7 {

        hardware ethernet 00:0c:29:ba:3c:76;

        fixed-address 192.168.1.65;

    }

# 如果是 PXE 网卡来获取到了 IP 告诉网卡下一步联系的服务器 IP 192.168.1.120

    next-server 192.168.1.120;

#PXE 网卡联系了服务器之后告诉它应该去获取文件 pxelinux.0

    filename “pxelinux.0”;

}

EOF

——————————————————————————–

自建 DHCP TFTP 服务 用 PXE 启动实现无人值守安装 CentOS6

Linux 系统下构建 DHCP 服务器 http://www.linuxidc.com/Linux/2013-06/86531.htm

CentOS 下配置主从 DNS 服务器以及 DHCP 下的 DDNS http://www.linuxidc.com/Linux/2013-06/85634.htm

SUSE Linux 11 pxe+DHCP+tftp+ftp 无人值守安装 http://www.linuxidc.com/Linux/2013-06/85481.htm

Linux 下架设 DHCP 服务器过程及 3 种测试 http://www.linuxidc.com/Linux/2013-05/84832.htm

Linux 上一步一步实现 DHCP 服务器 http://www.linuxidc.com/Linux/2013-04/82244.htm

CentOS 6.5 系统下构建 DHCP 服务器 http://www.linuxidc.com/Linux/2014-06/103203.htm

Ubuntu 下 tftp 服务搭建 http://www.linuxidc.com/Linux/2012-08/67933.htm

TFTP 服务器配置 http://www.linuxidc.com/Linux/2012-07/64785.htm

Ubuntu Linux 配置 TFTP 下载服务器 http://www.linuxidc.com/Linux/2010-12/30394.htm

Ubuntu 11.10 配置 tftp Server http://www.linuxidc.com/Linux/2012-05/60808.htm

Ubuntu 12.04 搭建 TFTP 服务 http://www.linuxidc.com/Linux/2014-04/100144.htm

Ubuntu 12.04 搭建 tftp 服务器的安装、设置、调试 http://www.linuxidc.com/Linux/2014-04/100114.htm

3、检测 dhcp 配置和启动 dhcp

[root@localhost pxelinux.cfg]# service dhcpd configtest

Syntax: OK

# 检测 dhcp 配置,如果出现 Syntax: OK 则说明配置 OK 了

 

# 启动 DHCP 服务

service dhcpd start

——————————————————————————–

4、设置 TFTP 开机启动

chkconfig tftp on[/bash]

 

[bash highlight=”9,10″][root@localhost ~]# netstat -unl

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address              Foreign Address            State

udp        0      0 0.0.0.0:1005                0.0.0.0:*

udp        0      0 0.0.0.0:111                0.0.0.0:*

udp        0      0 0.0.0.0:631                0.0.0.0:*

udp        0      0 0.0.0.0:776                0.0.0.0:*

udp        0      0 0.0.0.0:48819              0.0.0.0:*

udp        0      0 0.0.0.0:67                  0.0.0.0:*

udp        0      0 0.0.0.0:69                  0.0.0.0:*

udp        0      0 :::1005                    :::*

udp        0      0 :::111                      :::*

udp        0      0 :::42066                    :::*

## 看看 67 69 端口是否被监听了,如果是的就说明好了

——————————————————————————–

开始为 PXE 启动做准备,由于我在当前 Windows 物理机上架设了 FTP 服务,所以我这里就直接用 FTP 服务器做源了

5、下载必要的文件到 TFTP 目录

ftpurl=”ftp://lookback:lookback@192.168.1.20/centos/6/x86_64/base/”

tftpdir=”/var/lib/tftpboot/”

for I in vmlinuz initrd.img; do wget -O ${tftpdir}$I ${ftpurl}images/pxeboot/$I;done

for II in splash.jpg vesamenu.c32 boot.msg isolinux.cfg; do

[“$II” == “isolinux.cfg”] && wget -O ${tftpdir}default ${ftpurl}/isolinux/$II

wget -O ${tftpdir}$II ${ftpurl}/isolinux/$II

done

 

# 安装 syslinux

yum -y install syslinux

# 复制 pxelinux.0 到 TFTP 目录下

cp $(rpm -ql syslinux | grep ‘\bpxelinux.0’) /var/lib/tftpboot/

 

# 最后核对下文件

tree /var/lib/tftpboot/ #结果和下图一样就对了

自建 DHCP TFTP 服务 用 PXE 启动实现无人值守安装 CentOS6

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2014-07/104881p2.htm

6、制作 kf.cfg 文件 用于自动化安装

下面是我自己制作的 ks.cfg,可根据自己的需求做改动 root 密码是 CentOS6, 这个文件存放的位置需要在系统安装的时候被获取到,我这里存放在我物理机上的 FTP 下

#platform=x86, AMD64, or Intel EM64T

#version=DEVEL

# Firewall configuration

firewall –disabled

# Install OS instead of upgrade

install

# Use network installation

url –url=”ftp://lookback:lookback@192.168.1.20/centos/6/x86_64/base”

repo –name=”CentOS” –baseurl=ftp://lookback:lookback@192.168.1.20/centos/6/x86_64/base

#repo –name=”Fedora EPEL” –baseurl=ftp://lookback:lookback@192.168.1.20/fedora-epel/6/x86_64/ –cost=1000

 

# Root password

rootpw –iscrypted $6$W6.dzk.2$fqenuNv62I4SF64gAie0OTQK5WdjUOxGbDPkIq/z/xlG42oUh7khkVhfWYDI8U0FmsIofmQtGSq9ruWuoHvy30

#root 密码为 centos6

 

# System authorization information

auth  –useshadow  –passalgo=sha512

# Use graphical install

graphical

firstboot –disable

# System keyboard

keyboard us

# System language

lang en_US

# SELinux configuration

selinux –disabled

# Installation logging level

logging –level=info

# Reboot after installation

reboot

# System timezone

timezone  Asia/Shanghai

# Network information

network  –bootproto=dhcp –device=eth0 –onboot=on

# System bootloader configuration

bootloader –append=”crashkernel=auto crashkernel=auto rhgb rhgb quiet quiet” –location=mbr –driveorder=”sda”

# Clear the Master Boot Record

zerombr

# Partition clearing information

clearpart –all –initlabel

# Disk partitioning information

part /boot –fstype=”ext4″ –size=200

part pv.001 –size=61440

 

volgroup vg0 –pesize=8192 pv.001

logvol  /  –fstype=ext4 –vgname=vg0  –size=20480  –name=root

logvol  /var  –fstype=ext4 –vgname=vg0  –size=20480  –name=var

logvol swap –name=swap –vgname=vg0 –size=2048

logvol /usr –fstype=ext4 –vgname=vg0 –size=10240 –name=usr

 

%post

echo -e ‘TEST Centos6\nhttp://www.000.org\n’ >> /etc/issue

 

sed -i ‘1,$s@id:[0-9]:initdefault:@id:3:initdefault:@g’ /etc/inittab

 

[! -d /root/.ssh] && mkdir /root/.ssh && chmod og=— /root/.ssh

# 下面是我自己为了方便自己使用对自动安装的系统做了免密码登录

cat >> /root/.ssh/authorized_keys << EOF

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfhGitgDKxQidZXLHS3DFalTvmzTwQ4UH3etQJUE7/iPNwLs6ZDzbR5pqTPfK1YdhUTuJOoNQZ71Fr9qwLtF6aLdgO+ybmK/8sNrMeTvGmKyr4YQ5k02vVIbBnQIEr08eXpV1y206CMWQ7FiiMlFvaeFZhj8trchiffhAUJdZOjl/BikzDJcYdp/sRXrFA4G21yXU0ffOn9aAAvqOqRBRoDhpLnSWaovGjd419Cy/pdhu4Vuispz1x834l975fLv4PIh+3nW9WMbhrmIXzWoTsxnc8OUbT4FnRdA33G8T3JXQc1n1UjX7H4BGfzKA6eax574rspAk51cslaydby2vX== root@lookback.dwhd.org

EOF

# Enable funcd 

sed -i ‘s@certmaster =.*@certmaster = 172.16.0.1@g’ /etc/certmaster/minion.conf

/sbin/chkconfig funcd off

# Set the hostname

ClientName=`ifconfig eth0 | awk ‘/inet addr:/{print $2}’ | awk -F. ‘{print $NF}’`

sed -i “s@HOSTNAME=.*@HOSTNAME=client$ClientName.dwhd.org@g” /etc/sysconfig/networks

# set puppet agent

sed -i ‘/\[main\]/a server=server.dwhd.org’ /etc/puppet/puppet.conf

/sbin/chkconfig puppet off

# set hosts

echo ‘172.16.0.1  server.dwhd.org server’ >> /etc/hosts

 

# yum repo

%end

 

%packages

@base

@basic-desktop

@chinese-support

@client-mgmt-tools

@core

@desktop-platform

@development

@fonts

@general-desktop

@graphical-admin-tools

@legacy-x

@network-file-system-client

@perl-runtime

@remote-desktop-clients

@server-platform-devel

@x11

 

%end

现在来修改下 PXE 启动后引导菜单

vi /var/lib/tftpboot/pxelinux.cfg/default

default vesamenu.c32

#prompt 1

timeout 60

 

display boot.msg

 

menu background splash.jpg

menu title Welcome to CentOS 6.5! This is test PXE Auto Install

menu color border 0 #ffffffff #00000000

menu color sel 7 #ffffffff #ff000000

menu color title 0 #ffffffff #00000000

menu color tabmsg 0 #ffffffff #00000000

menu color unsel 0 #ffffffff #00000000

menu color hotsel 0 #ff000000 #ffffffff

menu color hotkey 7 #ffffffff #ff000000

menu color scrollbar 0 #ffffffff #00000000

 

label pxelinux

  menu label ^Auto Install or upgrade an existing system

  menu default

  kernel vmlinuz

  append initrd=initrd.img ks=ftp://lookback:lookback@192.168.1.20/centos/6/ks.cfg

label linux

  menu label ^Install or upgrade an existing system

  kernel vmlinuz

  append initrd=initrd.img

label vesa

  menu label Install system with ^basic video driver

  kernel vmlinuz

  append initrd=initrd.img xdriver=vesa nomodeset

label rescue

  menu label ^Rescue installed system

  kernel vmlinuz

  append initrd=initrd.img rescue

label local

  menu label Boot from ^local drive

  localboot 0xffff

label memtest86

  menu label ^Memory test

  kernel memtest

  append –

自建 DHCP TFTP 服务 用 PXE 启动实现无人值守安装 CentOS6自建 DHCP TFTP 服务 用 PXE 启动实现无人值守安装 CentOS6自建 DHCP TFTP 服务 用 PXE 启动实现无人值守安装 CentOS6自建 DHCP TFTP 服务 用 PXE 启动实现无人值守安装 CentOS6自建 DHCP TFTP 服务 用 PXE 启动实现无人值守安装 CentOS6自建 DHCP TFTP 服务 用 PXE 启动实现无人值守安装 CentOS6

更多 CentOS 相关信息见 CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14

1、安装 DHCP TFTP

yum -y install dhcp tftp-server tftp

——————————————————————————–

2、配置 DHCP 文件

cat > /etc/dhcp/dhcpd.conf << EOF

#

option domain-name “dwhd.org”;

# 设置 DHCP 的 DNS

option domain-name-servers 172.16.0.1,114.114.114.114;

# 设置 DHCP 分配出去的 IP 超时时间 单位秒

default-lease-time 86440;

# 设置 DHCPlease-time 时间 单位秒

max-lease-time 100000;

 

log-facility local7;

# 设置 DHCP 的 IP 和掩码

subnet 192.168.1.0 netmask 255.255.255.0 {

# 设置 DHCP 对外分配 IP 段

    range 192.168.1.50 192.168.1.70;

# 设置路由 IP

    option routers 192.168.1.1;

# 下面的 4 行是根据 mac 分配指定 IP

    host CentOS7 {

        hardware ethernet 00:0c:29:ba:3c:76;

        fixed-address 192.168.1.65;

    }

# 如果是 PXE 网卡来获取到了 IP 告诉网卡下一步联系的服务器 IP 192.168.1.120

    next-server 192.168.1.120;

#PXE 网卡联系了服务器之后告诉它应该去获取文件 pxelinux.0

    filename “pxelinux.0”;

}

EOF

——————————————————————————–

自建 DHCP TFTP 服务 用 PXE 启动实现无人值守安装 CentOS6

Linux 系统下构建 DHCP 服务器 http://www.linuxidc.com/Linux/2013-06/86531.htm

CentOS 下配置主从 DNS 服务器以及 DHCP 下的 DDNS http://www.linuxidc.com/Linux/2013-06/85634.htm

SUSE Linux 11 pxe+DHCP+tftp+ftp 无人值守安装 http://www.linuxidc.com/Linux/2013-06/85481.htm

Linux 下架设 DHCP 服务器过程及 3 种测试 http://www.linuxidc.com/Linux/2013-05/84832.htm

Linux 上一步一步实现 DHCP 服务器 http://www.linuxidc.com/Linux/2013-04/82244.htm

CentOS 6.5 系统下构建 DHCP 服务器 http://www.linuxidc.com/Linux/2014-06/103203.htm

Ubuntu 下 tftp 服务搭建 http://www.linuxidc.com/Linux/2012-08/67933.htm

TFTP 服务器配置 http://www.linuxidc.com/Linux/2012-07/64785.htm

Ubuntu Linux 配置 TFTP 下载服务器 http://www.linuxidc.com/Linux/2010-12/30394.htm

Ubuntu 11.10 配置 tftp Server http://www.linuxidc.com/Linux/2012-05/60808.htm

Ubuntu 12.04 搭建 TFTP 服务 http://www.linuxidc.com/Linux/2014-04/100144.htm

Ubuntu 12.04 搭建 tftp 服务器的安装、设置、调试 http://www.linuxidc.com/Linux/2014-04/100114.htm

3、检测 dhcp 配置和启动 dhcp

[root@localhost pxelinux.cfg]# service dhcpd configtest

Syntax: OK

# 检测 dhcp 配置,如果出现 Syntax: OK 则说明配置 OK 了

 

# 启动 DHCP 服务

service dhcpd start

——————————————————————————–

4、设置 TFTP 开机启动

chkconfig tftp on[/bash]

 

[bash highlight=”9,10″][root@localhost ~]# netstat -unl

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address              Foreign Address            State

udp        0      0 0.0.0.0:1005                0.0.0.0:*

udp        0      0 0.0.0.0:111                0.0.0.0:*

udp        0      0 0.0.0.0:631                0.0.0.0:*

udp        0      0 0.0.0.0:776                0.0.0.0:*

udp        0      0 0.0.0.0:48819              0.0.0.0:*

udp        0      0 0.0.0.0:67                  0.0.0.0:*

udp        0      0 0.0.0.0:69                  0.0.0.0:*

udp        0      0 :::1005                    :::*

udp        0      0 :::111                      :::*

udp        0      0 :::42066                    :::*

## 看看 67 69 端口是否被监听了,如果是的就说明好了

——————————————————————————–

开始为 PXE 启动做准备,由于我在当前 Windows 物理机上架设了 FTP 服务,所以我这里就直接用 FTP 服务器做源了

5、下载必要的文件到 TFTP 目录

ftpurl=”ftp://lookback:lookback@192.168.1.20/centos/6/x86_64/base/”

tftpdir=”/var/lib/tftpboot/”

for I in vmlinuz initrd.img; do wget -O ${tftpdir}$I ${ftpurl}images/pxeboot/$I;done

for II in splash.jpg vesamenu.c32 boot.msg isolinux.cfg; do

[“$II” == “isolinux.cfg”] && wget -O ${tftpdir}default ${ftpurl}/isolinux/$II

wget -O ${tftpdir}$II ${ftpurl}/isolinux/$II

done

 

# 安装 syslinux

yum -y install syslinux

# 复制 pxelinux.0 到 TFTP 目录下

cp $(rpm -ql syslinux | grep ‘\bpxelinux.0’) /var/lib/tftpboot/

 

# 最后核对下文件

tree /var/lib/tftpboot/ #结果和下图一样就对了

自建 DHCP TFTP 服务 用 PXE 启动实现无人值守安装 CentOS6

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2014-07/104881p2.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计10316字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中