三、Cobbler 常用命令汇总
1.导入镜像文件
命令:cobbler import --path=镜像路径 -- name=安装引导名 --arch=32位或64位
参数:
path 是镜像所挂载的目录
name 是导入到cobbler里面显示的名字
arch 是32位系统还是64位系统
2.导入kickstart文件
命令:cobbler profile add --name=list名 --distro=镜像 --kickstart=路径
参数:
name是表示添加的ks 的名字,用cobbler report可以看到这个名字
distro 是用哪个镜像,list的distros里面选择一个,需要版本相对应
kickstart 是具体的 ks 文件路径
3.同步DHCP、HTTPD
命令:cobbler sync
注,每次修改完dhcp.template之类的配置文件需要执行一次使其生效。
4.查看Cobbler列表
命令:cobbler list
注,列出Cobbler所有的元素。
5.删除相关列表
命令:cobbler distro/profile remove --name=要删除的引导文件名
删除指定 distro , 也就是镜像
删除指定的 profile 文件,也就是 ks
四、Cobbler 各种目录说明(注,这里只介绍重点的文件或目录 )
1.cobbler配置文件目录/etc/cobbler
[root@node2 cobbler]# ls /etc/cobbler/
auth.conf cobblerd.service dnsmasq.template mongodb.conf rsync.exclude users.conf
cheetah_macros cobbler_web.conf import_rsync_whitelist named.template rsync.template users.digest
cobbler_bash completions iso power secondary.template version
cobbler.conf dhcp.template ldap pxe settings zone.template
cobblerd_rotate distro_signatures.json modules.conf reporting tftpd.template zone_templates
/etc/cobbler/settings cobbler主配置文件
/etc/cobbler/iso/ iso模板配置文件
/etc/cobbler/pxe pxe模板文件
/etc/cobbler/power 电源的配置文件
/etc/cobbler/users.conf Web 服务授权配置文件
/etc/cobbler/users.digest 用于web访问的用户名密码配置文件
/etc/cobbler/dhcp.template DHCP服务的配置模板
/etc/cobbler/dnsmasq.template DNS服务的配置模板
/etc/cobbler/tftpd.template tftp服务的配置模板
/etc/cobbler/modules.conf Cobbler模块配置文件
2.cobbler数据目录/var/lib/cobbler
[root@node2 cobbler]# ls /var/lib/cobbler/
config distro_signatures.json kickstarts loaders lock scripts snippets triggers web.ss
[root@node2 config]# ls
distros.d files.d images.d mgmtclasses.d packages.d profiles.d repos.d systems.d
[root@node2 loaders]# ls
COPYING.elilo COPYING.yaboot grub-x86_64.efi menu.c32 README
COPYING.syslinux elilo-ia64.efi grub-x86.efi pxelinux.0 yaboot
/var/lib/cobbler/config/ 用于存放distros、systems、profiles等信息配置文件
/var/lib/cobbler/triggers 用于存放用户定义的cobbler 命令
/var/lib/cobbler/kickstarts/ 默认存放kickstart文件
/var/lib/cobbler/loaders 存放的各种引导程序
3.镜像数据目录/var/www/cobbler
[root@node2 cobbler]# ls
aux images ks_mirror links localmirror pub rendered repo_mirror svc
/var/www/cobbler/ks_mirror/ 导入的发行版系统的所有数据
/var/www/cobbler/images/ 导入发行版的Kernel和initrd镜像用于远程网络启动
/var/www/cobbler/repo_mirror/ yum仓库存储目录
4.日志目录 /var/log/cobbler/
[root@node2 cobbler]# ls
anamon cobbler.log install.log kicklog syslog tasks
[root@node2 cobbler]# cat install.log
profile CentOS-5.5-x86_64 192.168.18.222 start 1384219313.49
profile CentOS-5.5-x86_64 192.168.18.222 stop 1384219512.05
/var/log/cobbler/install.log 客户端的安装系统日志
/var/log/cobbler/cobbler.log cobbler日志
五、自定义Kickstart文件详解
1.默认的Kickstart文件
[root@node2 kickstarts]# cd /var/lib/cobbler/kickstarts/
[root@node2 kickstarts]# ls
default.ks legacy.ks sample_end.ks sample_esxi5.ks sample.seed
esxi4-ks.cfg pxerescue.ks sample_esx4.ks sample.ks
esxi5-ks.cfg sample_autoyast.xml sample_esxi4.ks sample_old.seed
注,一般sample.ks与sample_end.ks用的比较多,下面我们来查看一下。
[root@node2 ~]# cobbler report
#上面部分内容省略
profiles:
==========
Name : CentOS-5.5-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : CentOS-5.5-x86_64
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {}
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/sample.ks
注,大家可以看到我们导入的CentOS5.5的镜像默认使用的kickstarts文件是sample.ks ,下面我们来具体看一下sample.ks的内容。
[root@node2 ~]# cat /var/lib/cobbler/kickstarts/sample.ks
#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth --useshadow --enablemd5 #用户登录认证
# System bootloader configuration
bootloader --location=mbr #mbr引导
# Partition clearing information
clearpart --all --initlabel #默认清除所以分区
# Use text mode install
text #默认以文本模式安装
# Firewall configuration
firewall --enabled #防火墙默认开启
# Run the Setup Agent on first boot
firstboot --disable #禁用启动代理
# System keyboard
keyboard us #默认英文键盘
# System language
lang en_US #默认语言英文
# Use network installation
url --url=$tree #网络安装路径
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza #默认的yum仓库
# Network information
$SNIPPET('network_config')
# Reboot after installation
reboot #安装完成后重启
#Root password
rootpw --iscrypted $default_password_crypted #密码是我们/etc/cobbler/settings设置密码
# SELinux configuration
selinux --disabled #默认关闭selinux
# Do not configure the X Window System
skipx #默认没有安装图形界面
# System timezone
timezone America/New_York #默认时区是美国/纽约
# Install OS instead of upgrade
install #定义的是安装系统而不是升级系统
# Clear the Master Boot Record
zerombr #默认清空所有的mbr
# Allow anaconda to partition the system as needed
autopart #默认自动分区
#下面就是Cobbler自定执行的一些脚本,我就不解释了。
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%packages
$SNIPPET('func_install_if_enabled')
$SNIPPET('puppet_install_if_enabled')
%post
$SNIPPET('log_ks_post')
# Start yum configuration
$yum_config_stanza
# End yum configuration
$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')
# Enable post-install boot notification
$SNIPPET('post_anamon')
# Start final steps
$SNIPPET('kickstart_done')
# End final steps
注,大家可以看到默认的Kickstart文件,有许多地方并不符合我们的安装需求,如:默认时区不符合、分区不符合等。所以,我们得自定义Kickstart文件。
2.自定义Kickstart文件
一般两种方案:
手动的修改已有的Kickstart文件
用system-config-kickstart工具生成Kickstart文件
(1).手动的修改已有的Kickstart文件
注,手动修改已存在的Kickstart文件,其中有两个地方有Kickstart文件。一个在root家目录下的anaconda-ks.cfg文件,另一个就是我们默认的/var/lib/cobbler/kickstarts/sample.ks文件。其中anaconda-ks.cfg文件中有我们需要的时区信息、分区信息等,而sample.ks文件有我们需要的其它信息。我们可以手动修改一下,整理出我们需要的Kickstart文件。好了,下面我们就来手动的修改一下。
注,查看默认的 anaconda-ks.cfg 文件。
[root@node2 ~]# cat anaconda-ks.cfg
# Kickstart file automatically generated by anaconda.
#version=DEVEL
install
cdrom
lang zh_CN.UTF-8
keyboard us
network --onboot no --device eth0 --bootproto dhcp --noipv6
rootpw --iscrypted $6$rLcXd8hdqBw35VJ4$xMY155kcD1IULRuOW5AllU48obFbIgp11OBg72nPAE575mo8oC9Eqo8tGzJgtM2HkrDSciAGVUtCMXTjiIdaG.
firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
timezone --utc Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
#clearpart --none
#part /boot --fstype=ext4 --size=200
#part / --fstype=ext4 --size=10000
#part /data --fstype=ext4 --size=5000
#part swap --size=1000
repo --name="CentOS" --baseurl=cdrom:sr0 --cost=100
%packages
@chinese-support
@core
@development
@server-policy
注,查看默认的/var/lib/cobbler/kickstarts/sample.ks文件。
[root@node2 ~]# cat /var/lib/cobbler/kickstarts/sample.ks
#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth --useshadow --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --enabled
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Use network installation
url --url=$tree
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $default_password_crypted
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone America/New_York
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
autopart
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%packages
$SNIPPET('func_install_if_enabled')
$SNIPPET('puppet_install_if_enabled')
%post
$SNIPPET('log_ks_post')
# Start yum configuration
$yum_config_stanza
# End yum configuration
$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')
# Enable post-install boot notification
$SNIPPET('post_anamon')
# Start final steps
$SNIPPET('kickstart_done')
# End final steps
注,修改后的Kickstart文件。
[root@node2 ~]# cd /var/lib/cobbler/kickstarts/
[root@node2 kickstarts]# cp sample.ks centos.ks
[root@node2 kickstarts]# cat centos.ks
#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth --useshadow --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --service=ssh #开启动防火墙但开放ssh服务
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Use network installation
url --url=$tree
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $default_password_crypted
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone --utc Asia/Shanghai #时区修改为亚洲/上海
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
#下面定义的是默认分区,这个分区大小可以自己定义,单位为MB。由于我这里是虚拟机只有20的硬盘空间,所以我是这样划分的/boot 200MB、/ 10G 、/data 5G、swap 1G。
part /boot --fstype=ext4 --size=200
part / --fstype=ext4 --size=10000
part /data --fstype=ext4 --size=5000
part swap --size=1000
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%packages #这里增加了默认安装的软件包,包括对中文的支持与开发组件。
$SNIPPET('func_install_if_enabled')
$SNIPPET('puppet_install_if_enabled')
@chinese-support
@core
@development
%post
$SNIPPET('log_ks_post')
# Start yum configuration
$yum_config_stanza
# End yum configuration
$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')
# Enable post-install boot notification
$SNIPPET('post_anamon')
# Start final steps
$SNIPPET('kickstart_done')
# End final steps
好了,到这里我们的手动修改Kickstart文件就全部讲解完成了,下面我们来说一下怎么用system-config-kickstart工具生成Kickstart文件。