首頁 > 軟體

PXE+DHCP+TFTP+Cobbler 無人值守安裝CentOS 7

2020-06-16 17:08:39

Cobbler(補鞋匠)是通過將DHCP、TFTP、DNS、HTTP等服務進行整合,建立一個中央管理節點,其可以實現的功能有設定服務,建立儲存庫,解壓縮作業系統媒介,代理或整合一個設定管理系統,控制電源管理等。 Cobbler的最終目的是實現無需進行人工干預即可安裝機器。

  pxe概述
  預啟動執行環境(Preboot eXecution Environment,PXE,也被稱為預執行環境)是讓計算機通過網絡卡獨立地使用資料裝置(如硬碟)或者安裝作業系統

    PXE Client傳送廣播包請求DHCP分配IP地址DHCP
    Server回復請求,給出IP地址以及Boot
    Server的地址PXE下載引導檔案執行載入程式

總結來說,

  pxe用戶端會呼叫網際協定(ip)、使用者資料包協定(udp)、動態主機設定協定(DHCP)、小型檔案傳輸協定(TFTP)

  pxe用戶端(client)指機器在pxe啟動過程中的角色。一個pxe用戶端可以是一台伺服器、筆記型電腦或者其他裝有pxe啟動程式碼的機器

  PXE主要是通過廣播的方式傳送一個包,並請注獲取一個地址,而後交給TFTP程式下載一個引導檔案。

cobbler和Kickstart批次裝機軟體

 Cobbler由Python語言開發,是對PXE和Kickstart以及DHCP的封裝。融合很多特性,提供了CLI和Web的管理形式。更加方便的實行網路安裝。同時,Cobbler也提供了API介面,使用其它語言也很容易做擴充套件。它不緊可以安裝物理機,同時也支援kvm、xen虛擬化、Guest OS的安裝。更多的是它還能結合Puppet等集中化管理軟體,實現自動化的管理。

  Kickstart 是一種無人值守的安裝方式,它的工作原理是在安裝過程中記錄人工干預填寫的各種引數,並生成一個名為ks.cfg的檔案。我們可以簡單理解為一個自動安裝應答設定管理程式。通過讀取這個組態檔,系統知道怎麼去分割區,要安裝什麼包,配什麼IP,優化什麼核心引數等等 

  一句話總結:Cobbler補鞋匠是對Kickstart的封裝,簡化安裝步驟、使用流程,官方號稱補鞋匠都能學會的批次裝機。

Cobbler 工作流程

server端:

    第一步,啟動Cobbler服務
    第二步,進行Cobbler錯誤檢查,執行cobbler check命令
    第三步,進行設定同步,執行cobbler sync命令
    第四步,複製相關啟動檔案檔案到TFTP目錄中
    第五步,啟動DHCP服務,提供地址分配
    第六步,DHCP服務分配IP地址
    第七步,TFTP傳輸啟動檔案
    第八步,Server端接收安裝資訊
    第九步,Server端傳送ISO映象與Kickstart檔案

Client端:

    第一步,用戶端以PXE模式啟動
    第二步,用戶端獲取IP地址
    第三步,通過TFTP伺服器獲取啟動檔案
    第四步,進入Cobbler安裝選擇介面
    第五步,用戶端確定載入資訊
    第六步,根據設定資訊準備安裝系統
    第七步,載入Kickstart檔案
    第八步,傳輸系統安裝的其它檔案
    第九步,進行安裝系統

正式環境準備:

  1.網路環境:host-only、nat網路,因為Cobbler需要用到自己的dhcp伺服器,所以為了防止都在同一個網路造成dhcp獲取混亂,需要切換網路!~ 

  2.類似安裝服務必要的環境準備:1,關閉iptables,selinux 2,設定靜態IP、設定主機名 並且在hosts檔案下系結 3.時間同步 4.設定本地iso映象裡的yum倉庫,163源epel源 (安裝軟體)

cobbler server    -------    client
                  192.168.100.221/24  ------------------------------------  裝機時候由DHCP自動設定

一.  在cobbler server上安裝cobbler

  yum install cobbler cobbler-web tftp* rsync xinetd http* syslinux dhcp* pykickstart

[root@bokeyuan ~]# yum install cobbler cobbler-web tftp* rsync xinetd http* syslinux dhcp* pykickstart
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Package rsync-3.0.9-17.el7.x86_64 already installed and latest version
Package 12:dhcp-common-4.2.5-47.el7.CentOS.x86_64 already installed and latest version
Package 12:dhcp-libs-4.2.5-47.el7.centos.x86_64 already installed and latest version
Package pykickstart-1.99.66.10-1.el7.noarch already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package cobbler.noarch 0:2.6.3-1.el6 will be installed
--> Processing Dependency: python-simplejson for package: cobbler-2.6.3-1.el6.noarch
--> Processing Dependency: python-cheetah for package: cobbler-2.6.3-1.el6.noarch
--> Processing Dependency: mod_wsgi for package: cobbler-2.6.3-1.el6.noarch
--> Processing Dependency: PyYAML for package: cobbler-2.6.3-1.el6.noarch
---> Package cobbler-web.noarch 0:2.6.3-1.el6 will be installed
--> Processing Dependency: mod_ssl for package: cobbler-web-2.6.3-1.el6.noarch
--> Processing Dependency: Django for package: cobbler-web-2.6.3-1.el6.noarch
---> Package dhcp.x86_64 12:4.2.5-47.el7.centos will be installed
---> Package httpcomponents-client.noarch 0:4.2.5-5.el7_0 will be installed
--> Processing Dependency: mvn(commons-logging:commons-logging) for package: httpcomponents-client-4.2.5-5.el7_0.noarch
--> Processing Dependency: mvn(commons-codec:commons-codec) for package: httpcomponents-client-4.2.5-5.el7_0.noarch
---> Package httpcomponents-core.noarch 0:4.2.4-6.el7 will be installed
---> Package httpd.x86_64 0:2.4.6-45.el7.centos will be installed
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-45.el7.centos.x86_64
---> Package httpd-devel.x86_64 0:2.4.6-45.el7.centos will be installed
--> Processing Dependency: apr-util-devel for package: httpd-devel-2.4.6-45.el7.centos.x86_64
--> Processing Dependency: apr-devel for package: httpd-devel-2.4.6-45.el7.centos.x86_64
---> Package httpd-manual.noarch 0:2.4.6-45.el7.centos will be installed
---> Package httpd-tools.x86_64 0:2.4.6-45.el7.centos will be installed
---> Package syslinux.x86_64 0:4.05-13.el7 will be installed
---> Package tftp.x86_64 0:5.2-13.el7 will be installed
---> Package tftp-server.x86_64 0:5.2-13.el7 will be installed
---> Package xinetd.x86_64 2:2.3.15-13.el7 will be installed
--> Running transaction check
---> Package Django14.noarch 0:1.4.20-1.el6 will be installed
--> Processing Dependency: python(abi) = 2.6 for package: Django14-1.4.20-1.el6.noarch
--> Processing Dependency: python-simplejson for package: Django14-1.4.20-1.el6.noarch
---> Package PyYAML.x86_64 0:3.10-11.el7 will be installed
--> Processing Dependency: libyaml-0.so.2()(64bit) for package: PyYAML-3.10-11.el7.x86_64
---> Package apache-commons-codec.noarch 0:1.8-7.el7 will be installed
---> Package apache-commons-logging.noarch 0:1.1.2-7.el7 will be installed
--> Processing Dependency: mvn(logkit:logkit) for package: apache-commons-logging-1.1.2-7.el7.noarch
--> Processing Dependency: mvn(log4j:log4j) for package: apache-commons-logging-1.1.2-7.el7.noarch
--> Processing Dependency: mvn(avalon-framework:avalon-framework-api) for package: apache-commons-logging-1.1.2-7.el7.noarch
---> Package apr-devel.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util-devel.x86_64 0:1.5.2-6.el7 will be installed
--> Processing Dependency: openldap-devel(x86-64) for package: apr-util-devel-1.5.2-6.el7.x86_64
--> Processing Dependency: libdb-devel(x86-64) for package: apr-util-devel-1.5.2-6.el7.x86_64
--> Processing Dependency: expat-devel(x86-64) for package: apr-util-devel-1.5.2-6.el7.x86_64
---> Package cobbler.noarch 0:2.6.3-1.el6 will be installed
--> Processing Dependency: python-simplejson for package: cobbler-2.6.3-1.el6.noarch
--> Processing Dependency: python-cheetah for package: cobbler-2.6.3-1.el6.noarch
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
---> Package mod_ssl.x86_64 1:2.4.6-45.el7.centos will be installed
---> Package mod_wsgi.x86_64 0:3.4-12.el7_0 will be installed
--> Running transaction check
---> Package Django14.noarch 0:1.4.20-1.el6 will be installed
--> Processing Dependency: python(abi) = 2.6 for package: Django14-1.4.20-1.el6.noarch
--> Processing Dependency: python-simplejson for package: Django14-1.4.20-1.el6.noarch
---> Package avalon-framework.noarch 0:4.3-10.el7 will be installed
--> Processing Dependency: xalan-j2 for package: avalon-framework-4.3-10.el7.noarch
---> Package avalon-logkit.noarch 0:2.1-14.el7 will be installed
--> Processing Dependency: tomcat-servlet-3.0-api for package: avalon-logkit-2.1-14.el7.noarch
--> Processing Dependency: jms for package: avalon-logkit-2.1-14.el7.noarch
---> Package cobbler.noarch 0:2.6.3-1.el6 will be installed
--> Processing Dependency: python-simplejson for package: cobbler-2.6.3-1.el6.noarch
--> Processing Dependency: python-cheetah for package: cobbler-2.6.3-1.el6.noarch
---> Package expat-devel.x86_64 0:2.1.0-8.el7 will be installed
---> Package libdb-devel.x86_64 0:5.3.21-19.el7 will be installed
---> Package libyaml.x86_64 0:0.1.4-11.el7_0 will be installed
---> Package log4j.noarch 0:1.2.17-15.el7 will be installed
--> Processing Dependency: mvn(Javax.mail:mail) for package: log4j-1.2.17-15.el7.noarch
---> Package openldap-devel.x86_64 0:2.4.40-13.el7 will be installed
--> Processing Dependency: cyrus-sasl-devel(x86-64) for package: openldap-devel-2.4.40-13.el7.x86_64
--> Running transaction check
---> Package Django14.noarch 0:1.4.20-1.el6 will be installed
--> Processing Dependency: python(abi) = 2.6 for package: Django14-1.4.20-1.el6.noarch
--> Processing Dependency: python-simplejson for package: Django14-1.4.20-1.el6.noarch
---> Package cobbler.noarch 0:2.6.3-1.el6 will be installed
--> Processing Dependency: python-simplejson for package: cobbler-2.6.3-1.el6.noarch
--> Processing Dependency: python-cheetah for package: cobbler-2.6.3-1.el6.noarch
---> Package cyrus-sasl-devel.x86_64 0:2.1.26-20.el7_2 will be installed
---> Package geronimo-jms.noarch 0:1.1.1-19.el7 will be installed
---> Package javamail.noarch 0:1.4.6-8.el7 will be installed
---> Package tomcat-servlet-3.0-api.noarch 0:7.0.69-10.el7 will be installed
---> Package xalan-j2.noarch 0:2.7.1-23.el7 will be installed
--> Processing Dependency: xerces-j2 for package: xalan-j2-2.7.1-23.el7.noarch
--> Processing Dependency: osgi(org.apache.xerces) for package: xalan-j2-2.7.1-23.el7.noarch
--> Running transaction check
---> Package Django14.noarch 0:1.4.20-1.el6 will be installed
--> Processing Dependency: python(abi) = 2.6 for package: Django14-1.4.20-1.el6.noarch
--> Processing Dependency: python-simplejson for package: Django14-1.4.20-1.el6.noarch
---> Package cobbler.noarch 0:2.6.3-1.el6 will be installed
--> Processing Dependency: python-simplejson for package: cobbler-2.6.3-1.el6.noarch
--> Processing Dependency: python-cheetah for package: cobbler-2.6.3-1.el6.noarch
---> Package xerces-j2.noarch 0:2.11.0-17.el7_0 will be installed
--> Processing Dependency: xml-commons-resolver >= 1.2 for package: xerces-j2-2.11.0-17.el7_0.noarch
--> Processing Dependency: xml-commons-apis >= 1.4.01 for package: xerces-j2-2.11.0-17.el7_0.noarch
--> Processing Dependency: osgi(org.apache.xml.resolver) for package: xerces-j2-2.11.0-17.el7_0.noarch
--> Processing Dependency: osgi(javax.xml) for package: xerces-j2-2.11.0-17.el7_0.noarch
--> Running transaction check
---> Package Django14.noarch 0:1.4.20-1.el6 will be installed
--> Processing Dependency: python(abi) = 2.6 for package: Django14-1.4.20-1.el6.noarch
--> Processing Dependency: python-simplejson for package: Django14-1.4.20-1.el6.noarch
---> Package cobbler.noarch 0:2.6.3-1.el6 will be installed
--> Processing Dependency: python-simplejson for package: cobbler-2.6.3-1.el6.noarch
--> Processing Dependency: python-cheetah for package: cobbler-2.6.3-1.el6.noarch
---> Package xml-commons-apis.noarch 0:1.4.01-16.el7 will be installed
---> Package xml-commons-resolver.noarch 0:1.2-15.el7 will be installed
--> Finished Dependency Resolution
Error: Package: Django14-1.4.20-1.el6.noarch (cobbler)
           Requires: python-simplejson
Error: Package: cobbler-2.6.3-1.el6.noarch (cobbler)
           Requires: python-simplejson
Error: Package: Django14-1.4.20-1.el6.noarch (cobbler)
           Requires: python(abi) = 2.6
           Installed: python-2.7.5-48.el7.x86_64 (@anaconda)
               python(abi) = 2.7
               python(abi) = 2.7
Error: Package: cobbler-2.6.3-1.el6.noarch (cobbler)
           Requires: python-cheetah
 You could try using --skip-broken to work around the problem
** Found 3 pre-existing rpmdb problem(s), 'yum check' output follows:
ipa-client-4.4.0-12.el7.centos.x86_64 has installed conflicts freeipa-client: ipa-client-4.4.0-12.el7.centos.x86_64
ipa-client-common-4.4.0-12.el7.centos.noarch has installed conflicts freeipa-client-common: ipa-client-common-4.4.0-12.el7.centos.noarch
ipa-common-4.4.0-12.el7.centos.noarch has installed conflicts freeipa-common: ipa-common-4.4.0-12.el7.centos.noarch

 報錯解決:提示--skip-broken ,檢查發現自己yum源不全yum無法安裝上面三個依賴包。補全yum源解決

安裝完成,啟動軟體

[root@bokeyuan ~]# systemctl restart cobblerd.service
[root@bokeyuan ~]# systemctl restart httpd.service
[root@bokeyuan ~]# systemctl enable cobblerd.service  //開機自啟動
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.
[root@bokeyuan ~]# systemctl enable httpd.service  //開機自啟動
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

為什麼啟動apache?血的教訓,排了很久。不先啟動apache 後續cobbler check 報python file 的錯誤!!!

二.基本設定

[root@bokeyuan ~]# cobbler check
The following are potential configuration items that you may want to fix:
 
1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work.  This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
3 : change 'disable' to 'no' in /etc/xinetd.d/tftp
4 : some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely.  Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
5 : enable and start rsyncd.service with systemctl
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
7 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one
8 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
 
Restart cobblerd and then run 'cobbler sync' to apply changes.

 一步步解決上述需求,部分需求可忽略。個體差異不同 每個人需求數量也不同,基本上大同小異

解決需求1、2、7
# openssl passwd -1 -salt 'werwqerwqr' '123456'        --123456為密碼(這是自動安裝用戶端系統成功後的root登入密碼),werwqerwqr為隨機位元組干擾碼(隨便寫)
$1$werwqerw$.prcfrYFbwuvkD8XspayN.

# vim /etc/cobbler/settings
384 server: 192.168.100.221   --換成cobbler伺服器端的IP
272 next_server: 192.168.100.221   --同上
101 default_password_crypted: "$1$werwqerw$.prcfrYFbwuvkD8XspayN."  --把密碼字串換成你上面產生的字串(此密碼為客戶機安裝後的root登入密碼)

解決需求3
# vim /etc/xinetd.d/tftp
        disable = no    --yes改為no

解決需求5

#systemctl restart rsyncd.service

#systemctl enable  rsyncd.service

解決需求8
# yum install fence-agents

OK,剩下的需求像

4 : some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely.  Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories

(問題4可以使用cobbler get-loaders解決,但需要有外網和外網的yum源 跳過,現在是NAT模式;問題6 是關於debian系統的,我們這裡可以忽略)

最後# systemctl restart cobblerd.service 重起下cobbler補鞋匠服務!

三.匯入centos7.3的iso映象

我的環境iso映象掛載在/yum目錄,此拷貝步驟時間較長

# cobbler import --path=/yum/ --name=centos7.3

# cobbler distro list   --匯入成功後,確認匯入的映象名
  centos7.3-x86_64
# cobbler profile list   --匯入成功後,確認預設的profile名
  centos7.3-x86_64

[root@bokeyuan ~]# cobbler import --path=/yum/ --name=centos7.3
task started: 2017-09-03_175701_import
task started (id=Media import, time=Sun Sep  3 17:57:01 2017)
Found a candidate signature: breed=RedHat, version=rhel6
Found a candidate signature: breed=redhat, version=rhel7
Found a matching signature: breed=redhat, version=rhel7
Adding distros from path /var/www/cobbler/ks_mirror/centos7.3:
creating new distro: centos7.3-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos7.3 -> /var/www/cobbler/links/centos7.3-x86_64
creating new profile: centos7.3-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/ks_mirror/centos7.3 for centos7.3-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos7.3
need to process repo/comps: /var/www/cobbler/ks_mirror/centos7.3
looking for /var/www/cobbler/ks_mirror/centos7.3/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos7.3/repodata
*** TASK COMPLETE *** 


四.修改dhcp設定
# vim /etc/cobbler/dhcp.template  --在此檔案的第21行到第25行修改成你對應的網段和ip   

subnet 192.168.100.0 netmask 255.255.255.0 {
    option routers            192.168.100.221;
    option domain-name-servers 192.168.100.221;
    option subnet-mask        255.255.255.0;
    range dynamic-bootp        192.168.100.100 192.168.100.254;


--圖形的操作過程這裡省略後續還有這一步 重要

# vim /etc/cobbler/settings   --再去修改這個組態檔,改成dhcp服務由cobbler來管理
242 manage_dhcp: 1       --把0改為1

#  systemctl restart cobblerd.service  --儲存後,再重新啟動此服務

五.使用cobbler sync同步,並啟動xinetd服務

下面的cobbler sync 很重要,如果這步報錯一定要排出來,就經驗來說這步出錯一般是IP設定出錯,記得細心一點,個體差異不用就不詳細表述~  

# cobbler sync

[root@bokeyuan ~]# cobbler sync
task started: 2017-09-03_180107_sync
task started (id=Sync, time=Sun Sep  3 18:01:07 2017)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/centos7.3-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/images/centos7.3-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /usr/share/syslinux/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /usr/share/syslinux/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
copying distros to tftpboot
copying files for distro: centos7.3-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos7.3/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos7.3-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos7.3/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos7.3-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: centos7.3-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos7.3/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos7.3-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos7.3/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos7.3-x86_64/initrd.img
Writing template files for centos7.3-x86_64
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: centos7.3-x86_64
cleaning link caches
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***

# systemctl restart xinetd.service
# systemctl enable xinetd.service

六.新建另一個虛擬機器 選擇網路安裝PXE (保證相同私有網路,並且最好2G記憶體,記憶體小的話會在安裝時報空間不夠的錯誤),進行安裝測試

   

安裝完成後,更改boot引導

更多詳情見請繼續閱讀下一頁的精彩內容http://www.linuxidc.com/Linux/2017-09/146706p2.htm


IT145.com E-mail:sddin#qq.com