centos安裝PXE(無人值守安裝)服務器

我是用http協議傳送安裝源給客戶機(我服務器的ip是192.168.10.103)

下面的centos6不能安裝,在這裏就是做比較,當然,用centos7不同版本也可以比較

這裏上傳的鏡像都是完整版的,如果不想安裝帶桌面的,也可以上傳centos7minimal版的,比較小點,步驟是一樣的,kickstart文件只需要寫最小安裝的就行

我這裏自動安裝的centos7客戶端的登錄名是root   密碼是yegoo@123

安裝必要服務

DHCP服務器

TFTP服務器

Kickstart HTTP

1.安裝服務

yum -y install httpd xinetd syslinux tftp-server system-config-kickstart dhcp

2.創建存放iso的目錄

mkdir -p /tmp/iso

3.將iso文件上傳到/tmp/iso(這裏我用Windows自帶的cmd上傳,以前的文章有介紹cmd傳文件的)

我的iso文件在E盤的鏡像\centos\

進入裏面

cd /d e:\鏡像\centos\

上傳

pscp CentOS-7-x86_64-DVD-1810.iso [email protected]:/tmp/iso

4.在/var/www/html創建掛載點和ks目錄

mkdir -p /var/www/html/centos{6,7}

mkdir -p /var/www/html/ks

5.掛載光盤

mount -o loop /tmp/iso/CentOS-6.10-x86_64-bin-DVD1.iso /var/www/html/centos6/

mount -o loop /tmp/iso/CentOS-7-x86_64-DVD-1810.iso /var/www/html/centos7/

這是臨時掛載   也可以開機自動掛載(寫fstab文件,我寫後會出錯,這裏不寫了   )

6.創建 /var/lib/tftpboot/pxelinux.cfg

mkdir /var/lib/tftpboot/pxelinux.cfg

創建/var/lib/tftpboot/centos{6,7}

mkdir -p /var/lib/tftpboot/centos{6,7}

7.拷貝文件

cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

下面兩個是通用的,6的和7的都一樣

cp /var/www/html/centos7/isolinux/vesamenu.c32 /var/lib/tftpboot/

cp /var/www/html/centos7/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

下面的就不一樣了

cp /var/www/html/centos6/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos6/

cp /var/www/html/centos7/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos7/

8.修改default

vim /var/lib/tftpboot/pxelinux.cfg/default

default vesamenu.c32
timeout 600

display boot.msg

# Clear the screen when exiting the menu, instead of leaving the menu displayed.
# For vesamenu, this means the graphical background is still displayed without
# the menu itself for as long as the screen remains in graphics mode.

label 1
  menu label ^Install CentOS 6-GUI
  menu default
  kernel centos6/vmlinuz
  append initrd=centos6/initrd.img text ks=http://192.168.10.103/ks/6.cfg

label 2
  menu label ^Install CentOS 6-minimal
  menu default
  kernel centos6/vmlinuz
  append initrd=centos6/initrd.img text ks=http://192.168.10.103/ks/6-minimal.cfg

label 3
  menu label ^Install CentOS 7-GUI
  menu default
  kernel centos7/vmlinuz
  append initrd=centos7/initrd.img text ks=http://192.168.10.103/ks/7.cfg

label 4
  menu label ^Install CentOS 7-minimal
  menu default
  kernel centos7/vmlinuz
  append initrd=centos7/initrd.img text ks=http://192.168.10.103/ks/7-minimal.cfg

9.配置kickstart文件

cd /var/www/html/ks/

下面是centos6的完全安裝

vim 6.cfg

  

   # version=DEVEL
   # X Window System configuration information
   xconfig  --startxonboot
   # License agreement
   eula --agreed
   # System authorization information
   auth --enableshadow --passalgo=sha512
   # Use CDROM installation media
   cdrom
   # Use network installation
   url --url="http://192.168.10.103/centos6"
   # Use graphical install
   graphical
   # Run the Setup Agent on first boot
   firstboot --enable
   # System services
   services --enabled="chronyd"
   # Keyboard layouts
   keyboard --vckeymap=us --xlayouts='us'
   # System language
   lang en_US.UTF-8

   ignoredisk --only-use=sda

   # Root password
   rootpw --iscrypted $6$QmzXBTCUJU1ANz4F$KKI3NS400dVdUL1PkQDumqUPLbq8wfyULZ0m0Mx7/C3l1.d8a8Moq6sTNP2Qfjgc.DydeHhQHlzscvaZerZk1.
   # System timezone
   timezone Asia/Shanghai --isUtc
   # System bootloader configuration
   bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
   autopart --type=lvm
   # Partition clearing information
   clearpart --none --initlabel

   %packages
   @^graphical-server-environment
   @base
   @desktop-debugging
   @dial-up
   @fonts
   @gnome-desktop
   @guest-agents
   @guest-desktop-agents
   @hardware-monitoring
   @input-methods
   @internet-browser
   @multimedia
   @print-client
   @x11
   chrony
   kexec-tools
   %end

   %addon com_redhat_kdump --enable --reserve-mb=auto
   %end

   %anaconda
   pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
   pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
   pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
   %end

下面是centos6的最小安裝

vim 6-minimal.cfg

   # version=DEVEL
   # X Window System configuration information
   xconfig  --startxonboot
   # License agreement
   eula --agreed
   # System authorization information
   auth --enableshadow --passalgo=sha512
   # Use CDROM installation media
   cdrom
   # Use network installation
   url --url="http://192.168.10.103/centos6"
   # Use graphical install
   graphical
   # Run the Setup Agent on first boot
   firstboot --enable
   # System services
   services --enabled="chronyd"
   # Keyboard layouts
   keyboard --vckeymap=us --xlayouts='us'
   # System language
   lang en_US.UTF-8

ignoredisk --only-use=sda

# Root password
   rootpw --iscrypted $6$QmzXBTCUJU1ANz4F$KKI3NS400dVdUL1PkQDumqUPLbq8wfyULZ0m0Mx7/C3l1.d8a8Moq6sTNP2Qfjgc.DydeHhQHlzscvaZerZk1.
   # System timezone
   timezone Asia/Shanghai --isUtc
   # System bootloader configuration
   bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
   autopart --type=lvm
   # Partition clearing information
   clearpart --none --initlabel

%packages
   @^minimal
   %end

%addon com_redhat_kdump --enable --reserve-mb=auto
   %end

%anaconda
   pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
   pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
   pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
   %end

下面是centos7的完全安裝

vim 7.cfg

   # version=DEVEL
   # X Window System configuration information
   xconfig  --startxonboot
   # License agreement
   eula --agreed
   # System authorization information
   auth --enableshadow --passalgo=sha512
   # Use CDROM installation media
   cdrom
   # Use network installation
   url --url="http://192.168.10.103/centos7"
   # Use graphical install
   graphical
   # Run the Setup Agent on first boot
   firstboot --enable
   # System services
   services --enabled="chronyd"
   # Keyboard layouts
   keyboard --vckeymap=us --xlayouts='us'
   # System language
   lang en_US.UTF-8

   ignoredisk --only-use=sda

   # Root password
   rootpw --iscrypted $6$QmzXBTCUJU1ANz4F$KKI3NS400dVdUL1PkQDumqUPLbq8wfyULZ0m0Mx7/C3l1.d8a8Moq6sTNP2Qfjgc.DydeHhQHlzscvaZerZk1.
   # System timezone
   timezone Asia/Shanghai --isUtc
   # System bootloader configuration
   bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
   autopart --type=lvm
   # Partition clearing information
   clearpart --none --initlabel

   %packages
   @^graphical-server-environment
   @base
   @desktop-debugging
   @dial-up
   @fonts
   @gnome-desktop
   @guest-agents
   @guest-desktop-agents
   @hardware-monitoring
   @input-methods
   @internet-browser
   @multimedia
   @print-client
   @x11
   chrony
   kexec-tools
   %end

   %addon com_redhat_kdump --enable --reserve-mb=auto
   %end

   %anaconda
   pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
   pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
   pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
   %end

下面是centos7的最小安裝

vim 7-minimal.cfg

   # version=DEVEL
   # X Window System configuration information
   xconfig  --startxonboot
   # License agreement
   eula --agreed
   # System authorization information
   auth --enableshadow --passalgo=sha512
   # Use CDROM installation media
   cdrom
   # Use network installation
   url --url="http://192.168.10.103/centos7"
   # Use graphical install
   graphical
   # Run the Setup Agent on first boot
   firstboot --enable
   # System services
   services --enabled="chronyd"
   # Keyboard layouts
   keyboard --vckeymap=us --xlayouts='us'
   # System language
   lang en_US.UTF-8

ignoredisk --only-use=sda

# Root password
   rootpw --iscrypted $6$QmzXBTCUJU1ANz4F$KKI3NS400dVdUL1PkQDumqUPLbq8wfyULZ0m0Mx7/C3l1.d8a8Moq6sTNP2Qfjgc.DydeHhQHlzscvaZerZk1.
   # System timezone
   timezone Asia/Shanghai --isUtc
   # System bootloader configuration
   bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
   autopart --type=lvm
   # Partition clearing information
   clearpart --none --initlabel

%packages
   @^minimal
   %end

%addon com_redhat_kdump --enable --reserve-mb=auto
   %end

%anaconda
   pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
   pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
   pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
   %end

10.配置dhcp

cd /etc/dhcp/

如果裏面有dhcpd.conf ,就刪除或改名字

然後複製示例的文件複製裏面

cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

內容如下(47行---57行)

subnet 192.168.10.0 netmask 255.255.255.0 {
  range 192.168.10.2 192.168.10.254;
  option domain-name-servers 192.168.10.103;
  option domain-name "PXEserver";
  option routers 192.168.10.1;
  option broadcast-address 192.168.10.255;
  next-server 192.168.10.103;
  default-lease-time 600;
  max-lease-time 7200;
  filename "pxelinux.0";
}

11.啓動服務

systemctl restart httpd
systemctl enable httpd
systemctl restart xinetd
systemctl enable xinetd
systemctl restart dhcpd
systemctl enable dhcpd

12.關閉防火牆與selinux

systemctl stop firewalld.service

systemctl disable firewalld.service

vim /etc/sysconfig/selinux

把SELINUX=enforcing改爲SELINUX=disabled

source /etc/sysconfig/selinux

13.檢查PXE Server的狀態

service dhcpd status   

service tftp status

service httpd status

以上三者結果都應該爲active(running)

如果關機後在開機  或重啓服務器了  就看看掛載和狀態

當你客戶機選擇網絡安裝是,會出下圖

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章