来自 电脑知识 2019-10-09 20:52 的文章
当前位置: 威尼斯国际官方网站 > 电脑知识 > 正文

下cobbler安装及布置

1.背景介绍

作为运维,在公司经常遇到一些机械性重复工作要做,例如:为新机器装系统,一台两台机器装系统,可以用光盘、U盘等介质安装,1小时也完成了,但是如果有成百台的服务器还要用光盘、U盘去安装,就显得有些力不从心了。PXE技术就能很好的解决这个问题,本文将会对PXE的工作原理有所介绍,而cobbler则是基于PXE技术的工作原理的二次封装,通过命令的方式简化了PXE配置过程。

2.PXE原理介绍

2.1原理与概念

事实上把PXE称作是一种引导方式而不是安装方式似乎更加准确,PXE(Pre-boot Execution Environment)是由Intel设计的协议,它可以使计算机通过网络启动,但是有一个前提条件是计算机的网卡必须具有引导功能,这个网卡中要有一个PXE客户端。当计算机POST自检成功以后,BIOS把网卡中ROM的PXE客户端调入内存执行,PXE客户端通过网络中的DHCP服务器获取一个IP地址,拿到IP地址以后PXE继续引导计算机与网络中的TFTP客户端建立连接,从而从TFTP服务器中获取开机引导文件之后请求并下载安装需要的文件。在这个过程中需要一台服务器来提供启动文件、安装文件、以及安装过程中的自动应答文件等。

2.2PXE工作步骤如下图:

图片 1

原理介绍

  • Client向PXE Server上的DHCP发送IP地址请求消息,DHCP检测Client是否合法(主要是检测Client的网卡MAC地址),如果合法则返回Client的IP地址,同时将启动文件pxelinux.0的位置信息一并传送给Client
  • Client向PXE Server上的TFTP发送获取pxelinux.0请求消息,TFTP接收到消息之后再向Client发送pxelinux.0大小信息,试探Client是否满意,当TFTP收到Client发回的同意大小信息之后,正式向Client发送pxelinux.0
  • Client执行接收到的pxelinux.0文件
  • Client向TFTP Server发送针对本机的配置信息文件(在TFTP服务的pxelinux.cfg目录下,这是系统菜单文件,格式和isolinux.cfg格式一样,功能也是类似),TFTP将配置文件发回Client,继而Client根据配置文件执行后续操作。
  • Client向TFTP发送Linux内核请求信息,TFTP接收到消息之后将内核文件发送给Client
  • Client向TFTP发送根文件请求信息,TFTP接收到消息之后返回Linux根文件系统
  • Client启动Linux内核
  • Client下载安装源文件,读取自动化安装脚本

3.Cobbler

鉴于pxe自动装系统网上一搜一大把,我就不详细操作举例了,今天主要讲一讲Cobbler。

3.1Cobbler介绍

Cobbler是一个Linux服务器快速网络安装的服务,由python开发,小巧轻便(15k行python代码),可以通过PXE的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS,TFTP、RSYNC以及yum仓库、构造系统ISO镜像。

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

3.2Cobbler工作流程

 图片 2

  • client裸机配置了从网络启动后,开机后会广播包请求DHCP服务器 (cobbler server)发送其分配好的一个IP
  • DHCP服务器(cobbler server)收到请求后发送responese,包括其ip地址
  • client裸机拿到ip后再向cobbler server发送请求OS引导文件的请求
  • cobbler server告诉裸机OS引导文件的名字和TFTP server的ip和 port
  • client裸机通过上面告知的TFTP server地址通信,下载引导文件
  • client裸机执行执行该引导文件,确定加载信息,选择要安装的os, 期间会再向cobbler server请求kickstart文件和os image
  • cobbler server发送请求的kickstart和os iamge
  • client裸机加载kickstart文件
  • client裸机接收os image,安装该os image

3.3Cobbler集成的服务

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

3.4配置目录

配置文件目录:
/etc/cobbler
/etc/cobbler/settings : cobbler 主配置文件
/etc/cobbler/iso/: iso模板配置文件
/etc/cobbler/pxe: pxe模板文件
/etc/cobbler/power: 电源配置文件
/etc/cobbler/user.conf: web服务授权配置文件
/etc/cobbler/users.digest: web访问的用户名密码配置文件
/etc/cobbler/dhcp.template : dhcp服务器的的配置末班
/etc/cobbler/dnsmasq.template : dns服务器的配置模板
/etc/cobbler/tftpd.template : tftp服务的配置模板
/etc/cobbler/modules.conf : 模块的配置文件
数据目录:
/var/lib/cobbler/config/: 用于存放distros,system,profiles 等信 息配置文件
/var/lib/cobbler/triggers/: 用于存放用户定义的cobbler命令
/var/lib/cobbler/kickstart/: 默认存放kickstart文件
/var/lib/cobbler/loaders/: 存放各种引导程序  镜像目录
/var/www/cobbler/ks_mirror/: 导入的发行版系统的所有数据
/var/www/cobbler/images/ : 导入发行版的kernel和initrd镜像用于 远程网络启动
/var/www/cobbler/repo_mirror/: yum 仓库存储目录
日志目录:
/var/log/cobbler/installing: 客户端安装日志
/var/log/cobbler/cobbler.log : cobbler日志

3.5命令介绍

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

3.6/etc/cobbler/settings中重要的参数设置

default_password_crypted: "$1$gEc7ilpP$pg5iSOj/mlxTxEslhRvyp/"
manage_dhcp:1
manage_tftpd:1
pxe_just_once:1
next_server:< tftp服务器的 IP 地址>
server:

4.Cobbler安装

4.1系统信息

 1 [root@localhost ~]#  cat /etc/redhat-release 
 2 CentOS Linux release 7.2.1511 (Core) 
 3 [root@localhost ~]#  uname -r
 4 3.10.0-327.el7.x86_64
 5 [root@localhost ~]#  getenforce 
 6 Disabled
 7 [root@localhost ~]#  systemctl status firewalld.service 
 8 ● firewalld.service - firewalld - dynamic firewall daemon
 9    Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
10    Active: inactive (dead)
11      Docs: man:firewalld(1)
12 [root@localhost ~]#  ifconfig eno16777736|awk -F "[ :]+" 'NR==2 {print $3}'
13 10.0.0.101
14 [root@localhost ~]#  hostname
15 localhost.localdomain
16 [root@localhost ~]#  

4.2配置yum源

[root@localhost ~]## rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-10.noarch.rpm

[root@localhost ~]## yum makecache

4.3开始安装Cobbler

4.3.1安装cobbler以及相关的软件

[root@localhost ~]# yum -y install httpd dhcp tftp python-ctypes cobbler  xinetd cobbler-web

4.3.2启动相关服务

[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
[root@localhost ~]# systemct1 enable cobblerd
[root@localhost ~]# systemctl start cobblerd

4.3.3通过cobbler check 核对当前设置是否有问题

 1 [root@localhost ~]# cobbler check
 2 The following are potential configuration items that you may want to fix:
 3 
 4 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.
 5 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.
 6 3 : change 'disable' to 'no' in /etc/xinetd.d/tftp
 7 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.
 8 5 : enable and start rsyncd.service with systemctl
 9 6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
10 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
11 8 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
12 
13 Restart cobblerd and then run 'cobbler sync' to apply changes.

按照提示一个一个的解决问题:

问题1:

[root@localhost ~]# sed -i 's/^server: 127.0.0.1/server: 10.0.0.101/' /etc/cobbler/settings  # 修改server的ip地址为本机ip

问题2:

[root@localhost ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 10.0.0.101/' /etc/cobbler/settings # TFTP Server 的IP地址

问题3:

 1 service tftp
 2 {
 3         socket_type             = dgram
 4         protocol                = udp
 5         wait                    = yes
 6         user                    = root
 7         server                  = /usr/sbin/in.tftpd
 8         server_args             = -s /var/lib/tftpboot
 9         disable                 = no  # 修改为no
10         per_source              = 11
11         cps                     = 100 2
12         flags                   = IPv4
13 }

问题4:

[root@localhost ~]# cobbler get-loaders  # 下载缺失的文件
task started: 2017-10-15_113824_get_loaders
task started (id=Download Bootloader Content, time=Sun Oct 15 11:38:24 2017)
downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***

问题5:

# 添加rsync到自启动并启动rsync
[root@localhost ~]# systemctl enable rsyncd 
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
[root@localhost ~]# systemctl start rsyncd 

 问题6:

跟debian 相关,可以忽略

问题7:

# 修改密码为123456 ,salt后面是常用的加盐方式加密
[root@localhost ~]# openssl passwd -1 -salt '123456' '123456' 
$1$123456$wOSEtcyiP2N/IfIl15W6Z0
[root@localhost ~]# vim /etc/cobbler/settings # 修改settings配置文件中下面位置,把新生成的密码加进去
default_password_crypted: "$1$123456$wOSEtcyiP2N/IfIl15W6Z0

再次执行cobbler check

[root@localhost ~]# 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 # debian相关
2 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them # fence设备相关,不需要

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

以上两个问题暂时可以忽略

4.3.4配置cobbler-DHCP

修改cobbler配置

[root@localhost ~]# vim /etc/cobbler/settings # 修改settings中参数,由cobbler控制dhcp
manage_dhcp: 1

修改dhcp.templates配置文件(仅列出修改部分)

[root@localhost ~]# vim /etc/cobbler/dhcp.template
subnet 10.0.0.0 netmask 255.255.255.0 {
     option routers             10.0.0.2;
     option domain-name-servers 10.0.0.2;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        10.0.0.100 10.0.0.250;

重启服务并同步配置,改完dhcp必须要sync同步配置

 1 [root@localhost ~]# systemctl restart cobblerd.service 
 2 [root@localhost ~]# cobbler sync
 3 task started: 2017-10-15_122732_sync
 4 task started (id=Sync, time=Sun Oct 15 12:27:32 2017)
 5 running pre-sync triggers
 6 cleaning trees
 7 removing: /var/lib/tftpboot/pxelinux.cfg/default
 8 removing: /var/lib/tftpboot/grub/efidefault
 9 removing: /var/lib/tftpboot/grub/grub-x86.efi
10 removing: /var/lib/tftpboot/grub/images
11 removing: /var/lib/tftpboot/grub/grub-x86_64.efi
12 removing: /var/lib/tftpboot/s390x/profile_list
13 copying bootloaders
14 trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
15 trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
16 copying distros to tftpboot
17 copying images
18 generating PXE configuration files
19 generating PXE menu structure
20 rendering DHCP files
21 generating /etc/dhcp/dhcpd.conf
22 rendering TFTPD files
23 generating /etc/xinetd.d/tftp
24 cleaning link caches
25 running post-sync triggers
26 running python triggers from /var/lib/cobbler/triggers/sync/post/*
27 running python trigger cobbler.modules.sync_post_restart_services
28 running: dhcpd -t -q
29 received on stdout: 
30 received on stderr: 
31 running: service dhcpd restart
32 received on stdout: 
33 received on stderr: Redirecting to /bin/systemctl restart  dhcpd.service
34 
35 running shell triggers from /var/lib/cobbler/triggers/sync/post/*
36 running python triggers from /var/lib/cobbler/triggers/change/*
37 running python trigger cobbler.modules.scm_track
38 running shell triggers from /var/lib/cobbler/triggers/change/*
39 *** TASK COMPLETE ***

检查dhcp

[root@localhost ~]# netstat -lnup|grep dhcp
udp        0      0 0.0.0.0:39776           0.0.0.0:*                           53381/dhcpd         
udp        0      0 0.0.0.0:67              0.0.0.0:*                           53381/dhcpd         
udp6       0      0 :::46146                :::*                                53381/dhcpd  

4.3.5导入CentOs-7的镜像

[root@localhost ~]# mount /dev/cdrom  /mnt # 挂载光盘镜像
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# cobbler import --path=/mnt --name=Centos-7.2 --arch=x86_64 # cobbler导入镜像
task started: 2017-10-15_145401_import
task started (id=Media import, time=Sun Oct 15 14:54:01 2017)
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/Centos-7.2-x86_64: # 导入镜像的位置
creating new distro: Centos-7.2-x86_64
trying symlink: /var/www/cobbler/ks_mirror/Centos-7.2-x86_64 -> /var/www/cobbler/links/Centos-7.2-x86_64
creating new profile: Centos-7.2-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/Centos-7.2-x86_64 for Centos-7.2-x86_64
processing repo at : /var/www/cobbler/ks_mirror/Centos-7.2-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/Centos-7.2-x86_64
looking for /var/www/cobbler/ks_mirror/Centos-7.2-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/Centos-7.2-x86_64/repodata
*** TASK COMPLETE ***
  • # --path 镜像路径
  • # --name 为安装源定义一个名字
  • # --arch 指定安装源是32位、64位、ia64, 目前支持的选项有: x86│x86_64│ia64
  • # 安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-7.1-x86_64,如果重复,系统会提示导入失败

导入完镜像以后,那么就使查看下cobbler

[root@localhost ks_mirror]# cobbler list                       
distros:
   Centos-7.2-x86_64

profiles:
   Centos-7.2-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:

4.3.6导入kickstarts配置文件

[root@localhost kickstarts]# ls
default.ks    esxi5-ks.cfg      legacy.ks     sample_autoyast.xml  sample_esx4.ks   sample_esxi5.ks  sample_old.seed
esxi4-ks.cfg  install_profiles  pxerescue.ks  sample_end.ks        sample_esxi4.ks  sample.ks        sample.seed
[root@localhost kickstarts]# pwd
/var/lib/cobbler/kickstarts
[root@localhost kickstarts]# rz
rz waiting to receive.
 zmodem trl+C ȡ

  100%       1 KB    1 KB/s 00:00:01       0 Errors.

查看导入信息及默认ks文件

[root@localhost kickstarts]# cobbler report
distros:
==========
Name                           : Centos-7.2-x86_64
Architecture                   : x86_64
TFTP Boot Files                : {}
Breed                          : redhat
Comment                        : 
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/ks_mirror/Centos-7.2-x86_64/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/Centos-7.2-x86_64/images/pxeboot/vmlinuz
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/Centos-7.2-x86_64'}
Management Classes             : []
OS Version                     : rhel7
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {}


profiles:
==========
Name                           : Centos-7.2-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : Centos-7.2-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  # 默认ks文件,这里需要修改为我们自己配置好的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


systems:
==========

repos:
==========

images:
==========

mgmtclasses:
==========

packages:
==========

files:
==========

我ks文件(只是简单配置的,具体可以按自己业务来)

 1 #platform=x86, AMD64, or Intel EM64T
 2 #version=DEVEL
 3 # Install OS instead of upgrade
 4 install
 5 # Keyboard layouts
 6 keyboard 'us'
 7 # Root password
 8 rootpw --iscrypted $1$m1pE0DG6$vALBphGGynqvUzfJaWZ6U1
 9 # Use network installation
10 url --url="$tree"
11 # System language
12 lang en_US
13 # Firewall configuration
14 firewall --disabled
15 # System authorization information
16 auth  --useshadow  --passalgo=sha512
17 # Use graphical install
18 graphical
19 firstboot --disable
20 # SELinux configuration
21 selinux --disabled
22 
23 # Network information
24 network  --bootproto=dhcp --device=eth0
25 network  --bootproto=dhcp --device=eth1
26 # Reboot after installation
27 reboot
28 # System timezone
29 timezone Asia/Shanghai
30 # System bootloader configuration
31 bootloader --location=mbr
32 # Clear the Master Boot Record
33 zerombr
34 # Partition clearing information
35 clearpart --all --initlabel
36 # Disk partitioning information
37 part /boot --asprimary --fstype="ext4" --size=200
38 part swap --fstype="swap" --size=1024
39 part / --fstype="ext4" --grow --size=1
40 %packages
41 @base
42 @core
43 @compat-libraries
44 @debugging
45 @development
46 @gnome-desktop
47 @X Window System
48 %end

检查ks命令

# 写完 ks 文件之后,先通过 validateks 测试一下有没有语法错误
# cobbler validateks
# 通过下面这个命令查看 ks 文件,发现一些逻辑上的问题
# cobbler system getks --name=test

 

编辑修改指定ks文件为我们刚刚上传的ks

 1 [root@localhost kickstarts]# cobbler profile list
 2    Centos-7.2-x86_64
 3 [root@localhost kickstarts]# cobbler profile edit --name Centos-7.2-x86_64 --kickstart=/var/lib/cobbler/kickstarts/Centos7.2-x86_64.cfg  # 编辑profile,修改ks文件为我们刚刚上传的Centos7.2-x86_64.cfg
 4 [root@localhost kickstarts]# cobbler profile edit --name Centos-7.2-x86_64 --kopts='net.ifnames=0 biosdevname=0' 
   # 修改安装系统的内核参数,在CentOS7系统有一个地方变了,就是网卡名变成eno16777736这种形式,但是为了运维标准化,我们需要将它变成我们常用的eth0,因此使用上面的参数。但要注意是CentOS7才需要上面的步骤,CentOS6不需要。
 5 [root@localhost kickstarts]# cobbler profile report
 6 Name                           : Centos-7.2-x86_64
 7 TFTP Boot Files                : {}
 8 Comment                        : 
 9 DHCP Tag                       : default
10 Distribution                   : Centos-7.2-x86_64
11 Enable gPXE?                   : 0
12 Enable PXE Menu?               : 1
13 Fetchable Files                : {}
14 Kernel Options                 : {'biosdevname': '0', 'net.ifnames': '0'}
15 Kernel Options (Post Install)  : {}
16 Kickstart                      : /var/lib/cobbler/kickstarts/Centos7.2-x86_64.cfg  # ks文件已经修改为我们上传的ks文件
17 Kickstart Metadata             : {}
18 Management Classes             : []
19 Management Parameters          : <<inherit>>
20 Name Servers                   : []
21 Name Servers Search Path       : []
22 Owners                         : ['admin']
23 Parent Profile                 : 
24 Internal proxy                 : 
25 Red Hat Management Key         : <<inherit>>
26 Red Hat Management Server      : <<inherit>>
27 Repos                          : []
28 Server Override                : <<inherit>>
29 Template Files                 : {}
30 Virt Auto Boot                 : 1
31 Virt Bridge                    : xenbr0
32 Virt CPUs                      : 1
33 Virt Disk Driver Type          : raw
34 Virt File Size(GB)             : 5
35 Virt Path                      : 
36 Virt RAM (MB)                  : 512
37 Virt Type                      : kvm

4.3.7同步cobbler

 1 [root@localhost kickstarts]# cobbler sync
 2 task started: 2017-10-15_154709_sync
 3 task started (id=Sync, time=Sun Oct 15 15:47:09 2017)
 4 running pre-sync triggers
 5 cleaning trees
 6 removing: /var/www/cobbler/images/Centos-7.2-x86_64
 7 removing: /var/lib/tftpboot/pxelinux.cfg/default
 8 removing: /var/lib/tftpboot/grub/efidefault
 9 removing: /var/lib/tftpboot/grub/grub-x86.efi
10 removing: /var/lib/tftpboot/grub/images
11 removing: /var/lib/tftpboot/grub/grub-x86_64.efi
12 removing: /var/lib/tftpboot/images/Centos-7.2-x86_64
13 removing: /var/lib/tftpboot/s390x/profile_list
14 copying bootloaders
15 trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
16 trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
17 copying distros to tftpboot
18 copying files for distro: Centos-7.2-x86_64
19 trying hardlink /var/www/cobbler/ks_mirror/Centos-7.2-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/Centos-7.2-x86_64/vmlinuz
20 trying hardlink /var/www/cobbler/ks_mirror/Centos-7.2-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/Centos-7.2-x86_64/initrd.img
21 copying images
22 generating PXE configuration files
23 generating PXE menu structure
24 copying files for distro: Centos-7.2-x86_64
25 trying hardlink /var/www/cobbler/ks_mirror/Centos-7.2-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/Centos-7.2-x86_64/vmlinuz
26 trying hardlink /var/www/cobbler/ks_mirror/Centos-7.2-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/Centos-7.2-x86_64/initrd.img
27 Writing template files for Centos-7.2-x86_64
28 rendering DHCP files
29 generating /etc/dhcp/dhcpd.conf
30 rendering TFTPD files
31 generating /etc/xinetd.d/tftp
32 processing boot_files for distro: Centos-7.2-x86_64
33 cleaning link caches
34 running post-sync triggers
35 running python triggers from /var/lib/cobbler/triggers/sync/post/*
36 running python trigger cobbler.modules.sync_post_restart_services
37 running: dhcpd -t -q
38 received on stdout: 
39 received on stderr: 
40 running: service dhcpd restart
41 received on stdout: 
42 received on stderr: Redirecting to /bin/systemctl restart  dhcpd.service
43 
44 running shell triggers from /var/lib/cobbler/triggers/sync/post/*
45 running python triggers from /var/lib/cobbler/triggers/change/*
46 running python trigger cobbler.modules.scm_track
47 running shell triggers from /var/lib/cobbler/triggers/change/*
48 *** TASK COMPLETE ***

5.新建一个虚拟机测试

为避免发生未知问题,先把服务端所有服务重启

[root@localhost cobbler]#systemctl restart xinetd.service
[root@localhost cobbler]#systemctl restart cobblerd.service
[root@localhost cobbler]#systemctl restart httpd.service

新建虚拟机从pxe启动,如果出现下面图形,则说明已经成功了

图片 3

上图中网址也可以定制为我们自己的

[root@localhost cobbler]# vim /etc/cobbler/pxe/pxedefault.template
MENU TITLE Cobbler | I'm here # 修改这里为你想修改的内容
[root@localhost cobbler]# cobbler sync # 同步之后就可以看到效果了

6.通过MAC地址定制化安装

我们可以根据不同的MAC地址来给安装 不同的操作系统,配置不同的静态iP,设置不同的主机名等等,虚拟机查看MAC地址步骤如图:

图片 4

配置定制化安装(需要验证,后续验证后添加验证结果)

[root@localhost cobbler]# cobbler system add    
--name=linux-web01 
--mac=00:0C:29:3B:03:9B 
--profile=Centos-7.2-x86_64 
--ip-address=10.0.0.200 
--subnet=255.255.255.0 
--gateway=10.0.0.2 
--interface=eth0 
--static=1 
--hostname=linux-web01 
--name-servers="10.0.0.2" 
--kickstart=/var/lib/cobbler/kickstarts/Centos7.2-x86_64.cfg

system add  #  添加定制系统

name  # 定制系统名称

mac # mac地址

profile #指定profile

ip-address # 指定IP地址

subnet # 指定子网掩码

gateway # 指定网关

interface # 指定网卡,eth0上面配置已经修改,centos7默认网卡名称不是eth0

static # 1表示启用静态IP

hostname # 定义hostname

name-server # dns服务器

kickstart # 指定ks文件

配置成功后我们可以查看到刚才定制的系统

[root@localhost cobbler]# cobbler system list
linux-web01

接下来我们创建一个虚拟机,mac地址为00:0C:29:3B:03:9B,启动后你就会发现自动进入安装系统了,等安装完以后,所有的配置都和我们当初设置的一样。

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

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

[root@localhost ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-10.noarch.rpm
[root@localhost ~]# yum install koan

查看cobbler上的配置文件

1 [root@localhost ~]# koan --server=10.0.0.101 --list=profiles
2 - looking for Cobbler at http://10.0.0.101:80/cobbler_api
3 Centos-7.2-x86_64

重新安装客户端系统

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

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

 

cobbler-web相关配置,后续文章再更。。。

参考文章:

本文由威尼斯国际官方网站发布于电脑知识,转载请注明出处:下cobbler安装及布置

关键词: