1. 程式人生 > >基於Centos7系統部署cobbler批量安裝系統

基於Centos7系統部署cobbler批量安裝系統

ks.cfg 建立 intern imp chang img 默認 cin 訪問控制

前言

cobbler是一個可以實現批量安裝系統的Linux應用程序。它有別於pxe+kickstart,cobbler可以實現同個服務器批量安裝不同操作系統版本

系統環境的準備及下載cobbler

一、系統環境

可以用任何模式來使用,不過要註意在局域網使用橋接容易出現DHCP分配IP換亂的問題,這裏我們使用僅主機模式

[[email protected] network-scripts]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link
/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:0d:4d:fc brd ff:ff:ff:ff:ff:ff inet
192.168.5.3/24 brd 192.168.5.255 scope global ens33 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe0d:4dfc/64 scope link valid_lft forever preferred_lft forever 3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00
:0c:29:0d:4d:06 brd ff:ff:ff:ff:ff:ff inet 169.254.12.2/16 brd 169.254.255.255 scope link ens37 #這是僅主機模式下的網卡 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe0d:4d06/64 scope link valid_lft forever preferred_lft forever

我使用了兩塊網卡,不過我這裏只使用僅主機模式的網卡 ——169.254.12.2

二、關閉安全服務

不關閉防火墻無法連接

[[email protected] ~]# systemctl stop firewalld                   #關閉防火墻
[[email protected] ~]# setenforce 0                               #關閉selinux

三、下載cobbler及其所需服務程序

[[email protected] ~]# yum install cobbler dhcp tftp-server xinetd syslinux httpd -y

cobbler:核心程序不用多解釋

dhcp:負責分配客戶端IP,因為客戶端沒有IP,所以需要dhcp服務

tftp(Trivial File Transfer Protocol,簡單文件傳輸協議):是TCP/IP協議族中的一個用來在客戶機與服務器之間進行簡單文件傳輸的協議,提供不復雜、開銷不大的文件傳輸服務。端口號為69。

xinetd:xinetd已經取代了inetd,並且提供了訪問控制、加強的日誌和資源管理功能,已經成了Red Hat 7 和 Mandrake 7.2的Internet標準超級守護進程

syslinux:syslinux是一個功能強大的引導加載程序,而且兼容各種介質。它的目的是簡化首次安裝Linux的時間,並建立修護或其它特殊用途的啟動盤。它提供pxelinux這個文件,pxelinux.0引導文件引導vmlinux和initrd兩個啟動文件

httpd:可以使別的主機可以從服務端獲取鏡像包

yum 安裝需要下面兩個源

[epel]
name=epel
enabled=1
gpgcheck=0
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/

[centos]
name=centos base
enabled=1
gpgcheck=0
baseurl=http://mirrors.163.com/centos/7/os/x86_64/

配置相關服務

第一步、配置dhcp服務

[[email protected] ~]# vim /etc/dhcp/dhcpd.conf 

subnet 169.254.12.0 netmask 255.255.0.0 {
  range 169.254.1.20 169.254.2.30;
  default-lease-time 600;
  max-lease-time 7200;
  filename "pxelinux.0";                    #加入pxelinux引導程序
}                   

第二步、配置tftp

安裝tftp服務器需要安裝xinetd

[[email protected] ~]# 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
}

第三步、啟動cobbler、httpd

[[email protected] ~]# systemctl restart cobblerd
[[email protected] ~]# systemctl restart httpd

第四步、檢查cobbler配置

[[email protected] ~]# 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 : 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.
4 : enable and start rsyncd.service with systemctl
5 : debmirror package is not installed, it will be required to manage debian deployments and repositories
6 : 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
7 : fencing tools were not found, and are required to use the (optional) power management features. install
cman or fence-agents to use them

Restart cobblerd and then run ‘cobbler sync‘ to apply changes

可以看到有7個錯誤,需要一一排錯

五、排錯

問題1.(文中紅字標識錯誤位置)在 /etc/cobbler/setting中

cobbler文件默認是127.0.0.1本地回環地址,需要更改為提供cobbler服務的ip地址169.254.12.2,在384行

384 server: 169.254.12.2

問題2.(文中紅字標識錯誤位置)在 /etc/cobbler/setting中

netx_server也是默認本地127.0.0.1回環地址,需要修改為提供cobbler服務的ip地址 同樣是169.254.12.2,在272行出

272 next_server: 169.254.12.2

問題3.(可以忽略)

若想解決,直接運行 cobbler get-loaders即可

問題4.未啟動rsync

啟動rsync並讓其開機自啟

[[email protected] ~]# systemctl restart rsyncd
[[email protected] ~]# systemctl enable rsync

問題5.直接忽略

問題6.更改密碼

[[email protected] ~]# openssl passwd -1 -salt "123" "123456"
$1$123$7mft0jKnzzvAdU4t0unTG1

把新生成的密碼填寫進 /etc/cobbler/setting,也就是 $ 後面的加密數據

101 default_password_crypted: "$1$123$7mft0jKnzzvAdU4t0unTG1"

問題7.同樣忽略

第六步、重啟服務並檢查

[[email protected] ~]# systemctl restart cobblerd
[[email protected] ~]# cobbler sync
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
[[email protected] ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : 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.
2 : debmirror package is not installed, it will be required to manage debian deployments and repositories 3 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents
to use them Restart cobblerd and then run
cobbler sync to apply changes.

更改完畢

補充:如果出現 selinux enable 錯誤提示,關閉防火墻仍無效果時可重啟系統便可解決

第七步、掛載光盤並進行數據導入

1.掛載光盤

[[email protected] ~]# mount /dev/cdrom  /mnt

2.導入數據(耐心等待)

[[email protected] ~]# cobbler import --path=/mnt --name="centos7.5"
task started: 2019-03-13_001927_import
task started (id=Media import, time=Wed Mar 13 00:19:27 2019)
Found a candidate signature: breed=redhat, version=rhel6
Found a candidate signature: breed=redhat, version=rhel7
Found a matching signature: breed=redhat, version=rhel7
Adding distros from path /var/www/cobbler/ks_mirror/centos7.5:
creating new distro: centos7.5-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos7.5 -> /var/www/cobbler/links/centos7.5-x86_64
creating new profile: centos7.5-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.5 for centos7.5-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos7.5
need to process repo/comps: /var/www/cobbler/ks_mirror/centos7.5
looking for /var/www/cobbler/ks_mirror/centos7.5/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos7.5/repodata
*** TASK COMPLETE ***

distro : 發行版, 就是我們安裝什麽版本的linux操作系統的名稱 一會我們會導入一個 distro.
profile : 類似於一個 配置文件,類似於你的 bash_profile, 裏面包含你可以添加 kernel 參數,對應的kickstart 文件 以及 此profile 對應的 distro 等等.

查看distro

[[email protected] ~]# cobbler distro list
centos7.5-x86_64

查看profile

[[email protected] ~]# cobbler profile list
centos7.5-x86_64

第八步、準備kickstart

在root目錄下找到ks文件,並移動到/var/lib/cobbler/kickstarts/到目錄下改名為ks.cfg

[[email protected] ~]# mv anaconda-ks.cfg /var/lib/cobbler/kickstarts/ks.cfg
[[email protected] ~]# vim /var/lib/cobbler/kickstarts/ks.cfg
[[email protected] ~]# cat /var/lib/cobbler/kickstarts/ks.cfg
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
url --url=http://192.168.182.128/cobbler/ks_mirror/centos7.5/  #這裏需要更改為repodata所在的http地址
# 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

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

# Root password
rootpw --iscrypted $6$7zu1wIUDgBGEFV1Y$KsLVeaGmyN92.QHr1fqKdTqPu8PDmd8K9V/s3Ru8NxE53NZz4gQKsmP6K0udcXVvDtponekICYUwBD7tYZJqU/
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel

%packages
@^minimal
@core

%end

%addon com_redhat_kdump --disable --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

第九步、自定義profile

[[email protected] ~]#  cobbler profile add --distro=centos7.5-x86_64 --name=centos7.5_songqi --kickstart=/var/lib/cobbler/kickstarts/ks.cfg
[[email protected] ~]# cobbler sync
task started: 2019-03-13_002724_sync
task started (id=Sync, time=Wed Mar 13 00:27:24 2019)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/centos7.5-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/images/centos7.5-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
copying distros to tftpboot
copying files for distro: centos7.5-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos7.5/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos7.5-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos7.5/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos7.5-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: centos7.5-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos7.5/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos7.5-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos7.5/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos7.5-x86_64/initrd.img
Writing template files for centos7.5-x86_64
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: centos7.5-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 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 ***

第十步、查看刪除

查看profile

[[email protected] ~]# cobbler profile list
   centos7.5-x86_64
   centos7.5_ken

刪除原有profile

[[email protected] ~]# cobbler profile remove --name=centos7.5-x86_64
[[email protected] ~]# cobbler profile list
   centos7.5_ken

cobbler自動化安裝測試

新建一個虛擬機,需要和cobbler服務器所在同一個虛擬網絡中即與我們上面設置的cobbler服務器的主機模式。內存需要3個G以上。

技術分享圖片

選擇第我們自定義的包即可進行自動化安裝。

技術分享圖片

技術分享圖片

技術分享圖片

基於Centos7系統部署cobbler批量安裝系統