搭建cobbler自动化安装系统

命令行

安装软件包

[root@localhost ~]# yum install cobbler cobbler-web dhcp pykickstart -y

开机启动

[root@localhost ~]# systemctl enable --now cobblerd httpd tftp dhcpd

关闭防火墙

[root@localhost ~]# systemctl disable --now firewalld

关闭selinux

[root@localhost ~]# sed -ri 's/^(SELINUX=)/\1disabled/' /etc/selinux/config

改tftp配置

[root@localhost ~]# vim /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
{
        disable                 = no    # 原来的yes 改成no
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -B 1380 -v -s /var/lib/tftpboot
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

重启服务

[root@localhost ~]# systemctl restart xinetd

去网络拉

[root@localhost ~]# cobbler get-loaders

如果没有网络情况下拷贝启动文件到TFTP服务文件夹

[root@localhost ~]# cp -a /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot

命令生成passwd添加到配置文件的password

[root@localhost ~]# openssl passwd -1 -salt `openssl rand -hex 4`

改cobbler配置

[root@localhost ~]# vim /etc/cobbler/settings
manage_dhcp: 1

default_password_crypted: "$1$3615869d$.n6qC68e6B05ibbdQaU1L/"

manage_tftpd: 1

next_server: 172.31.0.37
server: 172.31.0.37

重启服务

[root@localhost ~]# systemctl restart cobblerd

挂载镜像

[root@localhost ~]# mount /dev/cdrom /mnt

cobbler命令

[root@localhost ~]# cobbler
usage
=====
cobbler <distro|profile|system|repo|image|mgmtclass|package|file> ... 
        [add|edit|copy|getks*|list|remove|rename|report] [options|--help]
cobbler <aclsetup|buildiso|import|list|replicate|report|reposync|sync|validateks|version|signature|get-loaders|hardlink> [options|--help]

可以使用下面的方式得到使用帮助

[root@localhost ~]# cobbler distro --help
usage
=====
cobbler distro add
cobbler distro copy
cobbler distro edit
cobbler distro find
cobbler distro list
cobbler distro remove
cobbler distro rename
cobbler distro report

常见用法:

#列出当前导入的linux发行版条目
cobbler distro list
#报告当前所有的linux发行版详细信息
cobbler distro report
#导入系统源文件生成仓库
cobbler import --name=centos-8.0-x86_64 --path=/mnt --arch=x86_64
cobbler import --name=centos7-x86_64 --path=/mnt --arch=x86_64
#将linux发行版系统镜像与其对应的ks文件建立关联
cobbler profile add --name=centos7 --distro=centos7-x86_64 --
kickstart=/var/lib/cobbler/kickstarts/ks7.cfg

导入镜像

[root@localhost ~]# cobbler import --name=CentOS-7.6-x86_64 --path=/mnt

拷贝本地的制作应答文件

[root@localhost ~]# cp anaconda-ks.cfg centos7-cobbler.cfg

应答文件如下:

[root@localhost ~]# cat centos7-cobbler.cfg
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

url --url=http://172.31.0.37/cobbler/ks_mirror/CentOS-7.0-x86_64

# Network information
network  --bootproto=dhcp --device=eth0 --ipv6=auto --activate
network  --hostname=localhost.localdomain

# Root password
rootpw --iscrypted $6$4/BrvAUI44X3IBrc$hvBBzfJ5YytEaWipSMDRvPLtqY0ChCakRFYignwwQLL9XHqy4xZHEIPeWUZX/Ny9WZEFdIZYdqtdD7RJYrCeD1
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel

%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@localhost ~]# cat /etc/cobbler/pxe/pxedefault.template 
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.longxuan.vip/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT $pxe_timeout_profile

LABEL local
        MENU LABEL (local)
        MENU DEFAULT
        LOCALBOOT -1

$pxe_menu_items

MENU end

#启动并同步
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# cobbler sync

制作系统启动界面

[root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default

DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.longxuan.vip/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT local

LABEL local
        MENU LABEL (local)
        MENU DEFAULT
        LOCALBOOT -1

LABEL CentOS-7.6-x86_64
        kernel /images/CentOS-7.6-x86_64/vmlinuz
        MENU LABEL CentOS-7.6-x86_64
        append initrd=/images/CentOS-7.6-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://172.31.0.37/cblr/svc/op/ks/profile/CentOS-7.6-x86_64
        ipappend 2

MENU end

效果如下:
搭建cobbler自动化安装系统

改dhcp配置

[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
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 172.31.0.0 netmask 255.255.0.0 {
     option routers             172.31.0.254;
     option domain-name-servers 172.31.0.254;
     option subnet-mask         255.255.0.0;
     range dynamic-bootp        172.31.0.180 172.31.0.200;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                172.31.0.37;
     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";
          }
     }

}

重启

[root@localhost ~]# systemctl restart dhcpd

一、最后验证cobbler自动装机
然后新建一台虚拟机PC进行验证,不使用镜像,网络连接方式选择NAT,注意内存选择2G以上(否则会因内存不够而安装失败)。然后开启新建的虚拟机会出现cobbler画面,选择第二种回车继续等待

安装web界面

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

改配置文件

[root@localhost ~]# vim /etc/cobbler/modules.conf
[authentication]
#module=authn_configfile
module = authn_pam

创建用户并设置密码

[root@localhost ~]# useradd webuser
[root@localhost ~]# passwd webuser

配置文件添加用户

[root@localhost ~]# vim /etc/cobbler/users.conf

[admins]
admin = ""
cobbler = ""
webuser = ""  # 添加这行

登陆浏览器测试(注意是https)
https://172.31.0.37cobbler_web
搭建cobbler自动化安装系统

搭建cobbler自动化安装系统

搭建cobbler自动化安装系统

看到如下就是web界面安装完成!
搭建cobbler自动化安装系统

遇到同步报错:
搭建cobbler自动化安装系统
解决办法:查看dhcp配置文件发现数据还原了,修改回我们需要的ip,网关等信息,重启dhcp解决

上一篇:eclipse maven新建springMVC项目(原创)


下一篇:实战-使用 Cobbler 定制化安装指定系统