Cobbler實現多系統自動化安裝

Cobbler介紹:

 Cobbler能夠快速建立多系統同時安裝的網絡系統安裝環境;傳統的pxe+dhcp+tftp+kickstart僅能夠提供單一系統安裝,功能過于簡單;如果遇到安裝不同操作系統時就遇到瓶頸;而cobbler正好解決了這一問題。Cobbler是增強版的網絡系統安裝。

Cobbler由不同的組件配合完成系統安裝,各組件之間配合如下圖所示:

21.png

一、實驗環境準備:

(1)一臺主機,并且關閉SELinux和iptables防火墻

(2)準備兩個兩個光盤鏡像文件,一個是CentOS-6.5;另一個是CentOS-6.6

(3)tftp,dhcp,cobbler都在一臺主機

二、配置Cobbler:

(1)安裝Cobbler

[root@node2 ~]# yum -y install cobbler pykickstart debmirror httpd syslinux tfpt dhcp \\需要事先準備好epel源

(2)啟動httpd和cobbler

[root@node2 ~]# /etc/init.d/httpd  start
[root@node2 ~]# /etc/init.d/cobblerd start

(3)運行cobbler check檢查cobbler環境

[root@node2 ~]# 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 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:
    https://github.com/cobbler/cobbler/wiki/Selinux
4 : change 'disable' to 'no' in /etc/xinetd.d/tftp
5 : 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 : change 'disable' to 'no' in /etc/xinetd.d/rsync
7 : comment out 'dists' on /etc/debmirror.conf for proper debian support
8 : comment out 'arches' on /etc/debmirror.conf for proper debian support
9 : 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
10 : 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.

根據提示完善cobbler運行環境
1、編輯/etc/cobbler/settings,修改如下內容
server: 172.16.2.13  \\默認為127.0.0.1,要修改為cobbler的對外通信的IP
2、編輯/etc/cobbler/settings,修改如下內容:
next_server: 172.16.2.13 \\此處填寫tftp的地址,默認為127.0.0.1
3、編輯/etc/sysconfgi/selinux
SELINUX=disabled \\修改完需要重啟
4、設置tftp開機啟動
[root@node2 ~]# chkconfig tftp on
5、根據提示運行cobbler get-loaders
[root@node2 ~]# cobbler get-loaders 
   \\如果沒有網絡可以復制/usr/share/syslinux/*  /var/lib/cobbler/loaders
6、設置rsync開機啟動
[root@node2 ~]# chkconfig rsync on
7和8注釋掉/etc/debmirror.conf的選項
#@dists="sid";
#@arches="i386";  \\注釋掉這兩個選項
9、生成新的秘鑰,添加至/etc/cobbler/settings
[root@node2 ~]# openssl  passwd -1 -salt `openssl rand -hex 4`
Password: 
$1$28999937$ExBtgrSzOiI/ri3NknQQB1
編輯/etc/cobbler/settings配置文件,將生成的秘鑰添替換原有的秘鑰
default_password_crypted: "$1$28999937$ExBtgrSzOiI/ri3NknQQB1"
10、可以忽略

(4)以上修改操作完以后,進程同步,然后在進行檢查

[root@node2 ~]# cobbler sync
task started: 2014-12-16_114120_sync
task started (id=Sync, time=Tue Dec 16 11:41:20 2014)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
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 images
generating PXE configuration files
generating PXE menu structure
rendering TFTPD files
generating /etc/xinetd.d/tftp
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 ***

root@node2 ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them \\此提示可以忽略

(5)掛載CentOS6.5光盤鏡像,導入鏡像到cobbler

[root@node2 ~]# mount -r /dev/cdrom /mnt
[root@node2 ~]# mount -r /dev/cdrom /mnt
[root@node2 ~]# cobbler import --name=CentOS-6.5-x86_64 --path=/mnt
task started: 2014-12-16_114737_import
task started (id=Media import, time=Tue Dec 16 11:47:37 2014)
Found a candidate signature: breed=redhat, version=rhel6
Found a matching signature: breed=redhat, version=rhel6
Adding distros from path /var/www/cobbler/ks_mirror/CentOS-6.5-x86_64:
creating new distro: CentOS-6.5-x86_64
trying symlink: /var/www/cobbler/ks_mirror/CentOS-6.5-x86_64 -> /var/www/cobbler/links/CentOS-6.5-x86_64
creating new profile: CentOS-6.5-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/CentOS-6.5-x86_64 for CentOS-6.5-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS-6.5-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS-6.5-x86_64
looking for /var/www/cobbler/ks_mirror/CentOS-6.5-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS-6.5-x86_64/repodata
*** TASK COMPLETE ***

(6)導入CentOS6.6的光盤鏡像與CentOS的方法一樣,這里就不在講述了

(7)查看導入的關盤鏡像信息

[root@node2 ~]# cobbler distro list
   CentOS-6.5-x86_64
   CentOS-6.6-x86_64

(8)刪除導入鏡像文件自動生成的profile文件,添加自己定制的profile文件

[root@node2 ~]# cobbler profile remove --name=CentOS-6.5-x86_64; cobbler profile remove --name=CentOS-6.6-x86_64

(9)復制制作好的kickstart文件到/var/lib/cobbler/kickstarts

[root@node2 ~]# cp kickstart_6.6.cfg  /var/lib/cobbler/kickstarts/CentOS-6.6-x86_64
[root@node2 ~]# cp kickstart_6.5.cfg  /var/lib/cobbler/kickstarts/CentOS-6.5-x86_64
[root@node2 ~]# cobbler   profile add  --name=CentOS-6.5-x86_64 --distro=CentOS-6.5-x86_64   --kickstart=/var/lib/cobbler/kickstarts/CentOS-6.5-x86_64 
[root@node2 ~]# cobbler   profile add  --name=CentOS-6.6-x86_64 --distro=CentOS-6.6-x86_64   --kickstart=/var/lib/cobbler/kickstarts/CentOS-6.6-x86_64

(10)查看添加的profile文件

[root@node2 ~]# cobbler profile list
   CentOS-6.5-x86_64
   CentOS-6.6-x86_64

三、配置dhcp

編輯配置文件,修改內容如下:

[root@node2 ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf  \\添加配置文件
[root@node2 ~]# vim /etc/dhcp/dhcpd.conf
subnet 172.16.2.0 netmask 255.255.255.0 {
  range 172.16.2.10 172.16.2.100  ;
  option routers 172.16.2.1;
  next-server 172.16.2.13;  \\定義tftp服務器的地址
  filename "pxelinux.0";    \\定義安裝主機所需要獲取的文件
}
[root@node2 ~]# /etc/init.d/dhcpd start  \\啟動dhcp

四、利用cobbler安裝操作系統

CentOS6.5的安裝過程

22.png

24.png

25.png

26.png

CentOS6.6的安裝過程:

33.png

24.png25.png

32.png

五、配置cobbler的web控制端:

(1)安裝

[root@node2 ~]# yum -y install cobbler-web

(2)編輯配置文件/etc/cobbler/modules.conf修改內容如下:

[authentication]
module = authn_pam

(3)添加登錄cobbler的web用戶及密碼

[root@node2 ~]# useradd  cobbler;echo "admin" |passwd --stdin cobbler

(4)編輯配置文/etc/cobbler/users.conf修改內容如下:

[admins]
admin = "cobbler" \\填寫剛剛創建的cobbler用戶
cobbler = ""

(5)重新啟動cobbler,訪問web頁面,地址是:http://172.16.2.13/cobbler_web

44.png

45.png

關于web頁面配置cobbler的操作請各位大俠研究吧,我就先介紹到這里。

六、知識擴展:

經常有同學在配置網絡安裝時遇到以下故障:

blob.png

如果你去網上搜索全都是說內存不夠,其實根本就不是內存問題。

解決方法:在制作kickstart文件是沒有勾選清除mbr選項導致的,重新執行kickstart文件,選擇清除mbr即可,

如下圖所示:

34.png

到此cobbler的配置已經完成,可以在工作中使用,如有問題可以一起解決。

cobbler官網地址:http://cobbler.github.io/

原創文章,作者:馬行空,如若轉載,請注明出處:http://www.www58058.com/6908

(0)
馬行空馬行空
上一篇 2015-08-06
下一篇 2015-08-11

相關推薦

  • 如何在Java中避免equals方法的隱藏陷阱

    譯者注 :你可能會覺得Java很簡單,Object的equals實現也會非常簡單,但是事實并不是你想象的這樣,耐心的讀完本文,你會發現你對Java了解的是如此的少。如果這篇文章是一份Java程序員的入職筆試,那么不知道有多少人會掉落到這樣的陷阱中。原文轉自http://www.artima.com/lejava/articles/equality.…

    開發運維 2015-04-03
  • N27_網絡班第九周作業

    N27_網絡班第九周作業 1、寫一個腳本,判斷當前系統上所有用戶的shell是否為可登錄shell(即用戶的shell不是/sbin/nologin);分別這兩類用戶的個數;通過字符串比較來實現 #!/bin/bash loginuser=`grep -v ‘/sbin/nologin’ /etc/passwd | wc -l` nologin=`grep …

    2017-10-10
  • 命令行歷史和調用命令參數

    history顯示當前終端的歷史記錄 !! 重復執行上一條命令 !-n 重復執行倒數第n條命令 !n 重復執行第n條命令 ctrl+p 等于向上方向鍵,翻出上一條命令。 ctrl+n 等于向下方向鍵,翻出下一條命令。 ctrl+j 等于enter 執行當前命令 !:0 執行前一條命令(去除參數) !string 重復前一個以“string”開頭的命令(只限于…

    2017-07-14
  • LVS產生背景、原理及LVS-DR應用實例(一)

    一、什么是lvs? 它產生的背景,使用場景是什么?      LVS(Linux Virtual Server) 可以理解為一個虛擬服務器系統。       Internet的飛速發展,網絡帶寬的增長,Web服務中越來越多地使用CGI、動態主頁等CPU密集型應用,這對服務器的性能…

    Linux干貨 2016-10-29
  • 馬哥教育網絡班22期+第一周課程練習

    1、描述計算機的組成及其功能。 計算機由硬件系統、操作系統和應用軟件所組成,沒有安裝任何軟件的計算機稱為裸機。 1.1、硬件系統由運算器、控制器、存儲器、輸入設備和輸出設備五大部分組成,遵循馮、諾依曼原理。 控制器:讀取分析指令,向其它部分發出控制信號,保證計算機按照預先規定的目標和步驟有條不紊地進行操作及處理。  運算器:對數據進行各種運算,例如…

    Linux干貨 2016-08-22
  • 馬哥教育網絡班21期-第五周課程練習

    第五周作業 1、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行; [root@zz ~]# egrep "^[[:space:]]+" /boot/grub/grub.conf 2、顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符,而后又有…

    Linux干貨 2016-07-29
欧美性久久久久