Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。
Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。
Cobbler官网
PXE服务支持
DHCP服务管理
DNS服务管理(可选bind,dnsmasq)
电源管理
Kickstart服务支持
YUM仓库管理
TFTP(PXE启动时需要)
Apache(提供kickstart的安装源,并提供定制化的kickstart配置)
[root@lb02 ~]# cat /etc/redhat-release CentOS release 6.7 (Final) [root@lb02 ~]# uname -r 2.6.32-573.el6.x86_64 [root@lb02 ~]# getenforce Disabled [root@lb02 ~]# /etc/init.d/iptables status iptables: Firewall is not running. [root@lb02 ~]# ifconfig eth0|awk -F "[ :]+" 'NR==2 {print $4}' 10.10.10.18 # 配置阿里云的epel源 [root@lb02 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
注意:
虚拟机网卡采用NAT模式,不要使用桥接模式,因为稍后我们会搭建DHCP服务器,在同一局域网多个DHCP服务会有冲突。
VMware的NAT模式的dhcp服务也关闭,避免干扰。
[root@lb02 ~]# yum install -y cobbler # 查看安装的文件,下面列出部分。 /etc/cobbler # 配置文件目录 /etc/cobbler/settings # cobbler主配置文件,这个文件是YAML格式,Cobbler是python写的程序。 /etc/cobbler/dhcp.template # DHCP服务的配置模板 /etc/cobbler/tftpd.template # tftp服务的配置模板 /etc/cobbler/rsync.template # rsync服务的配置模板 /etc/cobbler/iso # iso模板配置文件目录 /etc/cobbler/pxe # pxe模板文件目录 /etc/cobbler/power # 电源的配置文件目录 /etc/cobbler/users.conf # Web服务授权配置文件 /etc/cobbler/users.digest # 用于web访问的用户名密码配置文件 /etc/cobbler/dnsmasq.template # DNS服务的配置模板 /etc/cobbler/modules.conf # Cobbler模块配置文件 /var/lib/cobbler # Cobbler数据目录 /var/lib/cobbler/config # 配置文件 /var/lib/cobbler/kickstarts # 默认存放kickstart文件 /var/lib/cobbler/loaders # 存放的各种引导程序 /var/www/cobbler # 系统安装镜像目录 /var/www/cobbler/ks_mirror # 导入的系统镜像列表 /var/www/cobbler/images # 导入的系统镜像启动文件 /var/www/cobbler/repo_mirror # yum源存储目录 /var/log/cobbler # 日志目录 /var/log/cobbler/install.log # 客户端系统安装日志 /var/log/cobbler/cobbler.log # cobbler日志
[root@lb02 ~]# vim /etc/httpd/conf/httpd.conf ServerName 127.0.0.1:80 #更改此处以取消警告! [root@lb02 ~]# /etc/init.d/httpd start Starting httpd: [ OK ] [root@lb02 ~]# /etc/init.d/xinetd start Starting xinetd: [ OK ] [root@lb02 ~]# /etc/init.d/cobblerd start Starting cobbler daemon: [ OK ] [root@lb02 ~]# cobbler check # 检查Cobbler的配置,如果看不到下面的结果,再次执行/etc/init.d/cobblerd restart 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 : change 'disable' to 'no' in /etc/xinetd.d/tftp 4 : 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. 5 : change 'disable' to 'no' in /etc/xinetd.d/rsync 6 : file /etc/xinetd.d/rsync does not exist 7 : debmirror package is not installed, it will be required to manage debian deployments and repositories 8 : ksvalidator was not found, install pykickstart 9 : 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 10 : 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、2、9个问题,顺便修改其他功能 [root@lb02 ~]# cp /etc/cobbler/settings{,.ori} # 备份 # server,Cobbler服务器的IP。 [root@lb02 ~]# sed -i 's/server: 127.0.0.1/server: 10.10.10.18/' /etc/cobbler/settings # next_server,如果用Cobbler管理DHCP,修改本项,作用不解释,看kickstart。 [root@lb02 ~]# sed -i 's/next_server: 127.0.0.1/next_server: 10.10.10.18/' /etc/cobbler/settings # 用Cobbler管理DHCP [root@lb02 ~]# sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings # 防止循环装系统,适用于服务器第一启动项是PXE启动。 [root@lb02 ~]# sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings # 用Cobbler管理rsync [root@lb02 ~]# sed -i 's/manage_rsync: 0/manage_rsync: 1/' /etc/cobbler/settings # 设置新装系统的默认root密码123456。下面的命令来源于提示9。random-phrase-here为干扰码,可以自行设定。 [root@lb02 ~]# openssl passwd -1 -salt 'tank' '123456' $1$tank$Q5MsMJ53sjS0l5Rjzcmjo1 [root@lb02 ~]# vim /etc/cobbler/settings default_password_crypted: "$1$tank$Q5MsMJ53sjS0l5Rjzcmjo1" #将生成的加密密码改之。 # 第4个问题 [root@lb02 ~]# cobbler get-loaders # 会自动从官网下载 [root@lb02 ~]# cd /var/lib/cobbler/loaders/ # 查看下载的内容 [root@lb02 loaders]# ls COPYING.elilo COPYING.yaboot grub-x86_64.efi menu.c32 README COPYING.syslinux elilo-ia64.efi grub-x86.efi pxelinux.0 yaboot # 第3、5个问题 [root@lb02 loaders]# vim /etc/xinetd.d/tftp disable = yes [root@lb02 loaders]# vim /etc/xinetd.d/rsync disable = no [root@lb02 loaders]# /etc/init.d/xinetd restart Stopping xinetd: [ OK ] Starting xinetd: [ OK ] # 第8个问题 [root@lb02 loaders]# yum install -y pykickstart [root@lb02 loaders]# /etc/init.d/cobblerd restart Stopping cobbler daemon: [ OK ] Starting cobbler daemon: [ OK ] [root@lb02 loaders]# cobbler check The following are potential configuration items that you may want to fix: 1 : dhcpd is not installed 2 : file /etc/xinetd.d/rsync does not exist #此提示一直存在!!! 3 : debmirror package is not installed, it will be required to manage debian deployments and repositories # 和debian系统相关,不需要 4 : 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.
[root@lb02 loaders]# yum install -y dhcp #配置DHCP # 修改cobbler的dhcp模版,不要直接修改dhcp本身的配置文件,因为cobbler会覆盖。 [root@lb02 loaders]# vim /etc/cobbler/dhcp.template # 仅列出修改过的字段 …… subnet 10.10.10.0 netmask 255.255.255.0 { option routers 10.10.10.2; option domain-name-servers 10.10.10.2; option subnet-mask 255.255.255.0; range dynamic-bootp 10.10.10.20 10.10.10.50;
# 同步最新cobbler配置,它会根据配置自动修改dhcp等服务。 [root@lb02 loaders]# cobbler sync # 同步所有配置,可以仔细看一下sync做了什么。 task started: 2016-03-19_221213_sync task started (id=Sync, time=Sat Mar 19 22:12:13 2016) running pre-sync triggers cleaning trees removing: /var/lib/tftpboot/pxelinux.cfg/default removing: /var/lib/tftpboot/grub/images removing: /var/lib/tftpboot/grub/efidefault removing: /var/lib/tftpboot/grub/grub-x86.efi removing: /var/lib/tftpboot/grub/grub-x86_64.efi removing: /var/lib/tftpboot/s390x/profile_list copying bootloaders trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi copying distros to tftpboot copying images generating PXE configuration files generating PXE menu structure rendering DHCP files generating /etc/dhcp/dhcpd.conf rendering TFTPD files generating /etc/xinetd.d/tftp cleaning link caches rendering Rsync files running post-sync triggers running python triggers from /var/lib/cobbler/triggers/sync/post/* running python trigger cobbler.modules.sync_post_restart_services running: dhcpd -t -q received on stdout: received on stderr: running: service dhcpd restart received on stdout: Shutting down dhcpd: [ OK ] Starting dhcpd: [ OK ] received on stderr: running shell triggers from /var/lib/cobbler/triggers/sync/post/* running python triggers from /var/lib/cobbler/triggers/change/* running python trigger cobbler.modules.scm_track running shell triggers from /var/lib/cobbler/triggers/change/* *** TASK COMPLETE *** # 再看一下dhcp的配置文件。 [root@lb02 loaders]# less /etc/dhcp/dhcpd.conf # ****************************************************************** # Cobbler managed dhcpd.conf file # generated from cobbler dhcp.conf template (Sat Mar 19 14:12:14 2016) # Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes # in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be # overwritten. # ****************************************************************** ... subnet 10.10.10.0 netmask 255.255.255.0 { option routers 10.10.10.2; option domain-name-servers 10.10.10.2; option subnet-mask 255.255.255.0; range dynamic-bootp 10.10.10.20 10.10.10.50;
# 启动相关服务并设置开机启动(可选) chkconfig httpd on chkconfig xinetd on chkconfig cobblerd on chkconfig dhcpd on
[root@lb02 loaders]# cobbler usage ===== cobbler <distro|profile|system|repo|image|mgmtclass|package|file> ... [add|edit|copy|getks*|list|remove|rename|report] [options|--help] cobbler <aclsetup|buildiso|import|list|replicate|report|reposync|sync|validateks|version|signature|get-loaders|hardlink> [options|--help] [root@lb02 loaders]# cobbler import --help # 导入镜像 Usage: cobbler [options] Options: -h, --help show this help message and exit --arch=ARCH OS architecture being imported --breed=BREED the breed being imported --os-version=OS_VERSION the version being imported --path=PATH local path or rsync location --name=NAME name, ex 'RHEL-5' --available-as=AVAILABLE_AS tree is here, don't mirror --kickstart=KICKSTART_FILE assign this kickstart file --rsync-flags=RSYNC_FLAGS pass additional flags to rsync cobbler check 核对当前设置是否有问题 cobbler list 列出所有的cobbler元素 cobbler report 列出元素的详细信息 cobbler sync 同步配置到数据目录,更改配置最好都要执行下 cobbler reposync 同步yum仓库 cobbler distro 查看导入的发行版系统信息 cobbler system 查看添加的系统信息 cobbler profile 查看配置信息
[root@lb02 loaders]# mount /dev/cdrom /mnt/ # 挂载CentOS7的系统镜像。 mount: block device /dev/sr0 is write-protected, mounting read-only # 导入系统镜像 [root@lb02 loaders]# cobbler import --path=/mnt/ --name=CentOS-7.1-x86_64 --arch=x86_64 task started: 2016-03-19_222438_import task started (id=Media import, time=Sat Mar 19 22:24:38 2016) 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/CentOS-6.7-x86_64: creating new distro: CentOS-6.7-x86_64 trying symlink: /var/www/cobbler/ks_mirror/CentOS-6.7-x86_64 -> /var/www/cobbler/links/CentOS-6.7-x86_64 creating new profile: CentOS-6.7-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/CentOS-6.7-x86_64 for CentOS-6.7-x86_64 processing repo at : /var/www/cobbler/ks_mirror/CentOS-6.7-x86_64 need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS-6.7-x86_64 looking for /var/www/cobbler/ks_mirror/CentOS-6.7-x86_64/repodata/*comps*.xml Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS-6.7-x86_64/repodata *** TASK COMPLETE *** # --path 镜像路径 # --name 为安装源定义一个名字 # --arch 指定安装源是32位、64位、ia64, 目前支持的选项有: x86│x86_64│ia64 # 安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-6.7-x86_64,如果重复,系统会提示导入失败。 [root@lb02 loaders]# cobbler distro list # 查看镜像列表 CentOS-6.7-x86_64 # 镜像存放目录,cobbler会将镜像中的所有安装文件拷贝到本地一份,放在/var/www/cobbler/ks_mirror下的CentOS-6.7-x86_64目录下。因此/var/www/cobbler目录必须具有足够容纳安装文件的空间。 [root@lb02 loaders]# cd /var/www/cobbler/ks_mirror/ [root@lb02 ks_mirror]# ls CentOS-6.7-x86_64 config [root@lb02 ks_mirror]# ls CentOS-6.7-x86_64/ CentOS_BuildTag GPL Packages RPM-GPG-KEY-CentOS-6 RPM-GPG-KEY-CentOS-Testing-6 EFI images RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Debug-6 TRANS.TBL EULA isolinux repodata RPM-GPG-KEY-CentOS-Security-6
# Cobbler的ks.cfg文件存放位置 [root@lb02 ks_mirror]# cd /var/lib/cobbler/kickstarts/ [root@lb02 kickstarts]# ls # 自带很多 default.ks esxi5-ks.cfg legacy.ks sample_autoyast.xml sample_esx4.ks sample_esxi5.ks sample_old.seed esxi4-ks.cfg install_profiles pxerescue.ks sample_end.ks (默认使用的ks文件) sample_esxi4.ks sample.ks sample.seed [root@lb02 kickstarts]# rz # 上传准备好的ks文件 rz waiting to receive. Starting zmodem transfer. Press Ctrl+C to cancel. Transferring Cobbler-CentOS-6.7-x86_64.cfg... 100% 1 KB 1 KB/sec 00:00:01 0 Errors [root@lb02 kickstarts]# mv Cobbler-CentOS-6.7-x86_64.cfg CentOS-6.7-x86_64.cfg # 在第一次导入系统镜像后,Cobbler会给镜像指定一个默认的kickstart自动安装文件在/var/lib/cobbler/kickstarts下的sample_end.ks。 [root@lb02 kickstarts]# cobbler list distros: CentOS-6.7-x86_64 profiles: CentOS-6.7-x86_64 systems: repos: images: mgmtclasses: packages: files: # 查看安装镜像文件信息 [root@lb02 kickstarts]# cobbler distro report --name=CentOS-6.7-x86_64 Name : CentOS-6.7-x86_64 Architecture : x86_64 TFTP Boot Files : {} Breed : redhat Comment : Fetchable Files : {} Initrd : /var/www/cobbler/ks_mirror/CentOS-6.7-x86_64/images/pxeboot/initrd.img Kernel : /var/www/cobbler/ks_mirror/CentOS-6.7-x86_64/images/pxeboot/vmlinuz Kernel Options : {} Kernel Options (Post Install) : {} Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/CentOS-6.7-x86_64'} Management Classes : [] OS Version : rhel6 Owners : ['admin'] Red Hat Management Key : <<inherit>> Red Hat Management Server : <<inherit>> Template Files : {} # 查看所有的profile设置 [root@lb02 kickstarts]# cobbler profile report # 查看指定的profile设置 [root@lb02 kickstarts]# cobbler profile report --name=CentOS-6.7-x86_64 Name : CentOS-6.7-x86_64 TFTP Boot Files : {} Comment : DHCP Tag : default Distribution : CentOS-6.7-x86_64 Enable gPXE? : 0 Enable PXE Menu? : 1 Fetchable Files : {} Kernel Options : {} Kernel Options (Post Install) : {} Kickstart : /var/lib/cobbler/kickstarts/sample_end.ks Kickstart Metadata : {} Management Classes : [] Management Parameters : <<inherit>> Name Servers : [] Name Servers Search Path : [] Owners : ['admin'] Parent Profile : Internal proxy : Red Hat Management Key : <<inherit>> Red Hat Management Server : <<inherit>> Repos : [] Server Override : <<inherit>> Template Files : {} Virt Auto Boot : 1 Virt Bridge : xenbr0 Virt CPUs : 1 Virt Disk Driver Type : raw Virt File Size(GB) : 5 Virt Path : Virt RAM (MB) : 512 Virt Type : kvm #如果是装7版本的系统就有点变化了。 详情见:
可以很愉快的告诉你到这里就可以安装系统了!
新建一台虚拟机,不解释,开机就可以看到下面的图片了!
有没有发现不美观的地方?
网址不是我的!改!
#修改Cobbler提示 [root@lb02 kickstarts]# vim /etc/cobbler/pxe/pxedefault.template MENU TITLE Cobbler | http://tank_ke.io [root@lb02 kickstarts]# cobbler sync # 修改配置都要同步
OK,现在好看多了。选择第二项就可以继续装机了。你可以让系统飞着,然后接着看下文!!
文件大部分参数含义见kickstart文章,此处只讲一些不同的地方。同时可以参考模板文件。
[root@lb02 kickstarts]# cat CentOS-6.7-x86_64.cfg # Cobbler for Kickstart Configurator for CentOS 6.7 by tank install url --url=$tree # 这些$开头的变量都是调用配置文件里的值。 text lang en_US.UTF-8 keyboard us zerombr bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet" # Network information $SNIPPET('network_config') timezone --utc Asia/Shanghai authconfig --enableshadow --passalgo=sha512 rootpw --iscrypted $default_password_crypted clearpart --all --initlabel part /boot --fstype ext4 --size 1024 # CentOS7系统磁盘默认格式xfs part swap --size 1024 part / --fstype ext4 --size 1 --grow firstboot --disable selinux --disabled firewall --disabled logging --level=info reboot %pre $SNIPPET('log_ks_pre') $SNIPPET('kickstart_start') $SNIPPET('pre_install_network_config') # Enable installation monitoring $SNIPPET('pre_anamon') %end %packages @base @compat-libraries @debugging @development tree nmap sysstat lrzsz dos2unix telnet iptraf ncurses-devel openssl-devel zlib-devel OpenIPMI-tools screen %end %post systemctl disable postfix.service %end
本文出自 “学习之旅” 博客,谢绝转载!