PXE装机

                                                                             PXE装机

PXE装机是安装大量服务器是常用的装机方式。原理是,通过将客户机调整为网络方式引导。之后通过局域网内的DHCP服务器获得一个IP。并且,在该DHCP服务器内会指定TFTP服务器的位置。之后客户机去与TFTP服务器通信,传输内核文件和安装包,来完成内核的安装。在内核安装完成后,会安装HTTPD服务。这个目的在于传输后期的安装包。在HTTPD安装后,回去寻找HTTPD服务器,去下载后期的安装包与应答文件。这里的应答文件是通过KickStart软件来得到的。

虚拟机环境的防火墙、Selinux权限是关闭的。操作系统版本是rhel6.5。下面给出相关配置文件的具体配置。

  1. 安装配置DNS服务。

1.1安装启动服务,并设置成开机自启

# yum -y install bind bind-chroot

# service named start

# chkconfig named on

# chkconfig named --list  

1.2 修改/etc/named.conf文件

# vim /etc/named.conf

//

// named.conf

//

// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS

// server as a caching only nameserver (as a localhost DNS resolver only).

//

// See /usr/share/doc/bind*/sample/ for example named configuration files.

//

 

options {

    listen-on port 53 { any; };         #监听端口

#   listen-on-v6 port 53 { ::1; };      

    directory   "/var/named";         #地址库文件所在目录

#   dump-file   "/var/named/data/cache_dump.db";

#        statistics-file "/var/named/data/named_stats.txt";

#        memstatistics-file "/var/named/data/named_mem_stats.txt";

    allow-query     { any; };                  #允许任何客户机查询

#   recursion yes;

 

#   dnssec-enable yes;

#   dnssec-validation yes;

 

    /* Path to ISC DLV key */

#   bindkeys-file "/etc/named.iscdlv.key";

 

#   managed-keys-directory "/var/named/dynamic";

};

 

logging {

        channel default_debug {

                file "data/named.run";

                severity dynamic;

        };

};

 

zone "." IN {

    type hint;

    file "named.ca";

};

 

zone "122.168.192.in-addr.arpa" IN {              #反向解析配置

        type master;

        file "192.168.122.arpa";

};

 

 

#zone "106.168.192.in-addr.arpa" IN {

#        type master;

#        file "192.168.106.arpa";

#};

 

include "/etc/named.rfc1912.zones";

include "/etc/named.root.key";

    1. 创建192.168.122.arpa文件

# cd /var/named/

# vim 192.168.122.arpa            

$TTL 1D

@       IN SOA  @ rname.invalid. (

                                        0       ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

        NS      PXE. #该位置写主机名即前面hostname的结果,但是需要以“.”结尾,请务必注意,否则重启服务会出现报错

$GENERATE 100-200 $ PTR pc-$.war.cn. #使用函数,生成从100到200连续的数字

# service named restart      #重启服务

    1. 验证

# nslookup 192.168.122.130 192.168.122.10

Server:     192.168.122.10

Address:    192.168.122.10#53

130.122.168.192.in-addr.arpa    name = pc-130.war.cn.

2 安转配置DHCP服务

2.1 安装启动dchpd服务,并设置成开机自启

# yum –y install dhcp

# service dhcpd start

# chkconfig dhcpd on

2.2 修改/etc/dhcp/dhcpd.conf文件

# vim /etc/dhcp/dhcpd.conf   #初始dhcpd服务主配置文件,没有缺省配置,需要我们自己添加

#

# DHCP Server Configuration file.

#   see /usr/share/doc/dhcp*/dhcpd.conf.sample     #模板文件,可使用r写入

#   see 'man 5 dhcpd.conf'    #使用man帮助查看该文件

#

subnet 192.168.122.0 netmask 255.255.255.0 {

  range 192.168.122.100 192.168.122.200;   #动态IP的分配范围

  option domain-name-servers 192.168.122.10;    #域名服务器

  option routers 192.168.122.1;

  default-lease-time 600;

  max-lease-time 7200;

  next-server 192.168.122.10;   #TFTP服务器的位置

  filename "pxelinux.0";    # 网卡引导文件(二进制文件),用来下载内核,驱动文件

}

# service dhcpd restart       #重启DHCP服务

3 安装配置tftp服务

3.1 安装启动tftp服务

# yum -y install tftp-server

# service xinetd start

# chkconfig xinetd on

3.2 配置/etc/xinetd.d/tftp文件

# vim /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

    disable         = no                  # 将此处的yes改为no

    per_source      = 11

    cps         = 100 2

    flags           = IPv4

}

# service xinetd restart

3.3 获得支持网络启动的程序pxelinux.0

# cd /var/lib/tftpboot/  # 进入tftp共享目录

# ls

# yum provides */pxelinux.0  # 查询该文件是由哪个rpm生成的

# yum provides */pxelinux.0

Loaded plugins: product-id, refresh-packagekit, security, subscription-manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

Repository zabbix is listed more than once in the configuration

Repository zabbix-non-supported is listed more than once in the configuration

puppetlabs-products/filelists_db                         | 1.0 MB     00:00    

updates/filelists_db                                     | 1.0 MB     00:00    

syslinux-nonlinux-4.04-3.el6.noarch : SYSLINUX modules which aren't run from

                                    : linux. # pxelinux.0 即是由该rpm包产生的,接下来只需要安装该包即可

Repo        : base

Matched from:

Filename    : /usr/share/syslinux/pxelinux.0

# yum -y install syslinux-nonlinux   # 由上面的提示信息,安装这个软件

# rpm -ql syslinux-nonlinux | grep pxelinux.0  # 查找该文件所在路径

/usr/share/syslinux/gpxelinux.0

/usr/share/syslinux/pxelinux.0

# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

# ls

pxelinux.0

4 安装httpd服务

# yum -y install httpd

# service httpd start

# chkconfig httpd on

# vim /etc/httpd/conf/httpd.conf  #httpd服务主配置文件,这里使用缺省配置即可,所以不需要修改,就是单纯的亮出来

5 接下来需要准备装机时的软件包,内核,驱动等相关文件

这些文件都在系统的ISO镜像文件中,当然以可以使用光驱挂载系统光盘,但是由于服务器一般不会带光驱,所以使用文件的情况会更多一些,这里我们使用ISO镜像文件。

# cd /var/www/html/   //httpd服务缺省文件路径,我们需要将ISO镜像文件挂载到这里,这里我们使用自动挂载,当然也可以使用手动挂载或者触发挂载

# mkdir redhat-6.7   # 创建挂载点

# vim /etc/fstab    # 配置开机自动挂载文件

#

# /etc/fstab

# Created by anaconda on Mon Feb  6 07:35:13 2017

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

/dev/mapper/vg_pxe-lv_root /                       ext4    defaults        1 1

UUID=39830b08-2160-48c2-99e4-189c64331459 /boot                   ext4    defaults        1 2

/dev/mapper/vg_pxe-lv_swap swap                    swap    defaults        0 0

tmpfs                   /dev/shm                tmpfs   defaults        0 0

devpts                  /dev/pts                devpts  gid=5,mode=620  0 0

sysfs                   /sys                    sysfs   defaults        0 0

proc                    /proc                   proc    defaults        0 0

/root/rhel-server-6.5-x86_64-dvd.iso    /var/www/html/redhat-6.5  iso9660  defaults,loop 0 0

# mount –a    # 加载文件/etc/fstab中设置的所有设备

6 现在ISO文件已经挂载好了,那么接下来需要回到tftp目录下,准备相关的文件

# cd /var/lib/tftpboot/

# ls

pxelinux.0

# mkdir redhat-6.5

ls /var/www/html/redhat-6.5/isolinux/

boot.cat  grub.conf   isolinux.bin  memtest     TRANS.TBL     vmlinuz

boot.msg  initrd.img  isolinux.cfg  splash.jpg  vesamenu.c32

# cp /var/www/html/redhat-6.7/isolinux/initrd.img  redhat-6.7/   //拷贝redhat的驱动文件

# cp /var/www/html/redhat-6.7/isolinux/vmlinuz  redhat-6.7/   //拷贝redhat的内核文件

# 创建菜单文件目录,并将菜单文件拷贝,拷贝的同时改名为default

# mkdir pxelinux.cfg     # 缺省配置,不能改变

# cp /var/www/html/centos-6.7/isolinux/isolinux.cfg pxelinux.cfg/default

# 拷贝图形化支持文件

cp /var/www/html/centos-6.7/isolinux/vesamenu.c32 /var/lib/tftpboot/

# 验证结果

# pwd

/var/lib/tftpboot

# ls

pxelinux.0  pxelinux.cfg  redhat-6.5  vesamenu.c32

# ls redhat-6.5/

initrd.img  vmlinuz

# ls pxelinux.cfg/

default

7 准备装机背景图片,由于这次安装时的菜单页面我们是要采用图形化页面,所以需要一张图片作为背景

# Linux装机时的背景图片是需要特殊制作的

# rpm -ql syslinux | grep .jpg

/usr/share/doc/syslinux-4.04/sample/m16-640x640-syslinux.jpg

/usr/share/doc/syslinux-4.04/sample/syslinux_splash.jpg

# cp /usr/share/doc/syslinux-4.04/sample/syslinux_splash.jpg pxelinux.cfg/

# ls pxelinux.cfg/

default  syslinux_splash.jpg

8 修改菜单文件

# chmod +w pxelinux.cfg/default  # 添加可写权限,当然在root用户下,可以强制修改,但是建议还是添加一下

# ll pxelinux.cfg/*

-rw-r--r--  1 root root   849 Apr  4 18:18 pxelinux.cfg/default

-rw-r--r--. 1 root root 56299 Feb  6 14:13 pxelinux.cfg/syslinux_splash.jpg

# vim pxelinux.cfg/default          # 修改菜单文件

default vesamenu.c32        # 图形化支撑文件   

#prompt 1

timeout 600               # 读秒时间,表示十分之一秒

 

display boot.msg

 

menu background pxelinux.cfg/syslinux_splash.jpg        # 背景图片路径  

menu title Welcome to Red Hat Enterprise Linux 6.5!  # 菜单文件标题,可随意

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 redhat-6.5          # 选项标签

  menu label Install ^RedHat6.5    # 标签显示内容,"^"表示可以通过按键后面的第一个字母进行快速选择

  menu default   # 默认,当读秒结束后,没有进行其他操作的话,会选择该配置所在的标签

  kernel redhat-6.5/vmlinuz   # redhat的内核文件,注意区分,也可以对vmlinuz进行改名操作,以名词区分,这里使用目录进行区分

  append initrd=redhat-6.5/initrd.img ks=http://192.168.122.10/redhat6.5.1-ks.cfg    #  应答文件,目前做到这是没有的。后面会有

label rescue    # 救援模式,任意选择使用哪一个版本的驱动和内核,该标签在装机时,并无作用

  menu label ^Rescue installed system

  kernel redhat-6.5/vmlinuz

  append initrd=redhat-6.5/initrd.img rescue

label local      # 从本地硬盘启动

  menu label Boot from ^local drive

  localboot 0xffff

9准备应答文件,接下来要将在装机时的选项和配置做成一个配置文件,以实现自动化装机操作。可以直接手动编写,但是那样难度较大,这里我们选择使用一款图像化的软件 system-config-kickstart。

# yum -y install system-config-kickstart

# system-config-kickstart #启动软件,这时候就可以通过图形化操作获得应答文件

# cd /var/www/html/

# ls

ks.cfg  redhat-6.5  redhat6.5.1-ks.cfg  config.sh

# 在这里,可以加入config.sh。这个脚本的意义是在装机后,去执行这个脚本,完成一些内容。

# 加入这个脚本的代码是

%post --interpreter=/bin/bash

wget http://192.168.4.254/config.sh

chmod +x config.sh

./config.sh

%end

# vim config.sh   # 该脚本的一个示例

rm -rf /etc/yum.repos.d/*

cd /etc/yum.repos.d/

echo '

[centos-yum]

ame=added from: http://192.168.4.254/CentOS-6

baseurl=http://192.168.4.254/CentOS6

enabled=1

gpgcheck=0'  > centos-yum.repo

yum clean all

yum repolist

yum -y install vsftpd

service vsftpd start

chkconfig vsftpd on

useradd test-user-01

echo 123456 | passwd --stdin test-user-01

# cat ks.cfg

#platform=x86, AMD64, or Intel EM64T

#version=DEVEL

# Firewall configuration

firewall --disabled

# Install OS instead of upgrade

install

# Use network installation

url --url="http://192.168.106.130/redhat-6.5"

# Root password

rootpw --iscrypted $1$ANXDclTg$u7z5T6KSWpl0rjVRcxRG2.

# System authorization information

auth  --useshadow  --passalgo=sha512

# Use text mode install

text

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  Africa/Abidjan

# Network information

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

# System bootloader configuration

bootloader --location=mbr

# Clear the Master Boot Record

zerombr

# Partition clearing information

clearpart --all --initlabel

# Disk partitioning information

part /boot --fstype="ext4" --size=300

part swap --fstype="swap" --size=1024

part / --fstype="ext4" --grow --size=1

 

%post --interpreter=/bin/bash

wget http://192.168.4.254/config.sh

chmod +x config.sh

./config.sh

%end

 

%packages

@base

 

%end

10 将应答文件添加进配置文件/var/lib/tftpboot/pxelinux.cfg/default文件

label redhat-6.5        

  menu label Install ^RedHat6.5   

  menu default  

  kernel redhat-6.5/vmlinuz  

  append initrd=redhat-6.5/initrd.img ks=http://192.168.122.10/redhat6.5.1-ks.cfg    #  应答文件

append initrd=redhat-6.5/initrd.img ks=http://192.168.122.10/redhat6.5.1-ks.cfg

 

到这里,整个Pxe配置结束。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值