一 、Cobbler簡介python
Cobbler是一個快速網絡安裝linux的服務,並且在通過調整也能夠支持網絡安裝windows。該工具使用python開發,小巧輕便(才15k 行python代碼),使用簡單的命令便可完成PXE網絡安裝環境的配置,同時還能夠管理DHCP、DNS、yum倉庫、構造系統ISO鏡像。linux
Cobbler支持命令行管理,web界面管理,還提供了API接口,方便二次開發web
Cobbler客戶端Koan支持虛擬機安裝和操做系統從新安裝,使重裝系統更便捷。算法
Cobbler提供的功能sql
使用Cobbler,您無需進行人工干預便可安裝機器。Cobbler設置一個PXE引導環境(它還可使用yaboot支持PowerPC),並控制與 安裝相關的全部方面,好比網絡引導服務(DHCP和TFTP)與存儲庫鏡像。當但願安裝一臺新機器時,Cobbler能夠:shell
1)使用一個之前定義的模板來配置DHCP服務(若是啓用了管理DHCP)express
2)將一個存儲庫(yum或rsync)創建鏡像或解壓縮一個媒介,以註冊一個新操做系統vim
3)在DHCP配置文件中爲須要安裝的機器建立一個條目,並使用指定的參數(IP和MAC)windows
4)在TFTP服務目錄下建立適當的PXE文件centos
5)從新啓動DHCP服務以反應更改
6)從新啓動機器以開始安裝(若是電源管理已啓動)
Cobbler支持衆多的發行版:RedHat、Fedora、CentOS、Debian、Ubuntu和SuSE。當添加一個操做系統(一般經過使用ISO文件)時,Cobbler知道如何解壓縮合適的文件並調整網絡服務,以正確引導機器。
Cobbler可使用kickstart模板。基於Red Hat或Fedora的系統使用kickstart文件來自動化安裝流程。經過使用模板,就會擁有基本的kickstart模板,而後定義如何針對一種配 置文件或機器配置而替換其中的變量。例如,一個模板可能包含兩個變量$domain和$machine_name.在Cobbler配置中,一個配置文件 指定domain=mydomain.com,而且每臺使用該配置文件的機器在machine_name變量中指定其名稱。該配置文件的全部機器都使用相 同的kickstart安裝且針對domain=mydomain.com進行配置,但每臺機器擁有其本身的機器名稱。您仍然可使用kickstart 模板在不一樣的域中安裝其餘機器並使用不一樣的機器名稱。
爲了協助管理系統,Cobbler可經過fence scripts鏈接到各個電源管理環境。Cobbler支持apc_snmp、bladecenter、bullpap、drac、 ether_wake、ilo、integrity、ipmilan、ipmitool、lpar、rsa、virsh和wti。要從新安裝一臺機器,可 運行reboot system foo命令,並且Cobbler會使用必要的 和信息來爲您運行恰當的fence scripts(好比機器插槽數)。
除了這些特性,還可使用一個配置管理系統(CMS)。你有兩種選擇:該工具內的一個內部系統,或者現成的外部CMS,好比Chef或Puppet。藉助 內部系統,你能夠指定文件模板,這些模板會依據配置參數進行處理(與kickstart模板的處理方式同樣),而後複製到你指定的位置。若是必須自動將配 置文件部署到特定機器,那麼此功能頗有用
使用koan客戶端,Cobbler可從客戶端配置虛擬機並從新安裝系統。
2、Cobbler的設計方式
Cobbler的配置結構基於一組註冊的對象。每一個對象表示一個與另外一個實體相關聯的實體(該對象指向另外一個對象,或者另外一個對象指向該對象)。當一個對象指向另外一個對象時,它就繼承了被指向對象的數據,並可覆蓋或添加更多特定信息。如下對象類型的定義
Distros(發行版):表示一個操做系統,它承載了內核和initrd的信息,以及內核參數等其餘數據
Profile(配置文件):包含一個發行版、一個kickstart文件以及可能的存儲庫,還包含更多特定的內核參數等其餘數據
Systems(系統):表示要配給的額機器。它包含一個配置文件或一個景象,還包含IP和MAC地址、電源管理(地址、憑據、類型)、(網卡綁定、設置valn等)
Repository(鏡像):保存一個yum或rsync存儲庫的鏡像信息
Image(存儲庫):可替換一個包含不屬於此類比的額文件的發行版對象(例如,沒法分爲內核和initrd的對象)。
基於註冊的對象以及各個對象之間的關聯,Cobbler知道如何更改文件系統以反應具體配置。由於系統配置的內部是抽象的,因此您能夠僅關注想要執行的操做。
3、Cobbler各個組件的關係
經過cobbler管理的或者手動管理的服務
TFTP
rsync
DHCP
DNS
4、安裝配置Cobbler
一、安裝方式
cobbler能夠手動編譯安裝,也能夠基於yum源的安裝,若是使用yum源安裝,則須要配置epel源epel源能夠經過下載官網的epel源的目錄來實現https://fedoraproject.org/wiki/EPEL
# yum -y install cobbler cobbler-web pykickstart debmirror
二、檢查配置文件,須要在啓動cobblerd和httpd服務的前提下檢查
[root@c3 ~]# service httpd start [root@c3 ~]# service cobblerd start [root@c3 ~]# 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 : 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. 4 : change 'disable' to 'no' in /etc/xinetd.d/rsync 5 : comment out 'dists' on /etc/debmirror.conf for proper debian support 6 : comment out 'arches' on /etc/debmirror.conf for proper debian support 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.
以上8個問題的解決方法
1.修改/etc/cobbler/settings文件中的server參數的值爲提供cobbler服務的主機對應的ip地址 server: 192.168.13.8
2.修改/etc/cobbler/settings文件的next_server參數的值爲提供PXE服務的主機的ip next_server: 192.168.13.8
3.若是當前節點能夠訪問互聯網,執行「cobbler get-loaders」命令下載pxelinux.0,menu.c32,elibo.efi,yaboot文件,不然則須要安裝syslinux程序 包,複製/usr/share/syslinux/中的pxelinux.0,menu.c32等文件至/var/lib/cobbler /loaders目錄中 4.將/etc/xinetd.d/rsync 中的disable改成no,或者執行 chkconfig rsync on 5.註釋/etc/debmirror.conf文件中的「@dists="sid";」一行 6.註釋/etc/debmirror.conf文件中的「@arches="i386";」一行 7.執行「openssl passwd -1 -salt `pensshl rand -hex 4`」生成密碼,並將密碼串替換掉/etc/cobbler/settings中的default_password_crypted default_password_crypted: "$1$6a385fbf$iOHgbfJ0BJRQh78yAMA2L1"
8.安裝cam和fence-agents來實現電源管理
同步數據
[root@c3 cobbler]# cobbler sync task started: 2014-04-06_224909_sync task started (id=Sync, time=Sun Apr 6 22:49:09 2014) running pre-sync triggers cleaning trees mkdir: /var/lib/tftpboot/pxelinux.cfg mkdir: /var/lib/tftpboot/grub mkdir: /var/lib/tftpboot/s390x mkdir: /var/lib/tftpboot/ppc mkdir: /var/lib/tftpboot/etc removing: /var/lib/tftpboot/grub/images copying bootloaders trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0 trying hardlink /var/lib/cobbler/loaders/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 ***
5、配置cobbler依賴的服務
cobbler的運行以來dhcp、tftp、rsync、dns服務
cobbler可行管理這些服務中的部分甚至所有,但須要配置/etc/cobbler/settings文件中的「manager_dhcp」、 「manage_tftpd」、「manage_rsync」、「manage_dns」來定義,同時各類服務都有着不一樣的實現方式,若是進行自定義,需 要經過修改/etc/cobbler/modules.conf配置文件中各個服務的模塊參數的值來實現
咱們經過獨立管理,不經過cobbler管理這些服務。
一、配置dhcp服務
[root@c3 ~]# yum -y install dhcp [root@c3 ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf [root@c3 ~]# vim /etc/dhcp/dhcpd.conf option domain-name "jungege.com"; option domain-name-servers 192.168.13.8; default-lease-time 43200; max-lease-time 86400; log-facility local7; subnet 192.168.13.0 netmask 255.255.255.0 { range 192.168.13.2 192.168.13.100; option routers 192.168.13.8; } filename "pxelinux.0"; next-server 192.168.13.8;
啓動服務測試
# service dhcpd start # ss -ntlup | grep 67 udp UNCONN 0 0 *:67 *:* users:(("dhcpd",2766,7))
二、配置tftpd服務
[root@c3 ~]# yum -y install tftp-server [root@c3 ~]# chkconfig tftp on
6、配置Cobbler
一、定義distro
實現coobler的第一步就是定義distro,能夠經過其指定外部的安裝引導內核及ramdisk文件的方式實現。而若是已經有現成的安裝樹(如OS的安裝鏡像)則使用import導入的方式
掛載安裝光盤 # mount /dev/cdrom /media 導入系統鏡像 # cobbler import --name=centos6.5-x86-64 --path=/media/ 導入過程以下 task started: 2014-04-06_230831_import task started (id=Media import, time=Sun Apr 6 23:08:31 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/centos6.5-x86-64: creating new distro: centos6.5-64-x86_64 trying symlink: /var/www/cobbler/ks_mirror/centos6.5-x86-64 -> /var/www/cobbler/links/centos6.5-64-x86_64 creating new profile: centos6.5-64-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/centos6.5-x86-64 for centos6.5-64-x86_64 processing repo at : /var/www/cobbler/ks_mirror/centos6.5-x86-64 need to process repo/comps: /var/www/cobbler/ks_mirror/centos6.5-x86-64 looking for /var/www/cobbler/ks_mirror/centos6.5-x86-64/repodata/*comps*.xml running: createrepo -c cache -s sha --groupfile /var/www/cobbler/ks_mirror/centos6.5-x86-64/repodata/b4e0b9342ef85d3059ff095fa7f140f654c2cb492837de689a58c581207d9632-c6-x86_64-comps.xml /var/www/cobbler/ks_mirror/centos6.5-x86-64 received on stdout: Spawning worker 0 with 3995 pkgs Workers Finished Gathering worker results Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete received on stderr: *** TASK COMPLETE ***
列出全部的distro
[root@c3 ~]# cobbler distro list centos6.5-64-x86_64
二、管理profile
cobbler使用profile來爲特定的需求類別提供所須要安裝的配置,即在distro的基礎上經過提供kickstart文件來生成一個特定的系統安裝配置。distro的profile能夠出如今pxe的引導菜單中做爲安裝的選擇之一。
提供:anaconda-ks.cfg 配置以下:
anaconda:將安裝分紅兩個階段 安裝前配置階段 鍵盤類型 安裝過程當中的語言 支持的語言 時區 選擇要使用的磁盤設備 分區格式化 選擇要安裝的程序包 管理員密碼 是否使用iptables 是否啓用selinux 安裝階段 在目標磁盤上根文件系統 將選定的程序包安裝至目標磁盤 安裝前配置階段: 配置的選項分爲: 必選項和可選項 kickstart文件的組成部分: 命令段:用於配置系統 軟件包:指定要安裝的程序包及程序包組 %packages 標識 @Base:使用@指定包組 lftp:直接寫程序包名 注意:軟件包段每一個軟件包和包組每行只能寫一個 注意:在程序包前加-,不安裝相關包 %end :軟件包結束 腳本段: %pre:安裝過程開始前的預備腳本 所能執行的操做較小,它是一個首先得環境,由於其是僅有簡裝版的shell環境 %post:全部的軟件完成以後執行的腳本 此時,具備完整意義上的shell環境,但並不是全部命令都安裝,先確保全部的程序包已經安裝 %end :結束 以上一篇博文來具體講解一些參數的使用 # Kickstart file automatically generated by anaconda. #version=DEVEL install -->安裝 url --url=http://192.168.1.20/wangfeng7399 -->引導程序所在的位置
lang en_US.UTF-8 -->選擇語言 keyboard us -->選擇鍵盤類型 network --onboot yes --device eth0 --bootproto dhcp --noipv6 -->網卡的信息,表示開機自啓動,並經過dhcp過去ip地址,關閉ipv6功能 rootpw --iscrypted $6$CGsqab6d$Cd.PnnWtlL5XZAyr9J2zoMqyJH1QodcDp1pQp0uZ1f0Cq4eq9.TMkSQU6IfpvYZEYc32.lmF0lKuQwavnC49a0 -->root帳戶的密碼 # Reboot after installation reboot -->安裝完成後執行的操做 firewall --disabled -->防火牆的運行狀態 authconfig --useshadow --passalgo=sha512 -->加密寫入的文件和加密算法,這裏必需要和上面root密碼的加密算法一致 selinux --disabled -->selinux的運行狀態 timezone Asia/Shanghai -->選擇時區 bootloader --location=mbr --driveorder=sda --append="crashkernel=auto crashkernel=auto rhgb rhgb quiet quiet" -->mbr表寫入的磁盤,已經給內核傳遞的啓動參數 # 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表 text -->文本模式安裝 part /boot --fstype=ext4 --size=200 -->建立200M的ext4格式的/boot分區 part pv.9009 --size=61440 -->建立lvm物理卷 volgroup vg0 --pesize=8192 pv.9009 --> 建立lvm卷組,指定pe大小爲8M logvol / --fstype=ext4 --name=root --vgname=vg0 --size=20480 -->建立邏輯卷 logvol swap --name=swap --vgname=vg0 --size=2048 logvol /usr --fstype=ext4 --name=usr --vgname=vg0 --size=10240 logvol /var --fstype=ext4 --name=var --vgname=vg0 --size=20480 repo --name="CentOS" --baseurl=http://192.168.13.8/cobbler/ks_mirror/centos6.5/ -->指定repo的讀取位置,即rpm包的讀取位置
%packages -->程序包段的開始 @Base @Core @base @basic-desktop @chinese-support @client-mgmt-tools @core @desktop-platform @fonts @general-desktop @graphical-admin-tools @legacy-x @network-file-system-client @perl-runtime @remote-desktop-clients @x11 ibus-table-cangjie ibus-table-erbi ibus-table-wubi lftp %end -->程序包段的
添加profile
# cobbler profile add --name=centos6.5 --distro=centos6.5-x86_64 --kickstart=/root/anaconda-ks.cfg 列出當前系統上的profile # cobbler profile list centos6.5-64-x86_64 centos6.5-x86_64 刪除掉一個profile # cobbler profile remove --name=centos6.5-64-x86_64 # cobbler profile list centos6.5-x86_64
# service cobblerd restart # cobbler sync
四、系統安裝測試
開始安裝。。。
7、配置cobbler_web
cobbler_web支持多種認證方式,如authn_configfil、authn_ldap或 authn_pam等,默認爲authn_denyall拒接全部。
下面咱們使用authn_pam模塊認證cobbler_web用戶
# vim /etc/cobbler/modules.conf module = authn_pam # useradd zxj # passwd zxj 輸入密碼 # vim /etc/cobbler/users.conf [admins] admin = "zxj"
訪問:https://172.16.13.8/cobbler_web (注意我使用的虛擬機是雙網卡172.16.13.8與192.168.13.8兩個ip地址)
此時咱們能夠手動的添加刪除配置,更靈活的對distro 、profile等組件的管理!
PS: 水平有限,有錯誤請指出!