码迷,mamicode.com
首页 > 其他好文 > 详细

PXE无人值守安装系统

时间:2016-04-05 20:12:43      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:pxe无人值守安装系统

实验拓扑:
             RHEL6.5_1
-----CentOS6.5(vmnet1)----------(vmnet1)
            RHEL6.5_2
实验一:搭建PXE装机服务器
    操作系统:RHEL 6.5
    网卡连接:eth0  (VMnet1)
    主机名:svr5.tarena.com
    IP地址:192.168.4.5/24
    关闭 iptables 防火墙、SELinux防护机制

1.检查实验环境
[root@svr5 ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:57:1E:86 
          inet addr:192.168.4.5  Bcast:192.168.4.255  Mask:255.255.255.0
...
[root@svr5 ~]# hostname
svr5.tarena.com
[root@svr5 ~]# yum repolist
[root@svr5 ~]# iptables -F
[root@svr5 ~]# service iptables save
[root@svr5 ~]# grep SELINUX=disabled /etc/sysconfig/selinux
SELINUX=disabled
[root@svr5 ~]# setenforce 0
2.配置YUM源(真实机之前已经配置好了,过程略...)
检查一下
ftp://192.168.4.1/pub/iso/rhel6.5
3.配置DNS
[root@svr5 ~]# rpm -q bind bind-chroot
[root@svr5 ~]# yum -y install bind bind-chroot bind-utils
[root@svr5 ~]# cp -p /etc/named.conf /etc/named.conf.bak
[root@svr5 ~]# vim /etc/named.conf
...
 11         listen-on port 53 { any; };
 12 //      listen-on-v6 port 53 { ::1; };
...
 17         allow-query     { any; };
...
 42 zone "tarena.com" IN {
 43         type master;
 44         file "tarena.com.zone";
 45 };
 46
 47 zone "4.168.192.in-addr.arpa" IN {
 48         type master;
 49         file "192.168.4.arpa";
 50 };
...
[root@svr5 ~]# named-checkconf /etc/named.conf
[root@svr5 ~]# cd /var/named/
[root@svr5 named]# cp -p named.empty tarena.com.zone
[root@svr5 named]# cat tarena.com.zone
$TTL 3H
@ IN SOA @ rname.invalid. (
     2015011401 ; serial
     1D ; refresh
     1H ; retry
     1W ; expire
     3H ) ; minimum
 IN NS dns1.tarena.com.
dns1 IN A 192.168.4.5
$GENERATE  100-200  pc$ IN   A 192.168.4.$
[root@svr5 named]# cp -p tarena.com.zone 192.168.4.arpa
[root@svr5 named]# cat 192.168.4.arpa
$TTL 3H
@ IN SOA @ rname.invalid. (
     2015011401 ; serial
     1D ; refresh
     1H ; retry
     1W ; expire
     3H ) ; minimum
 IN NS dns1.tarena.com.
5 IN PTR dns1.tarena.com.
$GENERATE 100-200 $ IN PTR pc$.tarena.com.
[root@svr5 ~]# rndc-confgen -r /dev/urandom -a
[root@svr5 ~]# service named restart
[root@svr5 ~]# chkconfig named on
[root@svr5 ~]# host pc100.tarena.com 192.168.4.5
[root@svr5 ~]# host 192.168.4.150 192.168.4.5
4.配置DHCP
[root@svr5 ~]# rpm -q dhcp
[root@svr5 ~]# yum -y install dhcp
[root@svr5 ~]# cat /etc/dhcp/dhcpd.conf
option domain-name "tarena.com";
option domain-name-servers 192.168.4.5;
default-lease-time 7200;
max-lease-time 14400;
subnet 192.168.4.0 netmask 255.255.255.0 {
   range 192.168.4.100 192.168.4.200;
   option routers 192.168.4.1;
 next-server 192.168.4.5;
 filename "pxelinux.0";
}
[root@svr5 ~]# service dhcpd restart
[root@svr5 ~]# chkconfig dhcpd on
5.配置TFTP
[root@svr5 ~]# rpm -q tftp-server
[root@svr5 ~]# yum -y install tftp-server
[root@svr5 ~]# chkconfig tftp on
[root@svr5 ~]# service xinetd restart
[root@svr5 ~]# chkconfig xinetd on
[root@svr5 named]# netstat -anptu | grep xinetd
udp   0  0 0.0.0.0:69    0.0.0.0:*   2526/xinetd    
6.准备启动文件
[root@svr5 ~]# yum -y install syslinux
[root@svr5 ~]# cd /usr/share/syslinux/
[root@svr5 syslinux]# cp pxelinux.0 /var/lib/tftpboot/
[root@svr5 syslinux]# cd /var/lib/tftpboot/
[root@svr5 tftpboot]# yum -y install wget
[root@svr5 tftpboot]# wget ftp://192.168.4.1/pub/iso/rhel6.5/isolinux/vmlinuz
[root@svr5 tftpboot]# wget ftp://192.168.4.1/pub/iso/rhel6.5/isolinux/initrd.img
[root@svr5 tftpboot]# ls
initrd.img  pxelinux.0  vmlinuz
7.测试tftp
[root@svr5 tftpboot]# cd /tmp/
[root@svr5 tmp]# yum -y install tftp
[root@svr5 tmp]# tftp 192.168.4.5 -c get pxelinux.0
[root@svr5 tmp]# ls -lh pxelinux.0
-rw-r--r-- 1 root root 27K 1月  14 14:43 pxelinux.0
8.配置启动菜单
[root@svr5 ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@svr5 ~]# cd /var/lib/tftpboot/pxelinux.cfg/
[root@svr5 pxelinux.cfg]# wget ftp://192.168.4.1/pub/iso/rhel6.5/isolinux/isolinux.cfg
[root@svr5 pxelinux.cfg]# mv isolinux.cfg default

准备应答文件
    找一台已装好的RHEL6.5模板客户机(本例中可选PXE服务器本机),通过system-config-kickstart工具创建rhel6-ks.cfg应答文件
[root@svr5 ~]# yum -y install system-config-kickstart
[root@svr5 ~]# system-config-kickstart  //在图形桌面下运行,详细见截图
     !!!! 基本配置:指定默认语言、时区、根口令(redhat)
     !!!! 安装方式:新安装、FTP安装(192.168.4.1、/pub/iso/rhel6.5)
     !!!! 分区信息:清除主引导记录、删除所有现存分区、初始化磁盘标签、/boot 200MB、SWAP 2GB、/  剩余空间
     !!!! 网络配置:第一块网卡DHCP自动获取
     !!!! 防火墙配置:禁用SELinux、禁用防火墙
     !!!! 软件包选择:不安装图形桌面
将文件另存为/root/rhel6.5-ks.cfg
2.将生成rhel6.5-ks.cfg文件上传到ftp服务器上面
[root@svr5 ~]# scp /root/rhel6.5-ks.cfg root@192.168.4.1:/var/ftp/pub/
[root@svr5 ~]# vim /var/lib/tftpboot/pxelinux.cfg/default   //修改引导配置文件
default  linux     //默认从哪个标签引导系统
prompt 1      //是否交互式安装
timeout 600      //进入默认系统的等待超时(单位:1/10秒)
label linux     //定义名为linux的标签
        kernel  vmlinuz //选择此标签时,需要加载的内核文件
        append  ks=ftp://192.168.4.1/pub/rhel6.5-ks.cfg initrd=initrd.img   //下载并启用自动应答文件
3.检查ftp://192.168.4.1上面的文件
[root@svr5 ~]# elinks --dump ftp://192.168.4.1/pub/rhel6.5-ks.cfg
4.启动一台裸客户机(新建虚拟机),测试无人值守安装
     !!!! 安装设置过程会自动应答,免手工交互
     !!!! 等待客户机系统安装完成

实验三:安装后脚本操作
 安装完成后自动配置yum客户端文件
 自动安装httpd服务并设置开机启动
 配置默认网页内容为"I Love Studying..."

1.直接编辑FTP服务器上的ks文件,在最下面添加如下内容
[root@localhost ~]# vim /var/ftp/pub/rhel6.5-ks.cfg
...
%post --interpreter=/bin/bash
rm -rf /etc/yum.repos.d/*
echo ‘[rhel6]
name=RedHat Linux 6.5
baseurl=ftp://192.168.4.1/pub/iso/rhel6.5
enabled=1
gpgcheck=0‘ > /etc/yum.repos.d/rhel6.repo
yum clean all
yum -y install httpd
echo ‘I Love Studying...‘ > /var/www/html/index.html
/etc/init.d/httpd start
chkconfig httpd on
%end
2.启动一台裸客户机(新建虚拟机),测试无人值守安装
3.检查装好的客户机,确认POST脚本设置结果
[root@pc100 ~]# ifconfig eth0 | grep "inet addr" //查看自动配置的IP地址
          inet addr:192.168.4.100  Bcast:192.168.4.255  Mask:255.255.255.0
[root@pc100 ~]# chkconfig --list httpd //查看Web服务的自启动态
httpd    0:off 1:off 2:on 3:on 4:on 5:on 6:关闭
[root@pc100 ~]# yum -y install elinks //确保可yum安装软件包
[root@pc100 ~]# elinks --dump http://127.0.0.1 //访问测试网页
I Love Linux...

 

PXE无人值守安装系统

标签:pxe无人值守安装系统

原文地址:http://liangzai818.blog.51cto.com/10003446/1760511

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!