欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

Cobbler--自动化部署

程序员文章站 2022-03-28 18:55:10
Cobbler自动化部署 cobbler简介 Cobbler 可以用来快速建立 Linux 网络安装环境,它已将Linux网络安装的技术门槛,从大专以上文化水平,成功降低到了初中水平,连补鞋匠都能学会。网络安装服务器套件Cobbler(补鞋匠)从前,我们一直在装机民工这份很有前途的职业。自打若干年前 ......

cobbler自动化部署

cobbler简介

cobbler 可以用来快速建立 linux 网络安装环境,它已将linux网络安装的技术门槛,从大专以上文化水平,成功降低到了初中水平,连补鞋匠都能学会。
网络安装服务器套件cobbler(补鞋匠)从前,我们一直在装机民工这份很有前途的职业。自打若干年前red hat推出了 kickstart,此后我们顿觉身价增倍。不再需要刻了光盘一台一台的安装linux,只要搞定pxedhcptftp,还有那满屏眼花缭乱不知所云的kickstart脚本,我们就可以像哈利波特一样,轻点魔棒,瞬间安装上百台服务器。这一堆花里胡哨的东西可不是一般人能够整明白的,没有大专以上的学历,通不过英语四级,根本别想玩转。总而言之,这是一份多么有前途,多么有技术含量的工作啊。很不幸,red hat 最新(cobbler项目最初在2008年左右发布)发布了网络安装服务器套件cobbler(补鞋匠),它已将linux网络安装的技术门槛,从大专以上文化水平,成功降低到初中以下水平,连补鞋匠都能学会。

1、cobbler是一个linux服务器安装的服务,可以通过网络启动(pxe)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理dhcpdns等。
2、cobbler可以使用命令行方式管理,也提供了基于web的界面管理工具(cobbler-web),还提供了api接口,可以方便二次开发使用。
3、cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
4、cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如puppet

参考网站

kickstart文件编写参考

cobbler对应关系

Cobbler--自动化部署

cobbler的配置结构基于一组注册的对象。每个对象表示一个与另一个实体相关联的实体。当一个对象指向另一个对象时,它就继承了被指向对象的数据,并可覆盖或添加更多特定信息。

  • 发行版(distros): 表示一个操作系统。它承载了内核和initrd的信息,以及内核参数等其他数据。
  • 配置文件(profiles):包含一个发行版、一个kickstart文件以及可能的存储库,还包括更多特定的内核参数等其他数据。
  • 系统(systems):表示要配给的机器。它包括一个配置文件或一个镜像、ipmac地址、电源管理(地址、凭据、类型)以及更为专业的数据等信息。
  • 镜像(images):可以替换一个保函不屑于此类别的文件的发行版对象(例如,无法分为内核和initrd的对象)。

cobbler集成的服务

  • pxe服务支持
  • dhcp服务管理
  • dns服务管理
  • 电源管理
  • kickstart服务支持
  • yum仓库管理
  • tftp
  • apache

cobbler工作原理

Cobbler--自动化部署

server端

  • 启动cobbler服务
  • 进行cobbler错误检查,执行cobbler check命令
  • 进行配置同步,执行cobbler sync命令
  • 复制相关启动文件到tftp目录中
  • 启动dhcp服务,提供地址分配
  • dhcp服务分配ip地址
  • tftp传输启动文件
  • server端接收安装信息
  • server端发送iso镜像与kickstart文件

client端

  • 客户端以pxe模式启动
  • 客户端获取ip地址
  • 通过tftp服务器获取启动文件
  • 进入cobbler安装选择界面
  • 根据配置信息准备安装系统
  • 加载kickstart文件
  • 传输系统安装的其它文件
  • 进行安装系统

cobbler安装

说明:虚拟机网卡采用nat模式或者仅主机模式,不要使用桥接模式,因为后面会搭建dhcp服务器,在同一个局域网多个dhcp服务会有冲突。
vmwarenat模式的dhcp服务也关闭,避免干扰。

Cobbler--自动化部署

环境准备

# 关闭防火墙、selinux等
[root@cobbler ~]# systemctl stop firewalld
[root@cobbler ~]# systemctl disable firewalld
[root@cobbler ~]# setenforce 0
[root@cobbler ~]# sed -i 's/^selinux=.*/selinux=disabled/' /etc/sysconfig/selinux

安装cobbler

# 配置epel源
[root@cobbler ~]# yum -y install epel-release

# 安装cobbler及dhcp httpd xinetd cobbler-web
[root@cobbler ~]# yum -y install cobbler cobbler-web tftp-server dhcp httpd xinetd

# 启动cobbler及httpd并加入开机启动
[root@cobbler ~]# systemctl start httpd cobblerd
[root@cobbler ~]# systemctl enable httpd cobblerd

查看安装后相关文件

[root@cobbler ~]# 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日志

配置cobbler

检查cobbler的配置,如果看不到下面的结果,再次重启cobbler

[root@cobbler ~]# 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 : ksvalidator was not found, install pykickstart
8 : 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
9 : 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.

看到上面出现的问题,然后一个一个的进行解决,先进行设置为可以动态配置,也可以直接更改配置文件。

# 设置可以动态修改配置文件
[root@cobbler ~]# sed -ri '/allow_dynamic_settings:/c\allow_dynamic_settings: 1' /etc/cobbler/settings
[root@cobbler ~]# grep allow_dynamic_settings /etc/cobbler/settings 
allow_dynamic_settings: 1
[root@cobbler ~]# systemctl restart cobblerd

逐个解决上面的问题

1. server
[root@cobbler ~]# cobbler setting edit --name=server --value=192.168.2.128

2. next_server
[root@cobbler ~]# cobbler setting edit --name=next_server --value=192.168.2.128

3. tftp_server
[root@cobbler ~]# sed -ri '/disable/c\disable = no' /etc/xinetd.d/tftp
[root@cobbler ~]# systemctl enable xinetd
[root@cobbler ~]# systemctl restart xinetd

4. boot-loaders
[root@cobbler ~]# cobbler get-loaders

5. rsyncd
[root@cobbler ~]# systemctl start rsyncd
[root@cobbler ~]# systemctl enable rsyncd

6. debmirror [optional]
# 这个是可选项的,可以忽略。这里就忽略了

7. pykickstart
[root@cobbler ~]# yum -y install pykickstart

8. default_password_crypted  #注意:这里设置的密码,也就是后面安装完系统的初始化登录密码
[root@cobbler ~]# openssl passwd -1 -salt `openssl rand -hex 4` 'admin'
$1$675f1d08$ojoamvxdbdkhjqxbgqntx0
[root@cobbler ~]# cobbler setting edit --name=default_password_crypted --value='$1$675f1d08$ojoamvxdbdkhjqxbgqntx0'

9. fencing tools [optional]
[root@cobbler ~]# yum -y install fence-agents

解决完成再次查看

[root@cobbler ~]# 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

restart cobblerd and then run 'cobbler sync' to apply changes.

配置dhcp

[root@cobbler ~]# cobbler setting edit --name=manage_dhcp --value=1

# 修改cobbler的dhcp模块,不要直接修改dhcp本身的配置文件,因为cobbler会覆盖
[root@cobbler ~]# vim /etc/cobbler/dhcp.template
...
subnet 192.168.2.0 netmask 255.255.255.0 { #这里改为分配的网段和掩码
     #option routers             192.168.1.5; #如果有网关,这里改为网关地址
     #option domain-name-servers 192.168.1.1; #如果有dns,这里改为dns地址
     option subnet-mask         255.255.255.0; #改为分配的ip的掩码
     range dynamic-bootp        192.168.2.100 192.168.2.254; #改为分配的ip的范围
...

同步cobbler配置

同步cobbler配置,它会根据配置自动修改dhcp等服务。

[root@cobbler ~]# cobbler rsync 
no such command: rsync
[root@cobbler ~]# cobbler sync
task started: 2019-06-12_152623_sync
task started (id=sync, time=wed jun 12 15:26:23 2019)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/centos6.9-x86_64
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/images/centos6.9-x86_64
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 files for distro: centos6.9-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos6.9-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos6.9-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos6.9-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos6.9-x86_64/initrd.img
copying images
generating pxe configuration files
generating pxe menu structure
copying files for distro: centos6.9-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos6.9-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos6.9-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos6.9-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos6.9-x86_64/initrd.img
writing template files for centos6.9-x86_64
rendering dhcp files
generating /etc/dhcp/dhcpd.conf
rendering tftpd files
generating /etc/xinetd.d/tftp
processing boot_files for distro: centos6.9-x86_64
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.manage_genders
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** task complete ***

这时候创建一个新虚拟机可以获取到如下信息,没有镜像选择,只能从本地启动

Cobbler--自动化部署

cobbler命令帮助

命令 说明
cobbler check 核对当前设置是否有问题
cobbler list 列出所有的cobbler元素
cobbler report 列出元素的详细信息
cobbler sync 同步配置到数据目录,更改配置最好都执行一下
cobbler reposync 同步yum仓库
cobbler distro 查看导入的发行版系统信息
cobbler system 查看添加的系统信息
cobbler profile 查看配置信息

 

cobbler配置安装centos6.x

由于我这里实在centos7系统上面配置的cobbler,所以上传了一个centos6的镜像并进行挂载。

1)创建挂载点,并进行挂载

[root@cobbler ~]# mkdir /centos6
[root@cobbler ~]# mount -o loop centos-6.9-x86_64-bin-dvd1.iso /centos6

2)查看挂载后的目录

[root@cobbler ~]# ls /centos6/
centos_buildtag  images                    repodata                       rpm-gpg-key-centos-testing-6
efi              isolinux                  rpm-gpg-key-centos-6           trans.tbl
eula             packages                  rpm-gpg-key-centos-debug-6
gpl              release-notes-en-us.html  rpm-gpg-key-centos-security-6

3)导入镜像

[root@cobbler ~]# cobbler import --path=/centos6 --name=centos6.9 --arch=x86_64
# --path 镜像路径
# --name 为安装源定义一个名字
# --arch 指定安装源是32位、64位、ia64, 目前支持的选项有: x86│x86_64│ia64
# 安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:centos6.9,如果重复,系统会提示导入失败。

4)查看导入后镜像信息

[root@cobbler ~]# cobbler distro report --name=centos6.9-x86_64
name                           : centos6.9-x86_64
architecture                   : x86_64
tftp boot files                : {}
breed                          : redhat
comment                        : 
fetchable files                : {}
initrd                         : /var/www/cobbler/ks_mirror/centos6.9-x86_64/images/pxeboot/initrd.img
kernel                         : /var/www/cobbler/ks_mirror/centos6.9-x86_64/images/pxeboot/vmlinuz
kernel options                 : {}
kernel options (post install)  : {}
kickstart metadata             : {'tree': 'http://@@http_server@@/cblr/links/centos6.9-x86_64'}
management classes             : []
os version                     : rhel6
owners                         : ['admin']
red hat management key         : <<inherit>>
red hat management server      : <<inherit>>
template files                 : {}

5)查看profile信息

[root@cobbler ~]# cobbler profile report --name=centos6.9-x86_64
name                           : centos6.9-x86_64
tftp boot files                : {}
comment                        : 
dhcp tag                       : default
distribution                   : centos6.9-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

6)copy一份profile文件(ks),进行修改

[root@cobbler ~]# cd /var/lib/cobbler/kickstarts/
[root@cobbler kickstarts]# ls
default.ks    install_profiles  sample_autoyast.xml  sample_esxi4.ks  sample.ks
esxi4-ks.cfg  legacy.ks         sample_end.ks        sample_esxi5.ks  sample_old.seed
esxi5-ks.cfg  pxerescue.ks      sample_esx4.ks       sample_esxi6.ks  sample.seed
[root@cobbler kickstarts]# cp sample_end.ks centos6.ks

# 编辑centos6的kickstart文件
[root@cobbler kickstarts]# vim centos6.ks 
# this kickstart file should only be used with el > 5 and/or fedora > 7.
# for older versions please use the sample.ks kickstart file.
# install os instead of upgrade
install
# use text mode install
text
# system keyboard
keyboard us
# system language
lang en_us
# system timezone
timezone  asia/shanghai
#root password
rootpw --iscrypted $default_password_crypted
# system authorization information
auth  --useshadow  --enablemd5
# firewall configuration
firewall --disabled
# selinux configuration
selinux --disabled
# use network installation
url --url=$tree

# clear the master boot record
zerombr
# system bootloader configuration
bootloader --location=mbr
# partition clearing information
clearpart --all --initlabel
part /boot --fstype=ext4 --size=500
part swap --fstype=swap --size=2048
part / --fstype=ext4 --grow --size=200 

# if any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# network information
$snippet('network_config')
# do not configure the x window system
skipx
# run the setup agent on first boot
firstboot --disable
# reboot after installation
reboot


%pre
$snippet('log_ks_pre')
$snippet('kickstart_start')
$snippet('pre_install_network_config')
# enable installation monitoring
$snippet('pre_anamon')
%end

%packages
$snippet('func_install_if_enabled')
@core
@base
tree
nmap
wget
lftp
lrzsz
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

sed -ri "/^#usedns/c\usedns no" /etc/ssh/sshd_config
sed -ri "/^gssapiauthentication/c\gssapiauthentication no" /etc/ssh/sshd_config
%end

7)编辑centos6镜像所使用的kickstart文件

# 动态编辑指定使用新的kickstart文件
[root@cobbler ~]# cobbler profile edit --name=centos6.9-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos6.ks

# 验证是否更改成功
[root@cobbler ~]# cobbler profile report --name=centos6.9-x86_64 |grep kickstart
kickstart                      : /var/lib/cobbler/kickstarts/centos6.ks

8)再次同步cobbler配置

[root@cobbler ~]# cobbler sync

9)新建虚拟机进行测试

Cobbler--自动化部署

选择centos6.9进行安装,会按照kickstart文件安装并启动

Cobbler--自动化部署

cobbler配置安装centos7.x

我这里cobbler服务器就是7的系统,所以直接挂载/dev/cdrom即可

1)创建挂载点,并进行挂载

[root@cobbler ~]# mkdir /centos7
[root@cobbler ~]# mount -o loop /dev/cdrom /centos7

2)查看挂载后的目录

[root@cobbler ~]# ls /centos7/
centos_buildtag  eula  images    liveos    repodata              rpm-gpg-key-centos-testing-7
efi              gpl   isolinux  packages  rpm-gpg-key-centos-7  trans.tbl

3)导入镜像

[root@cobbler ~]# cobbler import --path=/centos7 --name=centos7.4 --arch=x86_64
task started: 2019-06-12_165812_import
task started (id=media import, time=wed jun 12 16:58:12 2019)
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/centos7.4-x86_64:
creating new distro: centos7.4-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos7.4-x86_64 -> /var/www/cobbler/links/centos7.4-x86_64
creating new profile: centos7.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/centos7.4-x86_64 for centos7.4-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos7.4-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/centos7.4-x86_64
looking for /var/www/cobbler/ks_mirror/centos7.4-x86_64/repodata/*comps*.xml
keeping repodata as-is :/var/www/cobbler/ks_mirror/centos7.4-x86_64/repodata
*** task complete ***

4)查看导入后镜像信息

[root@cobbler ~]# cobbler distro report --name=centos7.4-x86_64
name                           : centos7.4-x86_64
architecture                   : x86_64
tftp boot files                : {}
breed                          : redhat
comment                        : 
fetchable files                : {}
initrd                         : /var/www/cobbler/ks_mirror/centos7.4-x86_64/images/pxeboot/initrd.img
kernel                         : /var/www/cobbler/ks_mirror/centos7.4-x86_64/images/pxeboot/vmlinuz
kernel options                 : {}
kernel options (post install)  : {}
kickstart metadata             : {'tree': 'http://@@http_server@@/cblr/links/centos7.4-x86_64'}
management classes             : []
os version                     : rhel7
owners                         : ['admin']
red hat management key         : <<inherit>>
red hat management server      : <<inherit>>
template files                 : {}

5)查看profile信息

[root@cobbler ~]# cobbler profile report --name=centos7.4-x86_64
name                           : centos7.4-x86_64
tftp boot files                : {}
comment                        : 
dhcp tag                       : default
distribution                   : centos7.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

6)copy一份profile文件( ks ),进行修改,这里直接copy上面6的了,然后修改修改即可

[root@cobbler ~]# cd /var/lib/cobbler/kickstarts/
[root@cobbler kickstarts]# cp centos6.ks centos7.ks

# 编辑centos7的kickstart文件
[root@cobbler kickstarts]# vim centos7.ks
# this kickstart file should only be used with el > 5 and/or fedora > 7.
# for older versions please use the sample.ks kickstart file.
# install os instead of upgrade
install
# use text mode install
text
# system keyboard
keyboard us
# system language
lang en_us
# system timezone
timezone  asia/shanghai
#root password
rootpw --iscrypted $default_password_crypted
# system authorization information
auth  --useshadow  --enablemd5
# firewall configuration
firewall --disabled
# selinux configuration
selinux --disabled
# use network installation
url --url=$tree

# clear the master boot record
zerombr
# system bootloader configuration
bootloader --location=mbr
# partition clearing information
clearpart --all --initlabel
part /boot --fstype=xfs --size=500
part swap --fstype=swap --size=2048
part / --fstype=xfs --grow --size=200 

# if any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# network information
$snippet('network_config')
# do not configure the x window system
skipx
# run the setup agent on first boot
firstboot --disable
# reboot after installation
reboot


%pre
$snippet('log_ks_pre')
$snippet('kickstart_start')
$snippet('pre_install_network_config')
# enable installation monitoring
$snippet('pre_anamon')
%end

%packages
$snippet('func_install_if_enabled')
@core
@base
tree
nmap
wget
lftp
lrzsz
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

sed -ri "/^#usedns/c\usedns no" /etc/ssh/sshd_config
sed -ri "/^gssapiauthentication/c\gssapiauthentication no" /etc/ssh/sshd_config
%end

7)编辑centos7镜像所使用的kickstart文件

# 动态编辑指定使用新的kickstart文件
[root@cobbler ~]# cobbler profile edit --name=centos7.4-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.ks

# 验证是否更改成功
[root@cobbler ~]# cobbler profile report --name=centos7.4-x86_64 |grep kickstart
kickstart                      : /var/lib/cobbler/kickstarts/centos7.ks

8)再次同步cobbler配置

[root@cobbler ~]# cobbler sync

9)新建虚拟机进行测试

Cobbler--自动化部署

选择centos7.4进行安装即可

Cobbler--自动化部署

说明:在client端系统安装时,可以在cobbler服务端上查看日志/var/log/messages,观察安装的每一个流程

cobbler web管理界面配置

web界面有很多功能,包括上传镜像、编辑kickstart、等等很多在命令行操作的都可以在web界面直接操作。
在上面已经安装了cobbler-web软件,访问地址:https://ip/cobbler_web 即可。默认账号为cobbler,密码也为cobbler

Cobbler--自动化部署

修改密码

/etc/cobbler/users.conf     #web服务授权配置文件
/etc/cobbler/users.digest   #用于web访问的用户名密码

[root@cobbler ~]# cat /etc/cobbler/users.digest 
cobbler:cobbler:a2d6bae81669d707b72c0bd9806e01f3

# 设置密码,在cobbler组添加cobbler用户,输入2遍密码确
[root@cobbler ~]# htdigest /etc/cobbler/users.digest "cobbler" cobbler
changing password for user cobbler in realm cobbler
new password: superman
re-type new password: superman

# 同步配置并重启httpd、cobbler
[root@cobbler ~]# cobbler sync
[root@cobbler ~]# systemctl restart httpd
[root@cobbler ~]# systemctl restart cobblerd

再次登录即使用新设置的密码登录即可。

 

上一篇: 初次接触CSS变量

下一篇: 数数并说