Cobbler實現自動化無人值守網絡批量安裝部署Linux系統

1、Cobbler(直譯爲補鞋匠)python

   使用 Cobbler,您無需進行人工干預便可安裝機器。Cobbler 設置一個 PXE 引導環境(它還可以使用 yaboot 支持 PowerPC),並控制與安裝相關的全部方面,好比網絡引導服務(DHCP 和 TFTP)與存儲庫鏡像。當但願安裝一臺新機器時,Cobbler 能夠:linux

1.使用一個之前定義的模板來配置 DHCP 服務(若是啓用了管理 DHCP)
2.將一個存儲庫(yum 或 rsync)創建鏡像或解壓縮一個媒介,以註冊一個新操做系統
3.在 DHCP 配置文件中爲須要安裝的機器建立一個條目,並使用您指定的參數(IP 和 MAC 地址)
4.在 TFTFP 服務目錄下建立適當的 PXE 文件
5.從新啓動 DHCP 服務以反映更改
6.從新啓動機器以開始安裝(若是電源管理已啓用)

    Cobbler 支持衆多的發行版:Red Hat、Fedora、CentOS、Debian、Ubuntu 和 SuSE。當添加一個操做系統(一般經過使用 ISO 文件)時,Cobbler 知道如何解壓縮合適的文件並調整網絡服務,以正確引導機器。git

    Cobbler 使用命令行方式管理,也提供了基於Web的圖形化配置管理工具(cobbler-web)。github

    經過配置cobbler自動部署DHCP、TFTP、HTTP,在安裝過程當中加載kiskstart無人值守安裝應答文件實現無人值守。從客戶端使用PXE引導啓動安裝。web


2、安裝EPEL源shell

# wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# rpm -ivh epel-release-latest-7.noarch.rpm
# yum repolist      ##檢查是否已添加至源列表


3、關閉SELinux和防火牆django

a、臨時關閉(不用重啓機器): json

# setenforce 0                       ##設置SELinux 成爲permissive模式  (關閉SELinux)
# setenforce 1                       ##設置SELinux 成爲enforcing模式     (開啓SELinux)

    

b、修改配置文件須要重啓機器:centos

# vi /etc/selinux/config

將SELINUX=enforcing 改成SELINUX=disabled(需重啓機器)瀏覽器


c、可本身作策略開放相應端口,這裏我直接關閉:

# systemctl status firewalld.service       ##查看防火牆狀態
# systemctl stop firewalld.service         ##關閉防火牆


4、cobbler安裝配置


①安裝

# yum install cobbler cobbler-web     ##安裝cobbler和其web管理工具
爲依賴而安裝:
 PyYAML                         
 libyaml                         
 mod_ssl                         
 mod_wsgi                        
 python-cheetah                 
 python-django                   
 python-django-bash-completion   
 python-markdown                 
 python-netaddr                  
 python-pillow                  
 python-pygments                 
 python-simplejson               
 tftp-server                     
 xinetd   
# yum install dhcp httpd rsync
# yum install fence-agents            ##執行電源管理活動的代理包


②配置


  1. 配置http服務器

# vi /etc/httpd/conf/httpd.conf
ServerName 127.0.0.1:80
# systemctl start httpd.service


2.配置tftp

# vi /etc/xinetd.d/tftp
disable                 = no
# systemctl start xinetd.service


3.配置cobbler主配置文件

# vi /etc/cobbler/settings
242 manage_dhcp: 1                ##開啓DHCP可管理狀態
258 manage_tftpd: 1               ##開啓tftp管理
261 manage_rsync: 1               ##開啓rsync管理
272 next_server:192.168.10.128    ##和cobbler服務器經過http和tftp等協議連接的IP
292 pxe_just_once: 1              ##PXE安裝 只容許一次,防止誤操做
358 restart_dns: 1
359 restart_dhcp: 1
384 server: 192.168.10.128        ##DHCP/PXE網絡引導文件被下載的TFTP服務器的IP


4.配置cobbler可管理服務

# vi /etc/cobbler/modules.conf 
[authentication]
module = authn_configfile
[authorization]
module = authz_allowall
[dns]
module = manage_bind
[dhcp]
module = manage_isc
[tftpd]
module = manage_in_tftpd


5.生成密鑰和配置默認密鑰

使用方法:openssl passwd -1 -salt '任意字符' '密碼'
# openssl passwd -1 -salt 'cobbler' '12345'
$1$cobbler$yheL/tcotyNfj2/ieNTcF.
# vi /etc/cobbler/settings 
101 default_password_crypted: "$1$cobbler$yheL/tcotyNfj2/ieNTcF."   ##安裝完系統root密碼


6.DHCP配置

# vi /etc/cobbler/dhcp.template     ##修改DHCP模板使其分配的地址和Cobbler在同一網段
subnet 192.168.10.0 netmask 255.255.255.0 {           ##修改網段
     option routers             192.168.10.2;           ##修改路由
     option domain-name-servers 114.114.114.114;        ##域名服務器地址
     option subnet-mask         255.255.255.0;            ##子網掩碼
     range dynamic-bootp        192.168.10.111 192.168.10.222;   ##可租用地址範圍
     default-lease-time         21600;               ##默認租約時間
     max-lease-time             43200;                 ##最大租約時間
     next-server                $next_server;         ##指定引導服務器
}


7.啓動服務並檢查

# systemctl start cobblerd.service          ##啓動cobbler
# systemctl enable cobblerd.service
# systemctl status cobblerd.service
cobblerd.service - Cobbler Helper Daemon
   Loaded: loaded (/usr/lib/systemd/system/cobblerd.service; enabled)
   Active: inactive (dead) since 五 2015-09-18 10:28:32 CST; 3s ago
  Process: 46405 ExecStartPost=/usr/bin/touch /usr/share/cobbler/web/cobbler.wsgi (code=exited, status=0/SUCCESS)
  Process: 46404 ExecStart=/usr/bin/cobblerd -F (code=exited, status=0/SUCCESS)
 Main PID: 46404 (code=exited, status=0/SUCCESS)
# 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 : file /etc/xinetd.d/rsync does not exist
3 : debmirror package is not installed, it will be required to manage debian deployments and repositories
Restart cobblerd and then run 'cobbler sync' to apply changes.
# cobbler get-loaders         ##根據提示下載相關文件
task started: 2015-09-18_121450_get_loaders
task started (id=Download Bootloader Content, time=Fri Sep 18 12:14:50 2015)
downloading http://cobbler.github.com/loaders/README to /var/lib/cobbler/loaders/README
downloading http://cobbler.github.com/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading http://cobbler.github.com/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading http://cobbler.github.com/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading http://cobbler.github.com/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading http://cobbler.github.com/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
downloading http://cobbler.github.com/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading http://cobbler.github.com/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading http://cobbler.github.com/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading http://cobbler.github.com/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***
# cobbler sync             ##執行同步
task started: 2015-09-18_122051_sync
task started (id=Sync, time=Fri Sep 18 12:20:51 2015)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/p_w_picpaths
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 /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 p_w_picpaths
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
rendering Rsync files
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 ***


5、掛載鏡像並執行導入cobbler

①掛載並導入

# mkdir /mnt/cdrom
# mount -t auto /dev/cdrom /mnt/cdrom
# cobbler import --name=centos7 --arch=x86_64 --path=/mnt/cdrom ##能夠不指定"--",耐心等待
task started: 2015-09-18_134401_import
task started (id=Media import, time=Fri Sep 18 13:44:01 2015)
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-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 ***


②查看導入源庫列表

# cobbler distro list
  centos7-x86_64
# cobbler profile list
  centos7-x86_64
 
# cobbler distro report          ##顯示具體細節
Name                           : centos7-x86_64
Architecture                   : x86_64
TFTP Boot Files                : {}
Breed                          : redhat
Comment                        : 
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/ks_mirror/centos7-x86_64/p_w_picpaths/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/centos7-x86_64/p_w_picpaths/pxeboot/vmlinuz
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/centos7-x86_64'}
Management Classes             : []
OS Version                     : rhel7
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {}


6、測試


測試中出現問題:

PXE-E32:TFTP open timeout

PXE-M0F:Exiting Inter PXE ROM

operating system not found

緣由:iptables未關閉


安裝成功

wKioL1X70SHC_7VYAABajx5KyV8666.jpg

最小化安裝的centos沒法使用ifconfig命令,使用ip addr查看DHCP分配地址

wKiom1X70sGSXQEkAAGTgAkJp1Y190.jpg

客戶端登陸並使用命令yum install net-tools安裝軟件包便可使用ifconfig


7、修改profile指定新的KS啓動文件

在第一次導入系統鏡像時,cobbler會給安裝鏡像指定一個默認的kickstart自動安裝文件,

文件位於/var/lib/cobbler/kickstarts/sample.ks

# cobbler profile list                 ##查看profile列表
# cobbler profile report --name centos7-x86_64   ##查看具體profile設置
# cobbler distro report --name  centos7-x86_64    ##查看安裝鏡像文件信息
# cobbler profile remove --name=centos7-x86_64    ##移除profile(可不移除,但需在被安裝
                                                               主機上進行選擇)
# cobbler profile add --name=centos7-1503 --distro=centos7-x86_64 
  --kickstart=/var/lib/cobbler/kickstarts/centos7-1503.ks    ##添加profile
# cobbler sync  ##進行同步


kiskstart自動安裝文件可以使用圖形界面工具system-config-kickstart生成

# yum install system-config-kickstart
# yum groupinstall "X Window System"      ##安裝X Window圖形界面
# system-config-kickstart             ##運行工具進行配置


這裏我根據本機的/root/anaconda-ks.cfg文件進行相應更改來製做ks文件

直接更改/var/lib/cobbler/kickstarts下的sample.ks和sample_end.ks文件.

# vi /var/lib/cobbler/kickstarts/sample.ks     
# vi /var/lib/cobbler/kickstarts/sample_end.ks  ##兩個文件更改、添加以下
# System language          ##更改系統語言
lang zh_CN.UTF-8
# System timezone          ##更改系統時間
timezone Asia/Shanghai --isUtc
# X Window System configuration information      ##安裝X Window圖形界面
xconfig  --startxonboot
%packages                ##安裝相關包
@base
@core
@desktop-debugging
@dial-up
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@multimedia
@print-client
@x11
%end
# cobbler sync               ##同步


命令:cobbler profile add|edit|remove --name=安裝引導名 --distro=系統鏡像名 

--kickstart=kickstart自動安裝文件路徑


參數說明:

--name:自定義的安裝引導名,注意不能重複

--distro:系統安裝鏡像名,用cobbler distro list能夠查看

--kickstart:與系統鏡像文件相關聯的kickstart自動安裝文件(此文件必須預先準備好)

# cobbler list   ##查看cobbler列表
# cobbler report   
# cobbler profile     ##profile命令列表
# cobbler profile list  ##profile文件列表
# cobbler distro list   ##查看導入列表
# cobbler system add

更多命令參數可執行cobbler --help查看


爲cobbler添加RPM倉庫:

# cobbler repo add --mirror=http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rp  --name=epel7 --arch=x86_64 --breed=yum     ##添加EPEL源
# cobbler reposync   ##同步源

8、使用Cobbler-web


瀏覽器中輸入:https://IP/cobbler_web便可進入

wKiom1X72L6gTZZfAADPiGHCoVg379.jpg

Cobbler-web有多種認證方式(默認authn_configfile模塊認證):

# vi /etc/cobbler/modules.conf
[authentication]
module = authn_configfile        ##認證方式

 用戶名和密碼存放處(默認用戶名和密碼爲cobbler):

# vi /etc/cobbler/users.digest
cobbler:Cobbler:a2d6bae81669d707b72c0bd9806e01f3      ##用戶名和密碼

wKioL1X747aBMUAXAADkq7C5mcU363.jpg

這樣就可使用Web來部署了


問題:如使用cobbler check檢查或cobbler sync同步出現以下問題:

# cobbler check
# cobbler sync
httpd does not appear to be running and proxying cobbler, or SELinux is in the way. Original traceback:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/cobbler/cli.py", line 252, in check_setup
    s.ping()
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1224, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1578, in __request
    verbose=self.__verbose
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1264, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1292, in single_request
    self.send_content(h, request_body)
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1439, in send_content
    connection.endheaders(request_body)
  File "/usr/lib64/python2.7/httplib.py", line 969, in endheaders
    self._send_output(message_body)
  File "/usr/lib64/python2.7/httplib.py", line 829, in _send_output
    self.send(msg)
  File "/usr/lib64/python2.7/httplib.py", line 791, in send
    self.connect()
  File "/usr/lib64/python2.7/httplib.py", line 772, in connect
    self.timeout, self.source_address)
  File "/usr/lib64/python2.7/socket.py", line 571, in create_connection
    raise err
error: [Errno 111] Connection refused

解決方法:

# systemctl start httpd.service
# systemctl start xinetd.service

未啓動http服務和xinetd服務;SELinux或防火牆問題。


附1:Cobbler目錄說明

①Cobbler配置文件目錄:/etc/cobbler
/etc/cobbler/settings          ##cobbler主配置文件
/etc/cobbler/dhcp.template      ##DHCP服務的配置模板
/etc/cobbler/tftpd.template       ##tftp服務的配置模板
/etc/cobbler/rsync.template        ##rsync服務的配置模板
/etc/cobbler/iso                 ##iso模板配置文件
/etc/cobbler/pxe                   ##pxe模板文件
/etc/cobbler/power          ##電源的配置文件
/etc/cobbler/users.conf       ##Web服務受權配置文件
/etc/cobbler/users.digest       ##用於web訪問的用戶名密碼配置文件
/etc/cobbler/dnsmasq.template     ##DNS服務的配置模板
/etc/cobbler/modules.conf           ##Cobbler模塊配置文件
②Cobbler數據目錄:/var/lib/cobbler
/var/lib/cobbler/config              ##配置文件
/var/lib/cobbler/triggers          ##Cobbler命令
/var/lib/cobbler/kickstarts        ##默認存放kickstart文件
/var/lib/cobbler/loaders             ##存放的各類引導程序
③系統安裝鏡像目錄:/var/www/cobbler
/var/www/cobbler/ks_mirror               ##導入的系統鏡像列表
/var/www/cobbler/p_w_picpaths             ##導入的系統鏡像啓動文件
/var/www/cobbler/repo_mirror            ##yum源存儲目錄
④日誌目錄:/var/log/cobbler
/var/log/cobbler/install.log         ##客戶端系統安裝日誌
/var/log/cobbler/cobbler.log           ##cobbler日誌


附2:http://cobbler.github.io/manuals/quickstart/#

相關文章
相關標籤/搜索