有沒有想過安裝系統跳過讨厭的選鍵盤,選滑鼠,分區,配置網路,選擇安裝包。
大緻介紹需要安裝的服務有:DHCP,COBBLER.
相關目錄:
cobbler使用目錄及檔案
cobbler相關配置檔案/etc/cobbler
cobbler資料存儲目錄/var/www/cobbler
cobbler系統設定/var/lib/cobbler/kickstarts/sample.ks
dhcp配置檔案/etc/dhcpd.conf
dhcp租期緩存檔案/var/lib/dhcpd/dhcpd.leases
如果需要修改引導時的啟動菜單,可修改以下檔案
[[email protected] ~]# vim/tftpboot/pxelinux.cfg/default
一、安裝dhcp服務
#yum -y install dhcp
配置DHCP服務
DHCP配置檔案為/etc/dhcp/dhcpd.conf,但該檔案預設是沒有内容的。
vim /etc/dhcp/dhcpd.conf
ddns-update-style interim;
allow booting;
allow bootp;
ignore client-updates;
set vendorclass = option vendor-class-identifier;
subnet 192.168.11.0 netmask 255.255.255.0 {
#比如你的主機(母雞)ip為172.18.0.24 設定subnet為172.18.0.0
range 192.168.11.240 192.168.11.253;
#這是你要配置設定給小雞的ip範圍
option domain-name-servers ns1.internal.example.org;
option domain-name "192.168.11.240";
option broadcast-address 192.168.11.255;
#廣播範圍,這裡是在172.18.0内廣播
default-lease-time 600;
max-lease-time 7200;
#在dhcpd.conf末尾添加如下内容:
# for Cobbler setup
host cobbler {
option host-name "cobbler";
ddns-hostname "cobbler";
hardware ethernet 00:0C:29:18:7D:7D;
#MAC address of cobbler server
fixed-address 192.168.11.240;
#母雞ip
#IP of Cobbler server
allow booting;
allow bootp;
class "PXE" {
match if substring(option vendor-class-identifier, 0, 9) = "PXEClient";
next-server 192.168.11.240; #IP of Cobbler server(母雞ip)
filename "pxelinux.0";
}
}
}
指定DHCP網卡
#sed -i 's/DHCPDARGS =/DHCPDARGS = eth0/g' /etc/sysconfig/dhcpd
修改成如下内容:
# Command line options here
DHCPDARGS=eth0
啟動DHCP伺服器
#service dhcpd start
讓dhcp服務随系統而啟動:
#chkconfig dhcpd on
二、安裝配置cobbler
由于Cobbler 不在 CentOS 6.3 的基本源中,需要導入 EPEL 源:
#rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm
#yum update
安裝 cobbler:
#yum install cobbler
這裡會安裝相關的依賴包
三、檢查修改cobbler配置
#cobbler check
如果提示安裝好後,shell提示無指令,可重新登入一下。
可能出現的問題:
The following are potential configuration items that you may want to fix:
1 : The 'server' field in /etc/cobbler/settings must be set to somethingother than localhost, or kickstarting features will not work. This shouldbe a resolvable hostname or IP for the boot server as reachable by all machinesthat will use it.
#修改 server 選項為主機名或是 IP 位址

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 shouldmatch the IP of the boot server on the PXE network.
#修改 next-server 對應的 IP 位址
3 : Must enable a selinux boolean to enable vital web services components,run: setsebool -P httpd_can_network_connecttrue
#修改 SELINUX setsebool -Phttpd_can_network_connect true
4 : you need to set some SELinux content rules to ensure cobbler servescontent correctly in your SELinux environment, run the following:/usr/sbin/semanage fcontext -a -t public_content_t "/tftpboot/.*"&& /usr/sbin/semanage fcontext -a -t public_content_t"/var/www/cobbler/p_w_picpaths/.*"
#修改 selinux 安全上下文标簽
5 : you need toset some SELinux rules if you want to use cobbler-web (an optional package),run the following:
/usr/sbin/semanagefcontext -a -t httpd_sys_content_rw_t "/var/lib/cobbler/webui_sessions/.*"
#修改 cobbler 對應的安全上下文标簽
6 : some networkboot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobblerget-loaders' to download them, or, if you only want to handlex86/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, shouldinclude pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders'command is the easiest way to resolve these requirements.
#運作 cobbler get-loaders以擷取 PXE 啟動需要的檔案
7 : change 'disable' to 'no' in /etc/xinetd.d/tftp
#開啟 tftp
8 : change 'disable' to 'no' in /etc/xinetd.d/rsync
#開啟 rsync
9 : since iptables may be running, ensure 69, 80, and 25151 are unblocked
#確定 69,80,25151 這個幾個端口沒有 iptables 阻止(iptables -L)
10 : debmirror package is not installed, it will be required to managedebian deployments and repositories
# debian的鏡像包沒有安裝,如果不安裝 debian ,這條可忽略
11 : The default password used by the sample templates for newly installedmachines (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
# 要求使用以上指令行建立新的密碼
12 : fencing tools were not found, and are required to use the (optional)power management features. install cman orfence-agents to use them
# 沒有安裝 fencing 工具,(yuminstall cman 或者yum install fence-agents)
解決完問題後繼續cobbler check
如沒有問題後可以繼續
四.導入引導系統
挂載 CentOS-6.3-x86_64-bin-DVD1.iso 安裝CD光牒然後導入到cobbler(注意這個 iso 檔案有 4GB 多,導入可能需要一段時間),導入成功後 cobbler list檢視一下:
挂載ios檔案,我可以使用
mkdir /mnt/cdrom
mount –o loop /root/soft/******.ios /mnt/cdrom
或者是從光驅導入:
#mount -t iso9660 /dev/cdrom /mnt/cdrom
完成上述二選一步驟後:
# cobbler import --path=/mnt/cdrom --name=CentOS-6.3-x86_64-bin-DVD --arch=x86_64
# cobbler sync
# cobbler list
顯示内容如下:
distros:
CentOS-6.3-bin-DVD1-x86_64
profiles:
CentOS-6.3-bin-DVD1-x86_64
systems:
repos:
p_w_picpaths:
五.測試
最後建立一台虛拟機測試一下,把虛拟機設定成網絡 PXE 啟動(和 cobbler 在同一個網絡),啟動後就可以看到 Cobbler 引導界面,看到界面後選擇CentOS-6.3-bin-DVD1-x86_64條目就可以順利開始無人工幹預安裝系統,Cobbler 引導界面如下:(注意虛拟機的設定)
六:關于安裝系統的設定比如分區、鍵盤、時區、軟體包
預設加載ks檔案為 /var/lib/cobbler/kickstarts/default.ks
檢視目前各個系統所使用的ks檔案
#cobbler report
Kickstart : /var/lib/cobbler/kickstarts/sample.ks
vim /var/lib/cobbler/kickstarts/sample.ks
可以看到各種設定(想研究的同學就要認真看看kickstart相關知識了)
值得注意的是cobbler在%pre和%post中加入了可執行指令或者腳本的功能
有興趣的同學研究一下下面的這些内容
You have the option of adding commands to run on thesystem once the installation is complete. This section must be at the end ofthe kickstart file and must start with the %post command. This section isuseful for functions such as installing additional software and configuring anadditional nameserver.
Note
If you configured the network with static IP information,including a nameserver, you can access the network and resolve IP addresses inthe %post section. If you configured the network for DHCP, the /etc/resolv.conffile has not been completed when the installation executes the %post section.You can access the network, but you can not resolve IP addresses. Thus, if youare using DHCP, you must specify IP addresses in the %post section.
Note
The post-install script is run in a chroot environment;therefore, performing tasks such as copying scripts or RPMs from theinstallation media do not work.
--nochroot
Allows you to specify commands that you would like to runoutside of the chroot environment.
The following example copies the file /etc/resolv.conf tothe file system that was just installed.
%post --nochroot
cp /etc/resolv.conf /mnt/sysp_w_picpath/etc/resolv.conf
--interpreter /usr/bin/python
Allows you to specify a different scripting language,such as Python. Replace /usr/bin/python with the scripting language of yourchoice.
--log /path/to/logfile
Logs the output of the post-install script. Note that thepath of the log file must take into account whether or not you use the--nochroot option. For example, without --nochroot:
This command is available in Red Hat Enterprise Linux 5.5and later.
%post --log=/root/ks-post.log
with --nochroot:
%post --nochroot --log=/mnt/sysp_w_picpath/root/ks-post.log
31.7.1. Examples
Register the system to a Red Hat Network Satellite, usinga subshell to log the result in Red Hat Enterprise Linux 5.4 and earlier:
%post
( # Note that in this example we run the entire %post section as asubshell for logging.
wget -O- http://proxy-or-sat.example.com/pub/bootstrap_script | /bin/bash
/usr/sbin/rhnreg_ks --activationkey=<activationkey>
# End the subshell and capture any output to a post-install log file.
) 1>/root/post_install.log 2>&1
Register the system to a Red Hat Network Satellite, usingthe --log option to log the result in Red Hat Enterprise Linux 5.5 and later:
%post --log=/root/ks-post.log
wget -O- http://proxy-or-sat.example.com/pub/bootstrap_script | /bin/bash
/usr/sbin/rhnreg_ks --activationkey=<activationkey>
Run a script named runme from an NFS share:
mkdir /mnt/temp
mount -o nolock 10.10.0.2:/usr/new-machines /mnt/temp open -s -w --
/mnt/temp/runme
umount /mnt/temp
七:/var/lib/cobbler/kickstarts/sample.ks
這是cobbler的另一個配置檔案,設定分區,安裝系統前後的腳本,安裝包的選擇
前面的設定為一些基本設定,分區,ip設定服務啟動,比較有用的是%pre,%package和%post這裡貼一個我的設定:
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%packages
$SNIPPET('cobbler_package')
%post
$SNIPPET('cobbler_test_rm')
$SNIPPET('cobbler_test')
$SNIPPET('cobbler_test_bash')
$SNIPPET('log_ks_post')
$SNIPPET('post_install_kernel_options')
$SNIPPET('post_install_network_config')
$SNIPPET('func_register_if_enabled')
$SNIPPET('puppet_register_if_enabled')
$SNIPPET('download_config_files')
$SNIPPET('koan_environment')
$SNIPPET('redhat_register')
$SNIPPET('cobbler_register')
# End final steps
配置檔案采用了載入檔案的方式,可載入得子產品在/var/lib/cobbler/snippets/目錄下,載入方式為$SNIPPET(‘檔案名’) ,可以在/var/lib/cobbler/snippets/下建立檔案,并在相應的子產品(%pre %package %post)載入,即可完成。其中
%packages指令支援下面的選項:
--nobase,不要安裝@Base 組.如果想建立一個很小的系統,可以使用這個選項.
--resolvedeps,選項已經被取消了.目前依賴關系可以自動地被解析.
--ignoredeps,選項已經被取消了.目前依賴關系可以自動地被解析.
--ignoremissing,忽略缺少的軟體包或軟體包組,而不是暫停安裝來向使用者詢問是中止還是繼續安裝.
%pre(kickstart預安裝腳本)開頭.可以在%pre部分通路網絡;然而,此時命名服務還未被配置,是以隻能使用IP位址.
注:預安裝腳本不在改換了的根環境(chroot)中運作.
--interpreter /usr/bin/python,允許指定不同的腳本語言,如Python.把/usr/bin/python替換成想使用的腳本語言.
%post(kickstart安裝後腳本)常用,即在系統安裝完成後執行一些腳本,即載入的$SINIPPET,(有興趣的同學可以檢視,/var/lib/cobbler/sinppets/下的各個檔案,還有一些相應的參數.
也可以加入在系統安裝完畢後運作的指令.這部分内容必須在kickstart的最後而且用%post指令開頭.它被用于實作某些功能,如安裝其他的軟體和配置其他的命名伺服器.
注:如果用靜态IP資訊和命名伺服器配置網絡,可以在%post部分通路和解析IP位址.如果使用DHCP配置網絡,當安裝程式執行到%post部分時,/etc/resolv.conf檔案還沒有準備好.此時,可以通路網絡,但是不能解析IP位址.是以,如果使用DHCP,必須在%post部分指定IP位址.
注:post-install 腳本是在 chroot 環境裡運作的.是以,某些任務如從安裝媒體複制腳本或RPM将無法執行.
--nochroot,允許指定想在chroot環境之外運作的指令
下例把/etc/resolv.conf檔案複制到剛安裝的檔案系統裡.
%post--nochroot cp /etc/resolv.conf /mnt/sysp_w_picpath/etc/resolv.conf
--interpreter /usr/bin/python
允許指定不同的腳本語言,如Python.把/usr/bin/python替換成想使用的腳本語言.
--log /path/to/logfile
%post --log=/root/ks-post.log
轉載于:https://blog.51cto.com/monkeyzhu/1324275