PXE和kickstart无人值守安装

一.实验目标

1.配置pxe服务,通过http的方式,实现无人职守安装系统。

2.服务器裸机选择网卡为第一启动项,pxe服务器选单提供centos6.5、rhel6.5和rhel5.9的操作系统安装,60秒不做选择则从本地硬盘启动

3.ks文件添加脚本:

操作系统安装完成后修改yum源

安装httpd服务

设置为开机启动

在/var/www/html/下创建index.html文件,文件内容为“Hello World”

在pxe服务器上以elinks查看访问index.html

4.需要配置的服务:

dhcp

tftp

dns //非必要

http //也可以使用ftp服务

二.实验环境

1.新建一台centos6.5虚拟机,作为PXE服务器,只安装图形界面,没有安装其他软件

主机名:server.linux.com

ip地址:172.16.1.254/24

2.dhcp地址池:172.16.1.1-172.16.1.100

3.关闭防火墙iptables和selinux

子网掩码:255.255.255.0

4.服务器设置正、反向解析dns服务,为新建服务器自动设置主机名:pc$.linux.com

三.实验步骤

1.设置服务器的ip地址

[[email protected] ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0

[[email protected] ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

TYPE=Ethernet

ONBOOT=yes

NM_CONTROLLED=yes

BOOTPROTO=static

IPADDR=172.16.1.254

NETMASK=255.255.255.0

2.关闭iptables和selinux

[[email protected] ~]# /etc/init.d/iptables stop

iptables: Setting chains to policy ACCEPT: filter          [  OK  ]

iptables: Flushing firewall rules:                         [  OK  ]

iptables: Unloading modules:                               [  OK  ]

[[email protected] ~]# chkconfig iptables off

[[email protected] ~]# vi /etc/selinux/config

[[email protected] ~]# grep -vE "^$|^#" /etc/selinux/config

SELINUX=permissive

SELINUXTYPE=targeted

3.重启网络服务并查看网卡信息

[[email protected] ~]# /etc/init.d/network restart

Shutting down interface eth0:  Device state: 3 (disconnected)

[  OK  ]

Shutting down loopback interface:                          [  OK  ]

Bringing up loopback interface:                            [  OK  ]

Bringing up interface eth0:  Active connection state: activated

Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/1

[  OK  ]

[[email protected] media]# ifconfig

eth0      Link encap:Ethernet  HWaddr 00:0C:29:94:96:B5

inet addr:172.16.1.254  Bcast:172.16.1.255  Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:fe94:96b5/64 Scope:Link

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

RX packets:36 errors:0 dropped:0 overruns:0 frame:0

TX packets:3 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:3312 (3.2 KiB)  TX bytes:258 (258.0 b)

lo        Link encap:Local Loopback

inet addr:127.0.0.1  Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING  MTU:16436  Metric:1

RX packets:208 errors:0 dropped:0 overruns:0 frame:0

TX packets:208 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:16512 (16.1 KiB)  TX bytes:16512 (16.1 KiB)

4.将centos6.5、rhel6.5和rhel5.9光盘内容拷贝到/var/www/html下的相应文件夹内

[[email protected] ~]# rpm -q httpd

httpd-2.2.15-29.el6.centos.x86_64

[[email protected] ~]# mount /dev/cdrom /media/

mount: block device /dev/sr0 is write-protected, mounting read-only

[[email protected] ~]# mkdir /var/www/html/centos6

[[email protected] ~]# cp -rf /media/* /var/www/html/centos6/

[[email protected] ~]# umount /media/

[[email protected] ~]# mount /dev/cdrom /media/

mount: block device /dev/sr0 is write-protected, mounting read-only

[[email protected] ~]# mkdir /var/www/html/rhel6

[[email protected] ~]# cp -rf /media/* /var/www/html/rhel6/

[[email protected] ~]# mkdir rhel6

[[email protected] ~]# cp -rf /media/* /rhel6/

[[email protected] ~]# mkdir /var/www/html/rhel5

[[email protected] ~]# umount /media/

[[email protected] ~]# mount /dev/cdrom /media/

[[email protected] ~]# cp -rf /media/* /var/www/html/rhel5/

5.配置server服务器yum源,将原/etc/yum.repos.d/下的.repo文件移动到/etc/yum.repos.d/repo目录内,创建centos_local_yum.repo

[[email protected] /]# cd /etc/yum.repos.d/

[[email protected] yum.repos.d]# ls

CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo  CentOS-Vault.repo

[[email protected] yum.repos.d]# mkdir repo

[[email protected] yum.repos.d]# mv C* repo

[[email protected] yum.repos.d]# ls

repo

[[email protected] yum.repos.d]# vi centos_local_yum.repo

[[email protected] yum.repos.d]# cat centos_local_yum.repo

[centos-local-yum]

name=centos6.5-server

baseurl=http://172.16.1.254/centos6

enabled=1

gpgcheck=0

#gpgkey=gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

6.清除yum缓存,重启httpd服务

[[email protected] yum.repos.d]# yum clean all

Loaded plugins: fastestmirror, refresh-packagekit

Cleaning repos:

Cleaning up Everything

[[email protected] yum.repos.d]# cd

[[email protected] ~]# /etc/init.d/httpd restart

Stopping httpd:                                            [FAILED]

Starting httpd: httpd: apr_sockaddr_info_get() failed for server.linux.com

httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName

[  OK  ]

[[email protected] ~]# chkconfig httpd on

7.验证结果

[[email protected] yum.repos.d]# yum repolist

Loaded plugins: fastestmirror, refresh-packagekit

centos-local-yum                                         | 4.0 kB     00:00 ...

centos-local-yum/primary_db                              | 4.4 MB     00:00 ...

repo id                              repo name                            status

centos-local-yum                     centos6.5-server                     6,367

repolist: 6,367

8.安装并启动tftp服务

[[email protected] ~]# yum -y install tftp-server

[[email protected] ~]# yum -y install vim //pxe只安装了图形界面,所以需要安装一下vim

[[email protected] ~]# vim /etc/xinetd.d/tftp

[[email protected] ~]# grep disable /etc/xinetd.d/tftp

disable = no

[[email protected] ~]# /etc/init.d/xinetd restart

Stopping xinetd:                                           [FAILED]

Starting xinetd:                                           [  OK  ]

[[email protected] ~]# chkconfig xinetd on

9.安装并配置dhcp服务

[[email protected] ~]# yum -y install dhcp

[[email protected] ~]# vim /etc/dhcp/dhcpd.conf

[[email protected] ~]# grep -vE "^#|^$" /etc/dhcp/dhcpd.conf

default-lease-time 3600;

max-lease-time 7200;

option domain-name "linux.com";

option domain-name-servers 172.16.1.254;

subnet 172.16.1.0 netmask 255.255.255.0 {

range 172.16.1.1 172.16.1.100;

next-server 172.16.1.254; //tftp服务器的ip地址

filename "pxelinux.0"; //网卡引导文件名

}

[[email protected] ~]# /etc/init.d/dhcpd restart

Shutting down dhcpd:                                       [FAILED]

Starting dhcpd:                                            [  OK  ]

[[email protected] ~]# chkconfig dhcpd on

10.安装dns服务所需文件bind、bind-chroot,bind-utils提供host、nslookup等命令

[[email protected] ~]# yum -y install bind

[[email protected] ~]# yum -y install bind-chroot

[[email protected] ~]# yum -y install bind-utils

[[email protected] ~]# mv /etc/named.conf /etc/named.conf.bak //将/etc/named.conf重命名

[[email protected] ~]# vim /var/named/chroot/etc/named.conf //创建新的named.conf

[[email protected] ~]# cat /var/named/chroot/etc/named.conf

options {

directory "/var/named";

};

zone "linux.com" IN {

type master;

file "linux.com.zone";

};

zone "1.16.172.in-addr.arpa" IN {

type master;

file "172.16.1.arpa" //这里少写了一个分号,下面会有报错

};

11.在/var/named/chroot/var/named/下创建正向解析区域数据文件linux.com.zone和反向解析区域数据文件172.16.1.arpa

[[email protected] ~]# cd /var/named/chroot/var/named/

[[email protected] named]# vim linux.com.zone

[[email protected] named]# cat linux.com.zone

$TTL 86400

@ IN SOA linux.com. root.linux.com. (

2014092101

4H

15M

4H

1D

)

@ IN NS server.linux.com.

server IN A 172.16.1.254

$GENERATE 1-100 pc$ IN A 172.16.1.$ //pc$.linux.com的ip地址为172.16.1.$($为1-100)

[[email protected] named]# vim 172.16.1.arpa

[[email protected] named]# cat 172.16.1.arpa

$TTL 86400

@ IN SOA linux.com. root.linux.com. (

2014092101

4H

15M

4H

)

@ IN NS server.linux.com.

254 IN PTR server.linux.co

1D m.

$GENERATE 1-100 $ IN PTR pc$.linux.com. //172.16.1.$的域名为pc$.linux.com($为1-100)

12.在/etc/resolv.conf文件中添加dns地址和搜索域

[[email protected] named]# vim /etc/resolv.conf

[[email protected] named]# grep "^$|^#" /etc/resolv.conf

[[email protected] named]# grep -vE "^$|^#" /etc/resolv.conf

search linux.com

nameserver 172.16.1.254

13.重启dns服务named

[[email protected] named]# /etc/init.d/named restart

Stopping named:                                            [  OK  ]

Generating /etc/rndc.key:                                  [  OK  ]

Starting named:

Error in named configuration:

/etc/named.conf:11: missing ‘;‘ before ‘}‘ //在第11行“}”前面少了一个“;”

[FAILED]

[[email protected] named]# vim /var/named/chroot/etc/named.conf //修改并重启服务

[[email protected] named]# cat /var/named/chroot/etc/named.conf

..........

zone "1.16.172.in-addr.arpa" IN {

type master;

file "172.16.1.arpa";

};

[[email protected] named]# /etc/init.d/named restart

Stopping named:                                            [  OK  ]

Starting named:                                            [  OK  ]

[[email protected] named]# chkconfig named on

14.测试正反向解析结果

[[email protected] named]# host server.linux.com

server.linux.com has address 172.16.1.254

[[email protected] named]# host 172.16.1.5

5.1.16.172.in-addr.arpa domain name pointer pc5.linux.com.

15.在/var/lib/tftpboot/创建cengos6、rhel5和rhel6目录,将相应操作系统的initrd.img和vmlinuz复制到相应目录中

[[email protected] named]# mkdir /var/lib/tftpboot/{centos6,rhel5,rhel6}

[[email protected] named]# cd /var/www/html/centos6/isolinux/

[[email protected] isolinux]# cp initrd.img vmlinuz /var/lib/tftpboot/centos6/

[[email protected] isolinux]# cd ../../rhel5

[[email protected] rhel5]# cd -

/var/www/html/centos6/isolinux

[[email protected] isolinux]# cd ../../rhel5/isolinux/

[[email protected] isolinux]# cp initrd.img vmlinuz /var/lib/tftpboot/rhel5

[[email protected] isolinux]# cd ../../rhel6/isolinux/

[[email protected] isolinux]# cp initrd.img vmlinuz /var/lib/tftpboot/rhel6

16.安装syslinux,将/usr/share/syslinux/pxelinux.0网卡引导文件复制到/var/lib/tftpboot/

[[email protected] isolinux]# yum -y install syslinux

[[email protected] isolinux]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

16、在/var/lib/tftpboot下创建pxelinux.cfg目录,放置启动菜单default

[[email protected] isolinux]# cd /var/lib/tftpboot

[[email protected] tftpboot]# mkdir pxelinux.cfg

[[email protected] tftpboot]# cd pxelinux.cfg/

[[email protected] pxelinux.cfg]# vim default

[[email protected] pxelinux.cfg]# cat default

default local //默认以local启动

timeout 600

UI UI  vesamenu.c32 //启动菜单模块,在操作系统镜像的isolinux内

display boot.msg

menu background splash.jpg

menu title Welcome to PXE Server! //菜单标题

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 linux

menu label install ^Centos6.5

menu default

kernel centos6/vmlinuz

append initrd=centos6/initrd.img //append后面还需要添加ks自动应答文件

label linux

menu label install ^Rhel6.5

menu default

kernel rhel6/vmlinuz

append initrd=rhel6/initrd.img

label linux

menu label install R^hel5.9

menu default

kernel rhel5/vmlinuz

append initrd=rhel5/initrd.img

label rescue

menu label ^Rescue installed system

kernel rhel6/vmlinuz

append initrd=rhel6/initrd.img rescue

label local

menu label Boot from ^local drive

localboot 1

17.使用centos6的启动菜单样式,将/var/www/html/centos6/isolinux/*复制到/var/lib/tftpboot/

[[email protected] pxelinux.cfg]# cp /var/www/html/centos6/isolinux/* /var/lib/tftpboot/

18.安装system-config-kickstart图形话ks配置文件,不同操作系统的ks文件需要在相应的操作系统中创建,这里以centos6.5为例,rhel5需要在创建ks的时候添加序列号

[[email protected] ~]# yum -y install system-config-kickstart

(1)设置语言,时区,root密码,安装完毕后重启,还可以选择字符安装(text mode)rhel5需要在installation key处添加序列号

(2)添加http服务器地址和目录

(3)设置默认分区:

/boot 200M

swap 2048M

/ 剩余所有

(4)网卡:etho dhcp

(5)关闭iptables和selinux

(6)添加安装后的脚本

19.将ks-×.cfg移动到/var/www/html/pxe/目录内

[[email protected] ~]# mkdir /var/www/html/pxe

[[email protected] ~]# cd /var/www/html/pxe/

[[email protected] pxe]# ls

ks-centos6.cfg  ks-rhel5.cfg  ks-rhel6.cfg

20.修改default文件,添加ks文件位置

[[email protected] ~]# vim /var/lib/tftpboot/pxelinux.cfg/default

[[email protected]rver ~]# grep -E "label|ks" /var/lib/tftpboot/pxelinux.cfg/default

label centos6.5

menu label install ^Centos6.5

append initrd=centos6/initrd.img ks=http://172.16.1.254/pxe/ks-centos6.cfg //就是这里

label rhel6.5

menu label install ^Rhel6.5

append initrd=rhel6/initrd.img ks=http://172.16.1.254/pxe/ks-rhel6.cfg

label rhel5.9

menu label install R^hel5.9

append initrd=rhel5/initrd.img ks=http://172.16.1.254/pxe/ks-rhel5.cfg

label rescue

menu label ^Rescue installed system

label local

menu label Boot from ^local drive

21.centos6需要将ks这一行注释掉

[[email protected] pxe]# vim ks-centos6.cfg

[[email protected] pxe]# grep "#repo" ks-centos6.cfg

#repo --name="CentOS" --baseurl=cdrom:sr0 --cost=100 //默认的光盘定义

22.创建新的虚拟机,验证pxe服务

(1)客户机验证

[[email protected] ~]# hostname //主机名

pc3.linux.com

[[email protected] ~]# ifconfig

eth0      Link encap:Ethernet  HWaddr 00:0C:29:68:F5:81

inet addr:172.16.1.3  Bcast:172.16.1.255  Mask:255.255.255.0 //ip地址

inet6 addr: fe80::20c:29ff:fe68:f581/64 Scope:Link

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

RX packets:50 errors:0 dropped:0 overruns:0 frame:0

TX packets:64 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:5988 (5.8 KiB)  TX bytes:5239 (5.1 KiB)

(2)在服务器查看客户机网页

[[email protected] ~]# yum -y install elinks

[[email protected] ~]# elinks --dump http://172.16.1.3

Hello World

时间: 2024-10-17 17:40:57

PXE和kickstart无人值守安装的相关文章

Linux PXE+DHCP+Kickstart无人值守安装   (1) 网络装机

PXE网络装机 注释:我们要安装的是 rhel-server-5.9_x86_64 下载地址是:地址晚一点给大家. linux PXE远程安装介绍: PXE是由Intel设计的协议,它可以使计算机通过网络启动.协议分为client和server两端,PXE client在网卡的ROM中,当计算机引导时,BIOS把PXE client调入内存执行,并显示出命令菜单,经用户选择后,PXE client将放置在远端的操作系统通过网络下载到本地运行,无盘工作站就是通过PXE来进行启动的.PXE协议的成功

RHEL7下PXE+NFS+Kickstart无人值守安装操作系统

1.配置yum源 vim /etc/yum.repos.d/development.repo [development] name=yum server baseurl=file:///mnt enabled=1 gpgcheck=0 2.挂载光盘 mount /dev/sr0 /mnt 3.安装相关软件包 yum install dhcp syslinux xinetd tftp-server 4.配置dhcp vim /etc/dhcp/dhcpd.conf 5.添加内容 subnet 19

RHEL7下PXE+Apache+Kickstart无人值守安装操作系统

1.配置yum源 vim /etc/yum.repos.d/development.repo [development] name=yum server baseurl=file:///mnt enabled=1 gpgcheck=0 2.挂载光盘 mount /dev/sr0 /mnt 3.安装相关软件包 yum install dhcp syslinux xinetd tftp-server 4.配置dhcp vim /etc/dhcp/dhcpd.conf 5.添加内容 subnet 19

RHEL7下PXE+FTP+Kickstart无人值守安装操作系统

1.配置yum源 vim /etc/yum.repos.d/development.repo [development] name=yum server baseurl=file:///mnt enabled=1 gpgcheck=0 2.挂载光盘 mount /dev/sr0 /mnt 3.安装相关软件包 yum install dhcp syslinux xinetd tftp-server 4.配置dhcp vim /etc/dhcp/dhcpd.conf 5.添加内容 subnet 19

CentOS 6.5下PXE+Kickstart无人值守安装操作系统

CentOS 6.5下PXE+Kickstart无人值守安装操作系统 一.简介 1.1 什么是PXE PXE(Pre-boot Execution Environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,在启动过程中,终端要求服务器分配IP地址,再用TFTP(trivial file transfer protocol)或MTFTP(multicasttrivia

Pxe+Kickstart无人值守安装Linxu操作系统

KICKSTART无人值守安装: 一.系统安装方法: 光盘安装系统===>一个服务器DVD内置光驱就要花很多钱,试想,几百台服务器仅是装系统用一次光驱,太耗资金,usb外置光驱一台一台插也是够麻烦的. U盘安装系统===>还是同样的问题,要一台一台服务器插U盘. 网络安装系统(ftp,http,nfs) ===>这个方法不错,只要服务器能联网就可以装系统了,但还是需要一台台服务器去敲键盘点鼠标.时刻想偷懒的我们,有没有更好的方法! 高效安装系统法:Kickstart.Cobbler 二.

PXE+Kickstart无人值守安装

kickstart无人值守安装原理 1)PXE Client向DHCP发送请求 PXE Client首先由PXE网卡引导,PXE BootROM内程序发送一个UDP广播请求,向DHCP服务器发送请求 2)DHCP服务器提供信息 DHCP服务器收到请求,验证请求是否合法,验证通过后返回客户端一个响应消息,包含分配的IP地址.PXELINUX启动程序(TFTP)位置,以及配置文件所在位置. 3)PXE客户端请求下载启动文件 客户端收到DHCP服务器的响应消息后,会向TFTP服务器(BootServe

CentOS 6.4下PXE+Kickstart无人值守安装操作系统

一.简介 1.1 什么是PXE PXE(Pre-boot Execution Environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,在启动过程中,终端要求服务器分配IP地址,再用TFTP(trivial file transfer protocol)或MTFTP(multicast trivial file transfer protocol)协议下载一个启动软

PXE+Kickstart无人值守安装CentOS 6.7

一.简介 1.1 什么是PXE PXE(preboot execute environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,在启动过程中,终端要求服务器分配IP地址,再用TFTP(trivial file transfer protocol)或MTFTP(multicast trivial file transfer protocol)协议下载一个启动软件包到