标签:pxe dhcp kickstart dns tftp http
一.实验目标
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地址
[root@server ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
[root@server ~]# 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
[root@server ~]# /etc/init.d/iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@server ~]# chkconfig iptables off
[root@server ~]# vi /etc/selinux/config
[root@server ~]# grep -vE "^$|^#" /etc/selinux/config
SELINUX=permissive
SELINUXTYPE=targeted
3.重启网络服务并查看网卡信息
[root@server ~]# /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 ]
[root@server 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下的相应文件夹内
[root@server ~]# rpm -q httpd
httpd-2.2.15-29.el6.centos.x86_64
[root@server ~]# mount /dev/cdrom /media/
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@server ~]# mkdir /var/www/html/centos6
[root@server ~]# cp -rf /media/* /var/www/html/centos6/
[root@server ~]# umount /media/
[root@server ~]# mount /dev/cdrom /media/
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@server ~]# mkdir /var/www/html/rhel6
[root@server ~]# cp -rf /media/* /var/www/html/rhel6/
[root@server ~]# mkdir rhel6
[root@server ~]# cp -rf /media/* /rhel6/
[root@server ~]# mkdir /var/www/html/rhel5
[root@server ~]# umount /media/
[root@server ~]# mount /dev/cdrom /media/
[root@server ~]# cp -rf /media/* /var/www/html/rhel5/
5.配置server服务器yum源,将原/etc/yum.repos.d/下的.repo文件移动到/etc/yum.repos.d/repo目录内,创建centos_local_yum.repo
[root@server /]# cd /etc/yum.repos.d/
[root@server yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
[root@server yum.repos.d]# mkdir repo
[root@server yum.repos.d]# mv C* repo
[root@server yum.repos.d]# ls
repo
[root@server yum.repos.d]# vi centos_local_yum.repo
[root@server 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服务
[root@server yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, refresh-packagekit
Cleaning repos:
Cleaning up Everything
[root@server yum.repos.d]# cd
[root@server ~]# /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 ]
[root@server ~]# chkconfig httpd on
7.验证结果
[root@server 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服务
[root@server ~]# yum -y install tftp-server
[root@server ~]# yum -y install vim //pxe只安装了图形界面,所以需要安装一下vim
[root@server ~]# vim /etc/xinetd.d/tftp
[root@server ~]# grep disable /etc/xinetd.d/tftp
disable = no
[root@server ~]# /etc/init.d/xinetd restart
Stopping xinetd: [FAILED]
Starting xinetd: [ OK ]
[root@server ~]# chkconfig xinetd on
9.安装并配置dhcp服务
[root@server ~]# yum -y install dhcp
[root@server ~]# vim /etc/dhcp/dhcpd.conf
[root@server ~]# 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"; //网卡引导文件名
}
[root@server ~]# /etc/init.d/dhcpd restart
Shutting down dhcpd: [FAILED]
Starting dhcpd: [ OK ]
[root@server ~]# chkconfig dhcpd on
10.安装dns服务所需文件bind、bind-chroot,bind-utils提供host、nslookup等命令
[root@server ~]# yum -y install bind
[root@server ~]# yum -y install bind-chroot
[root@server ~]# yum -y install bind-utils
[root@server ~]# mv /etc/named.conf /etc/named.conf.bak //将/etc/named.conf重命名
[root@server ~]# vim /var/named/chroot/etc/named.conf //创建新的named.conf
[root@server ~]# 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
[root@server ~]# cd /var/named/chroot/var/named/
[root@server named]# vim linux.com.zone
[root@server 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)
[root@server named]# vim 172.16.1.arpa
[root@server 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地址和搜索域
[root@server named]# vim /etc/resolv.conf
[root@server named]# grep "^$|^#" /etc/resolv.conf
[root@server named]# grep -vE "^$|^#" /etc/resolv.conf
search linux.com
nameserver 172.16.1.254
13.重启dns服务named
[root@server 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]
[root@server named]# vim /var/named/chroot/etc/named.conf //修改并重启服务
[root@server named]# cat /var/named/chroot/etc/named.conf
..........
zone "1.16.172.in-addr.arpa" IN {
type master;
file "172.16.1.arpa";
};
[root@server named]# /etc/init.d/named restart
Stopping named: [ OK ]
Starting named: [ OK ]
[root@server named]# chkconfig named on
14.测试正反向解析结果
[root@server named]# host server.linux.com
server.linux.com has address 172.16.1.254
[root@server 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复制到相应目录中
[root@server named]# mkdir /var/lib/tftpboot/{centos6,rhel5,rhel6}
[root@server named]# cd /var/www/html/centos6/isolinux/
[root@server isolinux]# cp initrd.img vmlinuz /var/lib/tftpboot/centos6/
[root@server isolinux]# cd ../../rhel5
[root@server rhel5]# cd -
/var/www/html/centos6/isolinux
[root@server isolinux]# cd ../../rhel5/isolinux/
[root@server isolinux]# cp initrd.img vmlinuz /var/lib/tftpboot/rhel5
[root@server isolinux]# cd ../../rhel6/isolinux/
[root@server isolinux]# cp initrd.img vmlinuz /var/lib/tftpboot/rhel6
16.安装syslinux,将/usr/share/syslinux/pxelinux.0网卡引导文件复制到/var/lib/tftpboot/
[root@server isolinux]# yum -y install syslinux
[root@server isolinux]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
16、在/var/lib/tftpboot下创建pxelinux.cfg目录,放置启动菜单default
[root@server isolinux]# cd /var/lib/tftpboot
[root@server tftpboot]# mkdir pxelinux.cfg
[root@server tftpboot]# cd pxelinux.cfg/
[root@server pxelinux.cfg]# vim default
[root@server 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/
[root@server pxelinux.cfg]# cp /var/www/html/centos6/isolinux/* /var/lib/tftpboot/
18.安装system-config-kickstart图形话ks配置文件,不同操作系统的ks文件需要在相应的操作系统中创建,这里以centos6.5为例,rhel5需要在创建ks的时候添加序列号
[root@server ~]# yum -y install system-config-kickstart
(1)设置语言,时区,root密码,安装完毕后重启,还可以选择字符安装(text mode)rhel5需要在installation key处添加序列号
(2)添加http服务器地址和目录
/boot 200M
swap 2048M
/ 剩余所有
19.将ks-×.cfg移动到/var/www/html/pxe/目录内
[root@server ~]# mkdir /var/www/html/pxe
[root@server ~]# cd /var/www/html/pxe/
[root@server pxe]# ls
ks-centos6.cfg ks-rhel5.cfg ks-rhel6.cfg
20.修改default文件,添加ks文件位置
[root@server ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
[root@server ~]# 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这一行注释掉
[root@server pxe]# vim ks-centos6.cfg
[root@server pxe]# grep "#repo" ks-centos6.cfg
#repo --name="CentOS" --baseurl=cdrom:sr0 --cost=100 //默认的光盘定义
22.创建新的虚拟机,验证pxe服务
(1)客户机验证
[root@pc3 ~]# hostname //主机名
pc3.linux.com
[root@pc3 ~]# 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)在服务器查看客户机网页
[root@server ~]# yum -y install elinks
[root@server ~]# elinks --dump http://172.16.1.3
Hello World
本文出自 “实验报告” 博客,请务必保留此出处http://9265038.blog.51cto.com/9255038/1556747
标签:pxe dhcp kickstart dns tftp http
原文地址:http://9265038.blog.51cto.com/9255038/1556747