1、基礎網絡建設與搭建DHCP服務
1)配置靜態IP地址並重起網卡
cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=static IPADDR=10.0.0.4 NETMASK=255.255.255.0 GATEWAY=10.0.0.2 /etc/init.d/network restart ifconfig eth0
2)安裝配置DHCP服務
yum -y install dhcp vim /etc/dhcp/dhcpd.conf default-lease-time 600; max-lease-time 7200; ddns-update-style none; option domain-name-servers 202.106.0.20; #DNS地址可配置2個用逗號分隔 ignore client-updates; subnet 10.0.0.0 netmask 255.255.255.0 { range 10.0.0.100 10.0.0.150; #宣告獲取地址段 option subnet-mask 255.255.255.0; #子網 option routers 10.0.0.2; #獲取網關地址 next-server 10.0.0.4; #重點配置PEX地址 filename "pxelinux.0"; #內核文件名
#配置開機自啟動
chkconfig --add dhcpd
chkconfig dhcpd on
chkconfig --list dhcpd
#查看DHCP監聽端口好UDP 67
netstat -lntup|grep 67
2、搭建TFTP服務
yum -y install tftp-server tftp
vim /etc/xinetd.d/tftp #配置TFTP配置文件: service tftp { socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /tftpboot #修改TFTP服務目錄 disable = no #修改為no,啟動TFTP per_source = 11 cps = 100 2 flags = IPv4 }
#配置自啟動
chkconfig tftp on
chkconfig --list tftp
chkconfig --list xinetd
#重啟動xinetd服務,TFTP是由xinetd服務運行的
/etc/init.d/xinetd restart
netstat -lntup|grep 69 ;netstat -a|grep tftp
udp 0 0 0.0.0.0:69 0.0.0.0:* 1877/xinetd
udp 0 0 *:tftp
#TFTP端口號為UDP的69
#測試下載
mkdir /tftpboot
cd /tftpboot/
touch test.txt
ls
test.txt
cd ..
tftp 10.0.0.4 -c get test.txt
ls #下載成功!
test.txt
3、搭建HTTP服務
yum -y install httpd
#配置自啟動
chkconfig --add httpd
chkconfig httpd on
chkconfig --list httpd
#啟動http服務
/etc/init.d/httpd start
netstat -lntup|grep 80
#使用瀏覽器測試
http://10.0.0.4
4、組建PXE服務環境
1)安裝syslinux包
yum -y install syslinux
#如不安裝syslinux包就沒有pxelinux.0文件
find / -type f -name "pxelinux.0"
/usr/share/syslinux/pxelinux.0
#將pxelinux.0拷貝到tftp服務目錄
cp /usr/share/syslinux/pxelinux.0 /tftpboot/
#在tftp服務目錄下創建pxelinux.cfg目錄
mkdir /tftpboot/pxelinux.cfg -p
2)掛載linux系統盤,拷貝linux內核,初始化鏡像文件
mkdir -p /media/cdrom
mount -t iso9660 -o loop /dev/sr0 /media/cdrom
cd /media/cdrom/images/pxeboot
cp vmlinuz initrd.img /tftpboot/
cd /tftpboot/
ls
initrd.img pxelinux.0 pxelinux.cfg vmlinuz
#配置啟動菜單文件,將系統自帶的啟動文件拷貝到TFTP目錄下改名為
cp /media/cdrom/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
#修改啟動菜單文件
cat default default auto #指定默認啟動項 prompt 0 #為0時不選擇自動按默認安裝,為1時可選擇選項安裝 label auto #配置選項auto kernel vmlinuz #指定內核 append initrd=initrd.img ks=http://10.0.0.4/ks.cfg devfs=nomount ramdisk_size=8192 #指定自動安裝文件ks.cfg label linux text kernel vmlinuz append initrd=initrd.img devfs=nomount ramdisk_size=8192 label rescue kernel vmlinuz append initrd=initrd.img rescue #重啟動TFTP服務加載配置 /etc/init.d/xinetd restart
5、創建kickstart文件
1)安裝system-config-kickstart
yum -y install system-config-kickstart
#注意安裝桌面服務才能啟動KICKSTART,創建啟動文件
/usr/bin/system-config-kickstart
cat ks.cfg #platform=x86, AMD64, or Intel EM64T #version=DEVEL # Firewall configuration關閉防火牆 firewall --disabled # Install OS instead of upgrade 安裝系統 install # Use network installation 使用網絡安裝,這里配置http獲取安裝包 url --url="http://192.168.146.128/" key --skip # Root password 配置ROOT密碼 rootpw --iscrypted $1$jIsDXG2F$EGT.VAhEBlZ/ww9GNOTo7. # System authorization information 系統授權信息 auth --useshadow --passalgo=md5 # Use graphical install 圖形安裝 graphical # System keyboard 配置鍵盤 keyboard us # System language 配置系統語言 lang en_US # SELinux configuration 關閉selinux selinux --disabled # Do not configure the X Window System 不安裝圖形界面 skipx # Installation logging level 安裝系統日志記錄級別 logging --level=info # Reboot after installation 安裝完重新引導 reboot # System timezone #配置時區 timezone Asia/Shanghai # Network information 配置網絡為自動獲取 network --bootproto=dhcp --device=eth0 --onboot=on # System bootloader configuration 系統引導程序配置 bootloader --location=mbr # Clear the Master Boot Record 清除主引導記錄 zerombr # Partition clearing information 分區信息 clearpart --all # Disk partitioning information 指定分區大小 part swap --fstype="swap" --size=2048 part /boot --fstype="ext4" --size=200 part / --fstype="ext4" --grow --size=1 %packages @base @compat-libraries @debugging @development %end
#將應答腳本拷貝到http目錄,並賦予權限
cp ks.cfg /var/www/html/
chown apache.apache /var/www/html/ks.cfg
6、啟動客戶機安裝
注意:客戶機要和服務器在同一個局域網內
如果使用vmware做實驗,需要關閉VMware自帶的DHCP功能
排除思路:
1)客戶機是否獲取IP地址,可查看網絡和DHCP服務
2)查看鏈接TFTP是否正常
如鏈接正常在獲取IP地址后會顯示:
TFTP prefix:
trying to load: pxelinux.cfg/default ok
然后加載內核:
loading vmlinuz........
loading initrd.img.........
3)加載完內核后會鏈接下載安裝系統文件,如tfp,http獲取等