Linux Cobbler搭建 发表于 2022-01-11 浏览量 648 没有评论 # 简介 1、Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。 2、Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。 3、Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。 4、Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet。 ## cobbler集成的服务 ``` PXE服务支持 DHCP服务管理 DNS服务管理 电源管理 Kickstart服务支持 YUM仓库管理 TFTP Apache ``` # Cobbler工作原理 ![](http://cdn.ewain.top/57078029.png) ## Server端 - 启动Cobbler服务 - 进行Cobbler错误检查,执行cobbler check命令 - 进行配置同步,执行cobbler sync命令 - 复制相关启动文件到TFTP目录中 - 启动DHCP服务,提供地址分配 - DHCP服务分配IP地址 - TFTP传输启动文件 - Server端接收安装信息 - Server端发送ISO镜像与Kickstart文件 ## Clinet端 - 客户端以PXE模式启动 - 客户端获取IP地址 - 通过TFTP服务器获取启动文件 - 进入Cobbler安装选择界面 - 根据配置信息准备安装系统 - 加载Kickstart文件 - 传输系统安装的其它文件 - 进行安装系统 # Cobbler安装 **说明**:虚拟机网卡采用NAT模式或者仅主机模式,不要使用桥接模式,因为后面会搭建DHCP服务器,在同一个局域网多个DHCP服务会有冲突。 **VMware的NAT模式的dhcp服务也关闭,避免干扰** ![](http://cdn.ewain.top/60252699.png) ## 环境准备 ``` # 关闭防火墙、selinux等 [root@cobbler ~]# systemctl stop firewalld [root@cobbler ~]# systemctl disable firewalld [root@cobbler ~]# setenforce 0 [root@cobbler ~]# sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config ``` ## 安装cobbler ``` # 配置epel源 [root@cobbler ~]# yum -y install epel-release # 安装cobbler及dhcp httpd xinetd cobbler-web [root@cobbler ~]# yum -y install cobbler cobbler-web tftp-server dhcp httpd xinetd # 启动cobbler及httpd并加入开机启动 [root@cobbler ~]# systemctl start httpd cobblerd [root@cobbler ~]# systemctl enable httpd cobblerd ``` *查看安装后相关文件* ``` [root@cobbler ~]# rpm -ql 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日志 ``` ## 配置cobbler 检查**cobbler**的配置,如果看不到下面的结果,再次重启**cobbler** ``` [root@cobbler ~]# 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 : enable and start rsyncd.service with systemctl 6 : debmirror package is not installed, it will be required to manage debian deployments and repositories 7 : ksvalidator was not found, install pykickstart 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. ``` 看到上面出现的问题,然后一个一个的进行解决,先进行设置为可以动态配置,也可以直接更改配置文件。 ``` # 设置可以动态修改配置文件 [root@cobbler ~]# sed -ri '/allow_dynamic_settings:/c\allow_dynamic_settings: 1' /etc/cobbler/settings [root@cobbler ~]# grep allow_dynamic_settings /etc/cobbler/settings allow_dynamic_settings: 1 [root@cobbler ~]# systemctl restart cobblerd ``` 逐个解决上面的问题,也可以直接进去修改`/etc/cobbler/setting` ``` 1. server [root@cobbler ~]# cobbler setting edit --name=server --value=192.168.2.3 2. next_server [root@cobbler ~]# cobbler setting edit --name=next_server --value=192.168.2.3 3. tftp_server [root@cobbler ~]# sed -ri '/disable/c\disable = no' /etc/xinetd.d/tftp [root@cobbler ~]# systemctl enable xinetd [root@cobbler ~]# systemctl restart xinetd 4. boot-loaders [root@cobbler ~]# cobbler get-loaders //他会自动下载相关的启动引导文件 5. rsyncd [root@cobbler ~]# systemctl start rsyncd [root@cobbler ~]# systemctl enable rsyncd 6. debmirror [optional] # 这个是可选项的,可以忽略。这里就忽略了 7. pykickstart [root@cobbler ~]# yum -y install pykickstart 8. default_password_crypted #注意:这里设置的密码,也就是后面安装完系统的初始化登录密码 [root@cobbler ~]# openssl passwd -1 -salt `openssl rand -hex 4` 'admin' $1$503abaff$CXaTZ68dDBAJ3Dwj/tz3u. [root@cobbler ~]# cobbler setting edit --name=default_password_crypted --value='$1$503abaff$CXaTZ68dDBAJ3Dwj/tz3u.' 9. fencing tools [optional] [root@cobbler ~]# yum -y install fence-agents ``` **执行 `cobbler get-loaders`报错** ``` [root@cobbler ~]# cobbler get-loaders task started: 2020-11-11_190107_get_loaders task started (id=Download Bootloader Content, time=Wed Nov 11 19:01:07 2020) path /var/lib/cobbler/loaders/README already exists, not overwriting existing content, use --force if you wish to update path /var/lib/cobbler/loaders/COPYING.elilo already exists, not overwriting existing content, use --force if you wish to update downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot Exception occured: Exception value: [Errno 12] Timeout on https://cobbler.github.io/loaders/yaboot-1.3.17: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 300 seconds') Exception Info: File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 82, in run rc = self._run(self) File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 176, in runner return self.remote.api.dlcontent(self.options.get("force",False), self.logger) File "/usr/lib/python2.7/site-packages/cobbler/api.py", line 735, in dlcontent return grabber.run(force) File "/usr/lib/python2.7/site-packages/cobbler/action_dlcontent.py", line 73, in run urlgrabber.grabber.urlgrab(src, filename=dst, proxies=proxies) File "/usr/lib/python2.7/site-packages/urlgrabber/grabber.py", line 773, in urlgrab return default_grabber.urlgrab(url, filename, **kwargs) File "/usr/lib/python2.7/site-packages/urlgrabber/grabber.py", line 1220, in urlgrab return _run_callback(opts.failfunc, opts) File "/usr/lib/python2.7/site-packages/urlgrabber/grabber.py", line 1071, in _run_callback return cb(obj) File "/usr/lib/python2.7/site-packages/urlgrabber/grabber.py", line 1065, in _do_raise raise obj.exception !!! TASK FAILED !!! ``` **解决办法** ``` [root@cobbler ~]# yum -y install syslinux [root@cobbler ~]# cp/usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/ [root@cobbler ~]# cp/usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/ [root@cobbler ~]# /etc/init.d/cobblerdrestart [root@cobbler ~]# cobbler get-loaders #再次执行则成功 ``` 解决完再查看 ``` [root@cobbler ~]# 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 Restart cobblerd and then run 'cobbler sync' to apply changes. ``` ## 配置DHCP ``` [root@cobbler ~]# cobbler setting edit --name=manage_dhcp --value=1 # 修改cobbler的dhcp模块,不要直接修改dhcp本身的配置文件,因为cobbler会覆盖 [root@cobbler ~]# vim /etc/cobbler/dhcp.template subnet 192.168.2.0 netmask 255.255.255.0 { //这里改为分配的网段和掩码 option routers 192.168.2.2; //如果有网关,这里改为网关地址 option domain-name-servers 192.168.2.2; //如果有DNS,这里改为DNS地址 option subnet-mask 255.255.255.0; //改为分配的IP的掩码 range dynamic-bootp 192.168.2.100 192.168.2.254; //改为分配的IP的范围 default-lease-time 21600; max-lease-time 43200; ``` ## 同步cobbler配置 同步cobbler配置,它会根据配置自动修改dhcp等服务。 ``` [root@cobbler ~]# cobbler sync task started: 2020-11-11_195705_sync task started (id=Sync, time=Wed Nov 11 19:57:05 2020) running pre-sync triggers cleaning trees removing: /var/lib/tftpboot/grub/images copying bootloaders trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0 trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32 trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk 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 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: received on stderr: Redirecting to /bin/systemctl restart dhcpd.service running shell triggers from /var/lib/cobbler/triggers/sync/post/* running python triggers from /var/lib/cobbler/triggers/change/* running python trigger cobbler.modules.manage_genders running python trigger cobbler.modules.scm_track running shell triggers from /var/lib/cobbler/triggers/change/* *** TASK COMPLETE *** ``` 这时候创建一个新虚拟机可以获取到如下信息,没有镜像选择,只能从本地启动。 ![](http://cdn.ewain.top/72136379.png) ## Cobbler 命令帮助 |命令|说明| |--|--| |cobbler check|核对当前设置是否有问题 |cobbler list|列出所有的cobbler元素 |cobbler report|列出元素的详细信息 |cobbler sync|同步配置到数据目录,更改配置最好都执行一下 |cobbler reposync|同步yum仓库 |cobbler distro|查看导入的发行版系统信息 |cobbler system|查看添加的系统信息 |cobbler profile|查看配置信息 ## cobbler 配置安装centos.X 1、创建挂载点,并进行挂载 ``` [root@cobbler /]# mkdir /centos7 [root@cobbler /]# mount -o loop centos.iso /centos7 ``` 2、查看挂载后的目录 ``` [root@cobbler centos7]# ls CentOS_BuildTag GPL LiveOS RPM-GPG-KEY-CentOS-7 EFI images Packages RPM-GPG-KEY-CentOS-Testing-7 EULA isolinux repodata TRANS.TBL ``` 3、导入镜像 ``` cobbler import --path=/centos7 --name=centos7.6 --arch=x86_64 # --path 镜像路径 # --name 为安装源定义一个名字 # --arch 指定安装源是32位、64位、ia64, 目前支持的选项有: x86│x86_64│ia64 # 安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:centos7.6,如果重复,系统会提示导入失败。 ``` 4、查看导入后的镜像 ``` [root@cobbler centos7]# cobbler distro report --name=centos7.6-x86_64 Name : centos7.6-x86_64 Architecture : x86_64 TFTP Boot Files : {} Breed : redhat Comment : Fetchable Files : {} Initrd : /var/www/cobbler/ks_mirror/centos7.6-x86_64/images/pxeboot/initrd.img Kernel : /var/www/cobbler/ks_mirror/centos7.6-x86_64/images/pxeboot/vmlinuz Kernel Options : {} Kernel Options (Post Install) : {} Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/centos7.6-x86_64'} Management Classes : [] OS Version : rhel6 Owners : ['admin'] Red Hat Management Key : <> Red Hat Management Server : <> Template Files : {} ``` 5、查看profile信息 ``` [root@cobbler ~]# cobbler profile report --name=centos7.6-x86_64 Name : centos7.6-x86_64 TFTP Boot Files : {} Comment : DHCP Tag : default Distribution : centos7.6-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 : <> Name Servers : [] Name Servers Search Path : [] Owners : ['admin'] Parent Profile : Internal proxy : Red Hat Management Key : <> Red Hat Management Server : <> Repos : [] Server Override : <> 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 ``` 6、再次同步cobbler配置 ``` [root@cobbler ~]# cobbler sync ``` 7、新建虚拟机测试 ![](http://cdn.ewain.top/76232066.png) 选择centos7.6-x86_64安装即可 ![](http://cdn.ewain.top/76306260.png) 说明:在clent端系统安装时候,可以在cobbler服务端上看日志 **/var/log/messages** ,可以看到安装的每个流程。 # Cobbler Web管理界面配置 web界面有很多功能,包括上传镜像、编辑kickstart、等等很多在命令行操作的都可以在web界面直接操作。 在上面已经安装了cobbler-web软件,访问地址:https://IP/cobbler_web 即可。默认账号为cobbler,密码也为cobbler ![](http://cdn.ewain.top/76695442.png)