利用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、生成CentOS7最小化安裝的ks7_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
具體生成ks7_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 實現系統自動化安裝

讀取內核文件

利用cobbler 實現系統自動化安裝

無需任何操作,真正的無人值守,自動安裝系統

利用cobbler 實現系統自動化安裝

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 實現系統自動化安裝
利用cobbler 實現系統自動化安裝

Cobbler自動化安裝搭建完成,感謝觀看^_^
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章