实验:搭建PXE服务器,实现无人值守自动安装系统
在PXE服务器和新安装的服务器上分别安装http实现均衡负载
建立主从DNS服务器
第一步,先配置DHCP,目的是给需要安装系统的主机分配ip地址
服务器IP地址设为192.168.100.11
[[email protected] ~]# ifconfig eth0 | grep "inet addr"
inet addr:192.168.100.11 Bcast:192.168.100.255 Mask:255.255.255.0
[[email protected] ~]#
安装dhcp
[[email protected] ~]# yum -y install dhcp
[[email protected] ~]# rpm -q dhcp
dhcp-3.0.5-31.el5_8.1
[[email protected] ~]#
dhcp配置文件修改成如下
[[email protected] ~]# 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;
}
[[email protected] ~]#
启动dhcp
[[email protected] ~]# service dhcpd restart
关闭 dhcpd: [确定]
启动 dhcpd: [确定]
[[email protected] ~]# chkconfig dhcpd on
[[email protected] ~]#
第二步,配置TFTP服务
tftp默认已安装
[[email protected] ~]# rpm -q tftp
tftp-0.49-2
[[email protected] ~]# rpm -q tftp-server
tftp-server-0.49-2
[[email protected] ~]#
启动xinetd服务
[[email protected] ~]# vi /etc/xinetd.d/tftp
disable = no
[[email protected] ~]# /etc/init.d/xinetd restart
停止 xinetd: [确定]
启动 xinetd: [确定]
[[email protected] ~]# chkconfig xinetd on
[[email protected] ~]#
把内核文件,初始化文件拷贝到tftp目录下
[[email protected] pxeboot]# cp initrd.img vmlinuz /tftpboot/
[[email protected] pxeboot]# pwd
/media/images/pxeboot
[[email protected] pxeboot]# cp /usr/share/syslinux/pxelinux.0 /tftpboot/
[[email protected] pxeboot]#
[[email protected] pxeboot]# cd /tftpboot/
[[email protected] tftpboot]# ls
initrd.img linux-install pxelinux.0 vmlinuz
[[email protected] tftpboot]# mkdir /tftpboot/pxelinux.cfg
[[email protected] tftpboot]#
[[email protected] tftpboot]# cp /media/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
[[email protected] tftpboot]#
第三步,配置NFS共享,使系统安装时能找到安装源
[[email protected] /]# mkdir -p /data/iso/rhel5.9
[[email protected] /]# cp -rf /misc/cd/* /data/iso/rhel5.9/
[[email protected] /]# cat /etc/exports
/data/iso/rhel5.9 *(ro)
[[email protected] /]# service portmap restart
停止 portmap: [确定]
启动 portmap: [确定]
[[email protected] /]# chkconfig portmap on
[[email protected] /]# service nfs restart
关闭 NFS mountd: [失败]
关闭 NFS 守护进程: [失败]
关闭 NFS quotas: [失败]
启动 NFS 服务: [确定]
关掉 NFS 配额: [确定]
启动 NFS 守护进程: [确定]
启动 NFS mountd: [确定]
Stopping RPC idmapd: [确定]
正在启动 RPC idmapd: [确定]
[[email protected] /]# chkconfig nfs on
[[email protected] /]#
第四步,配置DNS(可选)
[[email protected] /]# 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
[[email protected] /]#
[[email protected] /]#
[[email protected] /]# yum -y install caching-nameserver
[[email protected] /]# 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
[r[email protected] /]#
[[email protected] /]# cd /var/named/chroot/etc/
[[email protected] etc]# cp -p named.caching-nameserver.conf named.conf
[[email protected] etc]#
[[email protected] 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; };
[[email protected] etc]#
[[email protected] 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.$
[[email protected] named]#
[[email protected] 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.
[[email protected] named]#
[[email protected] named]# /etc/init.d/named restart
停止 named: [确定]
启动 named: [确定]
[[email protected] named]# chkconfig named on
[[email protected] named]#
[[email protected] 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
[[email protected] named]#
[[email protected] named]#
[[email protected] 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.
[[email protected] named]#
第五步,配置kickstart,实现无人值守安装
配置yum库的时候配置文件中的标题要以rhel开头,否则无法读取软件包
[[email protected] /]# yum -y install system-config-kickstart
[[email protected] ~]# system-config-kickstart
配置完成生产ks.cfg文件
利用http访问文件
[[email protected] ~]# ls /var/www/html/ks.cfg
/var/www/html/ks.cfg
[[email protected] ~]#
添加一下语句,是自动安装过程中跳过输入cdkey的步骤
[[email protected] ~]# vi /var/www/html/ks.cfg
key --skip
[[email protected] ~]# /etc/init.d/httpd restart
停止 httpd: [确定]
启动 httpd: [确定]
[[email protected] ~]#
修改以下文件,在安装过程中能过读取到ks.cfg文件
[[email protected] ~]# vi /tftpboot/pxelinux.cfg/default
append ks=http://192.168.100.11/ks.cfg initrd=initrd.img
[[email protected] ~]#
第六步,在新安装的机器上安装http,并进行配置
在pxe服务器上新建html文件,然后拷贝到新安装的服务器上
[[email protected] ~]# cat /var/www/html/index.html
<html><title> 2014-09-23 </title>
<head><h1> 201409231400 </h1></head>
<body></body>
</html>
[[email protected] ~]#
[[email protected] ~]# scp /var/www/html/index.html 192.168.100.21:/var/www/html/index.html
[[email protected] ~]#
两台服务器都设置相同的名字
[[email protected] ~]# grep ServerName /etc/httpd/conf/httpd.conf
ServerName www.candy.com:80
[[email protected] ~]#
[[email protected] /]# grep ServerName /etc/httpd/conf/httpd.conf
ServerName www.candy.com:80
[[email protected] /]#
第七步,设置从DNS服务器
修改主DNS的主配置文件,添加授权信息,只允许从DNS服务器更新
[[email protected] ~]# vi /var/named/chroot/etc/named.conf
allow-transfer { 192.168.100.21; };
[[email protected] ~]#
修改zone文件,添加从dns服务器的域名解析,和http服务器的域名解析
[[email protected] ~]# 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
[[email protected] ~]#
[[email protected] ~]# 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.
[[email protected] ~]#
配置从dns服务器,添加如下配置
[[email protected] /]# 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; };
};
[[email protected] /]#
重启服务后,自动生成zone文件
[[email protected] /]# /etc/init.d/named restart
停止 named: [确定]
启动 named: [确定]
[[email protected] /]# ls /var/named/chroot/var/named/slaves/
candy.com.arpa candy.com.zero
[[email protected] /]#