整個安裝系統的流程與pxe仍是同樣的,只不過由手動變成了自動,各個版本之間也更好管理。html
這裏仍是centos系統的。cobbler的大體基礎使用。python
環境:linux
平臺:VirtualBox 虛擬機web
服務機:CentOS7redis
所安裝的系統:CentOS7, CentOS6json
cobbler裏面有幾個概念要首先了解一下:centos
distro: 用來標識一個發行版。由於安裝不一樣版本的系統起碼要用不一樣的內核與initrd來啓動安裝程序。這個就是用來區分它們的。注意distro主要是來標識不一樣的內核與initrd,與整個光盤的軟件沒有關係,這些軟件是在ks文件裏配置的。
bash
profile: 用來區分不一樣的配置信息, 最主要的就是區分不一樣的ks文件。若有的ks文件是最小化安裝,有的是桌面版安裝。
服務器
system: 估計是用來以MAC地址來區分不一樣主機,來完成定製安裝的吧。沒有嘗試過,不敢確定。架構
必定要區分一下,cobbler作的只是第一二階段的引導,在客戶機加載完內核與initrd文件之後就與cobbler沒有關係了。以後在哪裏下載軟件還有系統配置和分區就是ks文件的關係了。
目錄:
1、 配置cobbler
2、使用
3、導入軟件庫
4、建立profile
5、建立distro
6、cobbler-web
在yum info cobbler裏面能夠看到:
Cobbler supports PXE, ISO virtualized installs, and re-installing existing Linux machines.
這裏的PXE就是咱們這裏要說的。 其實就是pxe安裝,所須要的軟件與pxe安裝的也都同樣。惟一的區別就是自動配置和管理了。
cobbler在pxe安裝centos系統主要就是封裝了bootloader第一二階段。 而以後的安裝仍是要依靠ks文件來完成。
安裝上所依賴的程序dhcpd,tftp,httpd,rsync還有提供bootloader的syslinux。
yum install dhcp tftp httpd rsync syslinux -y
dhcpd.tftp.httpd是幹嗎用的不用多說了吧,dhcpd用來分配IP地址,並給序客戶端要下載的文件和tftp服務器。 tftp用來下載基礎啓動文件,第一二引導文件與菜單文件,還有內核與initrd。httpd用來下載ks文件與全部軟件。至於rsync,在作import導入光盤的時候會用到,其它的時候就不清楚了。
dns服務可裝可不裝。
1、 配置cobbler:
直接yum安裝便可。要有epel源。
[root@localhost yum.repos.d]# yum install cobbler -y
[root@localhost yum.repos.d]# rpm -ql cobbler | less /etc/cobbler /etc/cobbler/auth.conf /etc/cobbler/cheetah_macros /etc/cobbler/cobbler_bash /etc/cobbler/completions /etc/cobbler/dhcp.template #dhcp 配置模板。 /etc/cobbler/distro_signatures.json /etc/cobbler/dnsmasq.template #dnsmasq的配置模板。 dnsmasq一個輕量的dhcp與dns轉發功能的程序。 /etc/cobbler/import_rsync_whitelist /etc/cobbler/iso/buildiso.template #生成iso文件的模板。cobbler能夠以distro來製做iso文件。 /etc/cobbler/modules.conf #cobbler用來管理其它程序的模塊或者是引擎。 /etc/cobbler/named.template #named的配置模板, dns咱們這裏壓根就不用安裝。 /etc/cobbler/settings #主配置文件。 /etc/cobbler/tftpd.template #tftp配置模板。 /etc/httpd/conf.d/cobbler.conf #httpd的配置文件,用來把/var/www/cobbler目錄由httpd輸出,也就是能夠經過httpd下載這個目錄裏的內容了。
好吧,大部分都不知道幹嗎用的。
直接啓動服務,再cobbler check 。 來解決一些必須的項。
[root@localhost cobbler]# systemctl start cobblerd [root@localhost cobbler]# cobbler check httpd does not appear to be running and proxying cobbler, or SELinux is in the way. Original traceback: Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/cobbler/cli.py", line 252, in check_setup s.ping() File "/usr/lib64/python2.7/xmlrpclib.py", line 1224, in __call__ return self.__send(self.__name, args) File "/usr/lib64/python2.7/xmlrpclib.py", line 1578, in __request verbose=self.__verbose File "/usr/lib64/python2.7/xmlrpclib.py", line 1264, in request return self.single_request(host, handler, request_body, verbose) File "/usr/lib64/python2.7/xmlrpclib.py", line 1292, in single_request self.send_content(h, request_body) File "/usr/lib64/python2.7/xmlrpclib.py", line 1439, in send_content connection.endheaders(request_body) File "/usr/lib64/python2.7/httplib.py", line 969, in endheaders self._send_output(message_body) File "/usr/lib64/python2.7/httplib.py", line 829, in _send_output self.send(msg) File "/usr/lib64/python2.7/httplib.py", line 791, in send self.connect() File "/usr/lib64/python2.7/httplib.py", line 772, in connect self.timeout, self.source_address) File "/usr/lib64/python2.7/socket.py", line 571, in create_connection raise err error: [Errno 111] Connection refused
啓動httpd再來試一下:
[root@localhost cobbler]# systemctl start httpd [root@localhost cobbler]# 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 : file /etc/xinetd.d/rsync does not exist 6 : debmirror package is not installed, it will be required to manage debian deployments and repositories 7 : ksvalidator was not found, install pykickstart 8 : 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 9 : 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.
修改setting配置文件中的server地址爲提供cobbler與httpd服務的主機名或ip。
修改setting配置文件中的next_server爲提供pxe服務的主機名或ip。
這個若是在centos6系統上按上面說的做就能夠, 但在centos7上面tftp由systemd管理,因此只要可以啓動tftp就能夠忽略這個了。
沒有bootloader文件,若是能夠連網,執行cobbler get-loaders能夠自動下載。也能夠用syslinux起供的bootloader文件。(第二階段的引導文件也能夠用光盤裏的vesamenu.c32,不過要更名爲menu.c32。
cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/cobbler/loaders/
一樣的只要肯定安裝了rsync就能夠。
這個軟件在只安裝centos系統的狀況下也能夠不安裝,只在部署debian系的系統時要用到。
還要安裝pykickstart軟件,yum安裝便可。
給default_password_crypted配置一個密碼,用openssl生成或是新建一個用戶,在shadow文件中複製出來均可以。
這個能夠忽略或是安裝cman 和 fence-agents。
/var/lib/cobbler/loaders/ 這個目錄能夠理解爲cobbler的工做目錄,一些要用到的引導文件或ks都要放到這裏,cobbler會自動從這裏複製。如:會把pxelinux.0複製到tftp根目錄。
啓動tftp與rsync
[root@localhost cobbler]# systemctl start tftp.socket [root@localhost cobbler]# systemctl start rsyncd.socket
密碼那個用openssl的話只能是md5加密的,若是要用其它的,能夠建立個臨用戶,給用戶設好密碼之後中,再把/etc/shadow文件中的密碼複製出來。
都完成之後就能夠執行cobbler sync而後再重啓cobbler。
[root@localhost cobbler]# cobbler sync [root@localhost cobbler]# systemctl restart cobblerd [root@localhost cobbler]# cobbler check The following are potential configuration items that you may want to fix: 1 : 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. 2 : file /etc/xinetd.d/rsync does not exist 3 : debmirror package is not installed, it will be required to manage debian deployments and repositories 4 : 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.
由於bootloader咱們只複製了一部分,不全,因此還會報故障。也能夠試試把/etc/share/syslinux/目錄裏的全部文件都複製過去再試試。 不過對於咱們這裏已經夠用了。
cobbler sync 是用來同步配置和文件的,如根據配置生成菜單文件,如爲內核和initrd文件作硬連接到tftp目錄裏,如複製ks文件,複製引導文件。總之就是準備好遠程系統安裝的一切所需。
在主配置文件中:
manage_dhcp: 0
manage_dns: 0
manage_tftpd: 1
manage_rsync: 0
這幾項表示是否由cobbler管理這些程序。tftpd不用怎麼配置,讓cobbler來管理也能夠。不過dhcp之類的若是讓它自動管理和配置的話,可能會很麻煩。 若是想讓cobbler來管理的話能夠改成1。而後再修改一下那幾個模板文件,還有modules裏面的管理模塊。
2、使用:
[root@localhost cobbler]# cobbler --help usage ===== cobbler <distro|profile|system|repo|p_w_picpath|mgmtclass|package|file> ... #主選項 [add|edit|copy|getks*|list|remove|rename|report] [options|--help] #次選項 cobbler <aclsetup|buildiso|import|list|replicate|report|reposync|sync|validateks|version|signature|get-loaders|hardlink> [options|--help] #輔助選項 [root@localhost cobbler]#
如查看當前distro與profile。
[root@localhost cobbler]# cobbler distro list [root@localhost cobbler]# cobbler profile list
固然咱們什麼也沒有添加呢。 也能夠像下面這樣查看profile有什麼次選項。 distro固然也同樣。
[root@localhost cobbler]# cobbler profile help usage ===== cobbler profile add cobbler profile copy cobbler profile dumpvars cobbler profile edit cobbler profile find cobbler profile getks cobbler profile list cobbler profile remove cobbler profile rename cobbler profile report [root@localhost cobbler]#
而次選項都有哪些選項能夠再加上--help
[root@localhost cobbler]# cobbler profile add --help
會有不少。 或許這個裏面纔是選項吧,上面那些應該叫子命令。
distro表示一個發行版,而同一個發行版能夠有多個profile。profile就是配置,如ks。 同一個系統按不一樣的安裝方式能夠有多個ks文件。
3、導入軟件庫
最簡單的添加distro的方式,就是cobbler import。 cobbler會複製全部系統文件到本身所管理的目錄中,並抽取內核與initrd文件來建立distro。 並根據ks文件來建立profile。
[root@localhost cobbler]# cobbler import --help Usage: cobbler [options] Options: -h, --help show this help message and exit --arch=ARCH OS architecture being imported #手動指定系統架構。 --breed=BREED the breed being imported --os-version=OS_VERSION the version being imported --path=PATH local path or rsync location #安裝倉庫的位置,能夠用光盤。 --name=NAME name, ex 'RHEL-5' #distro名稱,必選項。 --available-as=AVAILABLE_AS tree is here, don't mirror --kickstart=KICKSTART_FILE #指定要使用的ks文件,若是不指定,cobbler會使用一個自帶的最小安裝的ks文件。 assign this kickstart file --rsync-flags=RSYNC_FLAGS pass additional flags to rsync
如:導入centos6的。
注意: 顯示出來的只是python打印出來的信息,後面是在用rsync來同步光盤數據,因此想要中止的話要kill掉rsync才行,在這裏ctrl+c是沒有用的。能夠用lsof 來查看有哪些程序在使用某個文件。
[root@localhost cobbler]# cobbler import --name="CentOS6" --path=/mnt/cdrom1 task started: 2016-02-25_183411_import task started (id=Media import, time=Thu Feb 25 18:34:11 2016) 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: creating new distro: CentOS6-x86_64 trying symlink: /var/www/cobbler/ks_mirror/CentOS6 -> /var/www/cobbler/links/CentOS6-x86_64 creating new profile: CentOS6-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 for CentOS6-x86_64 processing repo at : /var/www/cobbler/ks_mirror/CentOS6 need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS6 looking for /var/www/cobbler/ks_mirror/CentOS6/repodata/*comps*.xml Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS6/repodata *** TASK COMPLETE *** [root@localhost cobbler]#
ok了, COMPLETE。
[root@localhost cobbler]# cobbler distro list CentOS6-x86_64 [root@localhost cobbler]# cobbler profile list CentOS6-x86_64
能夠看到distro和profile了。咱們還能夠以這個distro建立多個profile。
如今也能夠再看下tftp的根目錄有哪些文件了,通常在/var/lib/tftpboot裏面。還有httpd的/var/www/cobbler/目錄。
一下子還要建立profile, 咱們先把這個profile重命名一下:
[root@localhost cobbler]# cobbler profile rename --name=CentOS6-x86_64 --newname=CentOS6-x86_64_mini [root@localhost cobbler]# cobbler profile list CentOS6-x86_64_mini
應用部署環境:
[root@localhost cobbler]# cobbler sync
DHCP,把dhcp配置一下就能夠測試一下會不會自動安裝了。簡單配置一下。
default-lease-time 3600; # 默認租約 max-lease-time 7200; #最長租約 log-facility local5; #我這裏把日誌設施改了,還要在/etc/rsyslog.conf裏面添加這個日誌的存儲路徑。 如:local5.* /var/log/dhcp.log subnet 192.168.40.0 netmask 255.255.255.0 { #添加做用域。 range 192.168.40.10 192.168.40.20; #地址池 filename "pxelinux.0"; #客戶端要去找的文件。 next-server 192.168.40.100; #客戶端去×××filename的文件。 }
dhcp的示例配置文件在/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example。能夠把這個文件複製到/etc/dhcp/dhcpd.conf,原來的那個裏面是空的配置。而後根據這個文件來自定義配置。
啓動dhcp和tftpd.
[root@localhost cobbler]# systemctl start dhcpd.service tftp.socket
測試:
看起來工做正常, 我這裏選擇CentOS6那項了, 能看到在加載內核與initrd文件。 我這裏自動安裝完成。
4、建立profile。
[root@localhost cobbler]# cp /root/centos6.cfg /var/lib/cobbler/kickstarts/ [root@localhost cobbler]# cobbler profile add --name=CentOS6-server --distro=CentOS6-x86_64 --kickstart=/var/lib/cobbler/kickstarts//centos6.cfg [root@localhost cobbler]# cobbler profile list CentOS6-server CentOS6-x86_64_mini
須要把ks文件複製到cobbler所管理的目錄中, 也就是/var/lib/cobbler/kickstarts/目錄下。否則會報錯:
exception on server: 'Invalid kickstart template file location /root/centos6.cfg, it is not inside /var/lib/cobbler/kickstarts/'
ks文件:
firewall --disabled install url --url="/var/www/cobbler/ks_mirror/CentOS6/" #注意這個路徑 rootpw --iscrypted $6$3hHx9zVZ$ShB3kPo0UeHpetxNXEJr2GynXg2rcg2lgCflfTbuxN1yfUbrUmBJu3P/ncD/X467M1jN2yxiNWnBExozzjafg1 text firstboot --disable keyboard us lang en_US selinux --disabled reboot timezone Asia/Shanghai bootloader --append="rhgb crashkernel=auto quiet" --location=mbr --driveorder="sda" zerombr clearpart --all part /boot --fstype="ext4" --size=200 part pv.008 --size=61440 volgroup vg0 --pesize=8192 pv.008 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 %packages @base @core %end
應用部署,cobbler sync。
能夠看一下/var/lib/tftpboot/pxelinux.cfg/default。 這個是顯示的那個菜單的文件。
再來測試機上試一下:
能夠看到仍是同一個內核與initrd文件,相同的distro。 不過由於ks文件的不一樣,所安裝的軟件和所作的配置確定是不一樣的。
5、建立distro
向上面那種直接導入就是讓cobbler徹底管理了,比這種建立的要好。不過既然有,咱們就來試一下。
咱們知道distro中最主要的就是內核與initrd。因此指定這兩個就能夠了。
[root@localhost cobbler]# cobbler distro add --name=centos7 --kernel=/mnt/cdrom/p_w_picpaths/pxeboot/vmlinuz --initrd=/mnt/cdrom/p_w_picpaths/pxeboot/initrd.img [root@localhost cobbler]# cobbler distro list CentOS6-x86_64 centos7 [root@localhost cobbler]# cobbler profile list CentOS6-server CentOS6-x86_64_mini [root@localhost cobbler]#
只添加了一個distro,profile不會添加。咱們再來添加一個profile。由於ks文件要定義在哪裏下載軟件包,咱們先把光盤目錄綁定到http的下載目錄。
[root@localhost cobbler]# mount --bind /mnt/cdrom /var/www/html/centos7
再來定義ks文件:
install xconfig --startxonboot keyboard --vckeymap=cn --xlayouts='cn' reboot rootpw --iscrypted $1$HDHf2v4i$LMo.xGHfxQDOf8e043C.g/ timezone Asia/Shanghai url --url="http://192.168.40.100/centos7/" #注意下載路徑 user --groups=wheel --name=mageedu --password=$6$1eWrOetY$DfLZgquGiOaNkwpEF4ItMipz.1kpn7Q.s6oXyoW2bALkWesRWHCCACICkJ.2zBXDbwEw0ibR.wxStLI41ZhfF1 --iscrypted --gecos="MageEdu" firewall --disabled network --bootproto=dhcp --device=eth0 auth --useshadow --passalgo=sha512 text firstboot --disable selinux --permissive ignoredisk --only-use=sda bootloader --location=mbr --boot-drive=sda zerombr clearpart --all --initlabel part /boot --asprimary --fstype="xfs" --size=512 part swap --fstype="swap" --size=2048 part /usr --fstype="xfs" --size=20480 part / --fstype="xfs" --size=20480 %packages @base @core @fonts
建立profile:
[root@localhost cobbler]# cp /root/centos7.cfg /var/lib/cobbler/kickstarts/ [root@localhost cobbler]# cobbler profile add --name=centos7-server --distro=centos7 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg [root@localhost cobbler]# cobbler profile list CentOS6-server CentOS6-x86_64_mini centos7-server [root@localhost cobbler]#
應用部署:
[root@localhost cobbler]# cobbler sync
測試:
加載的centos7目錄下的內核與initrd文件。這個centos7好像就是咱們的distro名稱啊。
安裝完成了。
6、cobbler-web
用網頁來管理cobbler
安裝cobbler-web
[root@localhost cobbler]# yum install cobbler-web -y
設置認證方式。
cobbler_web支持多種認證方式,如authn_configfile、authn_ldap或authn_pam等,默認爲authn_denyall,即拒絕全部用戶登陸。
一、使用authn_pam模塊認證cobbler_web用戶。就是以系統用戶來認證。
修改modules.conf中[authentication]段的module參數的值爲authn_pam。
而後建立系統用戶就能夠了。
然後將建立的用戶添加至cobbler_web的admin組中。修改/etc/cobbler/users.conf文件,將用戶名添加爲admin參數的值便可。
最後重啓cobblerd和httpd服務,經過http://host/cobbler_web/ 訪問便可。
出現這個問題能夠查看/etc/httpd/conf.d/cobbler_web.conf。 由cobbler-web生成的。
如今的cobbler版本默認使用ssl。而且會自動安裝上mod-ssl模塊。這裏能夠用https來訪問,不過ssl證書是由mod-ssl模塊自帶的,能夠在/etc/httpd/conf.d/ssl.conf裏面改一下。 這裏就是httpd的配置了。
也能夠在cobbler_web.conf裏面註釋使用ssl,就能夠用http訪問了。
不過若是不使用https的話,最簡單的方法就是刪除/etc/httpd/conf.modules.d/00-ssl.conf和ssl.conf文件。重啓httpd服務。
二、使用authn_configfile模塊認證cobbler_web用戶
首先修改modules.conf中[authentication]段的module參數的值爲authn_configfile。
接着建立其認證文件/etc/cobbler/users.digest,並添加所需的用戶便可。
添加第一個用戶時,須要爲htdigest命令使用「-c」選項來建立文件,後續添加其餘用戶時不能再使用。
另外,cobbler_web的realm只能爲Cobbler。
[root@localhost ~]# htdigest --help Usage: htdigest [-c] passwordfile realm username The -c flag creates a new file. [root@localhost ~]# htdigest -c /etc/cobbler/users.digest Cobbler cobb Adding password for cobb in realm Cobbler. New password: Re-type new password:
realm就是在彈出窗口式的登陸中的提示信息。
最後重啓cobblerd服務,經過http://host/cobbler_web/訪問便可。
ks文件,有cobbler自帶的也有咱們剛纔複製進去的。
哦對了,咱們這裏試一下把centos7的vesamenu.c32當成bootloader試試。 syslinux帶的menu.c32是字符界面的窗口,而vesamenu.c32是圖形的。
[root@localhost ~]# cp /mnt/cdrom/isolinux/vesamenu.c32 /var/lib/cobbler/loaders/menu.c32 cp: overwrite ‘/var/lib/cobbler/loaders/menu.c32’? y [root@localhost ~]# cobbler sync
另外這個菜單也能夠自定義,如添加個什麼信息,修改個什麼信息。朋友們就本身嘗試吧。