Cobbler无人值守

Cobbler介绍

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配置)

注意:
虚拟机网卡采用NAT模式,不要使用桥接模式,因为稍后我们会搭建DHCP服务器,在同一局域网多个DHCP服务会有冲突。
VMware的NAT模式的dhcp服务也关闭,避免干扰。

cobbler功能介绍

  • 使用一个以前定义的模板来配置DHCP服务(如果启用了管理DHCP)
  • 将一个存储库(yum或rsync)建立镜像或解压缩一个媒介,以注册一个新操作系统
  • 在DHCP配置文件中为需要安装的机器创建一个条目,并使用您指定的参数(ip和mac地址)
  • 在TFTP服务目录下创建适当的PXE文件
  • 重新启动DHCP服务以反映更改 重新启动机器以开始安装(如果电源管理已启用)

cobbler官网:http://cobbler.github.io/

环境

centos7
ip:10.0.0.43

Cobbler安装配置

1、关闭防火墙和seliunx
[root@ c7-43 ~]# systemctl stop firewalld
[root@ c7-43 ~]# systemctl disable firewalld
[root@ c7-43 ~]# setenforce 0
[root@ c7-43 ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

2、安装cobbler

首先安装 epel-release,Cobbler 和 tftp-server 在 base 源中是没有的

[root@ c7-43 ~]# yum -y install epel-release

安装 Cobbler 其实有一部分软件会被当做依赖进行安装上去,比如 tftp 和 httpd 服务,我们这里为了方便可以一并安装,避免后续出现相关问题。

[root@ c7-43 ~]# yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd rsync xinetd

#cobbler #Cobbler 程序包
#cobbler-web #Cobbler 的 Web 服务包
#pykickstart #Cobbler 检查 kickstart 语法错误
#httpd #Apache Web 服务

[root@ c7-41 ~]# 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的配置文件
[root@ c7-41 ~]# cd /etc/httpd/conf.d/
[root@ c7-41 conf.d]# ls
autoindex.conf  cobbler.conf  cobbler_web.conf  README  ssl.conf  userdir.conf  welcome.conf
###如cobbler.conf、cobbler_web.conf

3、检查配置Cobbler

[root@ c7-41 ~]# systemctl start httpd     ##启动apache
[root@ c7-41 ~]# netstat -ntlp  | grep httpd   ##查看开启服务
tcp6       0      0 :::443                  :::*                    LISTEN      2904/httpd
tcp6       0      0 :::80                   :::*                    LISTEN      2904/httpd
[root@ c7-41 ~]# systemctl start cobblerd         ##启动cobbler
[root@ c7-41 ~]# cobbler check         ##检查cobbler
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 kickstartingfeatures 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 : 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
8 : 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.
##根据上图可以看到,使用cobbler需要完成的9个步骤,一个一个解决。

现在开始解决

问题 1:修改 server 地址为 10.0.0.43

# server,Cobbler服务器的IP。
[root@ c7-43 ~]# vim /etc/cobbler/settings
390行改: server: 10.0.0.43        
#或者sed -i 's/server: 127.0.0.1/server: 10.0.0.43/' /etc/cobbler/settings

问题 2:修改 next_server 地址为 10.0.0.43

# next_server,如果用Cobbler管理DHCP,修改本项,作用不解释,看kickstart。
[root@ c7-43 ~]# vim /etc/cobbler/settings
278行改:next_server: 10.0.0.43
###或者sed -i 's/next_server: 127.0.0.1/next_server: 10.0.0.43/' /etc/cobbler/settings

298行改:pxe_just_once: 1 #防止循环安装

问题 3:修改 tftp 服务被 xinetd 服务管理

[root@ c7-41 ~]# vim /etc/xinetd.d/tftp
disable                 = no
###或者sed -i '14s/= yes/= no/'  /etc/xinetd.d/tftp

xinetd 和 tftpd 服务开机启动

[root@ c7-43 ~]# systemctl start xinetd tftp && systemctl enable xinetd tftp

问题 4:下载操作系统引导文件

[root@ c7-43 ~]# cobbler get-loaders
task started: 2020-05-06_140250_get_loaders
task started (id=Download Bootloader Content, time=Wed May  6 14:02:50 2020)
downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
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
downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***

问题 5: rsyncd 服务为开机自启动状态并启用它

[root@ c7-43 ~]# systemctl start rsyncd && systemctl enable rsyncd

问题 6:关于 debian 相关部署管理配置,忽略。
debmirror package is not installed, it will be required to manage debian
deployments and repositories # debmirror 包尚未安装,需要它来管理 debian 部署和存储库

问题 7:修改操作系统默认密码

# 设置新装系统的默认root密码123456。 将生成的密码写入default_password_crypted
[root@ c7-43 ~]# openssl passwd -1 -salt 'cobbler' '123456'
$1$cobbler$sqDDOBeLKJVmxTCZr52/11
[root@ c7-43 ~]# vim /etc/cobbler/settings
default_password_crypted: "$1$cobbler$sqDDOBeLKJVmxTCZr52/11"

问题 8:电源管理相关服务,忽略

4、配置DHCP

修改完以上配置就可以检查 DHCP 配置了,由于 Cobbler 自动管理 DHCP 服务,我们只需要修改 Cobbler 中的模板配置文件即可

# 修改cobbler的dhcp模版,不要直接修改dhcp本身的配置文件,因为cobbler会覆盖。
[root@ c7-43 ~]# vim /etc/cobbler/dhcp.template
ssubnet 192.168.1.0 netmask 255.255.255.0 {
     option routers             10.0.0.254;
     option domain-name-servers 223.5.5.5,223.6.6.6;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        10.0.0.100 10.0.0.200;

修改 Cobbler 管理 dhcp 服务

[root@ c7-43 ~]# vim /etc/cobbler/settings
manage_dhcp: 1

同步cobbler配置

[root@ c7-43 ~]# systemctl restart cobblerd.service
# 同步最新cobbler配置,它会根据配置自动修改dhcp等服务。
[root@ c7-41 loaders]# cobbler sync       # 同步所有配置,可以仔细看一下sync做了什么。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章