Cobbler无人值守安装
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Cobbler无人值守安装相关的知识,希望对你有一定的参考价值。
1. 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配置)
2、系统环境准备
[[email protected] ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[[email protected] ~]# uname -r
3.10.0-693.5.2.el7.x86_64
[[email protected] ~]# getenforce
Disabled
[[email protected] ~]# systemctl status firewalld
Unit firewalld.service could not be found.
[[email protected] ~]# ifconfig eth0|awk -F "[ :]+" ‘NR==2 {print $3}‘
192.168.56.12
[[email protected] ~]# hostname
linux-node2
#配置阿里云epel源
[[email protected] ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
3、Cobbler安装配置
3.1Cobbler安装
[[email protected] ~]# yum install -y httpd tftp dhcp cobbler cobbler-web pykickstart
[[email protected] ~]# 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日志
3.2 cobbler配置
[[email protected] ~]# systemctl start httpd
[[email protected] ~]# systemctl start cobblerd
[[email protected] ~]# 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 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 : 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.
# 看着上面的结果,一个一个解决。
#1.2问题server,Cobbler服务器的IP。
[[email protected] ~]# vim /etc/cobbler/settings
384 server: 192.168.56.12
272 next_server: 192.168.56.12
#3问题解决启用tftp
[[email protected] ~]# yum install -y xinetd
[[email protected] ~]# vim /etc/xinetd.d/tftp
disable = no
[[email protected] ~]# systemctl start xinetd
#4问题解决bootload的插件安装,会自动从官网下载
[[email protected] ~]# cobbler get-loaders
task started: 2018-01-11_155827_get_loaders
task started (id=Download Bootloader Content, time=Thu Jan 11 15:58:27 2018)
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服务依赖
[[email protected] ~]# systemctl enable rsyncd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
[[email protected] ~]# systemctl start rsyncd.service
#7问题解决设置新装系统的默认root密码123123。下面的命令来源于提示7。random-phrase-here为干扰码,可以自行设定。
[[email protected] ~]# openssl passwd -1 -salt ‘123123‘ ‘123123‘
$1$123123$MAV.kVI/b3swmFLErPD2b0
[[email protected] ~]# vim /etc/cobbler/settings
101 default_password_crypted: "$1$123123$MAV.kVI/b3swmFLErPD2b0"
#重启cobbler服务,再检查
[[email protected] ~]# systemctl restart cobblerd
[[email protected] ~]# 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.
3.3配置DHCP
# 修改cobbler的dhcp模版,不要直接修改dhcp本身的配置文件,因为cobbler会覆盖。
[[email protected] ~]# vim /etc/cobbler/settings
manage_dchp: 1 #启用dchp服务
[[email protected] ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.56.0 netmask 255.255.255.0 {
option routers 192.168.56.2;
option domain-name-servers 192.168.56.2;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.56.100 192.168.56.254;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
3.4同步cobbler配置
[[email protected] ~]# systemctl restart cobblerd
[[email protected] ~]# cobbler sync
task started: 2018-01-11_161740_sync
task started (id=Sync, time=Thu Jan 11 16:17:40 2018)
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.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***
4、Cobbler导入镜像
4.1、Cobbler命令
cobbler check 核对当前设置是否有问题
cobbler list 列出所有的cobbler元素
cobbler report 列出元素的详细信息
cobbler sync 同步配置到数据目录,更改配置最好都要执行下
cobbler reposync 同步yum仓库
cobbler distro 查看导入的发行版系统信息
cobbler system 查看添加的系统信息
cobbler profile 查看配置信息
4.2、Cobbler导入镜像
[[email protected] ~]# mount -o loop /opt/CentOS-7-x86_64-Minimal-1708.iso /mnt/ # 挂载CentOS7.4的系统镜像。
mount: /dev/loop0 写保护,将以只读方式挂载
[[email protected] ~]# cobbler import --path=/mnt/ --name=Centos-7.4-x86_64 --arch=x86_64
# --path 镜像路径
# --name 为安装源定义一个名字
# --arch 指定安装源是32位、64位、ia64, 目前支持的选项有: x86│x86_64│ia64
# 安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-7.1-x86_64,如果重复,系统会提示导入失败。
task started: 2018-01-11_163234_import
task started (id=Media import, time=Thu Jan 11 16:32:34 2018)
Found a candidate signature: breed=redhat, version=rhel6
Found a candidate signature: breed=redhat, version=rhel7
Found a matching signature: breed=redhat, version=rhel7
Adding distros from path /var/www/cobbler/ks_mirror/Centos-7.4-x86_64:
creating new distro: Centos-7.4-x86_64
trying symlink: /var/www/cobbler/ks_mirror/Centos-7.4-x86_64 -> /var/www/cobbler/links/Centos-7.4-x86_64
creating new profile: Centos-7.4-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-7.4-x86_64 for Centos-7.4-x86_64
processing repo at : /var/www/cobbler/ks_mirror/Centos-7.4-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/Centos-7.4-x86_64
looking for /var/www/cobbler/ks_mirror/Centos-7.4-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/Centos-7.4-x86_64/repodata
*** TASK COMPLETE ***
[[email protected] ~]# ll /var/www/cobbler/ks_mirror/ #导入镜像的位置
总用量 4
drwxr-xr-x 8 root root 4096 9月 5 21:36 Centos-7.4-x86_64
drwxr-xr-x 2 root root 35 1月 11 16:34 config
[[email protected] ~]# cobbler list #查看镜像
distros:
Centos-7.4-x86_64
profiles:
Centos-7.4-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
4.3、指定ks.cfg文件及调整内核参数
(1)默认的ks.cfg文件
[[email protected] ~]# ll /var/lib/cobbler/kickstarts
总用量 56
-rw-r--r-- 1 root root 115 9月 17 01:33 default.ks
-rw-r--r-- 1 root root 22 9月 17 01:33 esxi4-ks.cfg
-rw-r--r-- 1 root root 22 9月 17 01:33 esxi5-ks.cfg
drwxr-xr-x 2 root root 54 1月 11 15:54 install_profiles
-rw-r--r-- 1 root root 1424 9月 17 01:33 legacy.ks
-rw-r--r-- 1 root root 292 9月 17 01:33 pxerescue.ks
-rw-r--r-- 1 root root 2825 9月 17 01:33 sample_autoyast.xml
-rw-r--r-- 1 root root 1856 9月 17 01:33 sample_end.ks
-rw-r--r-- 1 root root 0 9月 17 01:33 sample_esx4.ks
-rw-r--r-- 1 root root 324 9月 17 01:33 sample_esxi4.ks
-rw-r--r-- 1 root root 386 9月 17 01:33 sample_esxi5.ks
-rw-r--r-- 1 root root 386 9月 17 01:33 sample_esxi6.ks
-rw-r--r-- 1 root root 1913 9月 17 01:33 sample.ks
-rw-r--r-- 1 root root 3419 9月 17 01:33 sample_old.seed
-rw-r--r-- 1 root root 6658 9月 17 01:33 sample.seed
(2)查看所有profile的设置
[[email protected] ~]# cobbler profile report
Name : Centos-7.4-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : Centos-7.4-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] ~]# cobbler profile list #查看可用的镜像
Centos-7.4-x86_64
(3)# 编辑profile,修改关联的ks文件
[[email protected] ~]# cobbler profile edit --name=Centos-7.4-x86_64 --kickstart=/var/lib/cobbler/kickstarts/Centos-7.4-x86_64.cfg
[[email protected] ~]# cobbler profile report
Name : Centos-7.4-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : Centos-7.4-x86_64
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {}
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/Centos-7.4-x86_64.cfg #关联后,此处会变成修改的配置
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
(4)修改安装系统的内核参数,修改网卡名称
[[email protected] ~]# cobbler profile edit --name=Centos-7.4-x86_64 --kopts=‘net.ifnames=0 biosdevname=0‘
[[email protected] ~]# cobbler profile report
Name : Centos-7.4-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : Centos-7.4-x86_64
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {}
Kernel Options : {‘biosdevname‘: ‘0‘, ‘net.ifnames‘: ‘0‘} #此处会增加内核选项参数
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/Centos-7.4-x86_64.cfg
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] ~]# cobbler sync #同步
5、安装系统
5.1去除vm的DHCP
5.2开始安装
新建一台虚拟机(不解释)内存给2G不然坑呀
选择Centos-7.4-x86_64
5.3.Centos-7.4-x86_64.cfg文件
# Cobbler for Kickstart Configurator for CentOS 7.4 by Jason Zhao
# System language
lang en_US
# System keyboard
keyboard us
# System timezone
timezone Asia/Shanghai
#Root password
rootpw --iscrypted $default_password_crypted
#Use text mode install
text
#Install OS instead of upgrade
install
#Use NFS installation Media
url --url=$tree
#System bootloader configuration
bootloader --location=mbr
#Clear the Master Boot Record
zerombr
#Partition clearing information
clearpart --all --initlabel
#Disk partitioning information
part /boot --fstype xfs --size 1024 --ondisk sda
part swap --size 1024 --ondisk sda
part / --fstype xfs --size 1 --grow --ondisk sda
#System authorization --enablemd5
auth --useshadow --enablemd5
# Network information
$SNIPPET(‘network_config‘)
reboot
firewall --disabled
selinux --disabled
skipx
%pre
$SNIPPET(‘log_ks_pre‘)
$SNIPPET(‘kickstart_start‘)
$SNIPPET(‘pre_install_network_config‘)
$SNIPPET(‘pre_anamon‘)
%end
%packages
@base
@core
tree
nmap
sysstat
lrzsz
dos2unix
telnet
iptraf
ncurses-devel
openssl-devel
zlib-devel
OpenIPMI-tools
screen
%end
%post
systemctl disable postfix.service
%end
以上是关于Cobbler无人值守安装的主要内容,如果未能解决你的问题,请参考以下文章