实验:搭建PXE服务器,实现无人值守自动安装系统
在PXE服务器和新安装的服务器上分别安装http实现均衡负载
建立主从DNS服务器
第一步,先配置DHCP,目的是给需要安装系统的主机分配ip地址
服务器IP地址设为192.168.100.11
[root@localhost ~]# ifconfig eth0 | grep "inet addr"
inet addr:192.168.100.11 Bcast:192.168.100.255 Mask:255.255.255.0
[root@localhost ~]#
安装dhcp
[root@localhost ~]# yum -y install dhcp
[root@localhost ~]# rpm -q dhcp
dhcp-3.0.5-31.el5_8.1
[root@localhost ~]#
dhcp配置文件修改成如下
[root@localhost ~]# cat /etc/dhcpd.conf
ddns-update-style interim;
next-server 192.168.100.11;
filename "pxelinux.0";
subnet 192.168.100.0 netmask 255.255.255.0 {
option subnet-mask 255.255.255.0;
option domain-name "candy.com";
option domain-name-servers 192.168.100.11;
range dynamic-bootp 192.168.100.128 192.168.100.254;
}
[root@localhost ~]#
启动dhcp
[root@localhost ~]# service dhcpd restart
关闭 dhcpd: [确定]
启动 dhcpd: [确定]
[root@localhost ~]# chkconfig dhcpd on
[root@localhost ~]#
第二步,配置TFTP服务
tftp默认已安装
[root@localhost ~]# rpm -q tftp
tftp-0.49-2
[root@localhost ~]# rpm -q tftp-server
tftp-server-0.49-2
[root@localhost ~]#
启动xinetd服务
[root@localhost ~]# vi /etc/xinetd.d/tftp
disable = no
[root@localhost ~]# /etc/init.d/xinetd restart
停止 xinetd: [确定]
启动 xinetd: [确定]
[root@localhost ~]# chkconfig xinetd on
[root@localhost ~]#
把内核文件,初始化文件拷贝到tftp目录下
[root@localhost pxeboot]# cp initrd.img vmlinuz /tftpboot/
[root@localhost pxeboot]# pwd
/media/p_w_picpaths/pxeboot
[root@localhost pxeboot]# cp /usr/share/syslinux/pxelinux.0 /tftpboot/
[root@localhost pxeboot]#
[root@localhost pxeboot]# cd /tftpboot/
[root@localhost tftpboot]# ls
initrd.img linux-install pxelinux.0 vmlinuz
[root@localhost tftpboot]# mkdir /tftpboot/pxelinux.cfg
[root@localhost tftpboot]#
[root@localhost tftpboot]# cp /media/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
[root@localhost tftpboot]#
第三步,配置NFS共享,使系统安装时能找到安装源
[root@localhost /]# mkdir -p /data/iso/rhel5.9
[root@localhost /]# cp -rf /misc/cd/* /data/iso/rhel5.9/
[root@localhost /]# cat /etc/exports
/data/iso/rhel5.9 *(ro)
[root@localhost /]# service portmap restart
停止 portmap: [确定]
启动 portmap: [确定]
[root@localhost /]# chkconfig portmap on
[root@localhost /]# service nfs restart
关闭 NFS mountd: [失败]
关闭 NFS 守护进程: [失败]
关闭 NFS quotas: [失败]
启动 NFS 服务: [确定]
关掉 NFS 配额: [确定]
启动 NFS 守护进程: [确定]
启动 NFS mountd: [确定]
Stopping RPC idmapd: [确定]
正在启动 RPC idmapd: [确定]
[root@localhost /]# chkconfig nfs on
[root@localhost /]#
第四步,配置DNS(可选)
[root@localhost /]# rpm -q bind bind-chroot caching-nameserver
bind-9.3.6-20.P1.el5_8.5
bind-chroot-9.3.6-20.P1.el5_8.5
package caching-nameserver is not installed
[root@localhost /]#
[root@localhost /]#
[root@localhost /]# yum -y install caching-nameserver
[root@localhost /]# rpm -q bind bind-chroot caching-nameserver
bind-9.3.6-20.P1.el5_8.5
bind-chroot-9.3.6-20.P1.el5_8.5
caching-nameserver-9.3.6-20.P1.el5_8.5
[root@localhost /]#
[root@localhost /]# cd /var/named/chroot/etc/
[root@localhost etc]# cp -p named.caching-nameserver.conf named.conf
[root@localhost etc]#
[root@localhost etc]# diff named.caching-nameserver.conf named.conf
15c15
< listen-on port 53 { 127.0.0.1; };
---
> listen-on port 53 { 192.168.100.11; };
27,28c27,28
< allow-query { localhost; };
< allow-query-cache { localhost; };
---
> allow-query { any; };
> allow-query-cache { any; };
37,38c37,38
< match-clients { localhost; };
< match-destinations { localhost; };
---
> match-clients { any; };
> match-destinations { any; };
[root@localhost etc]#
[root@localhost named]# cat candy.com.zone
$TTL 86400
@ IN SOA candy.com. root.candy.com. (
2014092201 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS dns1.candy.com.
dns1 IN A 192.168.100.11
$GENERATE 20-30 station$ IN A 192.168.100.$
[root@localhost named]#
[root@localhost named]# cat candy.com.arpa
$TTL 86400
@ IN SOA candy.com. root.candy.com. (
2014092201 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS dns1.candy.com.
11 IN PTR dns1.candy.com.
$GENERATE 20-30 $ IN PTR station$.candy.com.
[root@localhost named]#
[root@localhost named]# /etc/init.d/named restart
停止 named: [确定]
启动 named: [确定]
[root@localhost named]# chkconfig named on
[root@localhost named]#
[root@localhost named]# host station21.candy.com 192.168.100.11
Using domain server:
Name: 192.168.100.11
Address: 192.168.100.11#53
Aliases:
station21.candy.com has address 192.168.100.21
[root@localhost named]#
[root@localhost named]#
[root@localhost named]# host 192.168.100.30 192.168.100.11
Using domain server:
Name: 192.168.100.11
Address: 192.168.100.11#53
Aliases:
30.100.168.192.in-addr.arpa domain name pointer station30.candy.com.
[root@localhost named]#
第五步,配置kickstart,实现无人值守安装
配置yum库的时候配置文件中的标题要以rhel开头,否则无法读取软件包
[root@localhost /]# yum -y install system-config-kickstart
[root@localhost ~]# system-config-kickstart
配置完成生产ks.cfg文件
利用http访问文件
[root@localhost ~]# ls /var/www/html/ks.cfg
/var/www/html/ks.cfg
[root@localhost ~]#
添加一下语句,是自动安装过程中跳过输入cdkey的步骤
[root@localhost ~]# vi /var/www/html/ks.cfg
key --skip
[root@localhost ~]# /etc/init.d/httpd restart
停止 httpd: [确定]
启动 httpd: [确定]
[root@localhost ~]#
修改以下文件,在安装过程中能过读取到ks.cfg文件
[root@localhost ~]# vi /tftpboot/pxelinux.cfg/default
append ks=http://192.168.100.11/ks.cfg initrd=initrd.img
[root@localhost ~]#
第六步,在新安装的机器上安装http,并进行配置
在pxe服务器上新建html文件,然后拷贝到新安装的服务器上
[root@localhost ~]# cat /var/www/html/index.html
<html><title> 2014-09-23 </title>
<head><h1> 201409231400 </h1></head>
<body></body>
</html>
[root@localhost ~]#
[root@localhost ~]# scp /var/www/html/index.html 192.168.100.21:/var/www/html/index.html
[root@localhost ~]#
两台服务器都设置相同的名字
[root@localhost ~]# grep ServerName /etc/httpd/conf/httpd.conf
ServerName www.candy.com:80
[root@localhost ~]#
[root@station30 /]# grep ServerName /etc/httpd/conf/httpd.conf
ServerName www.candy.com:80
[root@station30 /]#
第七步,设置从DNS服务器
修改主DNS的主配置文件,添加授权信息,只允许从DNS服务器更新
[root@localhost ~]# vi /var/named/chroot/etc/named.conf
allow-transfer { 192.168.100.21; };
[root@localhost ~]#
修改zone文件,添加从dns服务器的域名解析,和http服务器的域名解析
[root@localhost ~]# cat /var/named/chroot/var/named/candy.com.zone
$TTL 86400
@ IN SOA candy.com. root.candy.com. (
2014092302 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS dns1.candy.com.
IN NS dns2.candy.com.
dns1 IN A 192.168.100.11
dns2 IN A 192.168.100.21
www IN A 192.168.100.11
IN A 192.168.100.21
[root@localhost ~]#
[root@localhost ~]# cat /var/named/chroot/var/named/candy.com.arpa
$TTL 86400
@ IN SOA candy.com. root.candy.com. (
2014092301 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS dns1.candy.com.
IN NS dns2.candy.com.
11 IN PTR dns1.candy.com.
12 IN PTR dns2.candy.com.
[root@localhost ~]#
配置从dns服务器,添加如下配置
[root@station30 /]# tail -10 /var/named/chroot/etc/named.rfc1912.zones
zone "candy.com" IN {
type slave;
file "slaves/candy.com.zero";
masters { 192.168.100.11; };
};
zone "100.168.192.in-addr.arpa" IN {
type slave;
file "slaves/candy.com.arpa";
masters { 192.168.100.11; };
};
[root@station30 /]#
重启服务后,自动生成zone文件
[root@station30 /]# /etc/init.d/named restart
停止 named: [确定]
启动 named: [确定]
[root@station30 /]# ls /var/named/chroot/var/named/slaves/
candy.com.arpa candy.com.zero
[root@station30 /]#