歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> cobbler 主機自動化部署

cobbler 主機自動化部署

日期:2017/2/27 15:54:04   编辑:Linux教程

cobbler的相關優勢:

Cobbler支持命令行管理,web界面管理,還提供了API接口,可以方便二次開發使用。

cobbler不會因為在局域網中啟動了dhcp而導致有些機器因為默認從pxe啟動在重啟服務器後加載tftp內容導致啟動終止。

Cobbler作為一個預備工具,使部署RedHat/Centos/Fedora系統更容易,同時也支持Suse和Debian系統的部署

服務集成:

PXE服務支持

DHCP服務管理

DNS服務管理

Kickstart服務支持

yum倉庫管理

Cobbler客戶端Koan支持虛擬機安裝和操作系統重新安裝

Cobbler web界面 可以更好得管理用戶操作界面

安裝過程引導:


yum源的准備:
repo包的安裝。
# wget http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
## rpm -ivh epel-release-6-8.noarch.rpm



cobbler網絡安裝:
# yum install cobbler cobbler-web httpd xinetd tftp-server rsync koan dhcpd debmirror(debian的鏡像包) pykickstart cman fence-agent -y

cobbler的相關目錄信息:
/var/lib/cobbler 存儲導入的鏡像的配置信息,kickstarts目錄存放kickstarts腳本(多個.ks安裝模板),snippets目錄存放在kickstat 配置文件中可以執行的腳本,config目錄提供配置信息(比如distros和profile相關信息),還有其他目錄基本上無需配置。

/var/www/cobbler 是導入發行版的操作系統的數據目錄,ks_mirror裡面是導入的發行版系統,images裡面是所有發行版的kernel(vmlinuz)和initrd(initrd.img),用於遠程網絡啟動
/var/log/cobbler 是日志目錄
/etc/cobbler 是cobbler的配置文件目錄,settings是主配置文件,裡面還有一些相關配置模版,users.conf是用戶,users.digest是用戶及密碼


cobbler相關命令:
#cobbler list 列出相關cobber元素(distros和profile)
#cobbler check 檢查cobbler配置(一般會提示需要進行怎樣的配置)
#cobbler report 列出cobbler的詳細信息
#cobbler distro 查看導入的相關系統發行版信息
#cobbler profile 查看cobbler創建的相關pofile信息
#cobbler sync 同步cobbler相關配置(最好每次執行完配置後都進行修改)
#cobbler reposync 同步repo源

配置前首先進行配置檢測
# 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 : since iptables may be running, ensure 69, 80/443, and 25151 are unblocked
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.
1.提示需要在/etc/cobbler/settings中進行配置server選項。指定ip或者主機名
2.在主配置文件中修改next_server選項,以便使用pxe功能
3.缺少網絡啟動的boot-loader,可以執行"cobbler get-loaders"進行下載
4.開啟rsync功能(在/etc/xinetd.d/rsync中選擇啟用)
5.讓iptables可以允許69,80,443等端口訪問(可以直接使用iptables -F關閉)
6.debmirror包沒有安裝(這個是用來管理debian系統的配置和repo)
7.提示安裝pykickstart
8.在主配置文件中的default_password_crypted需要進行設置(使用'openssl passwd -1 -salt "任意字符" "密碼"')注意,此密碼會被默認用來做系統的root密碼
9.fence工具沒裝,需要被用來管理電源。可以安裝cman或者fence-agents
注意:執行完相關操作之後,請進行重啟cobbler服務,並進行'cobbler sync'操作。

重啟cobbler,重啟httpd,執行cobbler check執行檢測。

# openssl passwd -1 新建cobbler密碼
(# openssl passwd -1 -salt 'wyadmin' 'wyadmin' 密碼為wyadmin,生成一個加密字符
$1$wyadmin$eC7GvOUyR0IKHPqo5.FLg0)
注意:(這塊就是root密碼)
詳情可以觀察/var/lib/cobbler/kickstart/sample.ks中的密碼文件($default_password_crypted)而這個就是使用openssl生成的密碼(在/etc/cobbler/settings中配置過)

主配置文件詳情:
# vim /etc/cobbler/settings
server: 10.45.249.101
next_server: 10.45.249.101
default_password_crypted: "$1$wyadmin$eC7GvOUyR0IKHPqo5.FLg0"
manage_dhcp: 1 啟用dhcp(讓cobbler進行控制dhcp)
default_kickstart: /var/lib/cobbler/kickstarts/default.ks當在使用kickstart新建操作系統(其實這個文件是空的,默認可用的是sample.ks)

啟用tftp(disabled = no)
啟用rsync
啟動cobbler,dhcpd,httpd.關閉selinux(setenforce 0暫時關閉)

# cobbler get-loaders 會去pxe啟動需要的loader(boot-loader),執行此命令會進行下載boot-loader
# cobbler check 再次檢測cobbler所需要的配置

重啟cobbler並且執行cobbler sync


配置DHCP:
修改dhcp代理文件(簡單的dhcp修改)

# vim /etc/cobbler/dhcp.template 需要修改的地方(子網,網管以及范圍的設置)
subnet 10.45.249.0 netmask 255.255.255.0 {
option routers 10.45.249.102;
option domain-name-servers 10.45.249.102;
option subnet-mask 255.255.255.0;
range dynamic-bootp 10.45.249.10 10.45.249.0;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server; 這裡使用的是一個變量

# vim /etc/dhcp/dhcpd.conf 可用進行簡單的配置,將所有服務重啟後會發現這個文件和上面那個文件同步了
然而,剛開始配置好dhcp後很多情況下dhcp是無法啟動的。
# cat /etc/sysconfig/dhcpd
DHCPDARGS=eth1

同步cobbler配置:
/etc/init.d/cobblerd restart 再次重啟後發現dhcp啟動了
/etc/init.d/xinetd restart
/etc/init.d/dhcpd restart
/etc/init.d/httpd restart


###cobbler sync 在執行sync命令後會顯示相關的服務啟動
注意,每次修改完dhcp配置後,執行cobbler sync同步
注意:有時候dhcp服務不能起來,需要進行cobbler sync後才能啟動

#mount /dev/cdrom /mnt 掛載鏡像文件

# cobbler import --path=/mnt --name=rhel6.6_x86-64 導入系統介質(對distros起名)默認就導入/var/www/cobbler/ksmirror目錄
task started: 2015-03-25_040449_import
task started (id=Media import, time=Wed Mar 25 04:04:49 2015)
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/rhel6.6_x86-64:
creating new distro: rhel6.6-64-x86_64
trying symlink: /var/www/cobbler/ks_mirror/rhel6.6_x86-64 -> /var/www/cobbler/links/rhel6.6-64-x86_64
creating new profile: rhel6.6-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/rhel6.6_x86-64 for rhel6.6-64-x86_64
processing repo at : /var/www/cobbler/ks_mirror/rhel6.6_x86-64
directory /var/www/cobbler/ks_mirror/rhel6.6_x86-64 is missing xml comps file, skipping
*** TASK COMPLETE ***


重啟以下服務:
xinted cobblerd httpd dhcpd


# cobbler list 查看cobbler屬性
distros: 可用的發行版
rhel6.6-64-x86_64
profiles: 對應的配置文件(其實就是系統啟動模板)
rhel6.6-64-x86_64
systems: 系統的設置,針對系統對應的主機名.ip.MAC進行系統安裝
repos: 軟件倉庫
images:
mgmtclasses:
packages:

files:

定義kickstart文件:
設置profile,關聯鏡像和kickstart文件,profile可以理解為按角色進行分類

用cobbler安裝操作系統時,cobbler真正執行的kickstart文件其實不是 /var/lib/cobbler/kickstarts/default.ks,
而是 /var/lib/cobbler/kickstarts/sample.ks,可在配置文件/etc/cobbler/settings中看到。
在這塊其實可以定義多個ks的文件,進行關聯多個profile模板.


配置profile和system,使用某個kickstart文件:
1.添加profile(在裝機啟動的時候其實就會看見RHEL6.6.X86和rhel6.6-64-x86_64選項)
# cobbler profile add --name=RHEL6.6.X86 --distro=rhel6.6-64-x86_64 --kickstart=/var/lib/cobbler/kickstarts/esxi4-ks.cfg
(從rhel6.6-64-x86_64鏡像中,按照ks.cfg文件生成一個安裝模板)

將distro設定為自己的鏡像(cobbler list)
(注意,這個其實就是相當於修改一個裝機模板,用來在裝機選擇新加的esxi4-ks.cfg)

2.變更profile配置名稱
# cobbler profile rename --name=centos6.6 --newname=rhel6.6-x86_64
(cobbler list的時候可以查看到兩個profile)

3.刪除profile配置
# cobbler profile remove --name=rhel6.6-x86_64

測試安裝,類似於PXE,直接安裝就可。

可以看到兩個安裝選項,這個就是之前創建的兩個profile。安裝步驟就不再貼圖。

優化:在整個安裝中需要手動管理幾部分,這塊其實可以自定義好ks文件,進行全自動化安裝。

虛擬機創建成功!

注意:如果安裝的主機在某一個時間段被黑了,或則系統想統一,那麼可以使用cobbler中的koan來重新安裝。

重裝:
1.在客戶端安裝koan
#yum install koan -y
2.查看cobbler服務器上可選的安裝列表
# koan --list=profiles --server=10.45.249.102
- looking for Cobbler at http://10.45.249.102:80/cobbler_api
rhel6.6-x86_64
rhel6.6-64-x86_64
3.下載重裝模板(下載完畢後提示重啟)
# koan --replace-self --server=10.45.249.102 --profile=rhel6.6-64-x86_64
4.執行重啟安裝
#reboot
重啟之後主機會進行重新初始化設置,重新安裝系統!
Copyright © Linux教程網 All Rights Reserved