z8350键盘主机刷linux,自动化运维之系统篇:cobbler批量安装系统主机搭建
有沒(méi)有想過(guò)安裝系統(tǒng)跳過(guò)討厭的選鍵盤(pán),選鼠標(biāo),分區(qū),配置網(wǎng)路,選擇安裝包。
大致介紹需要安裝的服務(wù)有:DHCP,COBBLER.
相關(guān)目錄:
cobbler使用目錄及文件cobbler相關(guān)配置文件/etc/cobbler
cobbler數(shù)據(jù)存儲(chǔ)目錄/var/www/cobbler
cobbler系統(tǒng)設(shè)置/var/lib/cobbler/kickstarts/sample.ks
dhcp配置文件/etc/dhcpd.conf
dhcp租期緩存文件/var/lib/dhcpd/dhcpd.leases如果需要修改引導(dǎo)時(shí)的啟動(dòng)菜單,可修改以下文件
[root@cobbler ~]# vim/tftpboot/pxelinux.cfg/default
一、安裝dhcp服務(wù)
#yum -y install dhcp
配置DHCP服務(wù)
DHCP配置文件為/etc/dhcp/dhcpd.conf,但該文件默認(rèn)是沒(méi)有內(nèi)容的。
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 {
#比如你的主機(jī)(母雞)ip為172.18.0.24 設(shè)置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內(nèi)廣播
default-lease-time 600;
max-lease-time 7200;
#在dhcpd.conf末尾添加如下內(nèi)容:
# 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網(wǎng)卡
#sed -i 's/DHCPDARGS =/DHCPDARGS = eth0/g' /etc/sysconfig/dhcpd
修改成如下內(nèi)容:
# Command line options here
DHCPDARGS=eth0
啟動(dòng)DHCP服務(wù)器
#service dhcpd start
讓dhcp服務(wù)隨系統(tǒng)而啟動(dòng):
#chkconfig dhcpd on
二、安裝配置cobbler
由于Cobbler 不在 CentOS 6.3 的基本源中,需要導(dǎo)入 EPEL 源:
#yum update
安裝 cobbler:
#yum install cobbler
這里會(huì)安裝相關(guān)的依賴包
三、檢查修改cobbler配置
#cobbler check
如果提示安裝好后,shell提示無(wú)命令,可重新登錄一下。
可能出現(xiàn)的問(wèn)題:
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 選項(xiàng)為主機(jī)名或是 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 對(duì)應(yīng)的 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 安全上下文標(biāo)簽
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 對(duì)應(yīng)的安全上下文標(biāo)簽
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.
#運(yùn)行cobbler get-loaders以獲取 PXE 啟動(dòng)需要的文件
7 : change 'disable' to 'no' in /etc/xinetd.d/tftp
#開(kāi)啟 tftp
8 : change 'disable' to 'no' in /etc/xinetd.d/rsync
#開(kāi)啟 rsync
9 : since iptables may be running, ensure 69, 80, and 25151 are unblocked
#確保 69,80,25151 這個(gè)幾個(gè)端口沒(méi)有 iptables 阻止(iptables -L)
10 : debmirror package is not installed, it will be required to managedebian deployments and repositories
# debian的鏡像包沒(méi)有安裝,如果不安裝 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
#要求使用以上命令行創(chuàng)建新的密碼
12 : fencing tools were not found, and are required to use the (optional)power management features. install cmanorfence-agents to use them
#沒(méi)有安裝 fencing 工具,(yuminstall cman或者yum install fence-agents)
解決完問(wèn)題后繼續(xù)cobbler check
如沒(méi)有問(wèn)題后可以繼續(xù)
四.導(dǎo)入引導(dǎo)系統(tǒng)
掛載 CentOS-6.3-x86_64-bin-DVD1.iso 安裝光盤(pán)然后導(dǎo)入到cobbler(注意這個(gè) iso 文件有 4GB 多,導(dǎo)入可能需要一段時(shí)間),導(dǎo)入成功后 cobbler list查看一下:
掛載ios文件,我可以使用
mkdir /mnt/cdrom
mount–o loop /root/soft/******.ios /mnt/cdrom
或者是從光驅(qū)導(dǎo)入:
#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
顯示內(nèi)容如下:
distros:
CentOS-6.3-bin-DVD1-x86_64
profiles:
CentOS-6.3-bin-DVD1-x86_64
systems:
repos:
p_w_picpaths:
五.測(cè)試
最后創(chuàng)建一臺(tái)虛擬機(jī)測(cè)試一下,把虛擬機(jī)設(shè)置成網(wǎng)絡(luò) PXE 啟動(dòng)(和 cobbler 在同一個(gè)網(wǎng)絡(luò)),啟動(dòng)后就可以看到 Cobbler 引導(dǎo)界面,看到界面后選擇CentOS-6.3-bin-DVD1-x86_64條目就可以順利開(kāi)始無(wú)人工干預(yù)安裝系統(tǒng),Cobbler 引導(dǎo)界面如下:(注意虛擬機(jī)的設(shè)置)
六:關(guān)于安裝系統(tǒng)的設(shè)置比如分區(qū)、鍵盤(pán)、時(shí)區(qū)、軟件包
默認(rèn)加載ks文件為 /var/lib/cobbler/kickstarts/default.ks
查看當(dāng)前各個(gè)系統(tǒng)所使用的ks文件
#cobbler report
Kickstart : /var/lib/cobbler/kickstarts/sample.ks
vim /var/lib/cobbler/kickstarts/sample.ks
可以看到各種設(shè)置(想研究的同學(xué)就要認(rèn)真看看kickstart相關(guān)知識(shí)了)
值得注意的是cobbler在%pre和%post中加入了可執(zhí)行命令或者腳本的功能
有興趣的同學(xué)研究一下下面的這些內(nèi)容
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的另一個(gè)配置文件,設(shè)置分區(qū),安裝系統(tǒng)前后的腳本,安裝包的選擇
前面的設(shè)置為一些基本設(shè)置,分區(qū),ip設(shè)置服務(wù)啟動(dòng),比較有用的是%pre,%package和%post這里貼一個(gè)我的設(shè)置:
%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/下建立文件,并在相應(yīng)的模塊(%pre %package %post)載入,即可完成。其中
%packages指令支持下面的選項(xiàng):
--nobase,不要安裝@Base 組.如果想創(chuàng)建一個(gè)很小的系統(tǒng),可以使用這個(gè)選項(xiàng).
--resolvedeps,選項(xiàng)已經(jīng)被取消了.目前依賴關(guān)系可以自動(dòng)地被解析.
--ignoredeps,選項(xiàng)已經(jīng)被取消了.目前依賴關(guān)系可以自動(dòng)地被解析.
--ignoremissing,忽略缺少的軟件包或軟件包組,而不是暫停安裝來(lái)向用戶詢問(wèn)是中止還是繼續(xù)安裝.
%pre(kickstart預(yù)安裝腳本)開(kāi)頭.可以在%pre部分訪問(wèn)網(wǎng)絡(luò);然而,此時(shí)命名服務(wù)還未被配置,所以只能使用IP地址.
注:預(yù)安裝腳本不在改換了的根環(huán)境(chroot)中運(yùn)行.
--interpreter /usr/bin/python,允許指定不同的腳本語(yǔ)言,如Python.把/usr/bin/python替換成想使用的腳本語(yǔ)言.
%post(kickstart安裝后腳本)常用,即在系統(tǒng)安裝完成后執(zhí)行一些腳本,即載入的$SINIPPET,(有興趣的同學(xué)可以查看,/var/lib/cobbler/sinppets/下的各個(gè)文件,還有一些相應(yīng)的參數(shù).
也可以加入在系統(tǒng)安裝完畢后運(yùn)行的命令.這部分內(nèi)容必須在kickstart的最后而且用%post命令開(kāi)頭.它被用于實(shí)現(xiàn)某些功能,如安裝其他的軟件和配置其他的命名服務(wù)器.
注:如果用靜態(tài)IP信息和命名服務(wù)器配置網(wǎng)絡(luò),可以在%post部分訪問(wèn)和解析IP地址.如果使用DHCP配置網(wǎng)絡(luò),當(dāng)安裝程序執(zhí)行到%post部分時(shí),/etc/resolv.conf文件還沒(méi)有準(zhǔn)備好.此時(shí),可以訪問(wèn)網(wǎng)絡(luò),但是不能解析IP地址.因此,如果使用DHCP,必須在%post部分指定IP地址.
注:post-install 腳本是在 chroot 環(huán)境里運(yùn)行的.因此,某些任務(wù)如從安裝介質(zhì)復(fù)制腳本或RPM將無(wú)法執(zhí)行.
--nochroot,允許指定想在chroot環(huán)境之外運(yùn)行的命令
下例把/etc/resolv.conf文件復(fù)制到剛安裝的文件系統(tǒng)里.
%post--nochroot cp /etc/resolv.conf /mnt/sysp_w_picpath/etc/resolv.conf
--interpreter /usr/bin/python
允許指定不同的腳本語(yǔ)言,如Python.把/usr/bin/python替換成想使用的腳本語(yǔ)言.
--log /path/to/logfile
%post --log=/root/ks-post.log
總結(jié)
以上是生活随笔為你收集整理的z8350键盘主机刷linux,自动化运维之系统篇:cobbler批量安装系统主机搭建的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 企业的云服务选择:SaaS、PaaS、I
- 下一篇: Linux Huge page