centos7搭建cobbler服务

一、关闭防火墙和selinux

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld          
[root@localhost ~]# vi /etc/selinux/config 
[root@localhost ~]# getenforce
Disabled

上不了网就设置DNS解析
[root@localhost ~]# vi /etc/resolv.conf
# Generated by NetworkManager
nameserver 114.114.114.114
nameserver 8.8.8.8

二、导入epel源

使用第 7 代企业版 Linux,可以通过这个链接获取 'epel-release' 包的最新版本;https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

[root@localhost ~]# ls
anaconda-ks.cfg  epel-release-latest-7.noarch.rpm
[root@localhost ~]# rpm -ivh epel-release-latest-7.noarch.rpm 
Preparing...                          ################################# [100%]
	package epel-release-7-13.noarch is already installed

三、安装服务包:httpd、tftp-server、xinetd、cobbler、dhcp、pykickstart

[root@localhost ~]# yum -y install httpd tftp-server xinetd cobbler dhcp pykickstart
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * epel: mirrors.bfsu.edu.cn
 * extras: mirrors.163.com
 * updates: mirrors.163.com
Package httpd-2.4.6-97.el7.centos.x86_64 already installed and latest version
Package tftp-server-5.2-22.el7.x86_64 already installed and latest version
Package 2:xinetd-2.3.15-14.el7.x86_64 already installed and latest version
Package cobbler-2.8.5-0.3.el7.x86_64 already installed and latest version
Package 12:dhcp-4.2.5-82.el7.centos.x86_64 already installed and latest version
Package pykickstart-1.99.66.22-1.el7.noarch already installed and latest version
Nothing to do  //我这里已经安装好了,所以不要安装

四、修改配置参数

[root@localhost ~]# vi /etc/cobbler/settings 

server: 10.10.13.100  //修改提供服务的IP
next-server: 10.10.13.100  //修改本机IP
[root@localhost ~]# vi /etc/xinetd.d/tftp
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot
        disable                 = no  //把yes改成no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
[root@localhost ~]# systemctl start xinetd
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl start cobblerd.service 
[root@localhost ~]# systemctl start rsyncd
[root@localhost ~]# cobbler get-loaders //自动下载loaders程序
task started: 2021-03-28_110603_get_loaders
task started (id=Download Bootloader Content, time=Sun Mar 28 11:06:03 2021)
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.elilo 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/elilo-ia64.efi 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
path /var/lib/cobbler/loaders/grub-x86.efi already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/grub-x86_64.efi already exists, not overwriting existing content, use --force if you wish to update
*** TASK COMPLETE ***
[root@localhost ~]# systemctl start rsyncd  //启动服务

五、修改cobbler用户初始密钥

[root@localhost ~]# openssl passwd -1 -salt '' 'kuang@123456' //-salt参数后任意两个字符
$1$$W7Bx.wy68XwOissJRG4sa.
[root@localhost ~]# vi /etc/cobbler/settings
default_password_crypted: "$1$$W7Bx.wy68XwOissJRG4sa."  //选择粘贴密钥在这
manage_dhcp: 1 //把0改成1

六、修改dhcp.template文件

[root@localhost ~]# vi /etc/cobbler/dhcp.template 
subnet 10.10.13.0 netmask 255.255.255.0 {  //网段
     option routers             10.10.13.254; //网关
     option domain-name-servers 10.10.13.100; //DNS
     option subnet-mask         255.255.255.0; //掩码
     range dynamic-bootp        10.10.13.1 10.10.13.99;  //设置IP范围
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                10.10.13.100;
[root@localhost ~]# cobbler get-loaders  //再次获取程序

七、重启全部相关的服务程序

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

八、导入ISO镜像

使用cobbler的import命令从ISO安装镜像中导入安装所需要的程序包。数据文件较大,需等待。

命令格式;cobbler import --path=镜像路径 --name=安装引导名 --arch=32位或64位

--path表示镜像所挂载的目录

--name表示为安装源定义的名字-

--arch表示指定安装源是32位还是64位,目前支持的选项:x86,x86_64,ia64

如果在导入镜像包以下错误则需要更新一下cobbler
No signature matched in /var/www/cobbler/ks_mirror/fedora19-x86_64 !!! TASK FAILED !!!
root@localhost cdrom]# cobbler signature update //更新后再导入
task started: 2021-03-28_232512_sigupdate
task started (id=Updating Signatures, time=Sun Mar 28 23:25:12 2021)
Successfully got file from https://cobbler.github.io/signatures/2.8.x/latest.json
*** TASK COMPLETE ***
[root@localhost ~]# mkdir -p /mnt/cdrom/CentOS-7-x86_64  //创建挂载目录
[root@localhost ~]# mkdir -p /mnt/cdrom/ubuntu20.04 //创建挂载目录
[root@localhost ~]# mount -o loop /root/ubuntu-20.04-live-server-amd64.iso /mnt/cdrom/ubuntu20.04/ //挂载镜像
mount: /dev/loop1 is write-protected, mounting read-only
[root@localhost ~]# mount -o loop /root/CentOS-7-x86_64-Minimal-1810.iso /mnt/cdrom/CentOS-7-x86_64/
mount: /dev/loop2 is write-protected, mounting read-only
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   50G  5.1G   45G  11% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  8.7M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1               1014M  149M  866M  15% /boot
/dev/mapper/centos-home   26G   33M   26G   1% /home
tmpfs                    380M     0  380M   0% /run/user/0
/dev/loop0               908M  908M     0 100% /root/iso
/dev/loop1               908M  908M     0 100% /mnt/cdrom/ubuntu20.04
/dev/loop2               918M  918M     0 100% /mnt/cdrom/CentOS-7-x86_64
[root@localhost cdrom]# cobbler import --path=/root/ubuntu-20.04-live-server-amd64.iso --name=/ubuntu20.04 --arch=x86_64
[root@localhost cdrom]# cobbler list //查看列表
[root@localhost cdrom]# cobbler list
distros:
   Centos7-1810-x86_64
   ubuntu20.04-X86_64-casper-x86_64

profiles:
   Centos7-1810-x86_64
   ubuntu20.04-X86_64-casper-x86_64

systems:

repos:
   ubuntu20.04-X86_64-casper-x86_64
添加两个或以上需要执行以下命令启动
[root@localhost cdrom]# cobbler reposync

九、确认位置无误,重启cobbler服务及更新程序

[root@localhost cdrom]# systemctl restart cobblerd.service 
[root@localhost cdrom]# cobbler sync
task started: 2021-03-28_235448_sync
task started (id=Sync, time=Sun Mar 28 23:54:48 2021)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/Centos7-1810-x86_64
removing: /var/www/cobbler/images/ubuntu20.04-X86_64-casper-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/Centos7-1810-x86_64
removing: /var/lib/tftpboot/images/ubuntu20.04-X86_64-casper-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: Centos7-1810-x86_64
trying hardlink /var/www/cobbler/ks_mirror/Centos7-1810-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/Centos7-1810-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/Centos7-1810-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/Centos7-1810-x86_64/initrd.img
copying files for distro: ubuntu20.04-X86_64-casper-x86_64
trying hardlink /var/www/cobbler/ks_mirror/ubuntu20.04-X86_64-x86_64/casper/vmlinuz -> /var/lib/tftpboot/images/ubuntu20.04-X86_64-casper-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/ubuntu20.04-X86_64-x86_64/casper/initrd -> /var/lib/tftpboot/images/ubuntu20.04-X86_64-casper-x86_64/initrd
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: Centos7-1810-x86_64
trying hardlink /var/www/cobbler/ks_mirror/Centos7-1810-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/Centos7-1810-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/Centos7-1810-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/Centos7-1810-x86_64/initrd.img
Writing template files for Centos7-1810-x86_64
copying files for distro: ubuntu20.04-X86_64-casper-x86_64
trying hardlink /var/www/cobbler/ks_mirror/ubuntu20.04-X86_64-x86_64/casper/vmlinuz -> /var/www/cobbler/images/ubuntu20.04-X86_64-casper-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/ubuntu20.04-X86_64-x86_64/casper/initrd -> /var/www/cobbler/images/ubuntu20.04-X86_64-casper-x86_64/initrd
Writing template files for ubuntu20.04-X86_64-casper-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: Centos7-1810-x86_64
processing boot_files for distro: ubuntu20.04-X86_64-casper-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 ***

十、检查配置

cobbler check

十一、创建kickstart自动应答文件

[root@localhost cdrom]# cobbler profile list
   Centos7-1810-x86_64
   ubuntu20.04-X86_64-casper-x86_64
[root@localhost cdrom]# cobbler profile report --name=Centos7-1810-x86_64
Name                           : Centos7-1810-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : Centos7-1810-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.ks
Kickstart Metadata             : {}
Management Classes             : []
Management Parameters          : <>
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 : 
Internal proxy                 : 
Red Hat Management Key         : <>
Red Hat Management Server      : <>
Repos                          : []
Server Override                : <>
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

[root@localhost cdrom]# cobbler profile report --name=ubuntu20.04-X86_64-casper-x86_64
Name                           : ubuntu20.04-X86_64-casper-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : ubuntu20.04-X86_64-casper-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : 
Kickstart Metadata             : {}
Management Classes             : []
Management Parameters          : <>
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 : 
Internal proxy                 : 
Red Hat Management Key         : <>
Red Hat Management Server      : <>
Repos                          : []
Server Override                : <>
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

在centos7中加ubuntu镜像,我这里无法同步,所以演示不了ubuntu

访问网页:https://10.10.13.100/cobbler_web/

你可能感兴趣的:(自动化运维,部署,linux)