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

 1、介绍python

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

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

2、实验环境web

一、VMware Workstation虚拟机环境redis

二、CentOS7系统的虚拟PC做为Cobbler服务端,网卡使用NAT链接方式apache

3、前期准备django

一、linux能够上网;bootstrap

ping www.baidu.com

二、修改网卡配置,改成DHCP自动获取ip;vim

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

重启网络服务centos

systemctl restart network.service

得到本机IP

ifconfig

4、下载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

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

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

6、启动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

7、检查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

 8、重启cobbler并同步不检查

1 systemctl restart cobblerd
2 cobbler sync
3 cobbler check

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

9、经过cobbler来管理DHCP

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

10、配置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

11、挂载导入镜像

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

方法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命令查看(系统默认没有这个命令,须要单独安装相应软件包)

12、验证cobbler自动装机

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

若是是物理机须要保证和服务器网络畅通

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

十3、自定义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的方法:

方法一、 每安装好一台Centos机器,Centos安装程序都会建立一个kickstart配置文件,记录你的真实安装配置。若是你但愿实现和某系统相似的安装,能够基于该系统的kickstart配置文件来生成你本身的kickstart配置文件。(生成的文件名字叫anaconda-ks.cfg位于/root/anaconda-ks.cfg)

方法二、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更改都要执行同步

 

十4、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
相关文章
相关标签/搜索