设为首页 收藏本站
查看: 806|回复: 0

[经验分享] PXE和kickstart无人值守安装

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-9-22 09:04:38 | 显示全部楼层 |阅读模式
一.实验目标
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地址
[iyunv@server ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
[iyunv@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
[iyunv@server ~]# /etc/init.d/iptables stop
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[iyunv@server ~]# chkconfig iptables off
[iyunv@server ~]# vi /etc/selinux/config
[iyunv@server ~]# grep -vE "^$|^#" /etc/selinux/config
SELINUX=permissive
SELINUXTYPE=targeted

3.重启网络服务并查看网卡信息
[iyunv@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  ]
[iyunv@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下的相应文件夹内
[iyunv@server ~]# rpm -q httpd
httpd-2.2.15-29.el6.centos.x86_64
[iyunv@server ~]# mount /dev/cdrom /media/
mount: block device /dev/sr0 is write-protected, mounting read-only
[iyunv@server ~]# mkdir /var/www/html/centos6
[iyunv@server ~]# cp -rf /media/* /var/www/html/centos6/
[iyunv@server ~]# umount /media/
[iyunv@server ~]# mount /dev/cdrom /media/
mount: block device /dev/sr0 is write-protected, mounting read-only
[iyunv@server ~]# mkdir /var/www/html/rhel6
[iyunv@server ~]# cp -rf /media/* /var/www/html/rhel6/
[iyunv@server ~]# mkdir rhel6
[iyunv@server ~]# cp -rf /media/* /rhel6/
[iyunv@server ~]# mkdir /var/www/html/rhel5
[iyunv@server ~]# umount /media/
[iyunv@server ~]# mount /dev/cdrom /media/
[iyunv@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
[iyunv@server /]# cd /etc/yum.repos.d/
[iyunv@server yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo  CentOS-Vault.repo
[iyunv@server yum.repos.d]# mkdir repo
[iyunv@server yum.repos.d]# mv C* repo
[iyunv@server yum.repos.d]# ls
repo
[iyunv@server yum.repos.d]# vi centos_local_yum.repo
[iyunv@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服务
[iyunv@server yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, refresh-packagekit
Cleaning repos:
Cleaning up Everything
[iyunv@server yum.repos.d]# cd
[iyunv@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  ]
[iyunv@server ~]# chkconfig httpd on

7.验证结果
[iyunv@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服务
[iyunv@server ~]# yum -y install tftp-server
[iyunv@server ~]# yum -y install vim                        //pxe只安装了图形界面,所以需要安装一下vim
[iyunv@server ~]# vim /etc/xinetd.d/tftp
[iyunv@server ~]# grep disable /etc/xinetd.d/tftp
        disable                        = no
[iyunv@server ~]# /etc/init.d/xinetd restart
Stopping xinetd:                                           [FAILED]
Starting xinetd:                                           [  OK  ]
[iyunv@server ~]# chkconfig xinetd on

9.安装并配置dhcp服务
[iyunv@server ~]# yum -y install dhcp
[iyunv@server ~]# vim /etc/dhcp/dhcpd.conf
[iyunv@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";                                //网卡引导文件名
}
[iyunv@server ~]# /etc/init.d/dhcpd restart
Shutting down dhcpd:                                       [FAILED]
Starting dhcpd:                                            [  OK  ]
[iyunv@server ~]# chkconfig dhcpd on

10.安装dns服务所需文件bind、bind-chroot,bind-utils提供host、nslookup等命令
[iyunv@server ~]# yum -y install bind
[iyunv@server ~]# yum -y install bind-chroot
[iyunv@server ~]# yum -y install bind-utils
[iyunv@server ~]# mv /etc/named.conf /etc/named.conf.bak        //将/etc/named.conf重命名
[iyunv@server ~]# vim /var/named/chroot/etc/named.conf        //创建新的named.conf
[iyunv@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
[iyunv@server ~]# cd /var/named/chroot/var/named/
[iyunv@server named]# vim linux.com.zone
[iyunv@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)
[iyunv@server named]# vim 172.16.1.arpa
[iyunv@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地址和搜索域
[iyunv@server named]# vim /etc/resolv.conf
[iyunv@server named]# grep "^$|^#" /etc/resolv.conf
[iyunv@server named]# grep -vE "^$|^#" /etc/resolv.conf
search linux.com
nameserver 172.16.1.254

13.重启dns服务named
[iyunv@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]

[iyunv@server named]# vim /var/named/chroot/etc/named.conf        //修改并重启服务
[iyunv@server named]# cat /var/named/chroot/etc/named.conf
..........
zone "1.16.172.in-addr.arpa" IN {
         type master;
         file "172.16.1.arpa";
};
[iyunv@server named]# /etc/init.d/named restart
Stopping named:                                            [  OK  ]
Starting named:                                            [  OK  ]
[iyunv@server named]# chkconfig named on

14.测试正反向解析结果
[iyunv@server named]# host server.linux.com
server.linux.com has address 172.16.1.254
[iyunv@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复制到相应目录中
[iyunv@server named]# mkdir /var/lib/tftpboot/{centos6,rhel5,rhel6}
[iyunv@server named]# cd /var/www/html/centos6/isolinux/
[iyunv@server isolinux]# cp initrd.img vmlinuz /var/lib/tftpboot/centos6/
[iyunv@server isolinux]# cd ../../rhel5
[iyunv@server rhel5]# cd -
/var/www/html/centos6/isolinux
[iyunv@server isolinux]# cd ../../rhel5/isolinux/
[iyunv@server isolinux]# cp initrd.img vmlinuz /var/lib/tftpboot/rhel5
[iyunv@server isolinux]# cd ../../rhel6/isolinux/
[iyunv@server isolinux]# cp initrd.img vmlinuz /var/lib/tftpboot/rhel6

16.安装syslinux,将/usr/share/syslinux/pxelinux.0网卡引导文件复制到/var/lib/tftpboot/
[iyunv@server isolinux]# yum -y install syslinux
[iyunv@server isolinux]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
16、在/var/lib/tftpboot下创建pxelinux.cfg目录,放置启动菜单default
[iyunv@server isolinux]# cd /var/lib/tftpboot
[iyunv@server tftpboot]# mkdir pxelinux.cfg
[iyunv@server tftpboot]# cd pxelinux.cfg/
[iyunv@server pxelinux.cfg]# vim default
[iyunv@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/
[iyunv@server pxelinux.cfg]# cp /var/www/html/centos6/isolinux/* /var/lib/tftpboot/

18.安装system-config-kickstart图形话ks配置文件,不同操作系统的ks文件需要在相应的操作系统中创建,这里以centos6.5为例,rhel5需要在创建ks的时候添加序列号
[iyunv@server ~]# yum -y install system-config-kickstart
(1)设置语言,时区,root密码,安装完毕后重启,还可以选择字符安装(text mode)rhel5需要在installation key处添加序列号

wKioL1QexpewJPlGAAEAnSc_QlM529.png
(2)添加http服务器地址和目录
wKiom1QexojAEL-_AAC1O-Aeh_U841.png (3)设置默认分区:
                                        /boot        200M
                                        swap        2048M
                                        /                剩余所有
wKiom1QexpqxznTXAAD_121b5lI065.png (4)网卡:etho dhcp
wKioL1QextTSOgNUAAC2w3-Sjgg572.png (5)关闭iptables和selinux
wKiom1QexsKih3I0AAC6cjhuObI144.png (6)添加安装后的脚本
wKiom1QeybnwZsoFAADtZMPz5xo925.png
19.将ks-×.cfg移动到/var/www/html/pxe/目录内
[iyunv@server ~]# mkdir /var/www/html/pxe
[iyunv@server ~]# cd /var/www/html/pxe/
[iyunv@server pxe]# ls
ks-centos6.cfg  ks-rhel5.cfg  ks-rhel6.cfg

20.修改default文件,添加ks文件位置
[iyunv@server ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
[iyunv@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这一行注释掉
[iyunv@server pxe]# vim ks-centos6.cfg
[iyunv@server pxe]# grep "#repo" ks-centos6.cfg
#repo --name="CentOS" --baseurl=cdrom:sr0 --cost=100        //默认的光盘定义

22.创建新的虚拟机,验证pxe服务
(1)客户机验证
wKiom1QexveCjBa-AAarkjmZMsg321.png
[iyunv@pc3 ~]# hostname                                         //主机名
pc3.linux.com
[iyunv@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)在服务器查看客户机网页
[iyunv@server ~]# yum -y install elinks
[iyunv@server ~]# elinks --dump http://172.16.1.3
   Hello World



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-25117-1-1.html 上篇帖子: 设置修改CentOS系统时区 下篇帖子: Netty4.X 获取客户端IP
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表