天天看點

cobbler批量化安裝系統-CentOS7

1.1 cobbler簡介

  

cobbler批量化安裝系統-CentOS7
cobbler批量化安裝系統-CentOS7

1.1.1 cobbler內建的服務

    PXE服務支援

    DHCP服務管理

    DNS服務管理(可選bind,dnsmasq)

    電源管理

    Kickstart服務支援

    YUM倉庫管理

    TFTP(PXE啟動時需要)

    Apache(提供kickstart的安裝源,并提供定制化的kickstart配置)

1.2 安裝cobbler

1.2.1 環境說明

[root@Cobbler ~]# cat /etc/redhat-release

CentOS Linux release 7.2.1511 (Core)

[root@Cobbler ~]# uname -r

3.10.0-693.el7.x86_64

[root@Cobbler ~]# getenforceDisabled

[root@Cobbler ~]# systemctl status firewalld.service

● firewalld.service - firewalld - dynamic firewall daemon

Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)

Active: inactive (dead)

Docs: man:firewalld(1)

[root@Cobbler ~]# hostname -I

10.0.0.202 172.16.1.202

先配置好yum源:

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

1.2.2 使用yum安裝cobbler

yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd

   說明:cobbler是依賴與epel源下載下傳

1.2.3 cobbler文法檢查前先啟動http與cobbler

systemctl start httpd.service

systemctl start cobblerd.service

cobbler check

1.2.4 進行文法檢查

[root@Cobbler ~]# 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 : change 'disable' to 'no' in /etc/xinetd.d/tftp

4 : 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.

5 : enable and start rsyncd.service with systemctl

6 : debmirror package is not installed, it will be required to manage debian deployments and repositories

7 : 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

8 : 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.

1.2.5 解決當中的報錯

指令集合

########################################################################################################

sed -i 's/server: 127.0.0.1/server: 172.16.1.63/' /etc/cobbler/settings

sed -i 's/next_server: 127.0.0.1/next_server: 172.16.1.63/' /etc/cobbler/settings

sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings

sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings

sed -i 's#yes#no#' /etc/xinetd.d/tftp

sed -ri "/default_password_crypted/s#(.*: ).*#\1\"`openssl passwd -1 -salt 'asasd' '123456'`\"#" /etc/cobbler/settings

systemctl start rsyncd

systemctl enable rsyncd

systemctl enable tftp.socket

systemctl start tftp.socket

systemctl restart cobblerd.service

sed -i.ori 's#192.168.1#172.16.1#g;22d;23d' /etc/cobbler/dhcp.template

cobbler sync

以上指令詳解

解決1、2

#/etc/cobbler/setting中的server配置需要修改,将127.0.0.1修改為cobbler伺服器ip

cp /etc/cobbler/settings{,.ori}

sed -i 's/server: 127.0.0.1/server: 172.16.1.202/' /etc/cobbler/settings

sed -i 's/next_server: 127.0.0.1/next_server: 172.16.1.202/' /etc/cobbler/settings

問題3

#讓xinetd管理thtp服務

sed 's#yes#no#g' /etc/xinetd.d/tftp -i

4下載下傳包所需的軟體包

[root@Cobbler ~]# cobbler get-loaders

[root@Cobbler ~]# ls /var/lib/cobbler/loaders

COPYING.elilo elilo-ia64.efi menu.c32 yaboot

COPYING.syslinux grub-x86_64.efi pxelinux.0

COPYING.yaboot grub-x86.efi README

5啟動rsync服務

[root@Cobbler ~]# systemctl start rsyncd.service

[root@Cobbler ~]# systemctl enable rsyncd.service

6 debian相關無需修改

7、修改安裝完成後的root密碼

openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'

random-phrase-here 随機字元串(不是使用者名)

your-password-here 密碼

示例

[root@Cobbler ~]# openssl passwd -1 -salt 'sdfsdf' '123456'

$1$CLSN$LpJk4x1cplibx3q/O4O/K/

管理dhcp

防止重裝

修改dhcp模闆(切記不可連續執行)

cobbler組配置檔案位置

/etc/cobbler/settings

注意:修改完成之後要使用cobbler sync 進行同步,否則不生效。

1.2.6 修改之後

再次檢查文法:

1 : debmirror package is not installed, it will be required to manage debian deployments and repositories

2 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them

重新開機所有服務

systemctl restart httpd.service

systemctl restart dhcpd.service

systemctl restart rsyncd.service

systemctl restart tftp.socket

到此cobbler就安裝完成,下面進行web界面的操作。

1.3 cobbler的web及界面操作

浏覽器通路https://10.0.0.63/cobbler_web

   注意CentOS7中cobbler隻支援https通路。

   賬号密碼預設均為cobbler

cobbler批量化安裝系統-CentOS7
cobbler批量化安裝系統-CentOS7

1.3.1 操作說明--導入鏡像

1)在虛拟機上添加上鏡像

cobbler批量化安裝系統-CentOS7
cobbler批量化安裝系統-CentOS7

2)挂載上鏡像

[root@Cobbler ~]# mount /dev/cdrom /mnt/

mount: /dev/sr0 is write-protected, mounting read-only

[root@Cobbler ~]# df -h |grep mnt

/dev/sr0 4.3G 4.3G 0 100% /mnt

   3)進行導入鏡像

   選擇Import DVD  輸入Prefix(檔案字首),Arch(版本),Breed(品牌),Path(要從什麼地方導入)

   鏡像路徑在導入鏡像的時候要注意路徑,防止循環導入。

   資訊配置好後,點選run,即可進行導入。

cobbler批量化安裝系統-CentOS7
cobbler批量化安裝系統-CentOS7

導入過程使用rsync進行導入,三個程序消失表示導入完畢

[root@Cobbler mnt]# ps -ef |grep rsync

root 12026 1 0 19:04 ? 00:00:00 /usr/bin/rsync --daemon --no-detach

root 13554 11778 12 19:51 ? 00:00:06 rsync -a /mnt/ /var/www/cobbler/ks_mirror/CentOS7.4-x86_64 --progress

root 13555 13554 0 19:51 ? 00:00:00 rsync -a /mnt/ /var/www/cobbler/ks_mirror/CentOS7.4-x86_64 --progress

root 13556 13555 33 19:51 ? 00:00:17 rsync -a /mnt/ /var/www/cobbler/ks_mirror/CentOS7.4-x86_64 --progress

root 13590 10759 0 19:52 pts/1 00:00:00 grep --color=auto rsync

檢視日志可以發現右running程序

      日志位于 Events

cobbler批量化安裝系統-CentOS7
cobbler批量化安裝系統-CentOS7

導入完成後生成的檔案夾

[root@Cobbler ks_mirror]# pwd

/var/www/cobbler/ks_mirror

[root@Cobbler ks_mirror]# ls

CentOS7.4-x86_64 config

1.3.2 建立一台空白虛拟機,進行測試網路安裝

注意:虛拟機的記憶體不能小于2G,網卡的配置要保證網絡互通

啟動虛拟機

   啟動虛拟機即可發現會有cobbler的選擇界面

cobbler批量化安裝系統-CentOS7
cobbler批量化安裝系統-CentOS7

選擇CentOS7.4即可進行安裝,安裝過程與CD光牒安裝一緻,這裡就不在複述。

1.4 定制化安裝作業系統

1.4.1 添加核心參數

1)檢視導入的鏡像,點選edit

cobbler批量化安裝系統-CentOS7
cobbler批量化安裝系統-CentOS7

2)在核心參數中添加net.ifnames=0 biosdevname=0

   能夠讓顯示的網卡變為eth0 ,而不是CentOS7中的ens33

   修改完成後點選儲存

cobbler批量化安裝系統-CentOS7
cobbler批量化安裝系統-CentOS7

1.4.2 檢視鏡像屬性

cobbler批量化安裝系統-CentOS7
cobbler批量化安裝系統-CentOS7

1.4.3 編寫ks檔案

另一種方法:

1)建立新的ks檔案

cobbler批量化安裝系統-CentOS7
cobbler批量化安裝系統-CentOS7

2)添加ks檔案,并配置檔案名

      建立完成後點選Save進行儲存

cobbler批量化安裝系統-CentOS7
cobbler批量化安裝系統-CentOS7

CentOS7  ks配置檔案參考

# Cobbler for Kickstart Configurator for CentOS 7 by yao zhang

install

url --url=$tree

text

lang en_US.UTF-8

keyboard us

zerombr

bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"

#Network information

$SNIPPET('network_config')

#network --bootproto=dhcp --device=eth0 --onboot=yes --noipv6 --hostname=CentOS7

timezone --utc Asia/Shanghai

authconfig --enableshadow --passalgo=sha512

rootpw  --iscrypted $default_password_crypted

clearpart --all --initlabel

part /boot --fstype xfs --size 1024

part swap --size 1024

part / --fstype xfs --size 1 --grow

firstboot --disable

selinux --disabled

firewall --disabled

logging --level=info

reboot

%pre

$SNIPPET('log_ks_pre')

$SNIPPET('kickstart_start')

$SNIPPET('pre_install_network_config')

# Enable installation monitoring

$SNIPPET('pre_anamon')

%end

%packages

@^minimal

@compat-libraries

@core

@debugging

@development

bash-completion

chrony

dos2unix

kexec-tools

lrzsz

nmap

sysstat

telnet

tree

vim

wget

%post

systemctl disable postfix.service

1.4.4 自定義安裝系統

1)選擇systems 建立一個新的系統

cobbler批量化安裝系統-CentOS7
cobbler批量化安裝系統-CentOS7

2)定義系統資訊

cobbler批量化安裝系統-CentOS7
cobbler批量化安裝系統-CentOS7

3)配置全局網絡資訊

      可以配置主機名、網關、DNS等

        我這裡面是雙網卡,是以隻配置主機名和DNS

cobbler批量化安裝系統-CentOS7
cobbler批量化安裝系統-CentOS7

4)配置網卡資訊,eth0,eth1

   需要注意,選擇static靜态,

cobbler批量化安裝系統-CentOS7
cobbler批量化安裝系統-CentOS7

   以上的所有配置完成後,點選Save進行儲存

附錄:

   VMware workstation中檢視虛拟機mac位址的方法。在虛拟機設定中。

cobbler批量化安裝系統-CentOS7

 cobbler web 界面說明

cobbler批量化安裝系統-CentOS7

1.5 安裝虛拟機

1.5.1 開啟虛拟機

如果之前的設定就顯示安裝進度

cobbler批量化安裝系統-CentOS7
cobbler批量化安裝系統-CentOS7

1.5.2 安裝完成進行檢查
cobbler批量化安裝系統-CentOS7

cobbler批量化安裝系統-CentOS7

1.6 cobbler使用常見錯誤

1.6.1 cobbler check報錯

[root@Cobbler ~]# cobbler syncTraceback (most recent call last):

File "/usr/bin/cobbler", line 36, in <module>

sys.exit(app.main())

File "/usr/lib/python2.7/site-packages/cobbler/cli.py", line 662, in main

rc = cli.run(sys.argv)

File "/usr/lib/python2.7/site-packages/cobbler/cli.py", line 269, in run

self.token = self.remote.login("", self.shared_secret)

File "/usr/lib64/python2.7/xmlrpclib.py", line 1233, in __call__

return self.__send(self.__name, args)

File "/usr/lib64/python2.7/xmlrpclib.py", line 1587, in __request

verbose=self.__verbose

File "/usr/lib64/python2.7/xmlrpclib.py", line 1273, in request

return self.single_request(host, handler, request_body, verbose)

File "/usr/lib64/python2.7/xmlrpclib.py", line 1306, in single_request

return self.parse_response(response)

File "/usr/lib64/python2.7/xmlrpclib.py", line 1482, in parse_response

return u.close()

File "/usr/lib64/python2.7/xmlrpclib.py", line 794, in close

raise Fault(**self._stack[0])

xmlrpclib.Fault: <Fault 1: "<class 'cobbler.cexceptions.CX'>:'login failed'">

解決辦法

1.6.2 No space left on device

cobbler批量化安裝系統-CentOS7

   出現這個錯誤的原因是虛拟機的記憶體不足2G,

   将記憶體調為2G即可(這個錯誤隻會出現在CentOS7.3之上)

小夥伴們可以關注我的微信公衆号:linux運維菜鳥之旅

cobbler批量化安裝系統-CentOS7

關注“中國電信天津網廳”公衆号,首次綁定可免費領2G流量,為你的學習提供流量! 

繼續閱讀