【就业班作业】【第十二周】2、实现cobbler+pxe自动化装机

一、cobbler工作原理

1、裸机(无系统设备)配置了从网络启动后,通过DHCP广播包向请求DHCP服务器(cobbler server集成)获得IP地址、next server、dns等信息;
  (1)DHCP服务器(cobbler server)收到请求后发送response,包括其IP地址、TFTP地址、PXE程序名;
  (2)裸机拿到IP后再向cobbler server的TFTP服务器发送请求OS引导文件的请求;
2、client裸机通过上面告知的TFTP server地址通信,下载引导文件;
3、client裸机执行执行该引导文件,确定加载信息,选择要安装的系统版本,确认后再向cobbler server请求kickstart文件和os安装文件;
4、cobbler server发送请求的kickstart和os安装文件;
5、client裸机加载kickstart文件
6、client裸机接收os系统文件后,开始安装系统。

二、安装环境准备

1、cobbler 基于EPEL源(http://mirrors.aliyun.com/repo/epel-7.repo);

2、cobbler集成了PXE、HTTP、kickstart等服务(自动会安装好服务);

3、安装cobbler服务过程如下:

本次实验是以最小安装的CentOS7环境开局
(1)、配置EPEL的YUM源过程(下载阿里云提供的源)

[root@CentOS7 ~]# cd /etc/yum.repos.d/
[root@CentOS7 yum.repos.d]# ll
total 24
-rw-r--r--. 1 root root 1664 Apr  1  2015 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Apr  1  2015 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Apr  1  2015 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  290 Apr  1  2015 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 1331 Apr  1  2015 CentOS-Sources.repo
-rw-r--r--. 1 root root 1002 Apr  1  2015 CentOS-Vault.repo
[root@CentOS7 yum.repos.d]# wget http://mirrors.aliyun.com/repo/epel-7.repo
-bash: wget: command not found
[root@CentOS7 yum.repos.d]# yum -y install wget
Loaded plugins: fastestmirror
base                                                                                                                                                   | 3.6 kB  00:00:00     
extras                                                                                                                                                 | 2.9 kB  00:00:00     
updates                                                                                                                                                | 2.9 kB  00:00:00     
(1/4): base/7/x86_64/group_gz                                                                                                                          | 153 kB  00:00:00     
(2/4): extras/7/x86_64/primary_db                                                                                                                      | 206 kB  00:00:00     
(3/4): updates/7/x86_64/primary_db                                                                                                                     | 4.5 MB  00:00:06     
(4/4): base/7/x86_64/primary_db                                                                                                                        | 6.1 MB  00:00:13     
Determining fastest mirrors
 * base: mirrors.cn99.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.cn99.com
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.14-18.el7_6.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================
 Package                               Arch                                    Version                                            Repository                             Size
==============================================================================================================================================================================
Installing:
 wget                                  x86_64                                  1.14-18.el7_6.1                                    base                                  547 k

Transaction Summary
==============================================================================================================================================================================
Install  1 Package

Total download size: 547 k
Installed size: 2.0 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/wget-1.14-18.el7_6.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY      ]  0.0 B/s | 424 kB  --:--:-- ETA 
Public key for wget-1.14-18.el7_6.1.x86_64.rpm is not installed
wget-1.14-18.el7_6.1.x86_64.rpm                                                                                                                        | 547 kB  00:00:00     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-1.1503.el7.centos.2.8.x86_64 (@anaconda)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : wget-1.14-18.el7_6.1.x86_64                                                                                                                                1/1 
  Verifying  : wget-1.14-18.el7_6.1.x86_64                                                                                                                                1/1 

Installed:
  wget.x86_64 0:1.14-18.el7_6.1                                                                                                                                               

Complete!
[root@CentOS7 yum.repos.d]# wget http://mirrors.aliyun.com/repo/epel-7.repo
--2020-10-29 21:50:43--  http://mirrors.aliyun.com/repo/epel-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 61.162.48.181, 27.221.92.147, 27.221.120.241, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|61.162.48.181|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 664 [application/octet-stream]
Saving to: ‘epel-7.repo’

100%[====================================================================================================================================>] 664         --.-K/s   in 0s      

2020-10-29 21:50:43 (38.9 MB/s) - ‘epel-7.repo’ saved [664/664]

[root@CentOS7 yum.repos.d]# ls
CentOS-Base.repo  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-Sources.repo  CentOS-Vault.repo  epel-7.repo
[root@CentOS7 yum.repos.d]# cat epel-7.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
 
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
 
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
[root@CentOS7 yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
epel                                                                                                                                                   | 4.7 kB  00:00:00     
(1/3): epel/x86_64/group_gz                                                                                                                            |  95 kB  00:00:08     
(2/3): epel/x86_64/updateinfo                                                                                                                          | 1.0 MB  00:00:09     
(3/3): epel/x86_64/primary_db                                                                                                                          | 6.9 MB  00:00:02     
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.cn99.com
repo id                                                              repo name                                                                                          status
base/7/x86_64                                                        CentOS-7 - Base                                                                                    10,070
epel/x86_64                                                          Extra Packages for Enterprise Linux 7 - x86_64                                                     13,455
extras/7/x86_64                                                      CentOS-7 - Extras                                                                                     413
updates/7/x86_64                                                     CentOS-7 - Updates                                                                                  1,134
repolist: 25,072
[root@CentOS7 yum.repos.d]# 

 (2)、下载安装cobbler服务

[root@CentOS7 /]# yum -y install cobbler
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.cn99.com
Resolving Dependencies
--> Running transaction check
-------------------------------------
-------------------------------------
  Verifying  : rpm-build-libs-4.11.1-25.el7.x86_64                                                                                                                      45/47 
  Verifying  : rpm-4.11.1-25.el7.x86_64                                                                                                                                 46/47 
  Verifying  : rpm-python-4.11.1-25.el7.x86_64                                                                                                                          47/47 

Installed:
  cobbler.x86_64 0:2.8.5-0.3.el7                                                                                                                                              

Dependency Installed:
  PyYAML.x86_64 0:3.10-11.el7            apr.x86_64 0:1.4.8-5.el7                 apr-util.x86_64 0:1.5.2-6.el7          createrepo.noarch 0:0.9.9-28.el7                   
  deltarpm.x86_64 0:3.6-3.el7            genisoimage.x86_64 0:1.1.11-25.el7       httpd.x86_64 0:2.4.6-93.el7.centos     httpd-tools.x86_64 0:2.4.6-93.el7.centos           
  jbigkit-libs.x86_64 0:2.0-11.el7       libjpeg-turbo.x86_64 0:1.2.90-8.el7      libtiff.x86_64 0:4.0.3-32.el7          libusal.x86_64 0:1.1.11-25.el7                     
  libwebp.x86_64 0:0.3.0-7.el7           libxml2-python.x86_64 0:2.9.1-6.el7.4    libyaml.x86_64 0:0.1.4-11.el7_0        mailcap.noarch 0:2.1.41-2.el7                      
  mod_wsgi.x86_64 0:3.4-18.el7           mtools.x86_64 0:4.0.18-5.el7             python-chardet.noarch 0:2.2.1-3.el7    python-cheetah.x86_64 0:2.4.4-5.el7.centos         
  python-deltarpm.x86_64 0:3.6-3.el7     python-kitchen.noarch 0:1.1.1-5.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-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           
  rsync.x86_64 0:3.1.2-10.el7            syslinux.x86_64 0:4.05-15.el7            tftp-server.x86_64 0:5.2-22.el7        yum-utils.noarch 0:1.1.31-54.el7_8                 

Dependency Updated:
  libxml2.x86_64 0:2.9.1-6.el7.4    python-urlgrabber.noarch 0:3.10-10.el7 rpm.x86_64 0:4.11.3-43.el7 rpm-build-libs.x86_64 0:4.11.3-43.el7 rpm-libs.x86_64 0:4.11.3-43.el7
  rpm-python.x86_64 0:4.11.3-43.el7 yum.noarch 0:3.4.3-167.el7.centos     

Complete!
[root@CentOS7 /]# 
[root@CentOS7 /]# 
[root@CentOS7 /]# systemctl status cobblerd
cobblerd.service - Cobbler Helper Daemon
   Loaded: loaded (/usr/lib/systemd/system/cobblerd.service; disabled)
   Active: inactive (dead)

[root@CentOS7 /]# systemctl start  cobblerd
[root@CentOS7 /]# systemctl status cobblerd
cobblerd.service - Cobbler Helper Daemon
   Loaded: loaded (/usr/lib/systemd/system/cobblerd.service; disabled)
   Active: active (running) since Thu 2020-10-29 21:56:06 CST; 3s ago
  Process: 8930 ExecStartPost=/usr/bin/touch /usr/share/cobbler/web/cobbler.wsgi (code=exited, status=1/FAILURE)
 Main PID: 8929 (cobblerd)
   CGroup: /system.slice/cobblerd.service
           └─8929 /usr/bin/python2 -s /usr/bin/cobblerd -F

Oct 29 21:56:06 CentOS7 systemd[1]: Starting Cobbler Helper Daemon...
Oct 29 21:56:06 CentOS7 touch[8930]: /usr/bin/touch: cannot touch ‘/usr/share/cobbler/web/cobbler.wsgi’: No such file or directory
Oct 29 21:56:06 CentOS7 systemd[1]: Started Cobbler Helper Daemon.
[root@CentOS7 /]# 
[root@CentOS7 /]# cobbler check
httpd does not appear to be running and proxying cobbler, or SELinux is in the way. Original traceback:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/cobbler/cli.py", line 251, in check_setup
    s.ping()
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1224, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1578, in __request
    verbose=self.__verbose
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1264, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1292, in single_request
    self.send_content(h, request_body)
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1439, in send_content
    connection.endheaders(request_body)
  File "/usr/lib64/python2.7/httplib.py", line 969, in endheaders
    self._send_output(message_body)
  File "/usr/lib64/python2.7/httplib.py", line 829, in _send_output
    self.send(msg)
  File "/usr/lib64/python2.7/httplib.py", line 791, in send
    self.connect()
  File "/usr/lib64/python2.7/httplib.py", line 772, in connect
    self.timeout, self.source_address)
  File "/usr/lib64/python2.7/socket.py", line 571, in create_connection
    raise err
error: [Errno 111] Connection refused
[root@CentOS7 /]# 
[root@CentOS7 /]# 
[root@CentOS7 /]# systemctl status httpd
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
   Active: inactive (dead)
     Docs: man:httpd(8)
           man:apachectl(8)

[root@CentOS7 /]# sestatus
SELinux status:                 disabled
[root@CentOS7 /]# 
[root@CentOS7 /]# systemctl status firewalld
firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled)
   Active: inactive (dead)

[root@CentOS7 /]# systemctl start  httpd
[root@CentOS7 /]# systemctl enable  httpd
[root@CentOS7 /]# 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@CentOS7 /]# 

出现报错:httpd does not appear to be running and proxying cobbler, or SELinux is in the way. Original traceback:

  解决办法:默认已关闭selinux和firewall,没有启用httpd服务,启用httpd服务即可

(3)、根据cobbler check得出的问题逐一解决

修改:/etc/cobbler/setting中的相关参数。(要特别注意冒号后空格,否则启动cobbler服务时报错)

1、修改server 192.168.0.11
2、修改next-server 192.168.0.11
3、修改default_password_crypted
通过openssl passwd -1 -salt 12345678生成新密码
4、其他几个主要参数修改:
manage_dhcp: 1
manage_tftpd: 1
pxe_just_once: 1

sed -ri '/^$/d' /etc/cobbler/settings   //将空白行删除(可选操作)
sed -ri '/^#/d' /etc/cobbler/settings   //将以#号开头的删除(可选操作)

最终效果:
[root@CentOS7 /]# cat /etc/cobbler/settings
---
allow_duplicate_hostnames: 0
allow_duplicate_ips: 0
allow_duplicate_macs: 0
allow_dynamic_settings: 0
anamon_enabled: 0
authn_pam_service: "login"
auth_token_expiration: 3600
build_reporting_enabled: 0
build_reporting_sender: ""
build_reporting_email: [ 'root@localhost' ]
build_reporting_smtp_server: "localhost"
build_reporting_subject: ""
build_reporting_ignorelist: [ "" ]
cheetah_import_whitelist:
 - "random"
 - "re"
 - "time"
createrepo_flags: "-c cache -s sha"
default_kickstart: /var/lib/cobbler/kickstarts/default.ks
default_name_servers: []
default_ownership:
 - "admin"
default_password_crypted: "$1$12345678$1FBsaeP7xzRBjDmbDRefx1"
default_template_type: "cheetah"
default_virt_bridge: xenbr0
default_virt_file_size: 5
default_virt_ram: 512
default_virt_type: xenpv
enable_gpxe: 0
enable_menu: 1
func_auto_setup: 0
func_master: overlord.example.org
http_port: 80
kernel_options:
 ksdevice: bootif
 lang: ' '
 text: ~
kernel_options_s390x:
 RUNKS: 1
 ramdisk_size: 40000
 root: /dev/ram0
 ro: ~
 ip: off
 vnc: ~
ldap_server: "ldap.example.com"
ldap_base_dn: "DC=example,DC=com"
ldap_port: 389
ldap_tls: 1
ldap_anonymous_bind: 1
ldap_search_bind_dn: ''
ldap_search_passwd: ''
ldap_search_prefix: 'uid='
ldap_tls_cacertfile: ''
ldap_tls_keyfile: ''
ldap_tls_certfile: ''
mgmt_classes: []
mgmt_parameters:
 from_cobbler: 1
puppet_auto_setup: 0
sign_puppet_certs_automatically: 0
puppetca_path: "/usr/bin/puppet"
remove_old_puppet_certs_automatically: 0
manage_dhcp: 1
manage_dns: 0
bind_chroot_path: ""
bind_master: 127.0.0.1
manage_genders: 0
bind_manage_ipmi: 0
manage_tftpd: 1
manage_rsync: 0
manage_forward_zones: []
manage_reverse_zones: []
next_server: 192.168.0.11
power_management_default_type: 'ipmitool'
power_template_dir: "/etc/cobbler/power"
pxe_just_once: 1
pxe_template_dir: "/etc/cobbler/pxe"
consoles: "/var/consoles"
redhat_management_type: "off"
redhat_management_server: "xmlrpc.rhn.redhat.com"
redhat_management_key: ""
redhat_management_permissive: 0
register_new_installs: 0
reposync_flags: "-l -n -d"
restart_dns: 1
restart_dhcp: 1
run_install_triggers: 1
scm_track_enabled: 0
scm_track_mode: "git"
server: 192.168.0.11 
client_use_localhost: 0
client_use_https: 0
snippetsdir: /var/lib/cobbler/snippets
template_remote_kickstarts: 0
virt_auto_boot: 1
webdir: /var/www/cobbler
xmlrpc_port: 25151
yum_post_install_mirror: 1
yum_distro_priority: 1
yumdownloader_flags: "--resolve"
serializer_pretty_json: 0
replicate_rsync_options: "-avzH"
replicate_repo_rsync_options: "-avzH"
always_write_dhcp_entries: 0
proxy_url_ext: ""
proxy_url_int: ""
[root@CentOS7 /]# systemctl restart cobblerd
[root@CentOS7 /]# systemctl restart cobblerd 
[root@CentOS7 /]# 
[root@CentOS7 /]# cobbler check
The following are potential configuration items that you may want to fix:

1 : ISC DHCP server (dhcp/dhcpd) is not installed
2 : change 'disable' to 'no' in /etc/xinetd.d/tftp
3 : 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.
4 : enable and start rsyncd.service with systemctl
5 : debmirror package is not installed, it will be required to manage debian deployments and repositories
6 : ksvalidator was not found, install pykickstart
7 : 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.

修改DHCP服务相关参数:

[root@CentOS7 /]# cat /etc/cobbler/dhcp.template
# ******************************************************************
# Cobbler managed dhcpd.conf file
#
# generated from cobbler dhcp.conf template ($date)
# 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.0.0 netmask 255.255.255.0 {
     option routers             192.168.0.11;
     option domain-name-servers 192.168.0.11;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.0.251 192.168.0.254;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
     class "pxeclients" {
          match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
          if option pxe-system-type = 00:02 {
                  filename "ia64/elilo.efi";
          } else if option pxe-system-type = 00:06 {
                  filename "grub/grub-x86.efi";
          } else if option pxe-system-type = 00:07 {
                  filename "grub/grub-x86_64.efi";
          } else if option pxe-system-type = 00:09 {
                  filename "grub/grub-x86_64.efi";
          } else {
                  filename "pxelinux.0";
          }
     }

}

#for dhcp_tag in $dhcp_tags.keys():
    ## group could be subnet if your dhcp tags line up with your subnets
    ## or really any valid dhcpd.conf construct ... if you only use the
    ## default dhcp tag in cobbler, the group block can be deleted for a
    ## flat configuration
# group for Cobbler DHCP tag: $dhcp_tag
group {
        #for mac in $dhcp_tags[$dhcp_tag].keys():
            #set iface = $dhcp_tags[$dhcp_tag][$mac]
    host $iface.name {
        #if $iface.interface_type == "infiniband":
        option dhcp-client-identifier = $mac;
        #else
        hardware ethernet $mac;
        #end if
        #if $iface.ip_address:
        fixed-address $iface.ip_address;
        #end if
        #if $iface.hostname:
        option host-name "$iface.hostname";
        #end if
        #if $iface.netmask:
        option subnet-mask $iface.netmask;
        #end if
        #if $iface.gateway:
        option routers $iface.gateway;
        #end if
        #if $iface.enable_gpxe:
        if exists user-class and option user-class = "gPXE" {
            filename "http://$cobbler_server/cblr/svc/op/gpxe/system/$iface.owner";
        } else if exists user-class and option user-class = "iPXE" {
            filename "http://$cobbler_server/cblr/svc/op/gpxe/system/$iface.owner";
        } else {
            filename "undionly.kpxe";
        }
        #else
        filename "$iface.filename";
        #end if
        ## Cobbler defaults to $next_server, but some users
        ## may like to use $iface.system.server for proxied setups
        next-server $next_server;
        ## next-server $iface.next_server;
    }
        #end for
}
#end for

[root@CentOS7 /]# 

原因:因cobbler启动DHCP服务时会使用其模板文件中的地址池配置,我们需要将其改自己实际需求的信息。

安装DHCP服务(cobbler并没有集成DHCP安装包)

[root@CentOS7 /]# 
[root@CentOS7 /]# systemctl status dhcpd
Unit dhcpd.service could not be found.
[root@CentOS7 /]# 
[root@CentOS7 /]# 
[root@CentOS7 /]# systemctl start  dhcpd
Failed to start dhcpd.service: Unit not found.
[root@CentOS7 /]# 
[root@CentOS7 /]# 
[root@CentOS7 /]# yum -y install dhcp
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.cn99.com
Resolving Dependencies
--> Running transaction check
---> Package dhcp.x86_64 12:4.2.5-79.el7.centos will be installed
--> Processing Dependency: dhcp-libs(x86-64) = 12:4.2.5-79.el7.centos for package: 12:dhcp-4.2.5-79.el7.centos.x86_64
---------------------
---------------------
Installed:
  dhcp.x86_64 12:4.2.5-79.el7.centos                                                                                                                                                           

Dependency Installed:
  bind-export-libs.x86_64 32:9.11.4-16.P2.el7_8.6                                                                                                                                              

Dependency Updated:
  dhclient.x86_64 12:4.2.5-79.el7.centos                        dhcp-common.x86_64 12:4.2.5-79.el7.centos                        dhcp-libs.x86_64 12:4.2.5-79.el7.centos                       

Complete!
[root@CentOS7 /]# 
[root@CentOS7 /]# cobbler check
The following are potential configuration items that you may want to fix:

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 : 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.
[root@CentOS7 /]# 

修改/etc/xinetd.d/tftp:

[root@CentOS7 /]# cat /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
#    protocol.  The tftp protocol is often used to boot diskless \
#    workstations, download configuration files to network-aware printers, \
#    and to start the installation process for some operating systems.
service tftp
{
    socket_type        = dgram
    protocol        = udp
    wait            = yes
    user            = root
    server            = /usr/sbin/in.tftpd
    server_args        = -s /var/lib/tftpboot
    disable            = no
    per_source        = 11
    cps            = 100 2
    flags            = IPv4
}
[root@CentOS7 /]# systemctl restart tftp.socket
[root@CentOS7 /]# 

安装pykickstart、fence-agents,(debmirror可选项可不改)

yum -y install  pykickstart  fence-agents

启用并开机启用rsyncd.service 服务

[root@CentOS7 /]# systemctl enable  rsyncd.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
[root@CentOS7 /]# systemctl start  rsyncd.service 
[root@CentOS7 /]# 
[root@CentOS7 /]# 
[root@CentOS7 /]# systemctl status rsyncd.service 
● rsyncd.service - fast remote file copy program daemon
   Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-10-29 22:48:31 CST; 2s ago
 Main PID: 10875 (rsync)
   CGroup: /system.slice/rsyncd.service
           └─10875 /usr/bin/rsync --daemon --no-detach

Oct 29 22:48:31 CentOS7 systemd[1]: Started fast remote file copy program daemon.
Oct 29 22:48:31 CentOS7 rsyncd[10875]: rsyncd version 3.1.2 starting, listening on port 873
[root@CentOS7 /]# 

执行cobbler get-loaders,下载网络启动的准备文件

[root@CentOS7 loaders]# cobbler get-loaders
task started: 2020-10-30_000620_get_loaders
task started (id=Download Bootloader Content, time=Fri Oct 30 00:06:20 2020)
path /var/lib/cobbler/loaders/README already exists, not overwriting existing content, use --force if you wish to update
downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
Exception occured: <class 'urlgrabber.grabber.URLGrabError'>
Exception value: [Errno 14] curl#7 - "Failed connect to cobbler.github.io:443; Connection refused"
Exception Info:
  File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 82, in run
    rc = self._run(self)
   File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 176, in runner
    return self.remote.api.dlcontent(self.options.get("force",False), self.logger)
   File "/usr/lib/python2.7/site-packages/cobbler/api.py", line 735, in dlcontent
    return grabber.run(force)
   File "/usr/lib/python2.7/site-packages/cobbler/action_dlcontent.py", line 73, in run
    urlgrabber.grabber.urlgrab(src, filename=dst, proxies=proxies)
   File "/usr/lib/python2.7/site-packages/urlgrabber/grabber.py", line 773, in urlgrab
    return default_grabber.urlgrab(url, filename, **kwargs)
   File "/usr/lib/python2.7/site-packages/urlgrabber/grabber.py", line 1220, in urlgrab
    return _run_callback(opts.failfunc, opts)
   File "/usr/lib/python2.7/site-packages/urlgrabber/grabber.py", line 1071, in _run_callback
    return cb(obj)
   File "/usr/lib/python2.7/site-packages/urlgrabber/grabber.py", line 1065, in _do_raise
    raise obj.exception

!!! TASK FAILED !!!
[root@CentOS7 loaders]# 

[root@CentOS7 loaders]# vi /etc/hosts
[root@CentOS7 loaders]# 
[root@CentOS7 loaders]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
185.199.111.153 cobbler.github.io
[root@CentOS7 loaders]# 
[root@CentOS7 loaders]# cobbler get-loaders
task started: 2020-10-30_000531_get_loaders
task started (id=Download Bootloader Content, time=Fri Oct 30 00:05:31 2020)
downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
Exception occured: <class 'urlgrabber.grabber.URLGrabError'>
Exception value: [Errno 14] curl#35 - "Peer reports incompatible or unsupported protocol version."
Exception Info:
  File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 82, in run
    rc = self._run(self)
   File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 176, in runner
    return self.remote.api.dlcontent(self.options.get("force",False), self.logger)
   File "/usr/lib/python2.7/site-packages/cobbler/api.py", line 735, in dlcontent
    return grabber.run(force)
   File "/usr/lib/python2.7/site-packages/cobbler/action_dlcontent.py", line 73, in run
    urlgrabber.grabber.urlgrab(src, filename=dst, proxies=proxies)
   File "/usr/lib/python2.7/site-packages/urlgrabber/grabber.py", line 773, in urlgrab
    return default_grabber.urlgrab(url, filename, **kwargs)
   File "/usr/lib/python2.7/site-packages/urlgrabber/grabber.py", line 1220, in urlgrab
    return _run_callback(opts.failfunc, opts)
   File "/usr/lib/python2.7/site-packages/urlgrabber/grabber.py", line 1071, in _run_callback
    return cb(obj)
   File "/usr/lib/python2.7/site-packages/urlgrabber/grabber.py", line 1065, in _do_raise
    raise obj.exception

!!! TASK FAILED !!!
[root@CentOS7 loaders]# yum update -y nss curl libcurl
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.cn99.com
Resolving Dependencies
--> Running transaction check
---> Package curl.x86_64 0:7.29.0-19.el7 will be updated
---> Package curl.x86_64 0:7.29.0-57.el7_8.1 will be an update
---> Package libcurl.x86_64 0:7.29.0-19.el7 will be updated
---> Package libcurl.x86_64 0:7.29.0-57.el7_8.1 will be an update
-----------------------------
-----------------------------
Dependency Installed:
  nss-pem.x86_64 0:1.0.3-7.el7                                                                                                                                                                 

Updated:
  curl.x86_64 0:7.29.0-57.el7_8.1                                libcurl.x86_64 0:7.29.0-57.el7_8.1                                nss.x86_64 0:3.44.0-7.el7_7                               

Dependency Updated:
  libssh2.x86_64 0:1.8.0-3.el7       nspr.x86_64 0:4.21.0-1.el7        nss-softokn.x86_64 0:3.44.0-8.el7_7  nss-softokn-freebl.x86_64 0:3.44.0-8.el7_7  nss-sysinit.x86_64 0:3.44.0-7.el7_7 
  nss-tools.x86_64 0:3.44.0-7.el7_7  nss-util.x86_64 0:3.44.0-4.el7_7 

Complete!
[root@CentOS7 loaders]# 
[root@CentOS7 loaders]# cobbler check
The following are potential configuration items that you may want to fix:

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 : 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.
[root@CentOS7 loaders]# systemctl restart cobblerd
[root@CentOS7 loaders]# 
[root@CentOS7 loaders]# cobbler get-loaders
task started: 2020-10-30_001151_get_loaders
task started (id=Download Bootloader Content, time=Fri Oct 30 00:11:51 2020)
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 ***
[root@CentOS7 loaders]# 
[root@CentOS7 loaders]# ll ./
total 1128
-rw-r--r-- 1 root root    631 Oct 24 21:43 COPYING.elilo
-rw-r--r-- 1 root root  18007 Oct 24 21:43 COPYING.syslinux
-rw-r--r-- 1 root root    626 Oct 24 21:43 COPYING.yaboot
-rw-r--r-- 1 root root 356493 Oct 24 21:43 elilo-ia64.efi
-rw-r--r-- 1 root root 243679 Oct 24 21:43 grub-x86_64.efi
-rw-r--r-- 1 root root 237224 Oct 24 21:43 grub-x86.efi
-rw-r--r-- 1 root root  54964 Oct 24 21:43 menu.c32
-rw-r--r-- 1 root root  16794 Oct 24 21:43 pxelinux.0
-rw-r--r-- 1 root root   1054 Oct 24 21:43 README
-rw-r--r-- 1 root root 198236 Oct 24 21:43 yaboot
[root@CentOS7 loaders]# 

 执行cobbler get-loaders时,报了几个错误及解决办法:

1、Exception value: [Errno 14] curl#7 - "Failed connect to cobbler.github.io:443; Connection refused"

  ping cobbler.github.io时,是127.0.0.1回包,通过互联网找到其IP为185.199.111.153(http://tool.chinaz.com/);

  修改/etc/hosts,增加:185.199.111.153   cobbler.github.io 解决

 2、Exception value: [Errno 14] curl#35 - "Peer reports incompatible or unsupported protocol version."

  在网上查到是curl的版本问题,执行更新yum update -y nss curl libcurl。

3、完成以后操作后,重新启动cobbler服务,执行cobbler get-loaders即能下载相关文件了。

重启cobbler服务,执行cobbler sync操作后,所有安装工作基本结束

[root@CentOS7 loaders]# 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.
[root@CentOS7 loaders]# ss -ntul
Netid State      Recv-Q Send-Q                                                             Local Address:Port                                                               Peer Address:Port 
tcp   LISTEN     0      5                                                                              *:873                                                                           *:*     
tcp   LISTEN     0      128                                                                            *:22                                                                            *:*     
tcp   LISTEN     0      100                                                                    127.0.0.1:25                                                                            *:*     
tcp   LISTEN     0      5                                                                      127.0.0.1:25151                                                                         *:*     
tcp   LISTEN     0      5                                                                             :::873                                                                          :::*     
tcp   LISTEN     0      128                                                                           :::80                                                                           :::*     
tcp   LISTEN     0      128                                                                           :::22                                                                           :::*     
tcp   LISTEN     0      100                                                                          ::1:25                                                                           :::*      
[root@CentOS7 loaders]# systemctl restart cobblerd
[root@CentOS7 loaders]# cobbler sync
task started: 2020-10-30_002543_sync
task started (id=Sync, time=Fri Oct 30 00:25:43 2020)
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.manage_genders
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***
[root@CentOS7 loaders]# ll /var/lib/tftpboot/
total 300
drwxr-xr-x 3 root root     17 Oct 30 00:25 boot
drwxr-xr-x 2 root root      6 Oct 15  2019 etc
drwxr-xr-x 2 root root     77 Oct 30 00:25 grub
drwxr-xr-x 2 root root      6 Oct 15  2019 images
drwxr-xr-x 2 root root      6 Oct 15  2019 images2
-rw-r--r-- 2 root root  26140 Oct 31  2018 memdisk
-rw-r--r-- 2 root root  54964 Oct 24 21:43 menu.c32
drwxr-xr-x 2 root root      6 Oct 15  2019 ppc
-rw-r--r-- 2 root root  16794 Oct 24 21:43 pxelinux.0
drwxr-xr-x 2 root root     20 Oct 30 00:25 pxelinux.cfg
drwxr-xr-x 2 root root     25 Oct 30 00:25 s390x
-rw-r--r-- 2 root root 198236 Oct 24 21:43 yaboot
[root@CentOS7 loaders]# systemctl restart cobblerd
[root@CentOS7 loaders]# systemctl status dhcpd
● dhcpd.service - DHCPv4 Server Daemon
   Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2020-10-30 00:25:45 CST; 1min 0s ago
     Docs: man:dhcpd(8)
           man:dhcpd.conf(5)
 Main PID: 2716 (dhcpd)
   Status: "Dispatching packets..."
   CGroup: /system.slice/dhcpd.service
           └─2716 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid

Oct 30 00:25:45 CentOS7 dhcpd[2716]: Copyright 2004-2013 Internet Systems Consortium.
Oct 30 00:25:45 CentOS7 dhcpd[2716]: All rights reserved.
Oct 30 00:25:45 CentOS7 dhcpd[2716]: For info, please visit https://www.isc.org/software/dhcp/
Oct 30 00:25:45 CentOS7 dhcpd[2716]: Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file
Oct 30 00:25:45 CentOS7 dhcpd[2716]: Wrote 0 class decls to leases file.
Oct 30 00:25:45 CentOS7 dhcpd[2716]: Wrote 0 leases to leases file.
Oct 30 00:25:45 CentOS7 dhcpd[2716]: Listening on LPF/eth0/00:0c:29:d5:18:6b/192.168.0.0/24
Oct 30 00:25:45 CentOS7 dhcpd[2716]: Sending on   LPF/eth0/00:0c:29:d5:18:6b/192.168.0.0/24
Oct 30 00:25:45 CentOS7 dhcpd[2716]: Sending on   Socket/fallback/fallback-net
Oct 30 00:25:45 CentOS7 systemd[1]: Started DHCPv4 Server Daemon.
[root@CentOS7 loaders]# ss -ntul
Netid State      Recv-Q Send-Q                                                             Local Address:Port                                                               Peer Address:Port 
tcp   UNCONN     0      0                                                                              *:67                                                                            *:*     
tcp   LISTEN     0      5                                                                              *:873                                                                           *:*     
tcp   LISTEN     0      128                                                                            *:22                                                                            *:*     
tcp   LISTEN     0      100                                                                    127.0.0.1:25                                                                            *:*     
tcp   LISTEN     0      5                                                                      127.0.0.1:25151                                                                         *:*     
tcp   LISTEN     0      5                                                                             :::873                                                                          :::*     
tcp   LISTEN     0      128                                                                           :::80                                                                           :::*     
tcp   LISTEN     0      128                                                                           :::22                                                                           :::*     
tcp   LISTEN     0      100                                                                          ::1:25                                                                           :::*     
[root@CentOS7 loaders]# 

三、系统发行版本准备

1、导入本地光盘文件,制作distro(发行版本)

[root@CentOS7 /]# cobbler import --name=CentOS7.5-x86_64 --path=/mnt --arch=x86_64 
task started: 2020-10-30_003552_import
task started (id=Media import, time=Fri Oct 30 00:35:52 2020)
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.5-x86_64:
creating new distro: CentOS7.5-x86_64
trying symlink: /var/www/cobbler/ks_mirror/CentOS7.5-x86_64 -> /var/www/cobbler/links/CentOS7.5-x86_64
creating new profile: CentOS7.5-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.5-x86_64 for CentOS7.5-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS7.5-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS7.5-x86_64
looking for /var/www/cobbler/ks_mirror/CentOS7.5-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS7.5-x86_64/repodata
*** TASK COMPLETE ***
[root@CentOS7 /]# 

 2、查看distro、profile,自定义自己的profile

[root@CentOS7 cobbler]# cobbler distro list
   CentOS7.5-x86_64
[root@CentOS7 cobbler]#
[root@CentOS7 cobbler]# cobbler profile list
   CentOS7.5-x86_64
[root@CentOS7 cobbler]#
[root@CentOS7 kickstarts]# cobbler profile add --name=CentOS7.5-x86_64-mini --kickstart=/var/lib/cobbler/kickstarts/CentOS7.5-mini-ks.cfg
[root@CentOS7 kickstarts]# cobbler profile list
   CentOS7.5-x86_64
   CentOS7.5-x86_64-mini
[root@CentOS7 kickstarts]#

四、安装测试测试效果

1、菜单选择页面

2、安装过程

(结束)

 

posted @ 2020-10-29 15:28  sankeya  阅读(199)  评论(0编辑  收藏  举报