Cobbler批量部署安裝Linux系統


一:系統安裝過程

1.1運維自動化發展歷程及技術應用

 

 

PXE介紹

 1)Preboot Excution Environment 預啟動執行環境
 2)Intel公司研發
 3)基於Client/Server的網絡模式,支持遠程主機通過網絡從遠端服務器下載映像,並由此支持通過網絡啟動操作系統
 4)PXE可以引導和安裝Windows,linux等多種操作系統

PXE工作原理

  • Client向PXE Server上的DHCP發送IP地址請求消息,DHCP檢測Client是否合法(主要是檢測Client的網卡MAC地址),如果合法則返回Client的IP地址,同時將啟動文件pxelinux.0的位置信息一並傳送給Client

  • Client向PXE Server上的TFTP發送獲取pxelinux.0請求消息,TFTP接收到消息之后再向Client發送pxelinux.0大小信息,試探Client是否滿意,當TFTP收到Client發回的同意大小信息之后,正式向Client發送pxelinux.0 Client執行接收到的pxelinux.0文件

  • Client向TFTP Server發送針對本機的配置信息文件(在TFTP 服務的pxelinux.cfg目錄下),TFTP將配置文件發回Client,繼而Client根據配置文件執行后續操作。

  • Client向TFTP發送Linux內核請求信息,TFTP接收到消息之后將內核文件發送給Client

  • Client向TFTP發送根文件請求信息,TFTP接收到消息之后返回Linux根文件系統

  • Client啟動Linux內核

  • Client下載安裝源文件,讀取自動化安裝腳本

  •  

     

    操作系統安裝的流程

     1)通用流程:首先,bios啟動,選擇操作系統的啟動(安裝)模式(此時,內存是空白的),然后根據相關的安裝模式,尋找操作系統的引導程序(不同的模式,對應不同的引導程序當然也對應着不同的引導程序存在的位置),引導程序加載文件系統初始化(initrd)程序和內核初始鏡像(vmlinuz),完成操作系統安裝前的初始化;接着,操作系統開始安裝相關的系統和應用程序。
     2)硬盤安裝的流程:bios啟動——MBR尋找grub——grub程序讀取menu.list等配置文件,找到內核啟動鏡像和相關初始化程序,安裝(或者啟動)。
     3)PXE(Pre-boot Execution Environment)是由Intel設計,可以使計算機通過網絡啟動的協議。協議分為client和server兩端,PXE client在網卡的ROM中,當計算機啟動時,BIOS把PXE client調入內存執行,並顯示出命令菜單,經用戶選擇后,PXE client將放置在遠端的操作系統通過網絡下載到本地運行。
     4)pxe網絡安裝的流程:bios啟動——pxe client中的程序進入內存,顯示命令菜單——此程序開始尋找網絡引導程序(bootstrap文件,這個文件的名字隨着發行版的不同而不同,在centos中,它是pxelinux.0)——引導程序讀取配置文件pxelinux.cfg,
     獲得系統初始化的相關文件信息——系統啟動,開始進行安裝。

    PXE自動化安裝CentOS 7

    實驗:基於centos7的PXE自動化安裝centos7,6

    環境:

    兩台主機

    一台PXE,DHCP,HTTPD,TFTP服務器(一個網卡,一個主機),一台測試機(一個網卡,僅主機)

    1.yum install httpd tftp-server dhcp syslinux

    systemctl start httpd tftp

    2.准備yum源

    mkdir /var/www/html/centos{6,7}/os/x86_64 -pv
    mount /dev/sr0 /var/www/html/centos/7/os/x86_64/
    mount /dev/sr1 /var/www/html/centos/6/os/x86_64/
    mkdir /var/www/html/ksdir
    

    安裝前准備:關閉防火牆和SELINUX,DHCP服務器靜態IP

    安裝軟件包

     yum install tftp-server -y# 安裝服務端TFTP包
     yum install dhcp   -y     # 安裝dhcp
     yum install  http  -y     # 安裝http
    

    centos7啟動tftp服務:

     [root@centos7~]#systemctl start tftp     # 啟動tftp
     [root@centos7~]#systemctl enable tftp  
     [root@centos7~]#ss -nultp|grep 69
     users:(("rpc.statd",pid=6655,fd=10))
     udp UNCONN 0 0 :::69                     # tftp默認端口是69
    

    centos6啟動tftp服務:

     [root@centos6~]#chkconfig tftp on      # 啟動tftp,下次默認開機啟動
     [root@centos6~]#service xinetd start
     Starting xinetd:
    

    TFTP從服務器上上傳下載文件功能,下載時需要知道對方的文件名,下載下來的文件會在/var/lib/tftpboot目錄里(tftp獲取文件部分):

     [root@centos6data]#cp /etc/fstab /var/lib/tftpboot/f1  # 將服務器的文件放在/var/lib/tfpboot/目錄下,起名叫f1
     [root@centos6~]#tftp 10.0.0.200   # 通過連接tftp服務在/var/lib/tftpboot/目錄下下載必要的文件
     tftp> status
     tftp> get f1   # 在tftp服務上下載文件
     tftp> q        # 按q可以退出
    

    安裝http服務:

     [root@centos7~]# yum install httpd -y 安裝完http服務后
     [root@centos7~]# systemctl start httpd  啟動http服務
     [root@centos7~]# systemctl enable httpd  啟動http服務,默認下次開啟啟動
    

    創建網頁版yum源 :

     基於httpd服務的yum源倉庫 
    [root@centos7-2 ~]# yum install autofs -y  # 安裝autofs
     [root@centos7-2 ~]# systemctl start autofs  # 啟動autofs
     [root@centos7-2 ~]# systemctl enable autofs  # 下次開機啟動autofs
     [root@centos7-2 yum.repos.d]#mkdir -p /etc/yum.repos.d/bak/
     [root@centos7-2 yum.repos.d]#mv /etc/yum.repos.d/ /etc/yum.repos.d/bak/
     yum repolist
     ls /var/cache/yum/x86_64/7/
     yum clean all
     yum repolist
     ls /var/cache/yum/x86_64/7/
      rm -rf /var/cache/yum/*
     [root@centos7-2 yum.repos.d]#vim base.repo  開始創建yum倉庫
     [base]
     baseurl=http://10.0.0.200/CentOS/$releasever/os/$basearch
     gpgcheck= 0
     enable=1
     [root@centos7-2 yum.repos.d]#yum install httpd -y  安裝httpd服務
     [root@centos7-2 yum.repos.d]#systemctl start httpd  啟動httpd服務
     [root@centos7-2 yum.repos.d]#mkdir -pv  /var/www/html/centos/{6,7}/os/x86_64/ 新建一個類似光盤的路徑目錄
     ###訪問10.0.0.200/centos
     [root@centos7 html]# mount /dev/sr0 /var/www/html/centos/7/os/x86_64/
     mount: /dev/sr0 is write-protected, mounting read-only
     [root@centos7 7]#cd /var/www/html/centos/7
     [root@centos7 7]#rz
     ###訪問10.0.0.200/centos/7  刷新頁面
     [root@centos7~]#mkdir -pv /var/www/html/centos/{6,7}/os/x86_64/  創建一個centos6/7的文件
     [root@centos7html]#mount /dev/sr0  /var/www/html/centos/7/os/x86_64/  將光盤掛載到cnetos7文件夾下
     mount: /dev/sr0 is write-protected, mounting read-only
    將應答文件放到http服務上:
     yum install system-config-kickstart -y
     #默認的配置文件
     cat anaconda-ks.cfg 
     #version=DEVEL
     # System authorization information
     auth --enableshadow --passalgo=sha512
     # Use CDROM installation media
     cdrom
     # Use graphical install
     graphical
     # Run the Setup Agent on first boot
     firstboot --enable
     ignoredisk --only-use=sda
     # Keyboard layouts
     keyboard --vckeymap=us --xlayouts='us'
     # System language
     lang en_US.UTF-8 --addsupport=zh_CN.UTF-8
     # Network information
     network  --bootproto=static --device=ens33 --gateway=10.0.0.2 --ip=10.0.0.200 --nameserver=223.5.5.5 --netmask=255.255.255.0 --ipv6=auto --activate
     network  --hostname=centos7
     # Root password
     rootpw --iscrypted $6$7RQzNtx4jTL6TtKf$PzkdcXkthlpw0vOcJsyrPqCilwHlJdPlREVRT3RoR0SWD/.ut7vIZ3nljWmjYxPttD8ikJlltH5PpqvFt2llI0
     # System services
     services --disabled="chronyd"
     # System timezone
     timezone Asia/Shanghai --isUtc --nontp
     # System bootloader configuration
     bootloader --location=mbr --boot-drive=sda
     # Partition clearing information
     clearpart --none --initlabel
     # Disk partitioning information
     part swap --fstype="swap" --ondisk=sda --size=1024
     part /boot --fstype="xfs" --ondisk=sda --size=200
     part / --fstype="xfs" --ondisk=sda --size=80695
     %packages
     @compat-libraries
     @core
     @debugging
     @development
     @system-admin-tools
     %end
     %addon com_redhat_kdump --disable --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
     [root@centos7~]#mkdir /var/www/html/ksdir   新建了一個應答文件夾
     [root@centos7~]#cp anaconda-ks.cfg /var/www/html/ksdir/ks7_mini.cfg  將現有的家目錄文件anaconda-ks.cfg文件復制到ksdir文件夾下面,起名叫ks7_mini.cfg
     [root@centos7ksdir]#vim ks7_mini.cfg   修改里邊的應答文件信息
     #version=DEVEL
     # Use CDROM installation media
     url --url=http://10.0.0.200/centos/7/os/x86_64/  #將網頁掛載的光盤路徑寫上
     # Use graphical install
     text   #文本格式安裝
     # Run the Setup Agent on first boot
     firstboot --enable
     ignoredisk --only-use=sda
     # Keyboard layouts
     keyboard --vckeymap=us --xlayouts='us'
     # System language
     lang en_US.UTF-8
     # Network information
     network --bootproto=dhcp --device=ens33 --ipv6=auto --activate
     network --hostname=centos7
     # Root password
     rootpw --iscrypted $6$zQd4v6GjKalpnj.h$uutceFNO9vO0H2mJoBQYgpW5iNUrmKNHWulIKrSFfPJtpu4f.llg6rm9veeswxYrFXOpXV5M9MPqMBv/DGjdj.
     # System services
     firewall --disabled  #防火牆關掉
     selinux --disabled   #selinux關掉
     # System timezone
     timezone Asia/Shanghai --isUtc --nontp
     user --name=liu --password=$6$LlHE.xyYU4ZoUsbV$nBtUpJjkXmMa1lQFNoNhOs0AuVaOecBttShTt3wNrUncYh.JLfnBIIfMJtOu0Cnkemt1Wr76sHCEiHrD.yKxE1 --iscrypted --gecos="liu"
     # X Window System configuration information
     # System bootloader configuration
     bootloader --location=mbr --boot-drive=sda
     # Partition clearing information
     clearpart --all --initlabel  #磁盤全部格式化
     zerombr                      #mbr磁盤清空
     reboot                       #安裝完重啟
     # Disk partitioning information
     part /boot --fstype="xfs" --ondisk=sda --size=1024
     part / --fstype="xfs" --ondisk=sda --size=102400
     part swap --fstype="swap" --ondisk=sda --size=3072
     part /data --fstype="xfs" --ondisk=sda --size=51200
     %packages
     @^minimal    
     autofs                           
     %end
     [root@centos7ksdir]#ll
     total 4
     -rw------- 1 root root 1906 Oct 30 20:19 ks7_mini.cfg  #由於應答文件在root模式下有讀權限,需要全部加讀權限
     [root@centos7ksdir]#chmod +r ks7_mini.cfg  #將應答文件加讀權限
     [root@centos7~]#mkdir /var/www/html/ksdir   
     [root@centos7~]#cp anaconda-ks.cfg /var/www/html/ksdir/ks7_mini.cfg  
     [root@centos7ksdir]#vim ks7_mini.cfg   
     #version=DEVEL
     # Use CDROM installation media 
     url --url=http://10.0.0.200/centos/7/os/x86_64/ 
     # Use graphical install
     text  
     # Run the Setup Agent on first boot
     firstboot --enable
     ignoredisk --only-use=sda
     # Keyboard layouts
     keyboard --vckeymap=us --xlayouts='us'
     # System language
     lang en_US.UTF-8
     # Network information
     network --bootproto=dhcp --device=eth0 --ipv6=auto --activate
     network --hostname=centos7
     # Root password
     rootpw --iscrypted 
    $6$7RQzNtx4jTL6TtKf$PzkdcXkthlpw0vOcJsyrPqCilwHlJdPlREVRT3RoR0SWD/.ut7vIZ3nljWmjYxPttD8ikJlltH5PpqvFt2llI0
     # System services
     firewall --disabled  
     selinux --disabled   
     # System timezone
     timezone Asia/Shanghai --isUtc --nontp
     #ssh-keygen
     #ssh-copy-id 127.0.0.1
     #cat /root/.ssh/authorized_keys
     #ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC03UIO8ux8f0h4u1RXwKbUHq+rnhgJqSa/Bid9M9vv/EYzbxwHdDYdF+nqkt1cfxLzZ37HYpi80DREcBcaIWtfS/ZDyrlRQzSqUpBT70VMNvCTxFVWv2dWl8cBENAGyuVtMI8r0m56+ktFoILk/4uMiakAOw9ba8mGzQBhpTx0AnviKplGuaO6de7fmgzaA0awSYCH1Z0Tc7WJwyo7IoBSnENllr1dAGzPTUOrniEMPklEKcAIi4ZLYaDFVl9ErolVGT+eaYtcVqLriv7RcuWB7bo0Vf1zwGoH7gJFHif0LslTOzts4EtxdnK6j1QjSZXBYEroUs7pJYNFbhs/clFz root@centos7  配置圖形界面
     #user --name=liu --password=$6$LlHE.xyYU4ZoUsbV$nBtUpJjkXmMa1lQFNoNhOs0AuVaOecBttShTt3wNrUncYh.JLfnBIIfMJtOu0Cnkemt1Wr76sHCEiHrD.yKxE1 --iscrypted --gecos="liu"
     # X Window System configuration information
     # System bootloader configuration
     bootloader --location=mbr --boot-drive=sda
     # Partition clearing information
     clearpart --all --initlabel  
     zerombr                      
     reboot                      
     # Disk partitioning information
     part /boot --fstype="xfs" --ondisk=sda --size=1024
     part / --fstype="xfs" --ondisk=sda --size=102400
     part swap --fstype="swap" --ondisk=sda --size=3072
     part /data --fstype="xfs" --ondisk=sda --size=51200
     %packages
     @^minimal    
     autofs                        
     %end
     [root@centos7ksdir]#ll
     total 4
     -rw------- 1 root root 1906 Oct 30 20:19 ks7_mini.cfg  
     [root@centos7ksdir]#chmod +r ks7_mini.cfg  
    

    安裝和配置DHCP服務

     [root@centos7~]#yum install dhcp -y  安裝dhcp服務<br>
      [root@centos7~]#vim /etc/dhcp/dhcpd.conf  配置dhcp服務
     # dhcpd.conf
     #
     # Sample configuration file for ISC dhcpd
     #
      
     # option definitions common to all supported networks...
     option domain-name "example.org";
     option domain-name-servers ns1.example.org, ns2.example.org;
      
     default-lease-time 86400;
     max-lease-time 864000;
      
     # Use this to enble / disable dynamic dns updates globally.
     #ddns-update-style none;
      
     # If this DHCP server is the official DHCP server for the local
     # network, the authoritative directive should be uncommented.
     #authoritative;
      
     # Use this to send dhcp log messages to a different log file (you also
     # have to hack syslog.conf to complete the redirection).
     log-facility local7;
      
     # No service will be given on this subnet, but declaring it helps the
     # DHCP server to understand the network topology.
      
     subnet 10.0.0.0 netmask 255.255.255.0 {  聲明當前的IP地址段和子網掩碼
     range 10.0.0.10 10.0.0.200;     設置地址池:192.168.34.10-200
     option routers 10.0.0.1;            設置當前的網關地址
     option domain-name-servers 8.8.8.8;     設置DNS
     next-server 10.0.0.200;             指明引導所在的服務主機的IP地址           
     filename "pxelinux.0";           指明引導文件名稱  
     }
      
     # This is a very basic subnet declaration.
     ​
     [root@centos7~]#systemctl enable dhcpd  配置好dhcp服務后,啟動dhcp服務,默認下次開機啟動
    
     [root@centos7~]#yum install dhcp -y  安裝dhcp服務<br>
      [root@centos7~]#vim /etc/dhcp/dhcpd.conf  配置dhcp服務
     # dhcpd.conf
     #
     # Sample configuration file for ISC dhcpd
     #
      
     # option definitions common to all supported networks...
     option domain-name "example.org";
     option domain-name-servers ns1.example.org, ns2.example.org;
     default-lease-time 86400;
     max-lease-time 864000;
     # Use this to enble / disable dynamic dns updates globally.
     #ddns-update-style none;
     # If this DHCP server is the official DHCP server for the local
     # network, the authoritative directive should be uncommented.
     #authoritative;
     # Use this to send dhcp log messages to a different log file (you also
     # have to hack syslog.conf to complete the redirection).
     log-facility local7;
     # No service will be given on this subnet, but declaring it helps the
     # DHCP server to understand the network topology.
     subnet 10.0.0.0 netmask 255.255.255.0 { 
     range 10.0.0.10 10.0.0.200;     
     option routers 10.0.0.1;          
     option domain-name-servers 114.114.114.114,180.76.76.76;    
     next-server 10.0.0.200;                 
     filename "pxelinux.0";           
     }
     # This is a very basic subnet declaration.
     [root@centos7~]#systemctl enable dhcpd  配置好dhcp服務后,啟動dhcp服務,默認下次開機啟動
    

     


    安裝syslinux 里邊有pxelinux.0包文件**

     [root@centos7~]#yum install syslinux -y  安裝syslinux包

    syslinux配置文件相關的安裝包:

     [root@centos7~]#rpm -ql syslinux
     /usr/share/syslinux/menu.c32   開機啟動的藍色背景
     /usr/share/syslinux/pxelinux.0  pxelinux.0包位置
     [root@centos7~]#mkdir /var/lib/tftpboot/pxelinux.cfg  創建一個pxelinux.cfg相關文件夾
     [root@centos7~]#cp /usr/share/syslinux/{menu.c32,pxelinux.0}  /var/lib/tftpboot   將syslinux下的兩個配置文件放到tftpboot目錄下,其中menu.c32 開機時作為藍色背景。
     [root@centos7~]#cp /misc/cd/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot     將光盤下的內核啟動文件vmlinuz和initrd.img文件放到tftpboot目錄下
     [root@centos7~]#cd /var/lib/tftpboot
     [root@centos7tftpboot]#cp /misc/cd/isolinux/isolinux.cfg  /var/lib/tftpboot/pxelinux.cfg/default   
    將isolinux.cfg文件復制到pxelinux.cfg文件夾下,起名叫default,作為啟動菜單。 [root@centos7tftpboot]#tree 查看已經創建的文件信息,一個文件都不能少 . ├── initrd.img ├── menu.c32 ├── pxelinux.0 ├── pxelinux.cfg │ └── default └── vmlinuz

     

     

    修改pxelinux.cfg下的default配置文件的信息:

     [root@centos7tftpboot]#vim /var/lib/tftpboot/pxelinux.cfg/default   修改配置文件信息
     default menu.c32  開機藍色背景
     timeout 10   超時時長改為10秒
     menu title PXE CentOS 開機顯示的抬頭信息
     label mini      #最小化安裝名稱
     menu label ^Auto Install mini CentOS 7  #自動化安裝名稱
     kernel vmlinuz
     append initrd=initrd.img ks=http://192.168.34.101/ksdir/ks7_mini.cfg   #寫入引導文件路徑
     label desktop   #備用的桌面安裝
     menu label ^Auto Install desktop CentOS 7  #書寫相關備用桌面格式
     kernel vmlinuz
     append initrd=initrd.img ks=http://192.168.34.105/ksdir/ks7_mini.cfg
     label local
     menu default   #默認的本地安裝
     menu label Boot from ^local drive
     localboot 0xffff
    

    在新開一台機器開始安裝系統,將網卡模式設置為僅主機模式,將VMnet1對勾去掉,保證與服務端的網卡在一個網卡上:

     

    開機通過ARP廣播開始尋找同一網卡的配置文件信息,進而找到以上寫入的相關配置文件,實現自動化安裝:

    注意:centos7系統的內存盡量設置1.2G以上,否則會提示內存空間不足,導致無法安裝。

    centos6系統安裝過程:

    准備工作:

    [root@centos6~]#chkconfig tftp on   啟動tftp服務
     [root@centos6~]#service xinetd start
     Starting xinetd:
     [root@centos6~]#service httpd start  啟動http服務
     Starting httpd:
    

    將光盤掛載到網頁上:

     [root@centos6html]#mkdir -pv centos/6/os/x86_64   新建文件夾
     mkdir: created directory `centos'
     mkdir: created directory `centos/6'
     mkdir: created directory `centos/6/os'
     mkdir: created directory `centos/6/os/x86_64'
     [root@centos6html]#mount /dev/sr0 /var/www/html/centos/6/os/x86_64  將新建的文件掛載到網頁上
     mount: block device /dev/sr0 is write-protected, mounting read-only
    

    制作應答文件:

     [root@centos6tftpboot]#cp /root/anaconda-ks.cfg   ks6_mini.cfg   將系統中自帶的文件復制一份到/var/lib/tftpboot目錄下
     [root@centos6tftpboot]#vim ks6_mini.cfg   修改當前的應答文件信息
     url --url=http://192.168.34.105/centos/6/os/x86_64  指定掛載光盤路徑
     lang en_US.UTF-8
     keyboard us
     text   #以文本形式安裝
     reboot  #安裝完重啟
     network --onboot yes --device eth0 --bootproto dhcp --noipv6
     rootpw --iscrypted $6$6pdd/ulLIO5IoQ2u$EKDznPOR19rWTeBjVVTYGay3PbNd3t0v9.Ae.jOsxP9i3T8khOMhDxDwTzfa9E3gqirD7qD3Pw6qK1QKf2pDE0
     firewall --disabled  #關閉防火牆
     authconfig --enableshadow --passalgo=sha512
     selinux --disabled  關閉selinux
     timezone Asia/Shanghai
     bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
     # The following is the partition information you requested
     # Note that any partitions you deleted are not expressed
     # here so unless you clear all partitions first, this is
     # not guaranteed to work
     clearpart --all  #格式化磁盤
     zerombr  #情況mbr分區
      
     part /boot --fstype=ext4 --size=1024    #boot分區
     part / --fstype=ext4 --size=100000      #根分區
     part /data --fstype=ext4 --size=50000    #data分區
     part swap --size=2048   #swap 分區
     %packages
     @core    #只安裝核包
     %end
     [root@centos7tftpboot]#ksvalidator /var/www/html/ksdir/ks7_desktop.cfg   #檢測
     [root@centos7tftpboot]#chmod +r ks6_mini.cfg #因為應答文件只有root有讀權限,將全部屬組都加有讀權限
    

    安裝dhcp服務,並修改相關配置信息:

     [root@centos6~]#yum install dhcp  安裝dhcp服務<br>[root@centos6html]#vim /etc/dhcp/dhcpd.conf  修改dhcp配置信息
     default-lease-time 84600; 申請默認租期
     max-lease-time 86400; 最大申請租期
     # Use this to enble / disable dynamic dns updates globally.
     #ddns-update-style none;
     # If this DHCP server is the official DHCP server for the local
     # network, the authoritative directive should be uncommented.
     #authoritative;
     # Use this to send dhcp log messages to a different log file (you also
     # have to hack syslog.conf to complete the redirection).
     log-facility local7;
     # No service will be given on this subnet, but declaring it helps the
     # DHCP server to understand the network topology.
     subnet 192.168.34.0 netmask 255.255.255.0 {  聲明地址段和子網掩碼
     range 192.168.34.10 192.168.34.200;          設置地址池:192.168.34.10-200
     option domain-name-servers 8.8.8.8;          設置NDS
     next-server 192.168.34.105;                  指明引導服務主機所在的IP地址
     filename "pxelinux.0";                       指明引導的文件名稱
     }<br><br>[root@centos6html]#service dhcpd start 重新啟動dhcp服務
    

    將相關的配置文件放在/var/lib/tftpboot目錄下:

     [root@centos6html]#cd /var/lib/tftpboot
     [root@centos6tftpboot]#mkdir pxelinux.cfg
     [root@centos6tftpboot]#yum install syslinux-nonlinux
     [root@centos6tftpboot]#cp /misc/cd/isolinux/{initrd.img,boot.msg,vmlinuz,splash.jpg,vesamenu.c32} .
     [root@centos6tftpboot]#cp /misc/cd/isolinux//isolinux.cfg  pxelinux.cfg/default
    

    修改當前pxelinux.cfg下面的default配置文件信息:

     [root@centos6tftpboot]#vim pxelinux.cfg/default
     default vesamenu.c32
     #prompt 1
     timeout 100  超時時長修改至10s
     label linux
     menu label ^Auto Install Mini centos 6 system  修改為自動安裝
     menu default
     kernel vmlinuz
     append initrd=initrd.img ks=http://192.168.34.105/ksdir/ks6_mini.cfg  指定當前的應答文件路徑
     label local
     menu default  設置一個默認安裝
     menu label Boot from ^local drive
     localboot 0xffff
    

    至此,相關的配置文件設置完成,打開一個新的虛擬機進行安裝系統,將網卡默認設置成僅主機模式,將vmnet1的DHCP功能關掉,開機后按esc,選擇網卡啟動安裝,開始安裝系統,結束。

  •  

     

     
    選擇網卡啟動,然后按F10保存,就會自動重啟,新裝的主機就會通過廣播獲取DHCP相關的安裝配置信息,就會啟動進行安裝,至此,cnetos6安裝結束。

     

     

    在centos7基於PXE安裝centos6/7系統實驗:(此安裝適用於BIOS模式安裝)

    在centos7上新加一塊ISO鏡像:

  •  

     

    准備工作:

    啟動三個服務:

     [root@centos7tftpboot]#systemctl start dhcpd
     [root@centos7tftpboot]#systemctl start tftp
     [root@centos7tftpboot]#systemctl start httpd
    
     

    掛載光盤:

     [root@centos7~]#mkdir /var/www/html/centos/{6,7}/os/x86_64
     [root@centos7~]#mount /dev/sr0 /var/www/html/centos/7/os/x86_64/
     [root@centos7~]#mount /dev/sr1 /var/www/html/centos/6/os/x86_64/
    

    復制centos7之前制作的應答文件或者( 也可以復制家目錄的anaconda-ks.cfg里的相關應答文件 )和內核啟動文件

     [root@centos7ksdir]#cp /root/anaconda-ks.cfg  ks7_mini.cfg
     [root@centos7ksdir]#scp /root/anaconda-sks.cfg  /var/www/html/ksdir/ks6_mini.cfg   
     將centos6的默認應答文件復制到centos7目錄里,命令為ks6_mini.cfg,然后對其稍加修改即可。
     [root@centos7ksdir]#ll
     total 8
     -rw-r--r-- 1 root root 1400 Oct 31 09:21 ks6_mini.cfg
     -rw-r--r-- 1 root root 1400 Oct 30 20:29 ks7_mini.cfg
     [root@centos7tftpboot]#mkdir linux{6,7}
     [root@centos7tftpboot]#mv vmlinuz initrd.img linux7/ 
    將本地的內核啟動文件復制在新建的linux7下
     [root@centos7tftpboot]#cp /var/www/html/centos/6/os/x86_64/isolinux/{vmlinuz,initrd.img}  linux6/  將掛載的iso光盤的啟動文件復制到新建的linux6下
     [root@centos7tftpboot]#cp /usr/share/syslinux/{menu.c32,pxelinux.0}  
     [root@centos7tftpboot]#cp /misc/cd/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg  將啟動菜單復制到pxelinu.cfg目錄下
     [root@centos7tftpboot]#tree
     .
     ├── linux6
     │   ├── initrd.img
     │   └── vmlinuz
     ├── linux7
     │   ├── initrd.img
     │   └── vmlinuz
     ├── menu.c32
     ├── pxelinux.0
     └── pxelinux.cfg
      └── default  修改此配置文件信息
    

    修改引導文件信息:  

     vim pxelinux.cfg/default
     default menu.c32
     timeout 100
     menu title PXE Insall CentOS
     label mini7
     menu label ^Auto Install mini7 CentOS 7   修改啟動顯示的信息
     kernel linux7/vmlinuz     由於新建了linux7,啟動文件路徑在此目錄下,需要指定啟動文件在linux7下面
     append initrd=linux7/initrd.img ks=http://192.168.34.101/ksdir/ks7_mini.cfg  指定應答文件路徑
     label mini6
     menu label ^Auto Install mini6 CentOS 6   修改顯示的信息
     kernel linux6/vmlinuz      由於新建了一個linux6,啟動文件路徑在此目錄下,因此需要添加linux6路徑指定應答文件
     append initrd=linux6/initrd.img ks=http://192.168.34.101/ksdir/ks6_mini.cfg  指定應答文件路徑
     label local
     menu default
     menu label Boot from ^local drive
     localboot 0xffff
    

    修改centos6的應答文件內容:

     [root@centos7tftpboot]#vim /var/www/html/ksdir/ks6_mini.cfg
     url  --url=http://192.168.34.101/centos/6/os/x86_64  指定centos6光盤掛載路徑
     text  以文本方式安裝
     # System services
     firewall --disabled 防火牆關掉
     selinux --disabled  selinux關掉
     # System timezone
     timezone Asia/Shanghai --isUtc --nontp
     user --name=liu --password=$6$LlHE.xyYU4ZoUsbV$nBtUpJjkXmMa1lQFNoNhOs0AuVaOecBttShTt3wNrUncYh.JLfnBIIfMJtOu0Cnkemt1Wr76sHCEiHrD.yKxE1 --iscrypted --gecos="liu"
     # X Window System configuration information
     #xconfig --startxonboot
     # System bootloader configuration
     bootloader --location=mbr --boot-drive=sda
     # Partition clearing information
     clearpart --all --initlabel  格式化磁盤
     zerombr   清空mbr磁盤
     reboot     重啟
     # Disk partitioning information
     part /boot --fstype="xfs" --ondisk=sda --size=1024
     part / --fstype="xfs" --ondisk=sda --size=102400
     part swap --fstype="swap" --ondisk=sda --size=3072
     part /data --fstype="xfs" --ondisk=sda --size=51200
      
      
     %post
     mkdir /etc/yum.repos.d/bak
     mv /etc/yum.repos.d/*.repo  /etc/yum.repos.d/bak
     cat > /etc/yum.repos.d/base.repo << EOF
     [base]
     basurl=http://192.168.34.100/centos/6/os/x86_64
     gpgckeck=0
     EOF
     useradd wang
     echo centos |passwd --stdin wang
        
     mkdir /root/.ssh   生產公鑰腳本
     cat > /root/.ssh/authorized.keys << EOF  將已經安裝好的centos6的id_rsa.pub公鑰信息寫入。
     ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA5hEv1/BQLBftA/tK5h+cF+zop59zMlpsMpXdaww8j3zktwSywDHhJI1cpWHS+rbUD1BKnapSL3Lfvi7o03rFAauAECgFjrJkAHX53Q1eh2ORfMpScaSPQ78CALSQ3pWN6Elgs6xwAAIc2MUXyoG5TTOJ0PSekzKrTww5xHuNsitXgrKfD2dBIAWFk7vwekk4kvRLBT3rbG19fYc0cTv9u+b6+Xi8EhpwR+v4BAN3eE+CFvEIsZDrp0ul566B9NZBBUBe8EJkr+H/dPRA4PR5Hctyhd27uE9hQ70QzBGBuhrL+NKxi3hRTWuLWoSUs3pP99x9km02FjzDDVOHWS7MVQ== root@centos6.10.localdomain
     EOF
     chmod 700 /root/.ssh
     chmod 600 /root/.ssh/authorized.keys
     %end
     @
      Mi^ni
     %packages
     @core  安裝內核包
     %end
    

    修改centos7的應答文件配置信息:

     [root@centos7tftpboot]#vim /var/www/html/ksdir/ks7_mini.cfg
     url --url=http://192.168.34.101/centos/7/os/x86_64/  指定centos7掛載光盤路徑
     # Use graphical install
     text   文本方式安裝
     # Run the Setup Agent on first boot
     firstboot --enable
     ignoredisk --only-use=sda
     # Keyboard layouts
     keyboard --vckeymap=us --xlayouts='us'
     # System language
     lang en_US.UTF-8
      
     # Network information
     network --bootproto=dhcp --device=ens33 --ipv6=auto --activate
     network --hostname=centos7.localdomain
      
     # Root password
     rootpw --iscrypted $6$zQd4v6GjKalpnj.h$uutceFNO9vO0H2mJoBQYgpW5iNUrmKNHWulIKrSFfPJtpu4f.llg6rm9veeswxYrFXOpXV5M9MPqMBv/DGjdj.
     # System services
     firewall --disabled  關閉防火牆
     selinux --disabled   關閉selinux
     # System timezone
     timezone Asia/Shanghai --isUtc --nontp
     user --name=liu --password=$6$LlHE.xyYU4ZoUsbV$nBtUpJjkXmMa1lQFNoNhOs0AuVaOecBttShTt3wNrUncYh.JLfnBIIfMJtOu0Cnkemt1Wr76sHCEiHrD.yKxE1 --iscrypted --gecos="liu"
     # X Window System configuration information
     #xconfig --startxonboot
     # System bootloader configuration
     bootloader --location=mbr --boot-drive=sda
     # Partition clearing information
     clearpart --all --initlabel  清空磁盤分區
     zerombr   清空mbr磁盤
     reboot  重啟
     # Disk partitioning information
     part /boot --fstype="xfs" --ondisk=sda --size=1024
     part / --fstype="xfs" --ondisk=sda --size=102400
     part swap --fstype="swap" --ondisk=sda --size=3072
     part /data --fstype="xfs" --ondisk=sda --size=51200
      
     %post
     mkdir /etc/yum.repos.d/bak
     mv /etc/yum.repos.d/*.repo  /etc/yum.repos.d/bak
     cat > /etc/yum.repos.d/base.repo << EOF
     [base]
     basurl=http://192.168.34.100/centos/6/os/x86_64
     gpgckeck=0
     EOF
     useradd wang
     echo centos |passwd --stdin wang
        
     mkdir /root/.ssh   生產公鑰腳本
     cat > /root/.ssh/authorized.keys << EOF  將已經安裝好的centos6的id_rsa.pub公鑰信息寫入。
     ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA5hEv1/BQLBftA/tK5h+cF+zop59zMlpsMpXdaww8j3zktwSywDHhJI1cpWHS+rbUD1BKnapSL3Lfvi7o03rFAauAECgFjrJkAHX53Q1eh2ORfMpScaSPQ78CALSQ3pWN6Elgs6xwAAIc2MUXyoG5TTOJ0PSekzKrTww5xHuNsitXgrKfD2dBIAWFk7vwekk4kvRLBT3rbG19fYc0cTv9u+b6+Xi8EhpwR+v4BAN3eE+CFvEIsZDrp0ul566B9NZBBUBe8EJkr+H/dPRA4PR5Hctyhd27uE9hQ70QzBGBuhrL+NKxi3hRTWuLWoSUs3pP99x9km02FjzDDVOHWS7MVQ== root@centos6.10.localdomain
     EOF
     chmod 700 /root/.ssh
     chmod 600 /root/.ssh/authorized.keys
        
     %end
      
     %packages
     @core  安裝最小的核包
     %end
    

    上面的相關配置文件已經全部做完,現在可以打開一個主機,將網卡設置為僅主機模式,開機后按esc,設置為Network boot from Intel E1000引導進入,進不了這個界面可以在開機界面設置“打開電源時進入固件”,修改boot界面進入:

    img

     

    按+將網卡設置第一項啟動,然后按F10保存就會重啟,下來新安裝的主機就會通過DHCP獲取相關信息安裝系統:

     

     

     

    顯示要安裝的界面,選擇上面兩個任意一個,對應的安裝centos6/7的系統,選擇后等待安裝結束。

     

     

     






免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM