cobblerによるシステム自動化インストール


cobblerによるシステム自動化インストール
捜狐epelソースからcobblerインストールパッケージをダウンロードすることをお勧めします
[root@centos ~]#cat /etc/yum.repos.d/epel.repo
[epel]
name=sohu-epel
baseurl=http://mirrors.sohu.com/fedora-epel/7/x86_64/
gpgcheck=0
[root@centos ~]#yum repolist

1、インストールパッケージ、構成サービス
[root@centos ~]#yum install cobbler dhcp -y
[root@centos ~]#systemctl enable tftp dhcpd httpd cobblerd
Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.
[root@centos ~]#systemctl start tftp  httpd cobblerd

2、自動化インストールシステムの起動パスワードを生成する
[root@centos ~]#openssl passwd -1
Password:
Verifying - Password:
$1$JQDPVGcR$UopQ.pfS6P48TAC3ww07Z/

3、cobblerプロファイルの修正
[root@centos ~]#vim /etc/cobbler/settings
[root@centos ~]#sed -n -e 101p -e 242p -e 272p -e 384p /etc/cobbler/settings
default_password_crypted: "$1$JQDPVGcR$UopQ.pfS6P48TAC3ww07Z/"      #     
manage_dhcp: 1      #     dhcp   
next_server: 192.168.36.101      # TFTP  
server: 192.168.36.101      # Cobbler     
[root@centos ~]#systemctl restart cobblerd
  TFTP         
[root@centos ~]#cobbler get-loaders
task started: 2019-04-22_125917_get_loaders
task started (id=Download Bootloader Content, time=Mon Apr 22 12:59:17 2019)
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 ***
 TFTP     tftp   
[root@centos ~]#cobbler sync
task started: 2019-04-22_130210_sync
task started (id=Sync, time=Mon Apr 22 13:02:10 2019)
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 ***

4、dhcpサービスの構成
[root@centos ~]#vim /etc/cobbler/dhcp.template
[root@centos ~]#sed -n 21,28p /etc/cobbler/dhcp.template
subnet 192.168.36.0 netmask 255.255.255.0 {
     option routers             192.168.36.254;
     option domain-name-servers 1.1.1.1;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.36.100 192.168.36.254;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
[root@centos ~]#cobbler sync
task started: 2019-04-22_130606_sync
task started (id=Sync, time=Mon Apr 22 13:06:06 2019)
running pre-sync triggers
cleaning trees
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/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 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サービスを再起動してdhcpdを発見する.confプロファイルが自動的に同期されました
[root@centos ~]#systemctl restart dhcpd
[root@centos ~]#cat /etc/dhcp/dhcpd.conf
# ******************************************************************
# Cobbler managed dhcpd.conf file
# generated from cobbler dhcp.conf template (Mon Apr 22 05:06:07 2019)
# Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes
# in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
# overwritten.
# ******************************************************************

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 192.168.36.0 netmask 255.255.255.0 {
     option routers             192.168.36.254;
     option domain-name-servers 1.1.1.1;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.36.100 192.168.36.254;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                192.168.36.101;
     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";
          }
     }

}

# group for Cobbler DHCP tag: default
group {
}

5、インストール元ファイルのインポート
[root@centos ~]#cobbler import --path=/media/cdrom --name=CentOS7 --arch=x86_64
task started: 2019-04-22_130948_import
task started (id=Media import, time=Mon Apr 22 13:09:48 2019)

Found a candidate signature: breed=redhat, version=rhel6
Found a matching signature: breed=redhat, version=rhel6
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 ***

6、CentOS 7の最小化インストールのks 7_を生成するmini.cfgファイル
[root@centos ~]#vim /var/lib/cobbler/kickstarts/ks7_mini.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$Tyo.RXcB$GcWeYoXa/uPKb/JlLeYkl/
# Use network installation
url --url=$tree     #    $tree  ,    cobbler      
# System language
lang en_US
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled

# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=ens33   
# Reboot after installation
reboot
# System timezone   
timezone Asia/Shanghai    
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information   
part / --fstype="ext4" --size=10240
part /boot --fstype="ext4" --size=500
part /home --fstype="ext4" --size=1024
part swap --fstype="swap" --size=2048

%packages
@core

%end

具体的にks 7_を生成するmini.cfgファイルの方式は応答ファイルの中で見てください
7、メニュー項目の表示
[root@centos ~]#cobbler profile list
   CentOS7
   CentOS7-x86_64

                 
[root@centos ~]#cobbler profile remove --name=CentOS7
[root@centos ~]#cobbler profile list
   CentOS7-x86_64

8.ksファイルとシステムを関連付けてスタートメニューを生成する
[root@centos ~]#cobbler profile add --name=CentOS7 --distro=CentOS7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks7_mini.cfg

9、仮想マシンテストの作成
メニューバーの選択
利用cobbler 实现系统自动化安装_第1张图片
カーネルファイルの読み込み
利用cobbler 实现系统自动化安装_第2张图片
何の操作も必要なく、本格的な無人監視、自動インストールシステム
利用cobbler 实现系统自动化安装_第3张图片
Cobbler Web管理
パッケージのインストール
[root@centos ~]#yum install -y cobbler-web
[root@centos ~]#systemctl restart httpd

cobblerアカウントとパスワードの追加
[root@centos ~]#htdigest -c /etc/cobbler/users.digest Cobbler cobbler1
Adding password for cobbler1 in realm Cobbler.
New password:
Re-type new password:
[root@centos ~]#cat /etc/cobbler/users.digest
cobbler1:Cobbler:6d3d694017aea7a8cb58c8ad284d8cb9

ブラウザアクセスCobbler管理ページ
アドレスはhttps://192.168.36.101/cobbler_webデフォルトのユーザー名、パスワード:cobbler、cobbler 利用cobbler 实现系统自动化安装_第4张图片 利用cobbler 实现系统自动化安装_第5张图片
Cobbler自動化インストール構築完了、ご覧いただきありがとうございます^^;