cobbler装机之照猫画虎

cobbler

[root@Cobbler ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)

[root@Cobbler ~]# uname -r
3.10.0-693.el7.x86_64

[root@Cobbler ~]# getenforce
Disabled

[root@Cobbler ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)

[root@Cobbler ~]# hostname -I
192.168.233.199 192.168.122.1

5.2.1 安装EPEL源
[root@ops-cobbler ~]# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@ops-cobbler ~]# wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
[root@ops-cobbler ~]# rpm -Uvh remi-release-6.rpm epel-release-6-8.noarch.rpm

以上需联网环境,如果没有可以自行下载拷贝过来后安装

yum install epel-release
————————————————

wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7.rpm

5.2.3 安装Cobbler并修改Setting主配置文件
首先安装Cobbler units和所需要的服务

[root@ops-cobbler ~]# yum install cobbler cobbler-web pykickstart httpd dhcp tftp xinetd
1
然后再改配置文件,主要是修改配置文件中默认的值:

修改默认的Server IP
修改默认的next_server IP
配置dhcp\dns由cobbler管理
将pxe_just_once改为1,防止误重装系统
该选项作用:
*防止机器循环安装配置始终从网络引导
*激活此选项,机器回传Cobbler安装完成
*Cobbler将系统对象的netboot标志更改为false,强制要求机器从本地磁盘引导。
设置Cobbler系统默认密码
配置rsync、tftp服务,由cobbler管理,并要保证xinetd服务为开机自启动状态,因rsync、tftp服务由xinetd服务统一管理
备注:(1)默认情况下,Cobbler安装完成后,会自己去管理tftp服务,因manage_tftp和managed_tftpd的值默认为1,所以不需要手动设置;(2)要想让Cobbler来管理rsync、tftp服务,只要保证各自服务已安装,并设置为开机自启动即可;(3)此外,需要保证xinetd服务为开机自启动状态,因rsync、tftp服务由xinetd服务统一管理。
————————————————

Installed:
cobbler.x86_64 0:2.8.5-0.3.el7 cobbler-web.noarch 0:2.8.5-0.3.el7 dhcp.x86_64 12:4.2.5-77.el7.centos httpd.x86_64 0:2.4.6-90.el7.centos
tftp.x86_64 0:5.2-22.el7 xinetd.x86_64 2:2.3.15-13.el7

Dependency Installed:
bind-export-libs.x86_64 32:9.11.4-9.P2.el7 mailcap.noarch 0:2.1.41-2.el7 mod_ssl.x86_64 1:2.4.6-90.el7.centos
mod_wsgi.x86_64 0:3.4-18.el7 python-cheetah.x86_64 0:2.4.4-5.el7.centos python-django-bash-completion.noarch 0:1.11.27-1.el7
python-netaddr.noarch 0:0.7.5-9.el7 python-pillow.x86_64 0:2.0.0-20.gitd1c6db8.el7_7 python-pygments.noarch 0:1.4-10.el7
python2-django.noarch 0:1.11.27-1.el7 python2-markdown.noarch 0:2.4.1-4.el7 python2-pyyaml.noarch 0:3.10-0.el7
python2-simplejson.x86_64 0:3.10.0-2.el7 syslinux.x86_64 0:4.05-15.el7 tftp-server.x86_64 0:5.2-22.el7

Updated:
pykickstart.noarch 0:1.99.66.21-1.el7

Dependency Updated:
dhclient.x86_64 12:4.2.5-77.el7.centos dhcp-common.x86_64 12:4.2.5-77.el7.centos dhcp-libs.x86_64 12:4.2.5-77.el7.centos
httpd-tools.x86_64 0:2.4.6-90.el7.centos

Complete!

cp /etc/cobbler/settings{,.bak}
sed -i ‘s/server: 127.0.0.1/server: 172.16.1.202/’ /etc/cobbler/settings
sed -i ‘s/next_server: 127.0.0.1/next_server: 172.16.1.202/’ /etc/cobbler/setting
sed -i ‘s/manage_dhcp: 0/manage_dhcp: 1/’ /etc/cobbler/settings
sed -i ‘s/manage_dns: 0/manage_dns: 1/’ /etc/cobbler/settings #DNS管理可选,看需求
sed -i ‘s/pxe_just_once: 0/pxe_just_once: 1/’ /etc/cobbler/settings
#设置系统密码 (加密)
sed -ri “/default_password_crypted/s#(.: ).#\1"openssl passwd -1 -salt 'xzy' '123456'”#" /etc/cobbler/settings
#即:default_password_crypted: “ 1 1 1oldboy$Npg9Pt9k98Mlg0ZeqHAuN1”
#openssl passwd -1 -salt ‘xzy’ ‘123456’ (以xzy为填充字符)
sed -i ‘/diable/ s/yes/no/’ /etc/xinetd.d/rsync
sed -i ‘/diable/ s/yes/no/’ /etc/xinetd.d/tftp
chkconfig --level 35 xinetd on #设置开机自启动

[root@client cobbler]# openssl passwd -1 -salt ‘xzy’ ‘123456’
1 1 1xzy$PU32Ia238CAYJ7ecxcayH0

5.2.4 启动依赖服务
systemctl start httpd
systemctl enable httpd # 设置开机自启动
systemctl start cobblerd
systemctl enable cobblerd # 设置开机自启动
systemctl start tftp
systemctl enable tftp # 设置开机自启动
service xinetd start
————————————————
5.2.5 Cobbler自检
检查还有哪些步骤需要做,按提示逐一解决即可,需要注意的就是:需要在cobblerd和httpd启动的情况下检查,所以上述5.2.4需要先做。
为显示更多的错误内容做示范,我找了其他博主的检查记录7,我们逐一来看(实际上如果你按照本文的操作顺序做的话其中一些问题是不会出现的):
————————————————
执行Cobbler check 检查目前环境还缺少哪些东西
[root@localhost ~]#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 : 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 : 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.
2 : enable and start rsyncd.service with systemctl
3 : debmirror package is not installed, it will be required to manage debian deployments and repositories
4 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them

错误4: 找不到network boot-loaders引导文件(启动菜单),需要下载。如果当前节点可以访问互联网,执行“cobbler get-loaders”命令即可;
cobbler get-loaders
#拷贝一份 可选
tar xfP cobbler_load_for_CentOS7.tar.gz

如果无法联网,需要安装syslinux程序包,此处我们安装cobbler时已经安装好了syslinux,直接复制/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至/var/lib/cobbler/loaders/目录中;

cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/cobbler/loaders/
1
不过需要注意的就是,不连internet,只复制menu.c32,pxelinux.0两个文件的话,只支持安装x86/x86_64架构的系统,所以建议还是执行cobbler get-loaders,将所需的文件都下载到 /var/lib/cobbler/loaders来。

错误5:需要开启rsyncd.service服务
systemctl enable rsyncd
1
错误6:未安装debmirror包
yum -y install debmirror cman
1
错误7:密码没改,按照提示方式"openssl passwd -1 -salt ‘random-phrase-here’ ‘your-password-here’"创建一个新密码,然后以命令方式动态修改密码
#openssl passwd -1 -salt openssl rand -hex 4 ‘redhat’
1 1 1fe4c277f$tbAmxXGSIA7cc/AXLsQVd.
#cobbler setting edit --name=default_password_crypted --value=‘ 1 1 1fe4c277f$tbAmxXGSIA7cc/AXLsQVd.’

当然,也可以用sed命令修改密码,就是匹配写起来费劲:

sed -ri “/default_password_crypted/s#(.: ).#\1"openssl passwd -1 -salt 'openssl rand -hex 4' 'redhat'”#" /etc/cobbler/settings

错误8:电源管理工具fencing tools没找到,如果需要电源管理特性的话,则需要安装cman及fence-agents包

错误8:电源管理工具fencing tools没找到,如果需要电源管理特性的话,则需要安装cman及fence-agents包
#yum -y install cman fence-agents
1
错误9:file /etc/xinetd.d/rsync does not exist #没有这个文件
ls命令检查下该文件是否真的不在,实际上/etc/xinetd.d/rsync文件存在,此条忽略,应是个程序BUG,可以忽略
错误10:comment ‘dists’ on /etc/debmirror.conf for proper debian support;comment ‘arches’ on /etc/debmirror.conf for proper debian support,这是错误6中安装debmirror包后衍生出的错误,根据提示,在 /etc/debmirror.conf配置文件中注释掉这两行选项即可

#@dists=“sid”

#@arches="i386

错误11:change ‘disable’ to ‘no’ in /etc/xinetd.d/rsync
修改配置,可以用命令直接启动
sed -i ‘/disable/ s/yes/no/’ /etc/xinetd.d/rsync && grep -n ‘disable’ /etc/xinetd.d/rsync
chkconfig rsync on

错误12:selinux未禁用的话也会报错,不过因方案准备时我们已经关闭,所以不会遇到,如果遇到报错则按如下关闭即可
setenforce 0
#sed -i ‘/(^SELINUX=).*/ s//\1disabled/’ /etc/selinux/config
错误13:ksvalidator was not found , install pykickstart
需要安装ks文件验证支持包
#yum -y install pykickstart
检查更新完配置后重启下服务,并同步cobbler数据8

systemctl restart httpd.service # 即service httpd restart
systemctl restart cobblerd.service # 即service cobblerd restart
systemctl restart dhcpd.service
systemctl restart rsyncd.service
systemctl restart tftp.socket
cobbler sync

root@client dhcp]# vim /etc/cobbler/dhcp.template
[root@client dhcp]# ss -antulp | grep dhcp
udp UNCONN 0 0 :67 : users:((“dhcpd”,pid=7033,fd=7))
[root@client dhcp]# cobbler sync
task started: 2020-02-29_235054_sync
task started (id=Sync, time=Sat Feb 29 23:50:54 2020)
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.efi
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
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 DNS files
generating /etc/named.conf
generating /etc/secondary.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: service named restart
received on stdout:
received on stderr: Redirecting to /bin/systemctl restart named.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.manage_genders
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***

5.3.1 方式一:web界面配置8 9
5.3.1.1 打开WEB登录页面
在刚配置完的服务器端打开:https://10.0.0.202/cobbler_web/
用户名:cobbler 密码:cobbler
注意:CentOS7中cobbler只支持https访问。

然后挂载上镜像

[root@Cobbler ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only

[root@Cobbler ~]# df -h |grep mnt
/dev/sr0 4.3G 4.3G 0 100% /mnt

3)在Cobbler web中导入镜像
选择Import DVD 输入Prefix(文件前缀),Arch(版本),Breed(品牌),Path(要从什么地方导入)
在导入镜像的时候要注意路径,防止循环导入。
信息配置好后,点击run,即可进行导入。8

导入过程使用rsync进行导入,我们可以用以下命令查看进展,这三个进程消失表示导入完毕:

[root@Cobbler mnt]# ps -ef |grep rsync
root 25266 1582 15 17:30 ? 00:00:06 rsync -a /mnt/ /var/www/cobbler/ks_mirror/CentOS6.8-x86_64 --progress
root 25267 25266 0 17:30 ? 00:00:00 rsync -a /mnt/ /var/www/cobbler/ks_mirror/CentOS6.8-x86_64 --progress
root 25268 25267 11 17:30 ? 00:00:05 rsync -a /mnt/ /var/www/cobbler/ks_mirror/CentOS6.8-x86_64 --progress

[root@Cobbler mnt]# ps -ef |grep rsync
root 25266 1582 15 17:30 ? 00:00:06 rsync -a /mnt/ /var/www/cobbler/ks_mirror/CentOS6.8-x86_64 --progress
root 25267 25266 0 17:30 ? 00:00:00 rsync -a /mnt/ /var/www/cobbler/ks_mirror/CentOS6.8-x86_64 --progress
root 25268 25267 11 17:30 ? 00:00:05 rsync -a /mnt/ /var/www/cobbler/ks_mirror/CentOS6.8-x86_64 --progress

我们也可以在web界面的events菜单下查看具体日志,可以发现有running进程

可以查看下导入完成后生成的文件夹:

创建并编辑完成后点击Save进行保存,kickstart内容视不同的操作系统不同,每种类型保存一种kickstart文件。kickstart文件的生成可以直接修改模板文件,也可以运行system-config-kickstart命令后图形化界面中设置,详见附录1

5.3.1.4 系统及网络设置
(1)首先,创建一个新的系统system
在这里插入图片描述
(2)定义新系统的配置,
先在General选项卡中设置系统名、选择镜像、选择环境、选择kickstart文件

再在Netwarking(Global)中配置全局网络信息,包括主机名、网关、DNS

再配置网卡信息,eth0,eth1,需要注意,选择static静态
内网网卡不要设置网关,否则会导致无法上网

以上的所有配置完成后,点击Save进行保存

另外注意MAC地址不要填错了,VMware workstation中查看虚拟机mac地址的方法如下:在虚拟机设置中

由于根据无人值守安装的需求,无需人工干预,需要自动安装,这时候就要需要将local从启动项删除即可。修改方法如下:

首先找到PXE加载的菜单选项在哪,路径"/var/lib/tftpboot/pxelinux.cfg"下找到"default"文件,内容如下:

[root@cobbler-node ~]# cd /var/lib/tftpboot/pxelinux.cfg/
[root@cobbler-node pxelinux.cfg]# cp default default.bak
[root@cobbler-node 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 centos7.2-Minimal-x86_64
kernel /images/centos7.5-x86_64/vmlinuz
MENU LABEL centos7.5-x86_64
append initrd=/images/centos7.5-x86_64/initrd.img ksdevice=bootif lang= text biosdevname=0 net.ifname=0 kssendmac ks=http://172.16.60.222/cblr/svc/op/ks/profile/centos7.5-x86_64
ipappend 2

MENU end

如上,可以看出MENU菜单有俩个选项。这里删除“LABEL local”的内容,并修改“ONTIMEOUT”值为我们想要的启动项即可,如下:

[root@cobbler-node pxelinux.cfg]# vim default
DEFAULT menu
PROMPT 0
MENU XXXXXXXX | Cloud Of XXXXXX
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT centos7.2-Minimal-x86_64

LABEL centos7.2-Minimal-x86_64
kernel /images/centos7.5-x86_64/vmlinuz
MENU LABEL centos7.5-x86_64
append initrd=/images/centos7.5-x86_64/initrd.img ksdevice=bootif lang= text biosdevname=0 net.ifname=0 kssendmac ks=http://172.16.60.222/cblr/svc/op/ks/profile/centos7.5-x86_64
ipappend 2

MENU end

如上图,只留下了"LABELcentos7.2-Minimal-x86_64"这一个启动项,"ONTIMEOUT “改为了"centos7.2-Minimal-x86_64”,"MENUTITLE"可以修改成自定义内容。修改后保存即可,不要重启cobblerd服务,也不要执行"cobbler sync"同步。修改后的PXE启动页面如下:

默认的20秒超时一过就可以进入该选项进行自动安装。这样就可以做到了无人工干预的自动无人值守安装需求。

对于单一操作系统的可以这样操作哈,一般多操作系统可选的没必要~

PS:如何让cobbler下载yum源?
可通过cobbler web页面导入本地或者公网yum源

root@CentOS6 ~]# cd /var/www/cobbler/repo_mirror/
[root@CentOS6 repo_mirror]# ls
oldboyedu

最后,装系统的时候如何关联到本地yum源呢?在Profiles中选择好可用的yum源并保存即可

附录1.1 图形化界面设置
命令行调用图形化界面后自上而下而顺序设置即可:

system-config-kickstart

附录1.3 CentOS-7-x86_64.cfg参考模板
#CentOS7的ks文件 CentOS-7-x86_64.cfg
#Cobbler for Kickstart Configurator for CentOS 7 by yao zhang
install
url --url=$tree
text
lang en_US.UTF-8
keyboard us
zerombr
bootloader --location=mbr --driveorder=sda --append=“crashkernel=auto rhgb quiet”
#Network information
$SNIPPET(‘network_config’)
#network --bootproto=dhcp --device=eth0 --onboot=yes --noipv6 --hostname=CentOS7
timezone --utc Asia/Shanghai
authconfig --enableshadow --passalgo=sha512
rootpw --iscrypted $default_password_crypted
clearpart --all --initlabel
part /boot --fstype xfs --size 1024
part swap --size 1024
part / --fstype xfs --size 1 --grow
firstboot --disable
selinux --disabled
firewall --disabled
logging --level=info
reboot
%pre
$SNIPPET(‘log_ks_pre’)
$SNIPPET(‘kickstart_start’)
$SNIPPET(‘pre_install_network_config’)
#Enable installation monitoring
$SNIPPET(‘pre_anamon’)
%end
%packages
@^minimal
@compat-libraries
@core
@debugging
@development
bash-completion
chrony
dos2unix
kexec-tools
lrzsz
nmap
sysstat
telnet
tree
vim
wget
%end
%post
systemctl disable postfix.service
%end

附录1.4 CentOS-6.8-x86_64.cfg参考模板
Cobbler for Kickstart Configurator for CentOS 6.8 by la la
install
url --url=$tree
text
lang en_US.UTF-8
keyboard us
zerombr
bootloader --location=mbr --driveorder=sda --append=“crashkernel=auto rhgb quiet”
$SNIPPET(‘network_config’)
timezone --utc Asia/Shanghai
authconfig --enableshadow --passalgo=sha512
rootpw --iscrypted $default_password_crypted
clearpart --all --initlabel
part /boot --fstype=ext4 --asprimary --size=200
part swap --size=1024
part / --fstype=ext4 --grow --asprimary --size=200
firstboot --disable
selinux --disabled
firewall --disabled
logging --level=info
reboot
%pre
$SNIPPET(‘log_ks_pre’)
$SNIPPET(‘kickstart_start’)
$SNIPPET(‘pre_install_network_config’)
#Enable installation monitoring
$SNIPPET(‘pre_anamon’)
%end
%packages
@base
@compat-libraries
@debugging
@development
tree
nmap
sysstat
lrzsz
dos2unix
telnet
%end
%post --nochroot
$SNIPPET(‘log_ks_post_nochroot’)
%end
%post
$SNIPPET(‘log_ks_post’)
#Start yum configuration
$yum_config_stanza
#End yum configuration
$SNIPPET(‘post_install_kernel_options’)
$SNIPPET(‘post_install_network_config’)
$SNIPPET(‘func_register_if_enabled’)
$SNIPPET(‘download_config_files’)
$SNIPPET(‘koan_environment’)
$SNIPPET(‘RedHat_register’)
$SNIPPET(‘cobbler_register’)
#Enable post-install boot notification
$SNIPPET(‘post_anamon’)
Start final steps
$SNIPPET(‘kickstart_done’)
End final steps
%end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值