Cobbler自動化安裝Centos7系統

簡介

Cobbler 能夠用來快速創建 Linux 網絡安裝環境,再也不須要使用光盤一臺一臺地安裝 Linux,只要配置好PXE、DHCP、TFTP和 Kickstart 腳本,便可瞬間完成安裝上百臺服務器的任務
Cobbler特色:
1)Cobbler支持多種Linux操做系統得快速部署,對DHCP、HTTP、TFTP、Kiskstart、YUM倉庫、電源等進行統一管理
2)Cobbler提供實現不一樣用戶需求得可定製系統部署方案
3)Cobbler分別提供命令管理和Web界面管理、方便Cobbler管理員使用linux

前期準備

準備一臺Centos7虛擬機,配置IP地址和hostname,關閉防火牆和selinux,同步系統時間
安裝epel源git

[root@localhost ~]# yum install epel-release -y

部署Cobbler

安裝相關軟件包github

[root@localhost ~]# yum install -y cobbler cobbler-web tftp* rsync xinetd http* syslinux dhcp* pykickstart
#啓動服務
[root@localhost ~]# systemctl start cobblerd

Cobbler配置

Cobbler檢查web

#根據檢查結果進行修改
[root@localhost ~]# cobbler check
The following are potential configuration items that you may want to fix:
1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work. This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
3 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:
https://github.com/cobbler/cobbler/wiki/Selinux
4 : change 'disable' to 'no' in /etc/xinetd.d/tftp
5 : Some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely.  Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
6 : enable and start rsyncd.service with systemctl
7 : debmirror package is not installed, it will be required to manage debian deployments and repositories
8 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one
9 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them

處理錯誤一、二、8shell

#生成隨機密碼串
[root@localhost ~]# openssl passwd -1 -salt 'abcefghljkl' '123456789'
#123456789爲機器登錄密碼
#abcefghljkl爲隨意編寫的字節干擾碼

#修改配置文件
[root@localhost ~]# vi /etc/cobbler/settings
#改成本機ip
server: local_ip
next_server: local_ip
#設置新建機器的登錄密碼串
default_password_crypted: "$1$abcefghl$Gibcsp93juzDkZImG.xAk0"

處理錯誤3centos

[root@localhost ~]# setenforce 0

處理錯誤4服務器

[root@localhost ~]# vi /etc/xinetd.d/tftp
disable                 = no

處理錯誤6網絡

[root@localhost ~]# systemctl start rsyncd
[root@localhost ~]# systemctl enable rsyncd

處理錯誤9dom

[root@localhost ~]# yum install -y fence-agents

重啓服務koa

[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# systemctl restart xinetd

掛載並導入鏡像

[root@localhost ~]# mount /dev/cdrom /mnt
[root@localhost ~]# cobbler import --path=/mnt --name=Centos7-x86_64 --arch=x86_64

#查看導入狀況
[root@localhost ~]# cobbler list
distros:
   centos7-x86_64
profiles:
   Centos7-x86_64
[root@localhost ~]# ls /var/www/cobbler/ks_mirror/
centos7  config

配置網絡

配置dhcp服務

[root@localhost ~]# vi /etc/cobbler/dhcp.template
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.29.0 netmask 255.255.255.0 {
    #配置網關
     option routers             192.168.29.2;
     #配置DNS
     option domain-name-servers 192.168.29.2;
     #配置掩碼
     option subnet-mask         255.255.255.0;
     #配置IP的範圍
     range dynamic-bootp        192.168.29.130 192.168.29.254;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
     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 {
    host $iface.name {
        option dhcp-client-identifier = $mac;
        hardware ethernet $mac;
        fixed-address $iface.ip_address;
        option host-name "$iface.hostname";
        option subnet-mask $iface.netmask;
        option routers $iface.gateway;
        if exists user-class and option user-class = "gPXE" {
            filename "http://$cobbler_server/cblr/svc/op/gpxe/system/$iface.owner";
        } else if exists user-class and option user-class = "iPXE" {
            filename "http://$cobbler_server/cblr/svc/op/gpxe/system/$iface.owner";
        } else {
            filename "undionly.kpxe";
        }
        filename "$iface.filename";
        next-server $next_server;
    }
}

開啓dhcp管理

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

Cobbler服務配置

啓動服務

[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl restart dhcpd
[root@localhost ~]# systemctl restart cobblerd

同步cobbler配置並初始化

[root@localhost ~]# cobbler rsync

設定安裝方案

自定義ks配置文件

[root@localhost ~]#  vi /var/lib/cobbler/kickstarts/centos7.ks 
# This kickstart file should only be used with EL > 5 and/or Fedora > 7.
# For older versions please use the sample.ks kickstart file.
#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth  --useshadow  --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --enabled
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Use network installation
url --url=http://local_ip/cobbler/ks_mirror/centos7
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $default_password_crypted
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone  Asia/Shanghai --isUtc
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
part /boot --fstype="xfs" --size=500
part swap --fstype="swap" --size=4096
part pv.01 --size=10240
volgroup vg_uplooking pv.01
logvol  /  --vgname=vg_uplooking  --size=10230  --name=lv_root
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end
%packages
$SNIPPET('func_install_if_enabled')
@Development tools
@Compatibility libraries
%end
%post --nochroot
$SNIPPET('log_ks_post_nochroot')
%end
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $default_password_crypted
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone Asia/Shanghai --isUtc
# Install OS instead of upgrade
zerombr
# Disk partitioning information
part /boot --fstype="xfs" --size=500
part swap --fstype="swap" --size=4096
%post
$SNIPPET('log_ks_post')
# Start yum configuration
$yum_config_stanza
# End yum configuration
$SNIPPET('post_install_kernel_options')
$SNIPPET('post_install_network_config')
$SNIPPET('func_register_if_enabled')
$SNIPPET('download_config_files')
$SNIPPET('koan_environment')
$SNIPPET('redhat_register')
$SNIPPET('cobbler_register')
# Enable post-install boot notification
$SNIPPET('post_anamon')
# Start final steps
$SNIPPET('kickstart_done')
# End final steps
%end

自定義的ks文件指定成默認的安裝方案

[root@localhost ~]#  cobbler profile edit --name=Centos7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.ks

測試驗證

新建空白虛擬機
在這裏插入圖片描述
開啓虛擬機並進行自動化安裝
在這裏插入圖片描述
在這裏插入圖片描述安裝完成後經過用戶名和密碼登錄便可

相關文章
相關標籤/搜索