1. 程式人生 > >自動化運維之cobbler安裝多版本系統

自動化運維之cobbler安裝多版本系統

ado XML field 問題 som cfg 當前 command nag

一、引言與概述

1、說明
本文是緊接上一篇<自動化運維之CentOS7下PXE+Kickstart+DHCP+TFTP+HTTP無人值守安裝系統>補充篇,或叫基於上篇相關技術之上構建的cobbler服務;因此省略了部分服務的安裝配置;部署也是在之前的基礎上進行的;
2、cobbler介紹
cobbler是基於pxe kickstart,tftp-server,httpd,dhcp等綜合管理;基於python的包裝與二次開發;管理多個(linux)系統安裝環境(如通過CentOS7/centos6不同系統鏡像(distro) 基於不同kickstart(profile) 安裝出不同系統環境(system)),既可以通過命令去操作管理,也可以通過web管理(需要單獨安裝配置);

3、環境說明
環境基於上文中的測試環境即:
ip:172.16.3.152 (可上網)
內部測試ip(僅主機模式) 192.168.56.254
已經安裝好的服務:DHCP,tftp-server,httpd,syslinux

二、安裝cobbler服務

cobbler的安裝需要基於EPEL擴展倉庫因此需要先安裝epel
[root@pxe ~]# yum install epel-release -y
1、安裝cobbler

[root@pxe ~]# yum install cobbler cobbler-web pykickstart debmirror -y
安裝好先啟動cobblerd服務
[root@pxe ~]# systemctl start cobblerd
##檢查配置信息
[root@pxe yum.repos.d]# cobbler check
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 251, in check_setup
    s.ping()
  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 1321, in single_request
    response.msg,
ProtocolError: <ProtocolError for 127.0.0.1:80/cobbler_api: 404 Not Found>
解決方法:
禦載pxe時的光盤掛載web目錄
[root@pxe ~]# umount /var/www/html/centOS/7/x86_64
[root@pxe ~]# systemctl restart cobbler
#再次檢查
[root@pxe ~]# 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 : comment out ‘dists‘ on /etc/debmirror.conf for proper debian support
6 : comment out ‘arches‘ on /etc/debmirror.conf for proper debian support
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.

此時會發現有很多警告提示信息;不要緊,咱接下來一一解決
2、配置cobbler
a,針對以上第一條解決如下:
需要修改settings中的 server修改為本地的對外ip地址,如下是本次測試修改地址;

[root@pxe ~]# egrep -v ‘(^$|^#)‘ |grep "server:" /etc/cobbler/settings
server: 192.168.56.254

b,第二條解決:
修改next_server 即提供tftp-server的地址,由於本機就提供tftp-server故修改如下:

[root@pxe ~]# egrep -v ‘(^$|^#)‘ |grep "next_server:" /etc/cobbler/settings
next_server: 192.168.56.254

c,第三條
如果當前節點可以訪問互聯網,執行“cobbler get-loaders”命令亦可;或安裝syslinux程序包,再復制/usr/share/syslinux/{pxelinux.0,menu.c32}等文件至/var/lib/cobbler/loaders/目錄中;由於本次已經安裝好了syslinux,網速可能比較慢幫直接從syslinux中復制boot-loaders
[root@pxe ~]# cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/cobbler/loaders/

d,第四條
添加rsyncd服務開機啟動,如果沒有安裝此包請yum安裝
[root@pxe ~]# systemctl enable rsyncd
e,第五條和第六條
修改配置文件/etc/debmirror.conf 註釋第28 30行#@dists="sid";
br/>#@dists="sid";

f,第七條
生成密碼再替換到/etc/cobbler/settings配置文件中

[root@pxe ~ ]# openssl passwd -1 redhat
$1$YRGo5nnj$N99AHSP0wu5Y4Zhalrsqu/
大約在101行:
default_password_crypted: "$1$YRGo5nnj$N99AHSP0wu5Y4Zhalrsqu/"

說明:這個密碼是通過cobbler默認profile(kickstart)配置文件安裝好系統後的root默認密碼;

g,第八條
安裝相應的程序包即可;
[root@pxe ~ ]# yum install cman fence-agents
最後重啟cobblerd服務

[root@pxe ~ ]# systemctl restart cobblerd 
同步配置至cobbler
[root@pxe ~ ]# cobbler sync
再次檢查
[root@pxe ~ ]# cobbler check
No configuration problems found.  All systems go.

如果第三條使用cobbler get-loaders命令自動生成loaders文件就會像以上提示一樣沒有任務提示了;但要是自己復制,可能還會有第三條的警告提示,但不管如何都沒有問題了;

三、cobbler配置

通過以上配置cobbler部分基礎部分已經配置完成;接下來就是配置cobbler中的distro(可以理解為系統倉庫),profile(可以理解為針對distro的kickstart配置文件);基於distro和profile文件我們就可以來定制安裝我們的系統環境啦!
1、配置distro
加載CentOS7_x86_64_1511系統光盤

[root@pxe ~ ]# mount /dev/cdrom /media/cdrom
[root@pxe ~ ]# cobbler import --name="CentOS-7_x86_64-1511" --path=/media/cdrom

註意這個過程需要點時間,原因就是把cdrom中的鏡像復制到/var/www/cobller的對應目錄中
查看生成的distro和針對這個distro默認生成的profile

[root@pxe~ ]# cobbler distro list
   CentOS-7-1511-x86_64
[root@pxe lpxe ~ ]# cobbler profile list
   CentOS-7-1511-x86_64

2、同步配置文件
[root@pxe lpxe ~ ]# cobbler sync

新建一臺虛擬機測試:
網絡配置和過程同上文中的一樣;引導菜單效果如下:
技術分享圖片
local是默認的本地設備,這裏沒有用,選擇CentOS-7-1511-x86_64 即可安裝,這裏默認的是字符安裝;

3、定制自已的profile文件
由於默認的kickstart profile文件引導安裝時是無圖形是最小化安裝,因此我要定制一個porfile文件
a,先重命令默認profile文件

[root@pxe~ ]# cobbler profile rename --name=CentOS-7-1503-x86_64 --newname=CentOS7-7-1503-x86_64-minimal
[root@pxe~ ]# cobbler profile list
   CentOS7-7-1503-x86_64-minimal

b,定制
復制之前PXE時的kickstart cfg文件並修改url

[root@pxe~ ]# cp /var/www/html/ks/ks.cfg   /var/lib/cobbler/kickstarts/
修改ks中的url如下:
url --url=http://192.168.56.254/cobbler/ks_mirror/CentOS-7_x86_64-1511

#添加新的profile
[root@pxe kickstarts]# cobbler profile add --name=CentOS-7-x86_64-1503-server --distro=CentOS-7-1503-x86_64 --kickstart=/var/lib/cobbler/kickstarts/xx.cfg
#查看profile
[root@pxe kickstarts]# cobbler profile list
   CentOS-7-1511-x86_64-minimal
   CentOS-7-x86-1511-server
#重啟與同步cobbler配置
[root@pxe kickstarts]# systemctl restart cobblerd
[root@pxe kickstarts]# cobbler sync

再次新建一臺虛擬機網絡引導安裝測試:
技術分享圖片
選擇CentOS-7-x86-1511-server會自動進入圖形化安裝界面如圖:
技術分享圖片

以上是針對CentOS7的安裝與定制profile,既然cobbler能針對不同linxu發行版提供安裝環境;那麽接下來我們就加入centOS6的distro與profile安裝CentOS6系統
4、添加CentOS6 distro
添加CenOS6.7的distro

[root@pxe kickstarts]# cobbler import --name="CentOS-6_x86_64-7" --path=/media/cdrom
查看distro與profile
[root@pxe ~]# cobbler distro list
   CentOS-6-7-x86_64
   CentOS-7-1511-x86_64
[root@pxe ~]# cobbler profile list
   CentOS-6-7-x86_64
   CentOS-7-1511-x86_64-minimal
   CentOS-7-x86-1511-server
#同步配置文件
[root@pxe ~]# cobbler sync

再次新建一臺虛擬機網絡引導安裝測試時,引導菜單如下:
技術分享圖片
選擇CentOS-6-7-x86_64後自動化安裝如下:
技術分享圖片

總結:

cobbler通過基於PXE Kickstart(profile),dhcp,httpd,系統鏡像(distro),tftp-server等服務的包裝開發後,可能實現提供多種發版本即發行版的統一自動網絡安裝;主要分三大步:基礎配置好cobbler服務;通過光盤導入一個或多個distro,在此過程中會生成默認的profile文件;也可以自行定制profile文件;再基於distro與profile文件來安裝具體的生產系統;

自動化運維之cobbler安裝多版本系統