cobbler介绍
Cobbler集中和简化了通过网络安装操作系统需要使用到的DHCP、TFTP和DNS服务的配置。Cobbler不仅有一个命令行界面,还提供了一个Web界面,大大降低了使用者的入门水平。Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。
Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。
Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。
系统环境准备
[[email protected] ~]$ uname -r 2.6.32-642.el6.x86_64 [[email protected] ~]$ uname -m x86_64 [[email protected] ~]$ ifconfig eth0|awk -F "[ :]+" ‘NR==2 {print $4}‘ 10.0.0.101
安装cobbler
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd
检查Cobbler的配置,如果看不到下面的结果,再次执行/etc/init.d/cobblerd restart,执行后会有一堆错误
[[email protected] ~]$ cobbler check 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 : 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 9 : 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、6个问题,顺便修改其他功能 [[email protected]-node1 ~]# cp /etc/cobbler/settings{,.ori} # 备份 # server,Cobbler服务器的IP。 sed -i ‘s/server: 127.0.0.1/server: 10.0.0.101/‘ /etc/cobbler/settings # next_server,如果用Cobbler管理DHCP,修改本项,作用不解释,看kickstart。 sed -i ‘s/next_server: 127.0.0.1/next_server: 10.0.0.101/‘ /etc/cobbler/settings # 用Cobbler管理DHCP sed -i ‘s/manage_dhcp: 0/manage_dhcp: 1/‘ /etc/cobbler/settings # 防止循环装系统,适用于服务器第一启动项是PXE启动。 sed -i ‘s/pxe_just_once: 0/pxe_just_once: 1/‘ /etc/cobbler/settings # 设置新装系统的默认root密码123456。下面的命令来源于提示6。random-phrase-here为干扰码,可以自行设定。 [[email protected]-node1 ~]# openssl passwd -1 -salt ‘oldboy‘ ‘123456‘ $1$oldboy$Npg9Pt9k98Mlg0ZeqHAuN1 [[email protected]-node1 ~]# vim /etc/cobbler/settings default_password_crypted: "$1$oldboy$Npg9Pt9k98Mlg0ZeqHAuN1" # 第3个问题 [[email protected]-node1 ~]# cobbler get-loaders # 会自动从官网下载 [[email protected]-node1 ~]# cd /var/lib/cobbler/loaders/ # 下载的内容 [[email protected]-node1 loaders]# ls COPYING.elilo COPYING.yaboot grub-x86_64.efi menu.c32 README COPYING.syslinux elilo-ia64.efi grub-x86.efi pxelinux.0 yaboot # 第4个问题 [[email protected]-node1 ~]# vim /etc/xinetd.d/rsync disable = no [[email protected]-node1 ~]# /etc/init.d/xinetd restart 停止 xinetd: [确定] 正在启动 xinetd: [确定] [[email protected]-node1 ~]# /etc/init.d/cobblerd restart Stopping cobbler daemon: [确定] Starting cobbler daemon: [确定] [[email protected]-node1 ~]# cobbler check The following are potential configuration items that you may want to fix: 1 : debmirror package is not installed, it will be required to manage debian deployments and repositories # 和debian系统相关,不需要 2 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them # fence设备相关,不需要 Restart cobblerd and then run ‘cobbler sync‘ to apply changes.
执行下面的命令,修改配置文件
sed -i ‘s/server: 127.0.0.1/server: 172.16.1.101/‘ /etc/cobbler/settings sed -i ‘s/next_server: 127.0.0.1/next_server: 172.16.1.101/‘ /etc/cobbler/settings sed -i ‘s/manage_dhcp: 0/manage_dhcp: 1/‘ /etc/cobbler/settings sed -i ‘s/pxe_just_once: 0/pxe_just_once: 1/‘ /etc/cobbler/settings sed -ri "/default_password_crypted/s#(.*: ).*#\1\"`openssl passwd -1 -salt ‘oldboy‘ ‘123456‘`\"#" /etc/cobbler/settings sed -i ‘s#yes#no#‘ /etc/xinetd.d/rsync sed -i ‘s#yes#no#‘ /etc/xinetd.d/tftp
配置DHCP
# 修改cobbler的dhcp模版,不要直接修改dhcp本身的配置文件,因为cobbler会覆盖。
[[email protected] loaders]# sed -i ‘s#192.168.1#172.16.1#g;22d;23d‘ /etc/cobbler/dhcp.template
同步cobbler配置
[[email protected] ~]# cobbler sync task started: 2017-04-14_101410_sync task started (id=Sync, time=Fri Apr 14 10:14:10 2017) running pre-sync triggers cleaning trees removing: /var/lib/tftpboot/pxelinux.cfg/default removing: /var/lib/tftpboot/grub/grub-x86_64.efi removing: /var/lib/tftpboot/grub/efidefault removing: /var/lib/tftpboot/grub/grub-x86.efi removing: /var/lib/tftpboot/grub/images removing: /var/lib/tftpboot/s390x/profile_list copying bootloaders trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.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 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 ***
启动服务
/etc/init.d/xinetd restart
/etc/init.d/cobblerd restart
/etc/init.d/httpd restart
打开网页进行操作
输入http://10.0.0.101/cobbler
挂载光盘,到mnt下。或者下好的系统镜像
自动应答模板
#CentOS-6.8 install url --url=$tree text lang en_US.UTF-8 keyboard us zerombr bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet" $SNIPPET(‘network_config‘) timezone --utc Asia/Shanghai authconfig --enableshadow --passalgo=sha512 rootpw --iscrypted $default_password_crypted clearpart --all --initlabel part /boot --fstype=ext4 --asprimary --size=200 part swap --size=1024 part / --fstype=ext4 --grow --asprimary --size=200 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 %end %post --nochroot $SNIPPET(‘log_ks_post_nochroot‘) %end %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(‘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 %end
可以去http://blog.oldboyedu.com/autoinstall-cobbler/查看详细的过程
CentOS-7.1 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 xfs --size 1024 # CentOS7系统磁盘默认格式xfs part swap --size 1024 part / --fstype xfs --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
定制化安装
可能从学习kickstart开始就有人想怎样能够指定某台服务器使用指定ks文件,kickstart实现这功能可能比较复杂,但是Cobbler就很简单了。
区分一台服务器的最简单的方法就是物理MAC地址。
物理服务器的MAC地址在服务器上的标签上写了。
虚拟机的MAC查看
cobbler system add --name=oldboy --mac=00:0C:29:7F:2F:A1 --profile=CentOS-7.1-x86_64 --ip-address=10.0.0.111 --subnet=255.255.255.0 --gateway=10.0.0.2 --interface=eth0 --static=1 --hostname=oldboy.example.com --name-servers="114.114.114.114 8.8.8.8" # --name 自定义,但不能重复 # 查看定义的列表 [[email protected]-node1 ~]# cobbler system list oldboy [[email protected]-node1 ~]# cobbler sync
打开新建的虚拟机进行安装系统
原文地址:https://www.cnblogs.com/HByang/p/9207077.html