基于CentOS7操作cobbler批量装机-(centos7和redhat8)

1. cobbler简介

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

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

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

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

Cobbler官网

cobbler集成的服务

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

cobbler配置文件详解
cobbler配置文件目录在/etc/cobbler

配置文件作用
/etc/cobbler/settingscobbler 主配置文件
/etc/cobbler/iso/iso模板配置文件
/etc/cobbler/pxepxe模板配置文件
/etc/cobbler/power电源配置文件
/etc/cobbler/user.confweb服务授权配置文件
/etc/cobbler/users.digestweb访问的用户名密码配置文件
/etc/cobbler/dhcp.templatedhcp服务器的的配置模板
/etc/cobbler/dnsmasq.templatedns服务器的配置模板
/etc/cobbler/tftpd.templatetftp服务的配置模板
/etc/cobbler/modules.conf模块的配置文件

cobbler数据目录

目录作用
/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仓库存储目录

cobbler日志文件

日志文件路径说明
/var/log/cobbler/installing客户端安装日志
/var/log/cobbler/cobbler.logcobbler日志

cobbler命令详解

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

需求就是,使用cobbler 自动安装 centos7版本和centos8版本

2. cobbler服务端部署

需要最小化安装系统(也就是恢复快照到什么都没有的状态)
关闭防火跟SElinux

//配置yum源
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@localhost yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo


// 安装epel源
[root@localhost ~]# yum -y install epel-release
安装过程略。。。。

//安装cobbler以及相关的软件
[root@localhost ~]# yum -y install httpd dhcp tftp python-ctypes cobbler  xinetd cobbler-web pykickstart  syslinux-devel
安装过程略....

// 当前只有22 号端口
[root@localhost ~]# 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      128            [::]:22                         [::]:*
LISTEN     0      100           [::1]:25                         [::]:*
[root@localhost ~]#


//启动服务并设置开机自启
[root@localhost ~]# systemctl enable --now httpd
[root@localhost ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-08-12 21:53:07 CST; 41s ago
...省略N
[root@localhost ~]# systemctl enable --now cobblerd
[root@localhost ~]# systemctl status cobblerd
● cobblerd.service - Cobbler Helper Daemon
   Loaded: loaded (/usr/lib/systemd/system/cobblerd.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-08-12 21:53:19 CST; 50s ago
...省略N

[root@localhost ~]# 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        [::]:80                     [::]:*
LISTEN      0      128        [::]:22                     [::]:*
LISTEN      0      100       [::1]:25                     [::]:*
LISTEN      0      128        [::]:443                    [::]:*
[root@localhost ~]#


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

// 打印一下是否已进行修改
[root@localhost ~]# sed -n '/^server: 192.168.229.155/p' /etc/cobbler/settings
server: 192.168.229.155


//设置tftp的ip地址为本机ip
[root@localhost ~]#  sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.229.155/' /etc/cobbler/settings

[root@localhost ~]#  sed -n '/^next_server: 192.168.229.155/p' /etc/cobbler/settings
next_server: 192.168.229.155


//开启tftp
[root@localhost ~]# sed -i '/disable/s/yes/no/g' /etc/xinetd.d/tftp



//启动rsync并设置开机自启
[root@localhost ~]# systemctl status rsyncd
● rsyncd.service - fast remote file copy program daemon
   Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2022-08-13 07:56:08 CST; 2s ago


//生成加密的密码
[root@localhost ~]# openssl passwd -1 -salt "$RANDOM" 'agan9639!'
$1$31797$Nw1Srpd9vPMpL8VPCo28e1  //这是密码加密后的形式

//将新生成的加密密码加入到配置文件
[root@localhost ~]# vim /etc/cobbler/settings
....    //此处为省略内容
default_password_crypted: "$1$31797$Nw1Srpd9vPMpL8VPCo28e1"
.....   //此处为省略内容

//重启cobbler
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# 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 check 核对当前设置是否有问题
[root@localhost ~]# 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.  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.
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.
//以上两个是关于debian系统的错误,请忽略







//配置cobbler dhcp
//修改cobbler配置文件,让cobbler控制dhcp
[root@localhost ~]# sed -i '/^manage_dhcp/s/0/1/g' /etc/cobbler/settings
[root@localhost ~]# sed -n '/^manage_dhcp/p' /etc/cobbler/settings
manage_dhcp: 1



//配置dhcp
[root@localhost ~]# vim /etc/cobbler/dhcp.template
....    //此处为省略内容
subnet 192.168.229.0 netmask 255.255.255.0 {
     option routers             192.168.229.2;
     option domain-name-servers 114.114.114.114;   //此处为系统安装好后指定的dns地址
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.229.10 192.168.229.250;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
....    //此处为省略内容

//重启服务并同步配置,改完dhcp必须要sync同步配置
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# cobbler sync
task started: 2018-08-21_160420_sync
task started (id=Sync, time=Tue Aug 21 16:04:20 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@localhost ~]# ss -an|grep 67
u_str  ESTAB      0      0         * 16741                 * 16742
u_str  ESTAB      0      0         * 21968                 * 21967
u_str  ESTAB      0      0         * 21967                 * 21968
u_str  ESTAB      0      0         * 16742                 * 16741
u_dgr  UNCONN     0      0         * 16740                 * 333
udp    UNCONN     0      0         *:67                    *:*


# 空间只有16G 不够,加到200G
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G   12M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  2.0G   16G  12% /
/dev/sda1               1014M  153M  862M  16% /boot
tmpfs                    378M     0  378M   0% /run/user/0

[root@localhost ~]# init 0  // 关机

添加硬盘

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

添加完成后开机

[root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   20G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   19G  0 part
  ├─centos-root 253:0    0   17G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0  200G  0 disk  // 刚才添加的200G空间
sr0              11:0    1  4.4G  0 rom
把200G 扩充到根里

初始化为物理卷
[root@localhost ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created.
[root@localhost ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/sda2  centos lvm2 a--  <19.00g      0
  /dev/sdb          lvm2 ---  200.00g 200.00g  // 看到这个初始化成功
  
 将物理卷加到卷组 
[root@localhost ~]# vgextend centos /dev/sdb
  Volume group "centos" successfully extended
[root@localhost ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  centos   2   2   0 wz--n- 218.99g <200.00g
  
  
[root@localhost ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- <17.00g
  swap centos -wi-ao----   2.00g
  
  逻辑卷扩展,逻辑卷的扩展取决于卷组中的容量,逻辑卷扩展的容量不能超过卷组的容量
  将198G 扩展到根
[root@localhost ~]# lvextend -L +198G /dev/centos/root
  Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <215.00 GiB (55039 extents).
  Logical volume centos/root successfully resized.
[root@localhost ~]# lvs
  LV   VG     Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- <215.00g
  swap centos -wi-ao----    2.00g
  
  
[root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   20G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   19G  0 part
  ├─centos-root 253:0    0  215G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0  200G  0 disk
└─centos-root   253:0    0  215G  0 lvm  /
sr0              11:0    1  4.4G  0 rom

[root@localhost ~]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  898M     0  898M   0% /dev
tmpfs                   tmpfs     910M     0  910M   0% /dev/shm
tmpfs                   tmpfs     910M  9.6M  901M   2% /run
tmpfs                   tmpfs     910M     0  910M   0% /sys/fs/cgroup
/dev/mapper/centos-root xfs        17G  1.9G   16G  11% /
/dev/sda1               xfs      1014M  153M  862M  16% /boot
tmpfs                   tmpfs     182M     0  182M   0% /run/user/0

xfs扩容
[root@localhost ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=1113856 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=4455424, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 4455424 to 56359936

[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 898M     0  898M   0% /dev
tmpfs                    910M     0  910M   0% /dev/shm
tmpfs                    910M  9.6M  901M   2% /run
tmpfs                    910M     0  910M   0% /sys/fs/cgroup
/dev/mapper/centos-root  215G  1.9G  214G   1% /        # 在查看
/dev/sda1               1014M  153M  862M  16% /boot
tmpfs                    182M     0  182M   0% /run/user/0

挂载
[root@localhost ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 898M     0  898M   0% /dev
tmpfs                    910M     0  910M   0% /dev/shm
tmpfs                    910M  9.6M  901M   2% /run
tmpfs                    910M     0  910M   0% /sys/fs/cgroup
/dev/mapper/centos-root  215G  1.9G  214G   1% /
/dev/sda1               1014M  153M  862M  16% /boot
tmpfs                    182M     0  182M   0% /run/user/0
/dev/sr0                 4.5G  4.5G     0 100% /mnt  // 已经挂在上

在 导入7 镜像之前扩展空间
//导入redhat7镜像  、 装centos8就导入8镜像,

[root@localhost ~]# cobbler import --path=/mnt --name=centos7 --arch=x86_64
task started: 2022-08-13_084034_import
task started (id=Media import, time=Sat Aug 13 08:40:34 2022)
Found a candidate signature: breed=suse, version=opensuse15.0
Found a candidate signature: breed=suse, version=opensuse15.1
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-x86_64:
creating new distro: centos7-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos7-x86_64 -> /var/www/cobbler/links/centos7-x86_64
creating new profile: centos7-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-x86_64 for centos7-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos7-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/centos7-x86_64
looking for /var/www/cobbler/ks_mirror/centos7-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos7-x86_64/repodata
*** TASK COMPLETE ***  // 看到这个说明导入成功

//说明:
    --path      //镜像路径
    --name      //为安装源定义一个名字
    --arch      //指定安装源平台

//安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-7-x86_64,如果重复,系统会提示导入失败


//查看cobbler镜像列表
[root@localhost ~]# cobbler list
distros:
   centos7-x86_64  // 发行版
 
profiles:
   centos7-x86_64   // 配置文件

systems:

repos:

images:

mgmtclasses:

packages:

files:


## 生成自动安装脚本
[root@localhost ~]# cobbler profile getks --name=centos7-x86_64
auth --enableshadow --passalgo=sha512
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.229.155/cobbler/ks_mirror/centos7-x86_64
repo --name=source-1 --baseurl=http://192.168.229.155/cobbler/ks_mirror/centos7-x86_64

reboot

rootpw --iscrypted $6$BwgXphAWdoBw3ign$pBFoWBORQJkElTRBEsCxlXWiojpPwZluPL3kJoflO.q1xrF8aOAuOm9rQDsymJSWmr06wl3lu3a34WuWbdc4f/

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



复制到这里来
//创建kickstarts自动安装脚本
[root@localhost ~]# cat > /var/lib/cobbler/kickstarts/centos7.ks <<'EOF'
auth --enableshadow --passalgo=sha512
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.229.155/cobbler/ks_mirror/centos7-x86_64
repo --name=source-1 --baseurl=http://192.168.229.155/cobbler/ks_mirror/centos7-x86_64

reboot

rootpw --iscrypted $6$BwgXphAWdoBw3ign$pBFoWBORQJkElTRBEsCxlXWiojpPwZluPL3kJoflO.q1xrF8aOAuOm9rQDsymJSWmr06wl3lu3a34WuWbdc4f/

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

%packages
@^minimal  这个要跟系统的anaconda-ks.cfg文件的的一样
@core
kexec-tools

%end
EOF

//检查ks文件语法是否有误
[root@localhost ~]# cobbler validateks
task started: 2022-08-13_085422_validateks
task started (id=Kickstart Validation, time=Sat Aug 13 08:54:22 2022)
----------------------------
osversion: rhel7
checking url: http://192.168.229.155/cblr/svc/op/ks/profile/centos7-x86_64
running: /usr/bin/ksvalidator -v "rhel7" "http://192.168.229.155/cblr/svc/op/ks/profile/centos7-x86_64"
received on stdout:
received on stderr:
*** all kickstarts seem to be ok ***
*** TASK COMPLETE ***

//查看当前cobbler有哪些配置文件
[root@localhost ~]# cobbler profile list
   centos7-x86_64
   
   
//修改profile,将我们新建的ks文件设为默认的kickstarts安装文件
[root@localhost ~]# cobbler profile edit --name centos7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.ks

//配置网卡名称为传统网卡名称eth0
[root@localhost ~]# cobbler profile edit --name centos7-x86_64 --kopts='net.ifnames=0 biosdevname=0'


//检查当前系统cobbler配置文件信息
[root@localhost ~]# cobbler profile report
Name                           : centos7-x86_64
TFTP Boot Files                : {}
Comment                        :
DHCP Tag                       : default
Distribution                   : centos7-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.ks //使用的kickstarts配置文件的路径,必须为我们新建的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@localhost ~]# cobbler sync
...省略N
*** TASK COMPLETE ***



//为避免发生未知问题,先把服务端所有服务重启
[root@localhost ~]# systemctl restart xinetd
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# 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                  [::]:*

3. 客户端安装

创建虚拟机,不给镜像。
在这里插入图片描述
在这里插入图片描述

点击,他会自动安装

在这里插入图片描述

正在安装

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-a1p0SHGe-1660383293347)(D:/Markdown/%E5%8D%9A%E5%AE%A2/%E7%A0%B4%E8%A7%A3%E5%AF%86%E7%A0%81/1660352721050.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-osRGPd66-1660383293348)(D:/Markdown/%E5%8D%9A%E5%AE%A2/%E7%A0%B4%E8%A7%A3%E5%AF%86%E7%A0%81/1660353549378.png)]

上面是命令的方式安装

4. 定制安装

创建虚拟机给定制安装,创建过程忽略

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HB59ZRd2-1660383293349)(D:/Markdown/%E5%8D%9A%E5%AE%A2/%E7%A0%B4%E8%A7%A3%E5%AF%86%E7%A0%81/1660354486082.png)]

定制安装步骤:

  • 统计服务器mac地址
  • 配置cobbler
  • 安装

统计mac地址此处就不赘述了,直接最重要的配置
在 cobbler 的web界面上配置:

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

同步配置并重启相关服务:

[root@localhost ~]# cobbler sync
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# systemctl restart xinetd

最后开机自动会安装系统

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-qymwTXB0-1660383293356)(D:/Markdown/%E5%8D%9A%E5%AE%A2/%E7%A0%B4%E8%A7%A3%E5%AF%86%E7%A0%81/1660354912065.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-DYVNxKiX-1660383293357)(D:/Markdown/%E5%8D%9A%E5%AE%A2/%E7%A0%B4%E8%A7%A3%E5%AF%86%E7%A0%81/1660355309115.png)]

5.命令方式和定制安装CentOS8 虚拟机

# 导入镜像8
[root@localhost ~]# init 0 // 关机

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-XxG7IDre-1660383293359)(D:/Markdown/%E5%8D%9A%E5%AE%A2/%E7%A0%B4%E8%A7%A3%E5%AF%86%E7%A0%81/1660355803232.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HXnfmmd0-1660383293359)(D:/Markdown/%E5%8D%9A%E5%AE%A2/%E7%A0%B4%E8%A7%A3%E5%AF%86%E7%A0%81/1660355852539.png)]

挂载
[root@localhost ~]# mount /dev/cdrom /test
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 898M     0  898M   0% /dev
tmpfs                    910M     0  910M   0% /dev/shm
tmpfs                    910M  9.6M  901M   2% /run
tmpfs                    910M     0  910M   0% /sys/fs/cgroup
/dev/mapper/centos-root  215G  6.4G  209G   3% /
/dev/sda1               1014M  153M  862M  16% /boot
tmpfs                    182M     0  182M   0% /run/user/0
/dev/sr0                  11G   11G     0 100% /test


[root@localhost ~]# cobbler import --path=/mnt --name=centos8 --arch=x86_64
task started: 2022-08-13_145458_import
task started (id=Media import, time=Sat Aug 13 14:54:58 2022)
Found a candidate signature: breed=suse, version=opensuse15.0
Found a candidate signature: breed=suse, version=opensuse15.1
Found a candidate signature: breed=redhat, version=rhel8
Found a matching signature: breed=redhat, version=rhel8
Adding distros from path /var/www/cobbler/ks_mirror/centos8-x86_64:
creating new distro: centos8-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos8-x86_64 -> /var/www/cobbler/links/centos8-x86_64
creating new profile: centos8-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/centos8-x86_64 for centos8-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos8-x86_64/AppStream
need to process repo/comps: /var/www/cobbler/ks_mirror/centos8-x86_64/AppStream
looking for /var/www/cobbler/ks_mirror/centos8-x86_64/AppStream/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos8-x86_64/AppStream/repodata
processing repo at : /var/www/cobbler/ks_mirror/centos8-x86_64/BaseOS
need to process repo/comps: /var/www/cobbler/ks_mirror/centos8-x86_64/BaseOS
looking for /var/www/cobbler/ks_mirror/centos8-x86_64/BaseOS/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos8-x86_64/BaseOS/repodata
*** TASK COMPLETE ***


[root@localhost ~]# cobbler list
distros:
   centos7-x86_64
   centos8-x86_64

profiles:
   centos7-x86_64
   centos8-x86_64

systems:
   VM10

repos:

images:

mgmtclasses:

packages:

files:
[root@localhost ~]#


#查看centos8镜像目录
[root@localhost ~]# ll /var/www/cobbler/ks_mirror/centos8-x86_64/
total 52
dr-xr-xr-x 4 root root    38 Oct 13  2021 AppStream
dr-xr-xr-x 4 root root    38 Oct 13  2021 BaseOS
dr-xr-xr-x 3 root root    18 Oct 13  2021 EFI
-r--r--r-- 1 root root  8154 Oct 13  2021 EULA
-r--r--r-- 1 root root  1455 Oct 13  2021 extra_files.json
-r--r--r-- 1 root root 18092 Oct 13  2021 GPL
dr-xr-xr-x 3 root root    76 Oct 13  2021 images
dr-xr-xr-x 2 root root   256 Oct 13  2021 isolinux
-r--r--r-- 1 root root   103 Oct 13  2021 media.repo
-r--r--r-- 1 root root  1669 Oct 13  2021 RPM-GPG-KEY-redhat-beta
-r--r--r-- 1 root root  5135 Oct 13  2021 RPM-GPG-KEY-redhat-release
-r--r--r-- 1 root root  1796 Oct 13  2021 TRANS.TBL


# 创建kickstarts自动安装脚本
[root@localhost ~]# cd  /var/lib/cobbler/kickstarts
## 生成自动安装脚本,, 如果生成7的就把8修改为7
[root@localhost ~]# cobbler profile getks --name=centos8-x86_64
auth  --useshadow  --enablemd5
bootloader --location=mbr
clearpart --all --initlabel
text
firewall --disabled  // 关闭防火墙
firstboot --disable
keyboard us
lang en_US
url --url=http://192.168.229.155/cobbler/ks_mirror/centos8-x86_64
here.
repo --name=source-1 --baseurl=http://192.168.229.155/cobbler/ks_mirror/centos7-x86_64/AppStream
repo --name=source-2 --baseurl=http://192.168.229.155/cobbler/ks_mirror/centos7-x86_64/BaseOS
network --bootproto=dhcp --device=eth0 --onboot=on
reboot
rootpw --iscrypted $6$BwgXphAWdoBw3ign$pBFoWBORQJkElTRBEsCxlXWiojpPwZluPL3kJoflO.q1xrF8aOAuOm9rQDsymJSWmr06wl3lu3a34WuWbdc4f/
selinux --disabled
skipx
timezone  America/New_York
install
zerombr
autopart
%pre
set -x -v
exec 1>/tmp/ks-pre.log 2>&1
# Once root's homedir is there, copy over the log.
while : ; do
    sleep 10
    if [ -d /mnt/sysimage/root ]; then
        cp /tmp/ks-pre.log /mnt/sysimage/root/
        logger "Copied %pre section log to system"
        break
    fi
done &
%end
%packages
@^minimal  这个要跟系统anaconda-ks.cfg文件的的一样
%end

%post --nochroot
set -x -v
exec 1>/mnt/sysimage/root/ks-post-nochroot.log 2>&1

%end

%post
set -x -v
exec 1>/root/ks-post.log 2>&1

%end



#检查语法
[root@localhost ~]# cobbler validateks
...省略N
Potential templating errors:
Unknown variable found at line 16, column 22: '$BwgXphAWdoBw3ign'
Unknown variable found at line 16, column 39: '$pBFoWBORQJkElTRBEsCxlXWiojpPwZluPL3kJoflO.q1xrF8aOAuOm9rQDsymJSWmr06wl3lu3a34WuWbdc4f'
*** potential errors detected in kickstarts ***
!!! TASK FAILED !!!
     centos8版本不被pykickstart支持
 	# 如果有异常的变量参数,不要慌,只是虚拟机密码
 	
 	
#查看生成的配置文件 	
[root@localhost ~]# cobbler profile list
   centos7-x86_64
   centos8-x86_64



#配置系统默认文件
[root@localhost ~]# cobbler profile edit --name centos8-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos8.ks


#回归传统命名
[root@localhost ~]#  cobbler profile edit --name centos8-x86_64 --kopts='net.ifnames=0 biosdevname=0'


#同步sync
[root@localhost ~]# cobbler sync
...省略N
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***

#重启服务
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# systemctl restart xinetd
[root@localhost ~]# systemctl restart rsyncd

创建虚拟机的过程跟上面一样所以这里忽略

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-e1WlJBHa-1660383293360)(../../%E5%8D%9A%E5%AE%A2/%E7%A0%B4%E8%A7%A3%E5%AF%86%E7%A0%81/1660375172574.png)]

装7 就点击7,装8,就点击8。这里装8

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-JVIeDnjU-1660383293361)(../../%E5%8D%9A%E5%AE%A2/%E7%A0%B4%E8%A7%A3%E5%AF%86%E7%A0%81/1660375218240.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-i8DJkoSq-1660383293362)(../../%E5%8D%9A%E5%AE%A2/%E7%A0%B4%E8%A7%A3%E5%AF%86%E7%A0%81/1660378825893.png)]

定制安装

跟7 的操作是一样的

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-OY46bxog-1660383293363)(../../%E5%8D%9A%E5%AE%A2/%E7%A0%B4%E8%A7%A3%E5%AF%86%E7%A0%81/1660379116786.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-XlB9ejwk-1660383293364)(../../%E5%8D%9A%E5%AE%A2/%E7%A0%B4%E8%A7%A3%E5%AF%86%E7%A0%81/1660379225759.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Dw8sAuPW-1660383293364)(../../%E5%8D%9A%E5%AE%A2/%E7%A0%B4%E8%A7%A3%E5%AF%86%E7%A0%81/1660380447825.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-gsS03h3c-1660383293365)(../../%E5%8D%9A%E5%AE%A2/%E7%A0%B4%E8%A7%A3%E5%AF%86%E7%A0%81/1660379481541.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Ub7cHAK8-1660383293366)(../../%E5%8D%9A%E5%AE%A2/%E7%A0%B4%E8%A7%A3%E5%AF%86%E7%A0%81/1660379611766.png)]

创建虚拟机,然后开机他会自动装机

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-lXsQbw1J-1660383293367)(../../%E5%8D%9A%E5%AE%A2/%E7%A0%B4%E8%A7%A3%E5%AF%86%E7%A0%81/1660379532499.png)]

这时就没有哪个蓝屏让你点击了,不需要,他会自动装机

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-AEYNnCZW-1660383293367)(../../%E5%8D%9A%E5%AE%A2/%E7%A0%B4%E8%A7%A3%E5%AF%86%E7%A0%81/1660379687607.png)]
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值