一、安装
前提:cobbler由epel源提供,故此需要事先配置指向epel的yum源方可进行类似下面的安装过程。
[root@node4 ~]# yum install cobbler cobbler-web pykickstart debmirror fence-agents
[root@node4 ~]# systemctl restart httpd
[root@node4 ~]# systemctl start cobblerd
执行“cobbler check命令检查存的问题,而后逐一按提示解决之。常见的问题如下所示:
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 : 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.
4 : change 'disable' to 'no' in /etc/xinetd.d/rsync
5 : comment 'dists' on /etc/debmirror.conf for proper debian support
6 : comment 'arches' on /etc/debmirror.conf for proper debian support
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、修改/etc/cobbler/settings文件中的server参数的值为提供cobbler服务的主机相应的IP地址或主机名,如192.168.170.9;
2、修改/etc/cobbler/settings文件中的next_server参数的值为提供PXE服务的主机相应的IP地址,如192.168.170.96;
3、如果当前节点可以访问互联网,执行“cobbler get-loaders”命令即可;否则,需要安装syslinux程序包,而后复制/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至/var/lib/cobbler/loaders/目录中;
4、执行“systemctl restart sync”命令即可;
5、注释/etc/debmirror.conf文件中的“@dists="sid";”一行;
6、注释/etc/debmirror.conf文件中的“@arches="i386";”一行;
7、执行“openssl passwd -1 -salt $(openssl rand -hex 4)”生成密码,并用其替换/etc/cobbler/settings文件中default_password_crypted参数的值;
8、执行“yum install cman fence-agents”命令安装相应的程序包即可;
接着重启cobblerd,而后执行“cobbler sync”同步新的配置至cobbler。
[root@node4 ~]# systemctl restart cobblerd.service
[root@node4 ~]# cobbler check
No configuration problems found. All systems go
2.1 配置dhcp服务
定义好所需的“subnet”及其它参数或选项,而后启动dhcpd守护进程即可。本示例中所用的dhcpd的配置如下所示:
[root@node4 ~]# vi /etc/dhcp/dhcpd.conf
option domain-name "cobbler.com";
option domain-name-servers 192.168.170.10;
default-lease-time 43200;
max-lease-time 86400;
log-facility local7;
subnet 192.168.170.0 netmask 255.255.255.0 {
range 192.168.170.80 192.168.170.90;
option routers 192.168.170.9;
}
next-server 192.168.170.9;
filename="pxelinux.0";
启动服务
[root@node4 ~]# systemctl restart dhcpd.service
2.2 配置tftp服务
tftp已经在cobbler中启用了因此,我们直接启动服务器即可
[root@node4 ~]# systemctl restart tftp.socket
CentOS7光盘挂载
[root@node4 ~]# mount /dev/cdrom /media/cdrom
3.1 管理distro
使cobbler变得可用的第一步为定义distro,其可以通过为其指定外部的安装引导内核及ramdisk文件的方式实现。而如果已经有完整的系统安装树(如CentOS6的安装镜像)则推荐使用import直接导入的方式进行。
例如,对于已经挂载至/media/cdrom目录的CentOS 6.5 x86_64的安装镜像,则可以使用类似如下命令进行导入。
[root@node4 ~]# cobbler import --name="CentOS-7-x86_64" --path=/media/cdrom
task started: 2018-11-25_142209_import
task started (id=Media import, time=Sun Nov 25 14:22:09 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-x86_64:
creating new distro: CentOS-7-x86_64
trying symlink: /var/www/cobbler/ks_mirror/CentOS-7-x86_64 -> /var/www/cobbler/links/CentOS-7-x86_64
creating new profile: CentOS-7-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-x86_64 for CentOS-7-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS-7-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS-7-x86_64
looking for /var/www/cobbler/ks_mirror/CentOS-7-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS-7-x86_64/repodata
*** TASK COMPLETE ***
[root@node4 ~]# ls /var/www/cobbler/ks_mirror/
CentOS-7-x86_64 config
列出所有的distro
[root@node4 ~]# cobbler distro list
CentOS-7-x86_64
[root@node4 ~]# cobbler profile list
CentOS-7-x86_64
[root@node4 ~]# cobbler sync
没有提供kickstart文件,cobbler自己提供一个kickstart文件
[root@node4 ~]# vi /var/www/html/kickstarts/centos7.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# X Window System configuration information
xconfig --startxonboot
# Keyboard layouts
# old format: keyboard us
# new format:
keyboard --vckeymap=us --xlayouts='us'
# Root password
rootpw --iscrypted $1$J1l5IzTB$QzUs87Bx7I47bHGla96Qs1
# Use network installation
url --url="http://192.168.170.9/cobbler/ks_mirror/CentOS-7_x86_64-1503/"
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
# SELinux configuration
selinux --enforcing
# System services
services --disabled="chronyd"
ignoredisk --only-use=sda
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=ens192
# Halt after installation
# System timezone
timezone Asia/Shanghai --nontp
# System bootloader configuration
bootloader --append="crashkernel=auto" --location=mbr --boot-drive=sda
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --ondisk=sda --size=500
part swap --fstype="swap" --ondisk=sda --size=1536
part / --fstype="xfs" --ondisk=sda --size=16672
%packages
@base
@core
@desktop-debugging
@development
@dial-up
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@hardware-monitoring
@input-methods
@internet-browser
@multimedia
@print-client
@x11
%end
[root@node4 ~]# cp /var/www/html/kickstarts/centos7.cfg /var/lib/cobbler/kickstarts/
3.2 管理profile
cobbler使用profile来为特定的需求类别提供所需要安装配置,即在distro的基础上通过提供kickstart文件来生成一个特定的系统安装配置。distro的profile可以出现在PXE的引导菜单中作为安装的选择之一。
因此,如果需要为前面创建的centos-6.5-x86_64这个distro提供一个可引导安装条目,其用到的kickstart文件为/tmp/centos-6.5-x86_64.cfg(只提供了最基本的程序包),则可通过如下命令实现。
[root@node4 ~]# cobbler profile add --name=CentOS-7-x86_64-basic --distro=CentOS-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg
查看已经创建的profile
[root@node4 ~]# cobbler profile list
CentOS-7-x86_64
CentOS-7-x86_64-basic
同步新的配置至cobbler
[root@node4 ~]# cobbler sync
查看pxe文件
[root@node4 ~]# cd /var/lib/tftpboot/pxelinux.cfg/
[root@node4 pxelinux.cfg]# cat default
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT local
LABEL local
MENU LABEL (local)
MENU DEFAULT
LOCALBOOT -1
LABEL CentOS-7-x86_64
kernel /images/CentOS-7-x86_64/vmlinuz
MENU LABEL CentOS-7-x86_64
append initrd=/images/CentOS-7-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://192.168.170.9/cblr/svc/op/ks/profile/CentOS-7-x86_64
ipappend 2
LABEL CentOS-7-x86_64-basic
kernel /images/CentOS-7-x86_64/vmlinuz
MENU LABEL CentOS-7-x86_64-basic
append initrd=/images/CentOS-7-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://192.168.170.9/cblr/svc/op/ks/profile/CentOS-7-x86_64-basic
ipappend 2
MENU end
新建虚拟机通过cobbler来完成系统安装。
CentOS6光盘挂载(类似CentOS7安装)
[root@node4 ~]# mount /dev/cdrom /media/cdrom
mount: /dev/sr0 is write-protected, mounting read-only
[root@node4 ~]# ls /media/cdrom/
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 RPM-GPG-KEY-CentOS-Security-6
[root@node4 ~]# cobbler import --name=CentOS-6.7-x86_64 --path=/media/cdrom
task started: 2018-11-25_151711_import
task started (id=Media import, time=Sun Nov 25 15:17:11 2018)
Found a candidate signature: breed=redhat, version=rhel6
Found a matching signature: breed=redhat, version=rhel6
Adding distros from path /var/www/cobbler/ks_mirror/CentOS-6.7-x86_64:
creating new distro: CentOS-6.7-x86_64
trying symlink: /var/www/cobbler/ks_mirror/CentOS-6.7-x86_64 -> /var/www/cobbler/links/CentOS-6.7-x86_64
creating new profile: CentOS-6.7-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-6.7-x86_64 for CentOS-6.7-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS-6.7-x86_64
directory /var/www/cobbler/ks_mirror/CentOS-6.7-x86_64 is missing xml comps file, skipping
*** TASK COMPLETE *
[root@node4 ~]# ls /var/www/cobbler/ks_mirror/CentOS-6.7-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 RPM-GPG-KEY-CentOS-Security-6
[root@node4 ~]# cobbler distro list
CentOS-6.7-x86_64
CentOS-7-x86_64
[root@node4 ~]# cobbler profile list
CentOS-6.7-x86_64
CentOS-7-x86_64
CentOS-7-x86_64-basic
[root@node4 ~]# cat centos6.7.cfg
# Kickstart file automatically generated by anaconda.
#version=DEVEL
install
cdrom
lang en_US.UTF-8
keyboard us
url --url="http://192.168.170.9/cobbler/ks_mirror/CentOS-6.7_x86_64/"
network --device eth0 --bootproto dhcp
rootpw --iscrypted $6$7iU91LwOLOQg5rKD$5y0B2nSG7FhVY.qQACnt2p03ynU6CeLP7iKobpVsO8SqWO7rIMEC6R/kE9gnR2qnIhz6aM6wGYkcxzkAISGRE1
firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
timezone --utc Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
#clearpart --all
part /boot --fstype=ext4 --size=500
part swap --fstype=swap --size=2000
part / --fstype=ext4 --size=19500
repo --name="CentOS" --baseurl=cdrom:sr0 --cost=100
%packages --nobase
@core
%end
[root@node4 ~]# cp centos6.7.cfg /var/lib/cobbler/kickstarts/
[root@node4 ~]# cobbler profile add --name=CentOS-6.7-x86_64-basic --distro=CentOS-6.7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos6.7.cfg
[root@node4 ~]# cobbler profile list
CentOS-6.7-x86_64
CentOS-6.7-x86_64-basic
CentOS-7-x86_64
CentOS-7-x86_64-basic
同步新的配置至cobbler
[root@node4 ~]# cobbler sync
新建虚拟机通过cobbler来选择不同的操作系统,完成系统自动化安装。
安装cobbler-web图形化界面
[root@node4 ~]# yum -y install cobbler-web
[root@node4 ~]# rpm -ql cobbler-web
[root@node4 ~]# cd /etc/cobbler
[root@node4 cobbler]# cp modules.conf modules.conf.bak
[root@node4 cobbler]# htdigest -c /etc/cobbler/users.digest Cobbler cblradmin
Adding password for cblradmin in realm Cobbler.
New password:
Re-type new password:
[root@node4 cobbler]# systemctl restart cobblerd
浏览器输入https://192.168.170.9/cobbler_web/登录到图形化界面,如下图所示:
登录界面输入用户名和密码
到此为止,cobbler学习就完成了。