ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

cobbler 批量装机

2021-10-13 12:35:34  阅读:156  来源: 互联网

标签:批量 lib -- cobbler 装机 var root localhost


cobbler简介

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

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

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

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

Cobbler官网:http://cobbler.github.io/

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     //查看配置信息

cobbler服务端部署

// 关闭防火墙和selinux
[root@localhost ~]# systemctl disable --now firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# dnf install epel-release
CentOS Stream 8 - AppStream                              2.0 MB/s |  15 MB     00:07    
CentOS Stream 8 - BaseOS                                 7.9 MB/s |  12 MB     00:01    
CentOS Stream 8 - Extras                                 9.2 kB/s |  15 kB     00:01    
依赖关系解决。
=========================================================================================
 软件包                      架构             版本                仓库              大小
=========================================================================================
安装:
 epel-release                noarch           8-11.el8            extras            24 k
安装弱的依赖:
 epel-next-release           noarch           8-11.el8            extras            11 k

事务概要
=========================================================================================
安装  2 软件包

总下载:35 k
安装大小:38 k
确定吗?[y/N]: y
下载软件包:
(1/2): epel-next-release-8-11.el8.noarch.rpm             189 kB/s |  11 kB     00:00    
(2/2): epel-release-8-11.el8.noarch.rpm                   36 kB/s |  24 kB     00:00    
-----------------------------------------------------------------------------------------
总计                                                      24 kB/s |  35 kB     00:01     
警告:/var/cache/dnf/extras-9705a089504ff150/packages/epel-next-release-8-11.el8.noarch.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID 8483c65d: NOKEY
CentOS Stream 8 - Extras                                 1.6 MB/s | 1.6 kB     00:00    
导入 GPG 公钥 0x8483C65D:
 Userid: "CentOS (CentOS Official Signing Key) <security@centos.org>"
 指纹: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
 来自: /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
确定吗?[y/N]: y
导入公钥成功
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                          1/1 
  安装    : epel-release-8-11.el8.noarch                                             1/2 
  安装    : epel-next-release-8-11.el8.noarch                                        2/2 
  运行脚本: epel-next-release-8-11.el8.noarch                                        2/2 
  验证    : epel-next-release-8-11.el8.noarch                                        1/2 
  验证    : epel-release-8-11.el8.noarch                                             2/2 
Installed products updated.

已安装:
  epel-next-release-8-11.el8.noarch             epel-release-8-11.el8.noarch            

完毕!
//安装cobbler以及相关的软件
[root@localhost ~]# yum -y install httpd dhcp-* tftp xinetd pykickstart
[root@localhost ~]# dnf module enable cobbler
Extra Packages for Enterprise Linu 430 kB/s | 955 kB     00:02    
Extra Packages for Enterprise Linu 477 kB/s | 1.3 MB     00:02    
Extra Packages for Enterprise Linu 675 kB/s |  10 MB     00:15 
[root@localhost ~]# dnf list all|grep cobbler
cobbler.noarch                                                    3.2.2-3.module_el8+13166+f291d70c                 epel-modular
cobbler-tests.noarch                                              3.2.2-3.module_el8+13166+f291d70c                 epel-modular
cobbler-web.noarch                                                3.2.2-3.module_el8+13166+f291d70c                 epel-modular

[root@localhost ~]# dnf -y install cobbler cobbler-web

//启动服务并设置开机自启
[root@localhost ~]# systemctl enable --now httpd
[root@localhost ~]# systemctl enable --now cobblerd
[root@localhost ~]# ss -antl
State  Recv-Q Send-Q Local Address:Port  Peer Address:Port Process 
LISTEN 0      128          0.0.0.0:22         0.0.0.0:*            
LISTEN 0      5          127.0.0.1:25151      0.0.0.0:*            
LISTEN 0      128                *:80               *:*            
LISTEN 0      128             [::]:22            [::]:*            
LISTEN 0      128                *:443              *:*     

//设置tftp的ip地址为本机ip,修改server的ip地址为本机ip
[root@localhost ~]# cd /etc/cobbler/
[root@localhost cobbler]# vim settings.yaml
255 next_server: 192.168.126.155
353 server: 192.168.126.155
// 下载缺失文件
[root@localhost ~]# dnf -y install syslinux
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
[root@localhost ~]# cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# cobbler get-loaders
task started: 2021-10-12_205048_get_loaders
task started (id=Download Bootloader Content, time=Tue Oct 12 20:50:48 2021)
running python triggers from /var/lib/cobbler/triggers/task/get_loaders/pre/*
running shell triggers from /var/lib/cobbler/triggers/task/get_loaders/pre/*
shell triggers finished successfully
path /var/lib/cobbler/loaders/README already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/COPYING.yaboot already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/COPYING.syslinux already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/yaboot already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/pxelinux.0 already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/menu.c32 already exists, not overwriting existing content, use --force if you wish to update
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 ***

//生成加密的密码,然后再打开DHCP功能
[root@localhost cobbler]# openssl passwd -1
Password: 
Verifying - Password: 
$1$rvfzLlrV$Ovo3qJObV6uMnh7YH4e8q/
[root@localhost cobbler]# vim settings.yaml 
103 default_password_crypted: "$1$rvfzLlrV$Ovo3qJObV6uMnh7YH4e8q/"

// DHCP 管理和 DHCP 服务器模板
[root@localhost cobbler]# vim settings.yaml 
220 manage_dhcp: true

[root@localhost ~]# vim /etc/cobbler/dhcp.template
 23 subnet 192.168.126.0 netmask 255.255.255.0 {        // 前面为本机IP同一网段
24      option routers             192.168.126.155;    // 填写本机IP
 25      option domain-name-servers 192.168.126.1;      // 默认网关
 26      option subnet-mask         255.255.255.0;
 27      range dynamic-bootp        192.168.126.100 192.168.126.254;     // 分配的IP地址范围
 28      default-lease-time         21600;
 29      max-lease-time             43200;
 30      next-server                $next_server;
// 启动和启用 Cobbler 服务并同步配置,改完dhcp必须要sync同步配置
[root@localhost ~]# systemctl start cobblerd

[root@localhost ~]# systemctl status cobblerd
● cobblerd.service - Cobbler Helper Daemon
   Loaded: loaded (/usr/lib/systemd/system/cobblerd.service; enabl>
   Active: active (running) since Tue 2021-10-12 19:26:49 CST; 1h >
  Process: 28890 ExecStartPost=/usr/bin/touch /usr/share/cobbler/w>
 Main PID: 28889 (cobblerd)
    Tasks: 1 (limit: 17652)
   Memory: 29.6M
   CGroup: /system.slice/cobblerd.service
           └─28889 /usr/bin/python3.6 -s /usr/bin/cobblerd -F

[root@localhost ~]# cobbler sync
task started: 2021-10-12_210128_sync
task started (id=Sync, time=Tue Oct 12 21:01:28 2021)
running python triggers from /var/lib/cobbler/triggers/task/sync/pre/*
running shell triggers from /var/lib/cobbler/triggers/task/sync/pre/*
shell triggers finished successfully
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/system
removing: /var/lib/tftpboot/grub/system_link
removing: /var/lib/tftpboot/grub/grub.cfg
removing: /var/lib/tftpboot/grub/local_efi.cfg
removing: /var/lib/tftpboot/grub/local_legacy.cfg
removing: /var/lib/tftpboot/grub/local_powerpc-ieee1275.cfg
copying bootloaders
running: ['rsync', '-rpt', '--copy-links', '--exclude=.cobbler_postun_cleanup', '/var/lib/cobbler/loaders/', '/var/lib/tftpboot']
received on stdout: 
received on stderr: 
running: ['rsync', '-rpt', '--copy-links', '--exclude=README.grubconfig', '/var/lib/cobbler/grub_config/', '/var/lib/tftpboot']
received on stdout: 
received on stderr: 
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
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/*
shell triggers finished successfully
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.scm_track
running python trigger cobbler.modules.managers.genders
running shell triggers from /var/lib/cobbler/triggers/change/*
shell triggers finished successfully
*** TASK COMPLETE ***

//通过cobbler check 核对当前设置是否有问题
[root@localhost ~]# cobbler check
The following are potential configuration items that you may want to fix:

1: reposync is not installed, install yum-utils or dnf-plugins-core
2: yumdownloader is not installed, install yum-utils or dnf-plugins-core
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.

//检查dhcp是否正常
[root@localhost ~]# ss -anulp|grep dhcp
UNCONN 0      0            0.0.0.0:67         0.0.0.0:*    users:(("dhcpd",pid=153755,fd=10))
UNCONN 0      0            0.0.0.0:33400      0.0.0.0:*    users:(("dhcpd",pid=153755,fd=20))
UNCONN 0      0               [::]:36222         [::]:*    users:(("dhcpd",pid=153755,fd=21))

[root@localhost ~]# reboot 

//导入redhat7镜像
[root@localhost ~]# mount /dev/cdrom /mnt
[root@localhost ~]# cobbler import --path=/mnt --name=centos-8 --arch=x86_64     //说明:--path,镜像路径;--name,为安装源定义一个名字;--arch,指定安装源平台。安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-7-x86_64,如果重复,系统会提示导入失败
task started: 2021-10-12_214904_import
task started (id=Media import, time=Tue Oct 12 21:49:04 2021)
running python triggers from /var/lib/cobbler/triggers/task/import/pre/*
running shell triggers from /var/lib/cobbler/triggers/task/import/pre/*
shell triggers finished successfully
Found a candidate signature: breed=redhat, version=rhel8
Found a matching signature: breed=redhat, version=rhel8
Adding distros from path /var/www/cobbler/distro_mirror/centos-8-x86_64:
creating new distro: centos-8-x86_64
trying symlink: /var/www/cobbler/distro_mirror/centos-8-x86_64 -> /var/www/cobbler/links/centos-8-x86_64
creating new profile: centos-8-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/distro_mirror/centos-8-x86_64 for centos-8-x86_64
processing repo at : /var/www/cobbler/distro_mirror/centos-8-x86_64/AppStream
need to process repo/comps: /var/www/cobbler/distro_mirror/centos-8-x86_64/AppStream
looking for /var/www/cobbler/distro_mirror/centos-8-x86_64/AppStream/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/centos-8-x86_64/AppStream/repodata
processing repo at : /var/www/cobbler/distro_mirror/centos-8-x86_64/BaseOS
need to process repo/comps: /var/www/cobbler/distro_mirror/centos-8-x86_64/BaseOS
looking for /var/www/cobbler/distro_mirror/centos-8-x86_64/BaseOS/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/centos-8-x86_64/BaseOS/repodata
*** TASK COMPLETE ***

//查看cobbler镜像列表
[root@localhost ~]#  cobbler list
distros:
   centos-8-x86_64

profiles:
   centos-8-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:


//创建kickstarts自动安装脚本
[root@localhost ~]# cd /var/lib/cobbler/
[root@localhost cobbler]# mkdir kickstarts
[root@localhost cobbler]# cd kickstarts/
[root@localhost kickstarts]# cat centos-8-x86_64.ks 
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.47.160/cobbler/ks_mirror/centos-8-x86_64     //
$yum_repo_stanza
reboot

rootpw --iscrypted $6$2WTFvfNvAMgCUPuC$MJgWGzhakgxrRObcEbAwSe8vkz0s//xyiTllGwxRsHHruQhcskO69u2LVTU9u0eemHXH2pzcGawyAJ54R2E/x0

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

//检查ks文件语法是否有误
[root@localhost ~]# cobbler validateks
No such command: validateks

标签:批量,lib,--,cobbler,装机,var,root,localhost
来源: https://blog.csdn.net/a512153770/article/details/120741109

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有