Cobbler图文详解安装及遇到的问题说明

 一、介绍

Cobbler是一个使用Python开发的开源项目,通过将部署系统所涉及的所有服务集中在一起,来提供一个全自动批量快速建立linux系统的网络环境,

Cobbler提供了DHCP管理,YUM管理,电源管理等功能,除此之外还支持命令行管理,WEB界面管理,cobbler相关软件包由EPEL源提供。EPEL(Extra Pavkages for Enterprise Linux,企业版Linux的额外软件包)是Fedora小组维护的一个软件仓库项目。为RHEL/CentOS提供默认不提供的软件包,安装Cobbler除了EPEL源还需要CentOS自带的网络yum源以提供相关的依赖包。

二、实验环境

1、VMware Workstation虚拟机环境

2、CentOS7系统的虚拟PC作为Cobbler服务端,网卡使用NAT连接方式

三、前期准备

1、linux可以上网;

ping www.baidu.com

2、修改网卡配置,改为DHCP自动获取ip;

vim /etc/sysconfig/network-scripts/ifcfg-ens33

重启网络服务

systemctl restart network.service

获得本机IP

ifconfig

四、下载epel源;

方式1,直接安装

1 yum -y install epel-release    #安装epel源
#若出现 /var/run/yum.pid已被锁定 运行如下代码即可:
rm -f /var/run/yum.pid
2 cd /etc/yum.repos.d/ #检查该路径下是否有两个yum源:epel.repo epel-testing.repo 3 yum clean all && yum makecach #更新yum源,更新后就可以安装源

方式2,使用阿里的源

1 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

五、安装cobbler及所需的服务软件包

yum install cobbler cobbler-web pykickstart debmirror httpd dhcp tftp-server xinetd syslinux rsync -y

六、启动apache服务,cobbler服务,关闭防火墙,关闭增强型功能并设置开机自启

1 systemctl start httpd.service
2 systemctl enable httpd
3 systemctl start cobblerd.service
4 systemctl enable cobblerd
5 systemctl enable dhcpd
6 systemctl stop firewalld.service  #关闭防火墙
7 setenforce 0   #关闭SElinux

七、检查cobbler配置,而后逐一按提示解决

1 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 : comment out 'dists' on /etc/debmirror.conf for proper debian support
6 : comment out '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选项,修改为提供服务的ip地址,即本机ip,不能是127.0.0.1

2)编辑/etc/cobbler/settings文件,找到next_server选项,修改为本机的ip地址,也不能是127.0.0.1

方法1:

1 sed -i 's#^server: 127.0.0.1#server: 192.168.50.101#' /etc/cobbler/settings
2 sed -i 's#^next_server: 127.0.0.1#next_server: 192.168.50.101#' /etc/cobbler/settings

方法2:

1 vim /etc/cobbler/settings

.

3)编辑/etc/xinetd/tftp文件,将文件中的disable字段的配置由yes改为no,并启动xinetd服务

1 vim /etc/xinetd.d/tftp  #
2 systemctl start xinetd.service  #启动xinetd服务

4)执行“cobbler get-loaders”命令即可,即下载引导操作系统,需要几分钟

1 cobbler get-loaders

5)注释/etc/debmirror.conf文件中的@dists="sid";一行

1 sed -i 's/@dists="sid";/#@dists="sid";/' /etc/debmirror.conf

6)注释/etc/debmirror.conf文件中的@arches="i386";一行

1 sed -i 's/@arches="i386";/#@arches="i386";/' /etc/debmirror.conf

7)设置新系统默认的root密码,执行“openssl passwd -1 -salt $(openssl rand -hex 4)”生成密码,并用其替换/etc/cobbler/settings文件中default_password_crypted参数的值;

  8)安装相应的程序包

1 yum install fence-agents

 八、重启cobbler并同步不检查

1 systemctl restart cobblerd
2 cobbler sync
3 cobbler check

显示No configuration problems found. All systems go.(没有找到配置问题,一切正常)

九、通过cobbler来管理DHCP

1 sed -i 's#manage_dhcp: 0#manage_dhcp: 1#' /etc/cobbler/settings

十、配置DHCP服务

1 vi /etc/cobbler/dhcp.template

重启cobbler服务并同步配置

systemctl restart cobblerd.service
systemctl restart dhcpd.service  #此服务有可能无法重启可忽略
systemctl restart httpd.service
systemctl restart xinetd.service

systemctl restart rsync.service
cobbler sync

十一、挂载导入镜像

将镜像文件挂载到服务器上

方法1:直接将镜像文件拷贝至root目录下

1 mount -r CentOS-7-x86_64-Minimal-1804.iso /mnt/CentOS-7-x86_64/

方法2:将光驱中的内容进行挂载

1)设置CD/DVD设备状态勾选已连接

2)使用df -h命令查看光盘是否挂载,即是否有/dev/sr*的盘符

1 umount  /dev/sr1 #先卸载
2 mkdir /mnt/ #创建cdrom挂载点
3 mount  /dev/sr1  /mnt/  #将光盘挂载到刚才创建的cdrom
4 df-h    #查看当前挂载

导入ISO镜像文件

使用cobbler的import命令从ISO安装镜像中导入安装所需要的程序包。数据文件较大,需等待。

命令格式;cobbler import --path=镜像路径 --name=安装引导名 --arch=32位或64位

--path表示镜像所挂载的目录

--name表示为安装源定义的名字

--arch表示指定安装源是32位还是64位,目前支持的选项:x86,x86_64,ia64.

1 cobbler import --path=/mnt/CentOS-7-x86_64/ --name=CentOS-7.5-x86_64 --arch=x86_64

cobbler会将镜像中的所有安装文件拷贝到本地一份,放在/var/www/cobbler/ks_mirrors下。因此/var/www/cobbler目录必须具有足够容纳安装文件的空间,如果空间不够,可以对/var/www/cobbler目录进行移动,建软链接来修改文件存储位置。

导入镜像后可通过cobbler list来查看导入的结果,

其中distro表示一个发行版,

profile表示kickstart配置文件

此时tftp服务器的共享目录也有了启动linux所需的文件,因为从OS安装光盘导入时,同时会把内核vmlinuz和初始化镜像文件initrd.img复制到tftp共享目录下,

可以使用tree命令查看(系统默认没有这个命令,需要单独安装相应软件包)

十二、验证cobbler自动装机

新建一台虚拟机PC进行验证,不使用镜像,网络连接方式选择NAT,注意内存选择2G以上(否则会因内存不够而安装失败)。然后开启新建的虚拟机会出现cobbler画面,选择第二种回车继续等待。

如果是物理机需要保证和服务器网络畅通

等待一会系统就会自动安装好了,案后输入root用户和之前设好的密码进行登录

十三、自定义KickStart文件

在上面的实验中,我们没有进行任何的安装配置,全部都是Cobbler帮助我们完成的。可是在实际生产中,我们对每台主机的硬盘分区,安装的软件都有相应的要求,所以我们需要自己来定制KickStart文件,这样我们就能够定制地批量安装操作系统了。
我们就利用实验环境(CentOS 7.3)中的KickStart文件来定制我们自己的KickStart文件。

1)Cobbler的ks.cfg文件存放位置

cd /var/lib/cobbler/kickstarts/ && ls #自带很多
default.ks    install_profiles  sample_autoyast.xml  sample_esxi4.ks  sample_old.seed
esxi4-ks.cfg  legacy.ks         sample_end.ks(默认使用的ks文件)        sample_esxi5.ks  sample.seed
esxi5-ks.cfg  pxerescue.ks      sample_esx4.ks       sample.ks

提供两种配置ks的方法:

方法1、 每安装好一台Centos机器,Centos安装程序都会创建一个kickstart配置文件,记录你的真实安装配置。如果你希望实现和某系统类似的安装,可以基于该系统的kickstart配置文件来生成你自己的kickstart配置文件。(生成的文件名字叫anaconda-ks.cfg位于/root/anaconda-ks.cfg)

方法2、Centos提供了一个图形化的kickstart配置工具。在任何一个安装好的Linux系统上运行该工具,就可以很容易地创建你自己的kickstart配置文件。kickstart配置工具命令为redhat-config-kickstart(RHEL3)或system-config-kickstart(RHEL5/6/7)

# yum install system-config-kickstart #安装

# yum groupinstall "X Window System" #安装X Window图形界面

# system-config-kickstart #运行kickstart配置

#笔者不喜欢使用Linux运行图形化界面,浪费资源,有兴趣的伙伴可以研究一下

实例一(CentOS7.4 ks)

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
# old format: keyboard us
# new format:
keyboard --vckeymap=us --xlayouts='us'
# Root password
rootpw --iscrypted $1$ljohn$yBMDpKkntQ9jfV1ZAWKpU1
# Use network installation
url --url="http://192.168.137.38/cobbler/ks_mirror/CentOS-7.4-x86_64/"
# System language
lang en_US.UTF-8
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System services
services --disabled="chronyd"
ignoredisk --only-use=sda
# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on
#network  --bootproto=static --device=eth0 --gateway=192.168.137.1 --ip=192.168.137.40 --nameserver=8.8.8.8 --netmask=255.255.255.0  --activate
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --asprimary --fstype="xfs" --size=1024
part swap --fstype="swap" --size=2048
part / --fstype="xfs" --grow --size=1
%packages
@^minimal
@core
%end

实例二(CentOS6.8 ks):

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://192.168.137.38/cobbler/ks_mirror/CentOS-6.8-x86_64/"
#repo --name="CentOS" --baseurl=cdrom:sr0 --cost=100
# Root password
rootpw --iscrypted $1$ljohn$yBMDpKkntQ9jfV1ZAWKpU1
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
# System keyboard
keyboard us
# System language
lang en_US.UTF-8
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Installation logging level
#logging --level=info
# Reboot after installation
reboot
# System timezone
timezone  Asia/Shanghai
# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on
#network  --bootproto=dhcp --device=eth1 --onboot=on
# System bootloader configuration
bootloader --append="crashkernel=auto rhgb quiet" --location=mbr --driveorder="sda"
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --asprimary --fstype="ext4" --size=500
part swap --fstype="swap" --size=2048
part / --fstype="ext4" --grow --size=1
%packages --nobase
@core
%end

这两个实例安装包都使用了core的最小化版本安装,可以大大缩短系统部署时间,毕竟时间就是金钱。如果有需要的,可以在packages后面添加一些常用的工具,这里不再赘述。

2)关联镜像与kickstart 文件,修改kickstart文件为自定义的CentOS-7.5-x86_64.cfg

 # --name 我们需要添加的启动菜单的名字
 # --distro  我们自定制的ks文件关联的yum库
 # --kickstart 我们自定制的ks文件的路径
cobbler profile edit --name=CentOS-7.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.5-x86_64.cfg
# 查看Cobbler中现在还有多少个启动项
[root@localhost kickstarts]cobbler profile list
   centos6.9-x86_64
    centos7.3-x86_64
    centos7.3-x86_64-desktop

 

cobbler profile report --name CentOS-7.4-x86_64#查看镜像是否存在,
cobbler profile report --name CentOS-6.8-x86_64
cobbler profile edit --name=CentOS-7.4-x86_64 --kopts='net.ifnames=0 biosdevname=0'#这里还原centos7网卡名为“eth0”
cobbler profile edit --name=CentOS-7.4-x86_64 --distro=CentOS-7.4-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.4-x86_64.cfg #关联ks文件与对应的CentOS7.4镜像
cobbler profile edit --name=CentOS-6.8-x86_64 --distro=CentOS-6.8-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-6.8-x86_64.cfg
service cobbler sync #与cobbler sync作用相同,同步配置,每次对cobbler更改都要执行同步

 

十四、Cobbler的Web管理

cobbler web支持多种认证方式,下面介绍两种用户认证登录cobbler web的方式

1)使用cobbler默认的authn_configfile模块认证方式

cobbler web界面的身份认证和授权配置位于文件/etc/cobbler/modules.conf中,cobbler默认这种方式的认证

可以直接使用htdigest命令添加cobbler用户和密码

然后重启cobbler服务,apache服务即可

2)使用authn_pam模块认证方式

首先需要在配置文件/etc/cobbler/modules.conf里修改认证方式

然后添加系统用户

之后在文件/etc/cobbler/users.conf中,将新添加的webuser用户添加到admins组中,该组具有完整访问权限

配置完成后重启cobbler,apache服务,就可以用webuser的身份登录到cobbler web页面了。

使用https://192.168.195.128/cobbler_web地址访问cobbler web页面,使用设定的用户和密码就可以进行登录,在web页面进行相关配置。

附录1:错误汇总

1)Cobbler 登录web界面提示报错“Internal Server Error”

有可能是pythone-django版本问题

#下载pip.py
wget https://bootstrap.pypa.io/get-pip.py

#调用本地python运行pip.py脚本
python get-pip.py

#安装pip
pip install Django==1.8.9

#查看pip版本号
python -c "import django; print(django.get_version())"

#重启httpd
systemctl restart httpd

完美解决

附录2:cobbler命令

# 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]
Cobbler 命令介绍:
cobbler get-loaders  #加载部分缺失的网络boot-loaders
cobbler check          #检查cobbler配置
cobbler sync            #同步配置到dhcp pxe和数据目录
cobbler list              #列出所有的cobbler元素
cobbler import          #导入安装的系统光盘镜像
cobbler report          #列出各元素的详细信息
cobbler distro          #查看导入的发行版系统信息
cobbler profile         #查看配置信息
cobbler system         #查看添加的系统信息
cobbler reposync       #同步yum仓库到本地
cobbler signature update
cobbler --help           #获得cobbler的帮助
cobbler distro --help  #获得cobbler子命令的帮助
获取帮助:
#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, don't mirror
--kickstart=KICKSTART_FILE
assign this kickstart file
--rsync-flags=RSYNC_FLAGS
pass additional flags to rsync

 

posted @ 2019-03-26 19:04  罐头瓶  阅读(7085)  评论(1编辑  收藏  举报