Cobbler无人值守安装

Posted template

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Cobbler无人值守安装相关的知识,希望对你有一定的参考价值。

前言:建议在看Cobbler之前先看一下使用kickstart + pxe 部署无人值守安装无人值守安装,了解一下Cobbler的实现原理。但是Cobbler是独立的,不需要先安装Kickstart然后再安装Cobbler。

1、Cobbler简介
  Cobbler 官网:http://cobbler.github.io

  1. Cobbler是一个快速网络安装linux的服务,而且在经过调整也可以支持网络安装windows。该工具使用python开发,小巧轻便(才15k行python代码),使用简单的命令即可完成PXE网络安装环境的配置,同时还可以管理DHCP、DNS、TFTP、RSYNC以及yum仓库、构造系统ISO镜像。
  2. Cobbler客户端Koan支持虚拟机安装和操作系统重新安装,使重装系统更便捷。
  3. Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
  4. Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
  5. Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。 Cobbler 支持众多的发行版:Red
  6.  Cobbler 支持众多的发行版:Red  Hat、Fedora、CentOS、Debian、Ubuntu 和 SuSE。当添加一个操作系统(通常通过使用 ISO 文件)时,Cobbler 知道如何解压缩合适的文件 并调整网络服务,以正确引导机器。

1.1 Cobbler集成的服务

  • PXE服务支持
  • DHCP服务管理
  • DNS服务管理
  • 电源管理
  • Kickstart服务支持
  • YUM仓库管理
  • TFTP
  • Apache(提供Kickstart的安装源,并提供定制化的kickstart配置) 

2、基础环境说明:

[[email protected] ~]# cat /etc/redhat-release
CentOS release 6.9 (Final)
[[email protected] ~]# uname -r
2.6.32-696.28.1.el6.x86_64
[[email protected] ~]# getenforce
Disabled
[[email protected] ~]# hostname -I
10.0.0.200 172.16.1.200

 3、安装Cobbler

[[email protected] ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo     #需要用到epel源

[[email protected] ~]# yum install cobbler cobbler-web pykickstart httpd dhcp tftp xinetd 
报错:Error: Package: cobbler-web-2.6.11-6.git95749a6.el6.noarch (epel)Requires: Django >= 1.4You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest
[[email protected] ~]# yum -y install python-simplejson
[[email protected] ~]# wget https://kojipkgs.fedoraproject.org//packages/Django14/1.4.14/1.el6/noarch/Django14-1.4.14-1.el6.noarch.rpm
[[email protected] ~]# rpm -ivh Django14-1.4.14-1.el6.noarch.rpm
[[email protected] ~]# yum -y install cobbler cobbler-web pykickstart httpd dhcp tftp xinetd 

需要注意的是我们虚拟机需要采用NAT模式,不要使用桥接模式,应为我们需要搭建DHCP服务器,在同一个局域网多个DHCP服务器会起冲突。

 

3.1 Cobbler安装完成后的配置文件:

/etc/cobbler                   # 配置文件目录

/etc/cobbler/settings         # cobbler主配置文件

/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日志
[[email protected] cobbler]# /etc/init.d/cobblerd start        #启动cobbler程序
Starting cobbler daemon:                                   [  OK  ]
[[email protected] ~]# 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 : 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.

 

我们需要逐一解决上面check出来的问题:

[[email protected] ~]# cp /etc/cobbler/settings{,.bak}   #先备份下
[[email protected] ~]# sed -i ‘s/server: 127.0.0.1/server: 10.0.0.200/‘ /etc/cobbler/settings #Cobbler服务器的IP
[[email protected] ~]# sed -i ‘s/next_server: 127.0.0.1/next_server: 10.0.0.200/‘ /etc/cobbler/settings #告知客户端TFTP服务器IP
[[email protected] ~]# sed -i ‘s/manage_dhcp: 0/manage_dhcp: 1/‘ /etc/cobbler/settings           #用Cobbler来管理DHCP

[[email protected] ~]# openssl passwd -1 -salt ‘Template‘ ‘123456‘ #设置新装系统默认的root密码123456 random-phrase-here为干扰码,可自定
$1$Template$jrLre6/Amh1gZKDTbiS740
[[email protected] ~]# vim /etc/cobbler/settings
default_password_crypted: "$1$Template$jrLre6/Amh1gZKDTbiS740"
[[email protected] ~]# cobbler get-loaders        #执行之后会自动从官网下载安装需要的组件

[[email protected] loaders]# ls /var/lib/cobbler/loaders/                     #下载到的目录以及内容
COPYING.elilo COPYING.yaboot grub-x86_64.efi menu.c32 README
COPYING.syslinux elilo-ia64.efi grub-x86.efi pxelinux.0 yaboot

[[email protected] ~]# vim /etc/xinetd.d/rsync       #将disable改成no

disable = no

[[email protected] dhcp]# vim /etc/xinetd.d/tftp 

disable = no                        

[[email protected] ~]# /etc/init.d/xinetd restart        #重启下xinetd
Stopping xinetd: [FAILED]
Starting xinetd: [ OK ]      

 

#修改cobbler的dhcp模板,不要直接修稿dhcp本身的配置文件,因为cobbler会覆盖。
[[email protected] dhcp]# vim /etc/cobbler/dhcp.template         #配置DHCP模板,修改如下几行,注意结尾都有;号
...
21 subnet 10.0.0.0 netmask 255.255.255.0 {
 22      option routers             10.0.0.2;
 23      option domain-name-servers 10.0.0.2;
 24      option subnet-mask         255.255.255.0;
 25      range dynamic-bootp        10.0.0.100 10.0.0.200;
 26      default-lease-time         21600;
 27      max-lease-time             43200;
 28      next-server                $next_server;
....

  
[[email protected] dhcp]# cobbler sync               #同步最新Cobbler配置,它会根据配置自动修改dhcp等服务,可以看下输出sync做了什么
task started: 2018-06-13_184858_sync
task started (id=Sync, time=Wed Jun 13 18:48:58 2018)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
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/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: 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 ***
[[email protected] dhcp]# /etc/init.d/cobblerd restart
Stopping cobbler daemon:                                   [  OK  ]
Starting cobbler daemon:                                   [  OK  ]
[[email protected] dhcp]# 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.

 

#设置开机启动,并重启相关服务
chkconfig httpd on
chkconfig xinetd on
chkconfig cobblerd on
chkconfig dhcpd on
/etc/init.d/httpd restart
/etc/init.d/xinetd restart
/etc/init.d/cobblerd restart
/etc/init.d/dhcpd restart

 

4 Cobbler的命令行管理

[[email protected] dhcp]# 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]
[[email protected] dhcp]# 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, dont 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 查看配置信息

 

[[email protected] dhcp]# mount /dev/cdrom  /mnt        #挂载镜像
mount: block device /dev/sr0 is write-protected, mounting read-only
[[email protected] mnt]# cobbler import --path=/mnt/ --name=CentOS-6.9-x86_64 --arch=x86_64

#--path 镜像路径
#--name 为安装源定义一个名字
#--arch 指定安装源是32位、64位、ia64, 目前支持的选项有: x86│x86_64│ia64
#安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-6.9-x86_64,如果重复,系统会提示导入失败。
[[email protected] mnt]# cobbler distro list        #查看镜像列表
   CentOS-6.9-x86_64
#镜像存放目录,cobbler会将镜像中的所有安装文件拷贝到本地一份,放在/var/www/cobbler/ks_mirror下的CentOS-6.9-x86_64目录下。因此/var/www/cobbler目录必须具有足够容纳安装文件的空间。
[[email protected] ks_mirror]# cd /var/www/cobbler/ks_mirror/
[[email protected] ks_mirror]# ls CentOS-6.9-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

 

 

 4.1 指定ks.cfg文件及调整内核参数

kickstart 文件:

#Kickstart Configuration by Templeate
#platform=x86, AMD64 or Intel EM64T
#System language
lang en_US
#System keyboard
keyboard us
#System timezone
timezone Asia/Shanghai
#Root password
#rootpw --iscrypted $default_password_crypted              
rootpw  --iscrypted $default_password_crypted  #这些变量都是调用配置文件中的值       
#Use text mode install
text
#Install OS instead of upgrade
install
#Use NFS installation Media
url --url=$tree               
#url --url=http://10.0.0.200/CentOS-7.0-x86_64
#System bootloader configuration
bootloader --location=mbr
#Clear the Master Boot Record
zerombr
#Partition clearing information
clearpart --all --initlabel
#Disk partitioning information
part /boot --fstype ext4 --size 1024 --ondisk sda
part swap --size 1024 --ondisk sda
part / --fstype ext4 --size 1 --grow --ondisk sda
#$SNIPPET(network_config)
network --bootproto=dhcp --device=eth0 --onboot=on
#Reboot after installation
reboot
#Firewall --configuration
firewall --disabled
#SELinux configuration
selinux --disabled
#Do not configure XWindows
skipx
authconfig --enableshadow --passalgo=sha512
$SNIPPET(network_config)
%pre
$SNIPPET(log_ks_pre)
$SNIPPET(kickstart_start)
$SNIPPET(pre_install_network_config)
# Enable installation monitoring
$SNIPPET(pre_anamon)
%end

#Package install information
%packages
@ base
@ core
telnet
sysstat
iptraf
ntp
lrzsz
ncurses-devel
openssl-devel
OpenIPMI-tools
mysql
nmap
screen
%end


%post
systemctl disable postfix.service
%end

 

[[email protected] ks_mirror]# cd /var/lib/cobbler/kickstarts/
[[email protected] kickstarts]# rz #上传准备好的ks文件
[[email protected] kickstarts]# mv kickstart.cfg CentOS-6.9-x86_64.cfg
# 在第一次导入系统镜像后,Cobbler会给镜像指定一个默认的kickstart文件在/var/lib/cobbler/kickstarts下的sample_end.ks。

[[email protected] kickstarts]# cobbler list      
distros:
CentOS-6.9-x86_64

profiles:
CentOS-6.9-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:

[[email protected] kickstarts]# cobbler distro report --name=CentOS-6.9-x86_64      #查看安装镜像文件信息
Name : CentOS-6.9-x86_64
Architecture : x86_64
TFTP Boot Files : {}
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/ks_mirror/CentOS-6.9-x86_64/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/ks_mirror/CentOS-6.9-x86_64/images/pxeboot/vmlinuz
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart Metadata : {‘tree‘: ‘http://@@[email protected]@/cblr/links/CentOS-6.9-x86_64‘}
Management Classes : []
OS Version : rhel6
Owners : [‘admin‘]
Red Hat Management Key : <<inherit>>
Red Hat Management Server : <<inherit>>
Template Files : {}

 

[[email protected] kickstarts]# cobbler profile report     #查看所有的profie设置
Name : CentOS-6.9-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : CentOS-6.9-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

[[email protected] kickstarts]# cobbler profile edit --name=CentOS-6.9-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-6.9-x86_64.cfg 

#如果是安装CentOS7系统的话,为了标准化,我们最好将网卡名修改一下,改为eth0 可以加上  --kopts=‘net.ifnames=0 biosdevname=0‘ 参数

[[email protected] kickstarts]# cobbler sync #每次修改完都同步一下

好了,现在我们就可以安装系统了

 5、安装系统

新建一台虚拟机,开机就可以看到如下界面了

技术分享图片

如果觉得顶上的网址不好看,可以自定义修改

 

[[email protected] ~]# vim /etc/cobbler/pxe/pxedefault.template 
  3 MENU TITLE Cobbler | http://www.cnblogs.com/Template/              #将网址改成我博客的地址了 
[[email protected] ~]# cobbler sync

技术分享图片

网址已经变成了我的博客地址

 

6、定制化安装

有时候我们可能需要制定某台服务器使用制定的ks文件,kickstart实现这个功能可能比较复杂,但是cobbler就很简单了。区分一台服务器最简单的方法就是网卡的mac地址。

我们可以指定某一mac地址的服务器使用指定的ks文件。

[[email protected] ~]# cobbler system add --name=Template --mac=00:0C:29:37:3B:D6 --profile=CentOS-6.9-x86_64 --ip-address=10.0.0.102 --subnet=255.255.255.0 --gateway=10.0.0.2 --interface=eth0 --static=1 --name-servers="1.1.1.1 8.8.8.8"

#--name 自定义但不能重复
#查看定义列表

[[email protected] ~]# cobbler system list
Template

[[email protected] ~]# cobbler sync

再次开机安装就不再询问选择了,直接安装。

技术分享图片

 

7、Cobbler的web管理界面安装与配置

访问网址:http://10.0.0.200/cobbler_web  或 https://10.0.0.200/cobbler_web

默认用户名:cobbler 
默认密码 :cobbler

技术分享图片

/etc/cobbler/users.conf       # Web服务授权配置文件
/etc/cobbler/users.digest     # 用于web访问的用户名密码配置文件
[[email protected] kickstarts]# htdigest /etc/cobbler/users.digest "Cobbler" cobbler #修改web登录密码
改完之后需要cobbler sync 一下 然后重启httpd和cobblerd

 



























































































































以上是关于Cobbler无人值守安装的主要内容,如果未能解决你的问题,请参考以下文章

Cobbler无人值守安装

COBBLER无人值守安装

COBBLER无人值守安装

cobbler无人值守自动安装

cobbler 无人值守安装出现 PXE-E32:TFTP OPen timeout的解决办法

cobbler pxe 无人值守安装