COBBLER无人值守安装

csdn对markdown的语法支持很差劲,如果出现排版错误,可参考文档自动化语文之COBBLER无人值守安装

COBBLER无人值守安装

这里需要提一下
在看Cobbler之前请大家先看一下Kickstart无人值守安装,了解一下Cobbler的实现原理。但是Cobbler是独立的,不需要先安装Kickstart然后再安装Cobbler,这是写给不了解Kickstart的人看的。

1. Cobbler介绍

Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。

Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。

Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。

Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。

Cobbler官网

1.1 Cobbler集成的服务

  • PXE服务支持
  • DHCP服务管理
  • DNS服务管理(可选bind,dnsmasq)
  • 电源管理
  • Kickstart服务支持
  • YUM仓库管理
  • TFTP(PXE启动时需要)
    Apache(提供kickstart的安装源,并提供定制化的kickstart配置)

1.2 系统环境准备

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core) 
[root@localhost ~]# uname -r
3.10.0-862.el7.x86_64
[root@localhost ~]# getenforce 
Disabled
[root@localhost ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination 
[root@localhost ~]# ifconfig ens33|grep 'inet '|awk '{print $2}'
192.168.56.11
[root@linux-node01 ~]# hostname
linux-node01.zte.com.cn




#配置阿里云的epel源 [root@linux-node01 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

注意

  • 虚拟机网卡采用NAT模式,不要使用桥接模式,因为稍后我们会搭建DHCP服务器,在同一局域网多个DHCP服务会有冲突。
  • VMware的NAT模式的dhcp服务也关闭,避免干扰。

Markdown

2. Cobbler安装配置

2.1 安装Cobbler

[root@model ~]# yum install cobbler cobbler-web dhcp tftp-server pykickstart httpd -y
[root@linux-node1 ~]# 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日志

2.2 配置Cobbler

[root@linux-node01 ~]# systemctl start httpd
[root@linux-node01 ~]# systemctl start cobblerd
[root@linux-node01 ~]# 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、2、6个问题,顺便修改其他功能 [root@linux-node01 ~]# cp /etc/cobbler/settings{,.ori} #备份 # server,Cobbler服务器的IP。 [root@linux-node01 ~]# sed -i 's/server: 127.0.0.1/server: 192.168.56.11/' /etc/cobbler/settings # next_server,如果用Cobbler管理DHCP,修改本项,作用不解释,看kickstart。 [root@linux-node01 ~]# sed -i 's/next_server: 127.0.0.1/next_server: 192.168.56.11/' /etc/cobbler/settings # 用Cobbler管理DHCP [root@linux-node01 ~]# sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings # 防止循环装系统,适用于服务器第一启动项是PXE启动。 [root@linux-node01 ~]# sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings # 设置新装系统的默认root密码123456。下面的命令来源于提示6。random-phrase-here为干扰码,可以自行设定。 [root@linux-node01 ~]# openssl passwd -1 -salt 'baizuo' '123456' 1 1 baizuoWtro4OlXkhyUBAqBpkA611[root@linux-node01 ~]# vi /etc/cobbler/settingsdefault_password_crypted: "1 baizuo b a i z u o Wtro4OlXkhyUBAqBpkA611" # 第3个问题 [root@linux-node01 ~]# cobbler get-loaders [root@linux-node1 ~]# cd /var/lib/cobbler/loaders/ # 下载的内容 [root@linux-node1 loaders]# ls COPYING.elilo COPYING.yaboot grub-x86_64.efi menu.c32 README COPYING.syslinux elilo-ia64.efi grub-x86.efi pxelinux.0 yaboot # 第4个问题 [root@linux-node01 loaders]# vi /etc/xinetd.d/tftp disable = no [root@linux-node01 xinetd.d]# systemctl restart xinetd [root@linux-node01 loaders]#systemctl restart cobblerd [root@linux-node01 xinetd.d]# cobbler check The following are potential configuration items that you may want to fix: 1 : enable and start rsyncd.service with systemctl 2 : debmirror package is not installed, it will be required to manage debian deployments and repositories 3 : 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. #这些问题可以忽略,不影响使用

2.3 配置DHCP


# 修改cobbler的dhcp模版,不要直接修改dhcp本身的配置文件,因为cobbler会覆盖。 [root@linux-node1 ~]# vim /etc/cobbler/dhcp.template # 仅列出修改过的字段 …… subnet 192.168.56.0 netmask 255.255.255.0 { option routers 192.168.56.2; option domain-name-servers 192.168.56.2; option subnet-mask 255.255.255.0; range dynamic-bootp 192.168.56.100 192.168.56.254; ……

2.4 同步cobbler配置

[root@linux-node01 xinetd.d]# cobbler sync
task started: 2018-05-27_171527_sync
task started (id=Sync, time=Sun May 27 17:15:27 2018)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
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 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 shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***




#再看一下dhcp的配置文件是不是已经被修改了 [root@linux-node01 xinetd.d]# head -20 /etc/dhcp/dhcpd.conf # ****************************************************************** # Cobbler managed dhcpd.conf file # generated from cobbler dhcp.conf template (Sun May 27 09:15:28 2018) # Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes # in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be # overwritten. # ****************************************************************** ddns-update-style interim; allow booting; allow bootp; ignore client-updates; set vendorclass = option vendor-class-identifier; option pxe-system-type code 93 = unsigned integer 16; subnet 192.168.56.0 netmask 255.255.255.0 { option routers 192.168.56.2;

2.5 开机启动


#设置开机自启动 [root@linux-node01 xinetd.d]# systemctl enable httpd.service [root@linux-node01 xinetd.d]# systemctl enable xinetd.service [root@linux-node01 xinetd.d]# systemctl enable cobblerd.service #重启相关服务 [root@linux-node01 xinetd.d]# systemctl restart httpd.service [root@linux-node01 xinetd.d]# systemctl restart xinetd.service [root@linux-node01 xinetd.d]# systemctl restart cobblerd.service

3. Cobbler的命令行管理

3.1 查看命令帮助

[root@linux-node1 ~]# cobbler




usage ===== cobbler

3.2 导入镜像

[root@linux-node1 ~]# mount /dev/cdrom /mnt/  # 挂载CentOS7的系统镜像。
[root@linux-node1 ~]# cobbler import --path=/mnt/ --name=CentOS-7-x86_64 --arch=x86_64




# --path 镜像路径 # --name 为安装源定义一个名字 # --arch 指定安装源是32位、64位、ia64, 目前支持的选项有: x86│x86_64│ia64 # 安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-7-x86_64,如果重复,系统会提示导入失败。 [root@linux-node01 xinetd.d]# cobbler distro list #查看镜像列表 CentOS-7-x86_64 # 镜像存放目录,cobbler会将镜像中的所有安装文件拷贝到本地一份,放在/var/www/cobbler/ks_mirror下的CentOS-7.1-x86_64目录下。因此/var/www/cobbler目录必须具有足够容纳安装文件的空间。 [root@linux-node01 xinetd.d]# cd /var/www//cobbler/ks_mirror/ [root@linux-node01 ks_mirror]# ls CentOS-7-x86_64 config [root@linux-node01 ks_mirror]# ls CentOS-7-x86_64/ CentOS_BuildTag EFI EULA GPL images isolinux LiveOS Packages repodata RPM-GPG-KEY-CentOS-7 RPM-GPG-KEY-CentOS-Testing-7 TRANS.TBL

3.3 指定ks.cfg文件及调整内核参数


# Cobbler的ks.cfg文件存放位置 [root@linux-node01 ks_mirror]# cd /var/lib/cobbler/kickstarts/ [root@linux-node01 kickstarts]# ls #自带很多 default.ks esxi5-ks.cfg legacy.ks sample_autoyast.xml sample_esx4.ks sample_esxi5.ks sample.ks sample.seed esxi4-ks.cfg install_profiles pxerescue.ks sample_end.ks(默认使用的ks文件) sample_esxi4.ks sample_esxi6.ks sample_old.seed [root@linux-node01 kickstarts]# vi CentOS-7-x86_64.cfg #检测ks文件是否有问题 [root@linux-node01 kickstarts]# cobbler validateks task started: 2018-05-27_183403_validateks task started (id=Kickstart Validation, time=Sun May 27 18:34:03 2018) ---------------------------- osversion: rhel7 checking url: http://192.168.56.11/cblr/svc/op/ks/profile/CentOS-7-x86_64 running: /usr/bin/ksvalidator -v "rhel7" "http://192.168.56.11/cblr/svc/op/ks/profile/CentOS-7-x86_64" received on stdout: received on stderr: *** all kickstarts seem to be ok *** *** TASK COMPLETE *** # 在第一次导入系统镜像后,Cobbler会给镜像指定一个默认的kickstart自动安装文件在/var/lib/cobbler/kickstarts下的sample_end.ks。 [root@linux-node01 kickstarts]# cobbler list distros: CentOS-7-x86_64 profiles: CentOS-7-x86_64 systems: repos: images: mgmtclasses: packages: files: # 查看安装镜像文件信息 [root@linux-node01 kickstarts]# cobbler distro report --name=CentOS-7-x86_64 Name : CentOS-7-x86_64 Architecture : x86_64 TFTP Boot Files : {} Breed : redhat Comment : Fetchable Files : {} Initrd : /var/www/cobbler/ks_mirror/CentOS-7-x86_64/images/pxeboot/initrd.img Kernel : /var/www/cobbler/ks_mirror/CentOS-7-x86_64/images/pxeboot/vmlinuz Kernel Options : {} Kernel Options (Post Install) : {} Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/CentOS-7-x86_64'} Management Classes : [] OS Version : rhel7 Owners : ['admin'] Red Hat Management Key : # 查看所有的profile设置 [root@linux-node01 kickstarts]# cobbler distro report --name=CentOS-7-x86_64 Name : CentOS-7-x86_64 Architecture : x86_64 TFTP Boot Files : {} Breed : redhat Comment : Fetchable Files : {} Initrd : /var/www/cobbler/ks_mirror/CentOS-7-x86_64/images/pxeboot/initrd.img Kernel : /var/www/cobbler/ks_mirror/CentOS-7-x86_64/images/pxeboot/vmlinuz Kernel Options : {} Kernel Options (Post Install) : {} Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/CentOS-7-x86_64'} Management Classes : [] OS Version : rhel7 Owners : ['admin'] Red Hat Management Key : #编辑profile,修改关联的ks文件 [root@linux-node01 kickstarts]# cobbler profile edit --name=CentOS-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg # 修改安装系统的内核参数,在CentOS7系统有一个地方变了,就是网卡名变成eno16777736这种形式,但是为了运维标准化,我们需要将它变成我们常用的eth0,因此使用下面的参数。但要注意是CentOS7才需要下面的步骤,CentOS6不需要。 [root@linux-node01 kickstarts]# cobbler profile edit --name=CentOS-7-x86_64 --kopts='net.ifnames=0 biosdevname=0' [root@linux-node01 kickstarts]# cobbler profile report Name : CentOS-7-x86_64 TFTP Boot Files : {} Comment : DHCP Tag : default Distribution : CentOS-7-x86_64 Enable gPXE? : 0 Enable PXE Menu? : 1 Fetchable Files : {} Kernel Options : {'biosdevname': '0', 'net.ifnames': '0'} Kernel Options (Post Install) : {} Kickstart : /var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg Kickstart Metadata : {} Management Classes : [] Management Parameters : # 每次修改完都要同步一次 [root@linux-node1 ~]# cobbler sync

3.4 安装系统

可以很愉快的告诉你到这里就可以安装系统了!
新建一台虚拟机,不解释,开机就可以看到下面的图片了!

Markdown

有没有发现不美观的地方?

网址不是我的!改!


#修改Cobbler提示 [root@linux-node1 ~]# vim /etc/cobbler/pxe/pxedefault.template MENU TITLE Cobbler | http://wwww.zte.com.cn/ [root@linux-node1 ~]# cobbler sync # 修改配置都要同步

OK,现在好看多了。选择第二项就可以继续装机了。你可以让系统飞着,然后接着看下文!!

Markdown

4. ks.cfg文件简析

[root@linux-node01 kickstarts]# cat CentOS-7-x86_64.cfg 




#System timezone timezone Asia/Shanghai #Root password rootpw --iscrypted $default_password_crypted #Use text mode install text #Install OS installed of upgrade install #Use NFS installation Media url --url="$tree" #System bootloader configuration bootloader --location=mbr #Clear the Master Boot Record zerombr #Partition clearing information clearpart --all initlabel #Disk partitioning information part /boot --fstype xfs --size 102 part swap --size 1024 part / --fstype xfs --size 1 --grow firstboot --disable selinux --disabled firewall --disabled logging --level=info #System authorization information auth --useshadow --enablemd5 #Network information $SNIPPET('network_config') #network --bootproto=dhcp --device=em1 --onboot=on #reoot after installation reboot #Firewall configuration firewall --disabled #Selinux configuration selinux --disabled #Do not configure XWindows skipx #Package install information %pre SNIPPET(logkspre) S N I P P E T ( ′ l o g k s p r e ′ ) 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 iptraf ncurses-devel openssl-devel zlib-devel OpenIPMI-tools screen %end %post systemctl disable postfix.service %end

5. 定制化安装

可能从学习kickstart开始就有人想怎样能够指定某台服务器使用指定ks文件,kickstart实现这功能可能比较复杂,但是Cobbler就很简单了。

区分一台服务器的最简单的方法就是物理MAC地址。

物理服务器的MAC地址在服务器上的标签上写了。

虚拟机的MAC查看

Markdown

[root@linux-node01 kickstarts]#  cobbler system add --name=linux-node2.oldboyedu.com --mac=00:50:56:3A:F8:56 --profile=CentOS-7-x86_64 --ip-address=192.168.56.12 --subnet=255.255.255.0 --gateway=192.168.56.2 --interface=eth0 --static=1 /var/lib/cobbler/kickstarts/CentOS7-x86_64.cfg --name-servers="192.168.56.2" --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg




# --name 自定义,但不能重复 # 查看定义的列表 [root@linux-node1 ~]# cobbler system list oldboy [root@linux-node1 ~]# cobbler sync

再次开机安装就不再询问选择了,直接安装。

Markdown

6. Cobbler的Web管理界面的安装与配置

已经安装cobbler-web软件。

Markdown

访问网址:https://192.168.56.11/cobbler_web
默认用户名:cobbler
默认密码 :cobbler

/etc/cobbler/users.conf       # Web服务授权配置文件
/etc/cobbler/users.digest     # 用于web访问的用户名密码配置文件
[root@linux-node1 ~]# cat /etc/cobbler/users.digest
cobbler:Cobbler:a2d6bae81669d707b72c0bd9806e01f3




# 设置Cobbler web用户登陆密码 # 在Cobbler组添加cobbler用户,提示输入2遍密码确认 [root@linux-node1 ~]# htdigest /etc/cobbler/users.digest "Cobbler" cobbler Changing password for user cobbler in realm Cobbler New password: 123456 Re-type new password:123456 [root@linux-node1 ~]# cobbler sync [root@linux-node1 ~]#systemctl restart cobblerd [root@linux-node1 ~]#systemctl restart httpd

以后就需要用123456这个密码登录了。

接下来的操作就是点点鼠标了。

7.使用koan实现重新安装系统

在客户端安装koan(要配置好源)

[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@localhost ~]# yum install koan

查看cobbler上的配置文件

[root@localhost ~]# koan --server=192.168.56.11 --list=profiles
- looking for Cobbler at http://192.168.56.11:80/cobbler_api
Centos-7-x86_64

重新安装客户端系统

[root@localhost ~]# koan --replace-self --server=192.168.56.11 --profile=webserver1

重启系统后会自动重装系统

使用api自定义安装

api配置存放的位置:

[root@localhost ~]# cat /etc/httpd/conf.d/cobbler.conf
ProxyPass /cobbler_api http://127.0.0.1:25151/
ProxyPassReverse /cobbler_api http://127.0.0.1:25151/

写一个Python的小脚本来测试api:

[root@localhost scripts]# cat test_cobbler-api.py 




#!/usr/bin/python import xmlrpclib server=xmlrpclib.Server("http://192.168.56.11/cobbler_api") #print server.get_distors() print server.get_profiles() print server.get_systems() #print server.get_images() print server.get_repos()

查看执行结果:

[root@linux-node01 zxin10]# python test_cobbler-api.py 
[{'comment': '', 'kickstart': '/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg', 'name_servers_search': [], 'ks_meta': {}, 'kernel_options_post': {}, 'repos': [], 'redhat_management_key': '
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值