# 登入ROOT
su -
# 關閉開機後預設打開selinux
vim /etc/sysconfig/selinux
====
SELINUX=disabled
====
# 目前關閉selinux(開機後恢復)
setenforce 0
# 安裝網絡工具 etc:ifconfig
yum install net-tools wget
# 安裝dhcp服務
# 主要用來分配IP,合指向pxe的server地址
yum install dhcp
mv /etc/dhcp/dhcpd.conf /etc/dhcpd.conf.bak
vim /etc/dhcp/dhcpd.conf
===
ddns-update-style interim;
ignore client-updates;
subnet 10.0.2.0 netmask 255.255.255.0 {
# option routers 192.168.1.1;
# option subnet-mask 255.255.255.0;
option domain-name-servers 10.0.2.254;
range dynamic-bootp 10.0.2.11 10.0.2.100;
default-lease-time 21600;
max-lease-time 43200;
}
filename "pxelinux.0";
next-server 10.0.2.254; #NFS服务器地址
===
#解釋一下其中几行,“subnet”和“netmask”根据你自己的网络环境来配置;“option routers”和“option domain-name-servers”这两个是路由器和DNS地址,可以不用配置,我配置了是因为我所在单位的其它计算机有可能会从这里获得IP,而不是从路由器获得,为了不影响他们正常上网才配置的;“range dynamic-bootp”这个是IP地址分配池,不要跟路由器的分配池重叠了
systemctl start dhcpd #必須在設定檔規定的網域才能打開,然後本機自己設固定ip
systemctl enable dhcpd
yum install tftp-server xinetd
#TFTP 其實是由 xinetd 這個 super daemon 所管理的,因此設定好 TFTP 之後, 你要啟動的是 xinetd 才對喔!
vim /etc/xinetd.d/tftp
# 鳥哥是將所有的資料統一放置於 /install/ 目錄下的!那這個 TFTP 的根目錄我們就將他放置於 /install/tftpboot 底下囉!
# =============
# server_args = -s /install/tftpboot <== 重點在這裡!
# disable = no <==必須改
# =============
mkdir -p /install/tftpboot
# 給予ftp使用者權限(必要)
chcon --reference /var/lib/tftpboot /install/tftpboot
systemctl start xinetd
systemctl enable xinetd
systemctl enable tftp
# 給予tftp權限,這也是必要的
firewall-cmd --permanent --add-service=tftp
# 重開防火牆
firewall-cmd --reload
yum install syslinux <==底下的檔案是由這軟體所提供!
cp /usr/share/syslinux/menu.c32 /usr/share/syslinux/vesamenu.c32 /usr/share/syslinux/pxelinux.0 /install/tftpboot/
mkdir /install/tftpboot/pxelinux.cfg
ll /install/tftpboot/
====
-rw-r--r--. 1 root root 60928 2013-04-02 18:10 menu.c32 <==提供類選單模式的功能
-rw-r--r--. 1 root root 26828 2013-04-02 18:10 pxelinux.0 <==就是開機管理程式!
drwxr-xr-x. 2 root root 4096 2013-04-02 18:11 pxelinux.cfg <==開機的選單設定在這裡!
-rw-r--r--. 1 root root 162860 2013-04-02 18:41 vesamenu.c32 <==圖形化介面選單
====
mkdir /install/iso
cd /install/iso
wget http://ftp.ksu.edu.tw/pub/CentOS/7/isos/x86_64/CentOS-7-x86_64-Minimal-1611.iso
# 將iso暫時掛載在 /mnt 底下來抓資料用:(我們需要安裝 Linux 系統,所以得要從原版光碟裡面將核心檔案撈出來~)
mount -o loop /install/iso/CentOS-7-x86_64-Minimal-1611.iso /mnt
mkdir -p /install/tftpboot/kernel/centos7
cp -fr /mnt/* /install/tftpboot/kernel/centos7
#cp /mnt/isolinux/vmlinuz /install/tftpboot/kernel/centos7/
#cp /mnt/isolinux/initrd.img /install/tftpboot/kernel/centos7/
cp /mnt/isolinux/isolinux.cfg /install/tftpboot/pxelinux.cfg/demo
umount /mnt
#centos7 不能直接使用kernel安裝,因此需要一個service放iso檔
yum install httpd
systemctl start httpd
systemctl enable httpd
vim /etc/httpd/conf.d/pxeboot.conf
===
Alias /centos7 /install/tftpboot/kernel/centos7
<Directory /install/tftpboot/kernel/centos7>
Options Indexes FollowSymLinks
Require all granted
Allow from 127.0.0.1 10.0.2.0/24
</Directory>
===
systemctl restart httpd
# 給予http權限,這也是必要的
firewall-cmd --permanent --add-service=http
# 重開防火牆
firewall-cmd --reload
vim /install/tftpboot/pxelinux.cfg/default
===
UI vesamenu.c32 <== 使用 vesamenu.c32 這個類圖形的介面程式
TIMEOUT 300 <== 單位 0.1 秒,所以這個設定可等待 30 秒來進入預設開機
DISPLAY ./boot.msg <== 提供一些額外的資訊,讓使用者更瞭解選單意義!
MENU TITLE Welcome to CHOON's PXE Server System
<== 上面這行只是提供一個大標題而已!
LABEL local <== 第一個選單的項目
MENU LABEL Boot from local drive
MENU DEFAULT <== 此選單為預設項目 (等待逾時就進入此開機)
localboot 0 <== 本機磁碟開機的特定項目!
LABEL network1
MENU LABEL Boot from PXE Server for Install CentOS 7
kernel ./kernel/centos7/images/pxeboot/vmlinuz <== 核心所在的檔名
append initrd=./kernel/centos7/images/pxeboot/initrd.img method=http://10.0.2.254/centos7 devfs=nomount <== 就是核心外帶參數啊!和iso裡檔案鏈接
# 上述設定中,大寫的文件部分要特別注意!那是使用 vesamenu.c32 的關鍵字!
# 至於後面的部分,那就是每個設定項目的內容囉!
===
vim /install/tftpboot/boot.msg
===
Welcome to CHOON's PXE Server System.
The 1st menu can let you system goto hard disk menu.
The 2nd menu can goto interactive installation step.
===
# 假如需要ftp的服務可以使用以下方式開通,帳號密碼是linux user
ftp: 使用自己的帳號登入
yum install vsftpd
systemctl enable vsftpd
systemctl start vsftpd
firewall-cmd --permanent --add-service=ftp
firewall-cmd --reload
#參考來源
#http://linux.vbird.org/linux_enterprise/0120installation.php#pxe_dhcp
#http://tototo.blog.51cto.com/4567634/878509