z8350键盘主机刷linux,自动化运维之系统篇:cobbler批量安装系统主机搭建
有沒有想過安裝系統跳過討厭的選鍵盤,選鼠標,分區,配置網路,選擇安裝包。
大致介紹需要安裝的服務有: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如果需要修改引導時的啟動菜單,可修改以下文件
[root@cobbler ~]# 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 源:
#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 cmanorfence-agents to use them
#沒有安裝 fencing 工具,(yuminstall cman或者yum install fence-agents)
解決完問題后繼續cobbler check
如沒有問題后可以繼續
四.導入引導系統
掛載 CentOS-6.3-x86_64-bin-DVD1.iso 安裝光盤然后導入到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=
# 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=
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
總結
以上是生活随笔為你收集整理的z8350键盘主机刷linux,自动化运维之系统篇:cobbler批量安装系统主机搭建的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 企业的云服务选择:SaaS、PaaS、I
- 下一篇: 绿之韵传销是空穴来风,一心一意为健康事业