码迷,mamicode.com
首页 > 其他好文 > 详细

cobbler

时间:2020-12-01 11:57:15      阅读:4      评论:0      收藏:0      [点我收藏+]

标签:password   json   x86_64   关闭防火墙   mask   ase   address   empty   dhcpd   

cobbler介绍

cobbler服务端部署

环境描述

  • 关闭防火墙/SElinux
主机 ip地址 服务 角色
vm2(centos7) 192.168.225.128 cobbler,httpd,tftp 服务端

下载软件

配置yum源

[root@vm2 yum.repos.d]# curl -o /etc/yum.repos.d/CentOS7-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@vm2 yum.repos.d]# sed -i ‘s/#releasever/7/g‘ CentOS7-Base-163.repo 
[root@vm2 yum.repos.d]# sed -i ‘s/^enabled=.*/enabled=1/g‘ /etc/yum.repos.d/CentOS7-Base-163.repo
[root@vm2 yum.repos.d]# yum install -y epel-release

安装cobbler及相关软件

[root@vm2 ~]# yum -y install httpd dhcp tftp python-ctypes cobbler  xinetd cobbler-web pykickstart
[root@vm2 ~]# systemctl enable --now httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@vm2 ~]# systemctl enable --now cobblerd
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.
[root@vm2 ~]# ss -antl 
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      5      127.0.0.1:25151                    *:*                  
LISTEN     0      128          *:22                       *:*                  
LISTEN     0      100    127.0.0.1:25                       *:*                  
LISTEN     0      128       [::]:443                   [::]:*                  
LISTEN     0      128       [::]:80                    [::]:*                  
LISTEN     0      128       [::]:22                    [::]:*                  
LISTEN     0      100      [::1]:25                    [::]:*             

修改cobbler主配置并开启TFTP

  • 修改cobbler服务器地址,tftp服务地址,default_password_crypted
  • openssl工具生成加密密码
[root@vm2 ~]# openssl passwd -1 -salt "$RANDOM" ‘123456‘
$1$17000$QAQkn/hhoyjqvYHR8JRDQ1
[root@vm2 ~]# sed -i ‘s/^server: 127.0.0.1/server: 192.168.225.128/‘ /etc/cobbler/settings
[root@vm2 ~]# sed -i ‘s/^next_server: 127.0.0.1/next_server: 192.168.225.128/‘ /etc/cobbler/settings
[root@vm2 ~]# vim /etc/cobbler/settings
default_password_crypted: "$1$17000$QAQkn/hhoyjqvYHR8JRDQ1"
  • 修改/etc/xinetd.d/tftp配置文件开启TFTP服务
[root@localhost ~]# sed -i ‘/disable/s/yes/no/g‘ /etc/xinetd.d/tftp

下载启动的相关文件

[root@vm2 ~]# cobbler get-loaders
task started: 2020-11-24_163751_get_loaders
task started (id=Download Bootloader Content, time=Tue Nov 24 16:37: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@vm2 ~]# ls /var/lib/cobbler/loaders/
COPYING.elilo     COPYING.yaboot  grub-x86_64.efi  menu.c32    README
COPYING.syslinux  elilo-ia64.efi  grub-x86.efi     pxelinux.0  yaboot

重启cobbler并核对当前配置

[root@vm2 ~]# systemctl restart cobblerd
[root@vm2 ~]# ss -antl 
State      Recv-Q Send-Q          Local Address:Port                         Peer Address:Port              
LISTEN     0      5                   127.0.0.1:25151                                   *:*                  
LISTEN     0      128                         *:22                                      *:*                  
LISTEN     0      100                 127.0.0.1:25                                      *:*                  
LISTEN     0      128                      [::]:443                                  [::]:*                  
LISTEN     0      128                      [::]:80                                   [::]:*                  
LISTEN     0      128                      [::]:22                                   [::]:*                  
LISTEN     0      100                     [::1]:25                                   [::]:*                  
[root@vm2 ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:
    https://github.com/cobbler/cobbler/wiki/Selinux
2 : enable and start rsyncd.service with systemctl
3 : debmirror package is not installed, it will be required to manage debian deployments and repositories
4 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them

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

##1.selinux需要关闭
##2.需要开启rsync服务
##忽略3,4错误(debian系统)

开启rsync服务

[root@vm2 ~]# systemctl enable --now rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
[root@vm2 ~]# ss -antl 
State      Recv-Q Send-Q          Local Address:Port                         Peer Address:Port              
LISTEN     0      128                         *:22                                      *:*                  
LISTEN     0      100                 127.0.0.1:25                                      *:*                  
LISTEN     0      5                   127.0.0.1:25151                                   *:*                  
LISTEN     0      5                           *:873                                     *:*                  
LISTEN     0      128                      [::]:80                                   [::]:*                  
LISTEN     0      128                      [::]:22                                   [::]:*                  
LISTEN     0      100                     [::1]:25                                   [::]:*                  
LISTEN     0      128                      [::]:443                                  [::]:*                  
LISTEN     0      5                        [::]:873                                  [::]:*         

配置cobbler dhcp

开启manage_dhcp

[root@vm2 ~]# vim /etc/cobbler/settings
manage_dhcp: 1  ## 表示通过cobbler生成dhcp.conf配置文件

配置dhcp模板文件

[root@vm2 ~]# vim /etc/cobbler/dhcp.template
..................................................
subnet 192.168.225.0 netmask 255.255.255.0 {
     option routers             192.168.225.128;
     option domain-name-servers 192.168.225.2;       ##此处为系统安装好后指定的dns地址
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.225.100 192.168.225.120;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
...................................................
[root@vm2 ~]# systemctl restart cobblerd

cobbler sync同步

[root@vm2 ~]# tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── boot
├── etc
├── grub
├── images
├── images2
├── ppc
├── pxelinux.cfg
└── s390x

8 directories, 0 files
[root@vm2 ~]# cobbler sync
task started: 2020-11-24_174733_sync
task started (id=Sync, time=Tue Nov 24 17:47:33 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@vm2 ~]# tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── boot
│   └── grub
│       └── menu.lst
├── etc
├── grub
│   ├── efidefault
│   ├── grub-x86_64.efi
│   ├── grub-x86.efi
│   └── images -> ../images
├── images
├── images2
├── memdisk
├── menu.c32
├── ppc
├── pxelinux.0
├── pxelinux.cfg
│   └── default
├── s390x
│   └── profile_list
└── yaboot

10 directories, 10 files

##检查dhcp是否正常
[root@vm2 ~]# netstat -anulp| grep dhcp
udp        0      0 0.0.0.0:67              0.0.0.0:*                           1312/dhcpd          

导入centos8镜像

将ISO镜像挂载生成安装文件

[root@vm2 opt]# ls
CentOS-8.2.2004-x86_64-minimal.iso
[root@vm2 opt]# mkdir centos8
[root@vm2 opt]# ls
centos8  CentOS-8.2.2004-x86_64-minimal.iso
[root@vm2 opt]# mount -o loop CentOS-8.2.2004-x86_64-minimal.iso /opt/centos8/
mount: /dev/loop0 is write-protected, mounting read-only
[root@vm2 opt]# cd centos8/
[root@vm2 centos8]# ls
BaseOS  EFI  images  isolinux  media.repo  Minimal  TRANS.TBL

导入镜像

## --path指定镜像路径
## --name定义安装源名字
## --arch指定安装源平台
[root@vm2 centos7]# cobbler import --path=/opt/centos7 --name=centos-7-x86_64 --arch=x86_64
task started: 2020-11-24_214054_import
task started (id=Media import, time=Tue Nov 24 21:40:54 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/centos-7-x86_64:
creating new distro: centos-7-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos-7-x86_64 -> /var/www/cobbler/links/centos-7-x86_64
creating new profile: centos-7-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-x86_64 for centos-7-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos-7-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/centos-7-x86_64
looking for /var/www/cobbler/ks_mirror/centos-7-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos-7-x86_64/repodata
*** TASK COMPLETE ***

查看cobbler镜像列表

[root@vm2 centos7]# cobbler list
distros:
   centos-7-x86_64
   centos-8-x86_64

profiles:
   centos-7-x86_64
   centos-8-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:

[root@vm2 centos7]# tree /var/lib/cobbler/config/
/var/lib/cobbler/config/
├── distros.d
│   ├── centos-7-x86_64.json
│   └── centos-8-x86_64.json
├── files.d
├── images.d
├── mgmtclasses.d
├── packages.d
├── profiles.d
│   ├── centos-7-x86_64.json
│   └── centos-8-x86_64.json
├── repos.d
└── systems.d

创建kickstarts自动安装脚本

[root@vm2 ~]# vim /var/lib/cobbler/kickstarts/centos7-x86_64.ks 
auth --enableshadow --passalgo=md5
bootloader --location=mbr
clearpart --all --initlabel
part /boot --asprimary --fstype="ext4" --size=500
part swap --fstype="swap" --size=4096
part / --fstype="ext4" --grow --size=15000
text
firewall --disabled
firstboot --disable
keyboard us
lang en_US
url --url=http://192.168.225.128/cobbler/ks_mirror/centos-7-x86_64
$yum_repo_stanza
reboot

rootpw --iscrypted $default_password_crypted   ##这一般使用cobbler服务端anaconda-ks.cfg文件的加密密码

selinux --disabled
skipx
timezone Asia/Shanghai --isUtc --nontp
install
zerombr

%packages
@^minimal
@core
kexec-tools

%end

%addon com_redhat_kdump --enable --reserve-mb=‘auto‘

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end

[root@vm2 kickstarts]# cobbler validateks    ##检查ks文件语法
task started: 2020-11-25_004910_validateks
task started (id=Kickstart Validation, time=Wed Nov 25 00:49:10 2020)
----------------------------
osversion: rhel8
checking url: http://192.168.225.128/cblr/svc/op/ks/profile/centos-8-x86_64
running: /usr/bin/ksvalidator -v "rhel8" "http://192.168.225.128/cblr/svc/op/ks/profile/centos-8-x86_64"
received on stdout: The version rhel8 is not supported by pykickstart      ##rhel8系统不支持kickstart软件

received on stderr: 
----------------------------
osversion: rhel7
checking url: http://192.168.225.128/cblr/svc/op/ks/profile/centos-7-x86_64
running: /usr/bin/ksvalidator -v "rhel7" "http://192.168.225.128/cblr/svc/op/ks/profile/centos-7-x86_64"
received on stdout: 
received on stderr: 
*** potential errors detected in kickstarts ***
!!! TASK FAILED !!!

修改profile

  • 将我们新建的ks文件设为默认的kickstarts安装文件
  • 修改网卡名为eth0
[root@vm2 ~]# cobbler profile edit --name centos-7-x86_64 --kopts=‘net.ifnames=0 biosdevname=0‘
[root@vm2 ~]# cobbler profile edit --name centos-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7-x86_64.ks 

检查当前系统cobbler配置文件信息

[root@vm2 ~]# 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/centos7-x86_64.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

同步cobbler

[root@vm2 ~]# cobbler sync
task started: 2020-11-24_220412_sync
task started (id=Sync, time=Tue Nov 24 22:04:12 2020)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/centos-8-x86_64
removing: /var/www/cobbler/images/centos-7-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/centos-8-x86_64
removing: /var/lib/tftpboot/images/centos-7-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: centos-8-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos-8-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos-8-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos-8-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos-8-x86_64/initrd.img
copying files for distro: centos-7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos-7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos-7-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: centos-8-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos-8-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos-8-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos-8-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos-8-x86_64/initrd.img
Writing template files for centos-8-x86_64
copying files for distro: centos-7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos-7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos-7-x86_64/initrd.img
Writing template files for centos-7-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: centos-8-x86_64
processing boot_files for distro: centos-7-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 ***

重启服务

[root@vm2 ~]# systemctl restart xinetd
[root@vm2 ~]# systemctl restart cobblerd
[root@vm2 ~]# systemctl restart httpd
[root@vm2 ~]# ss -antl 
State      Recv-Q Send-Q  Local Address:Port                 Peer Address:Port              
LISTEN     0      5                   *:873                             *:*                  
LISTEN     0      128                 *:22                              *:*                  
LISTEN     0      100         127.0.0.1:25                              *:*                  
LISTEN     0      5           127.0.0.1:25151                           *:*                  
LISTEN     0      5                [::]:873                          [::]:*                  
LISTEN     0      128              [::]:80                           [::]:*                  
LISTEN     0      128              [::]:22                           [::]:*                  
LISTEN     0      100             [::1]:25                           [::]:*                  
LISTEN     0      128              [::]:443                          [::]:*    

创建虚拟机开机自动装机

  • 选择cobbler提供的安装源回车自安装

技术图片

cobbler—web定制装机

技术图片

技术图片

技术图片

技术图片

  • 创建新的虚拟机(其mac地址为上图指定的mac)
  • 自动安装系统(无须选择系统版本)

技术图片

cobbler

标签:password   json   x86_64   关闭防火墙   mask   ase   address   empty   dhcpd   

原文地址:https://www.cnblogs.com/fyjpeng/p/14040480.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!