cobbler实现无人值守自动安装

简介:

Cobbler简介

    使用cobbler,第一件事就是定义其distros 指的是定义一个特殊发行版的内核和init文件,这意味着我们要使用独立运行系统之外的独立引导内核来实现,也就是说要启动这个操作系统,首先加载的是init和内核文件,在我们真正启动系统之后initrd和内核则只要不重启则不会被使用,所以distros 主要是用来借助于外在的内核和initrd进行启动系统,而后通过其装置根进行部署

 

定义distros的方式有两种

·自己准备外部的内核和initrd 用来引导一些特殊的映像文件

·定义自己的引导内核

 

定义profile的时候核心是ks文件

因此定义profile的主要目的就是指向不同的ks文件的,这些不同的ks文件内部的repo所指的yum源则是同一个,因为我们指的是同一个distros,这些distros指向同一个源

只不过这些源里的程序包不一定每个都需要安装

某种特定场景下,我们可能只需要安装部分包,这些包定义到底安装哪些就是由ks定义的

所以profile的前提或最根本的目的就是指定一个ks文件,并给其指定一个lobale

 

这些ks文件是不一样的,所以本身安装的程序包就不一样

 

profile可以继承子profile等

所以在其层次做一个通用的profile在通用的profile分几个不通用的子profile

对我们而言不用考虑那么多,除非管理规模达到上千台的时候这时候子profile才有意义

 

 

systems

有些时候在虚拟化环境中,虚拟机本身的mac地址是随机生成的,因此有些时候我们不想让其随机生成,想指定一个地址的时候,则使用systems就有意义了,否则意义也不大

 

repos

如果我们是使用distros定义的,也就意味着我们只定义了启动安装过程使用的initrd文件以及vmlinux文件,那么真正的安装树很可能在互联网上,比如网易的镜像

试想:如果安装节点超过50个,这50个都通过一个节点进行安装则非常的慢

所以这时可以将远程的yum源镜像(下载)到本地,这时则需要定义repo 完成快速更新,同时也可以获取最新的更新包

 

其他功能

·bonding

·VLAN

·briding

安装Cobbler

接下来我们在没有pxe的环境下来安装配置cobbler

配置epelyum源

[root@node1 tools]# mkdir cobbler

[root@node1 tools]# cd cobbler/

[root@node1 cobbler]# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

[root@node1 cobbler]# rpm -ivh epel-release-6-8.noarch.rpm

[root@node1 cobbler]# yum install cobbler cobbler-web pykickstart debmirror httpd –y

与此同时还需要确保web服务正常工作,因为cobbler高级功能是依赖于httpd

安装完后其路径位于 /etc/cobbler/ 目录下

[root@node1 cobbler]# ls /etc/cobbler/

auth.conf      dhcp.template           iso           named.template  rsync.exclude       tftpd.template  zone.template

cheetah_macros distro_signatures.json  ldap          power           rsync.template      users.conf      zone_templates

cobbler_bash   dnsmasq.template       modules.conf  pxe             secondary.template  users.digest

completions    import_rsync_whitelist mongodb.conf  reporting       settings            version

本文出自http://yijiu.blog.51cto.com/  转载请注明

 

启动cobbler

cobbler依赖于httpd,所以首先启动httpd再启动cobbler

[root@node1 cobbler]# /etc/init.d/httpd start

[root@node1 cobbler]# /etc/init.d/cobblerd start

查看监听端口

[root@node1 cobbler]# ss -tunlp | grep cobb

tcp    LISTEN     0     5             127.0.0.1:25151                *:*     users:(("cobblerd",2568,9))

 

启动之前需检查环境配置

[root@node1 cobbler]# cobbler check

The following are potential configuration items that youmay want to fix:

 

1 : The 'server' field in /etc/cobbler/settings must beset to something other than localhost, or kickstarting features will notwork.  This should be a resolvablehostname or IP for the boot server as reachable by all machines that will useit.

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 shouldmatch the IP of the boot server on the PXE network.

3 : SELinux is enabled. Please review the following wikipage for details on ensuring cobbler works correctly in your SELinuxenvironment:

   https://github.com/cobbler/cobbler/wiki/Selinux

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 youhave installed a *recent* version of the syslinux package installed and canignore this message entirely.  Files inthis directory, should you want to support all architectures, should includepxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' commandis the easiest way to resolve these requirements.

5 : change 'disable' to 'no' in /etc/xinetd.d/rsync

6 : comment out 'dists' on /etc/debmirror.conf for properdebian support

7 : comment out 'arches' on /etc/debmirror.conf forproper debian support

8 : The default password used by the sample templates fornewly installed machines (default_password_crypted in /etc/cobbler/settings) isstill 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 usethe (optional) power management features. install cman or fence-agents to usethem

 

Restart cobblerd and then run 'cobbler sync' to applychanges.

可发现其检查爆出一系列信息,这一堆信息都需要我们自己手动去修改的

 

1./etc/cobbler/settings 的参数必须指定能够跟web主机交互的值而不能使用localhost,否则可能无法工作,因此要改server的自己,而server的地址应该是向外提供服务的地址

2.PXE服务要启动起来  /etc/cobbler/settings 配置文件中的next_server要指定tftp服务器,而不能使用127.0.0.1,就算是当前主机也必须指定一个能够跟其他主机通信的地址

解决如下:

找到next_server和 server分别改为网络地址

[root@node1 ~]# vim /etc/cobbler/settings

更改参数为:

next_server: 10.0.10.61

server: 10.0.10.61

 

3.需将selinux关闭

4.因为cobbler可能需要向各种不同的主机提供安装,但他们的安装方式可能各有不同,因此要为不同的版本都提供不同的服务,因此它所提供的有pxelinux.0, menu.c32, elilo.efi 等

需在联网的环境下执行

[root@node1 ~]# cobbler get-loaders

如果不能联网则需要安装syslinux去复制pxelinux.0 memu.c32 这几个文件即可

查看是否下载成功

[root@node1 ~]# 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启动起来,将参数distable从yes改为no

[root@node1 ~]# chkconfig rsync on

 

6/7.将配置文件/etc/debmirror.conf 中dists和arches 注释掉

vim /etc/debmirror.conf

将以下参数注释

#@dists="sid";

#@arches="i386";

 

8.默认的密码,因为colbber配置文件中为每个装好操作系统的管理员用户都提供了默认密码,这里我们需要定义为自己所需要的密码

[root@node1 cobbler]# openssl passwd -1 -salt `openssl rand -hex 4`

Password:

$1$faa927d5$mqa11pGo9/ILeHGm.sfNI1

复制粘贴至settings 

[root@node1 cobbler]# vim settings 

找到参数default_password_crypted,并修改为:

default_password_crypted:"$1$e9ef99ab$kC3I.Be1E58r8xvbQ5KTA."

 

9.实现电源管理,如果想使用这种功能需要安装cman和face-agents才可以

这个没有太大关系如果介意的话可以使用yum安装

[root@node1 cobbler]# yum -y install cman fence-agents

重启服务并重新检测配置

[root@node1 cobbler]# /etc/init.d/cobblerd restart

Stopping cobbler daemon:                                   [  OK  ]

Starting cobbler daemon:                                   [  OK  ]

[root@node1 cobbler]# cobbler check

The following are potential configuration items that youmay want to fix:

 

1 : SELinux is enabled. Please review the following wikipage for details on ensuring cobbler works correctly in your SELinuxenvironment:

   https://github.com/cobbler/cobbler/wiki/Selinux

 

Restart cobblerd and then run 'cobbler sync' to applychanges.

#PS:我的环境已将selinux关闭了,可check的时候依旧报出此条信息,目前暂时没有解决

 

同步cobbler

同步cobbler,将所数据都会同步到对应的目录下

[root@node1 ~]# cobbler sync

同步过后,将会在/var/lib/tftpboot/会生成一堆文件

[root@node1 ~]#  ll/var/lib/tftpboot/

total 300

drwxr-xr-x. 3 root root  4096 Aug 11 16:02 boot

drwxr-xr-x. 2 root root  4096 Aug 11 16:02 etc

drwxr-xr-x. 2 root root  4096 Aug 11 16:02 grub

drwxr-xr-x. 2 root root  4096 Jul 19 06:59 images

-rw-r--r--. 1 root root 54964 Aug 11 16:02 menu.c32

drwxr-xr-x. 2 root root  4096 Aug 11 16:02 ppc

-rw-r--r--. 1 root root 16794 Aug 11 16:02 pxelinux.0

drwxr-xr-x. 2 root root  4096 Aug 11 16:02 pxelinux.cfg

drwxr-xr-x. 2 root root  4096 Aug 11 16:02 s390x

-rw-r--r--. 1 root root 198192 Aug 11 16:02 yaboot

 

使用cobbler

cobbler 是可以自行定义管理模块的,先看下modules.conf

[root@node1 ~]# cd /etc/cobbler/

[root@node1 cobbler]# vim modules.conf 

可以看到每个模块以及模块配置参数都以[XXX]为准 本文出自http://yijiu.blog.51cto.com/  转载请注明

如下所示:

[dns]
module = manage_bind      #mange_bind
表示使用cobbler进行管理bind服务,如果使用dnsmasq则将后面注释去掉即可

[dhcp]
module = manage_isc      #
如果使用cobbler进行管理的话需要改成manage_dnsmasq 因为manage_dnsmasq既可以管理dns服务也可以管理dhcp服务

#默认所有服务都是独立运行的,因为没有必要去管理独立服务,如果有必要的话修改文件:

[root@node1 cobbler]# vim settings

找到相关参数,以tftp为例

manage_tftpd: 1     #将其默认值0改为1即可

我们这里不需要让其独立管理所以还是使用默认值

 

配置DHCP

[root@node1 cobbler]# yum install -y dhcp

[root@node1 cobbler]# cp/usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf

这里我们想让cobbler帮我们管理dhcp服务,则需要以下操作

直接替换参数,1为使cobbler进行管理

[root@node1 cobbler]# sed -i 's/manage_dhcp:0/manage_dhcp: 1/g' /etc/cobbler/settings

把manage_dhcp的值改为1 这样cobbler会根据dhcp.template 生成 dhcp.conf

[root@node1 cobbler]# vim /etc/cobbler/dhcp.template

修改如下:

subnet 10.0.10.0 netmask 255.255.255.0 {

     optionrouters             10.0.10.61;

本文出自http://yijiu.blog.51cto.com/  转载请注明

     optiondomain-name-servers 10.0.10.1;

     optionsubnet-mask         255.255.255.0;

     rangedynamic-bootp        10.0.10.2010.0.10.30;

    default-lease-time         21600;

    max-lease-time             43200;

    next-server               $next_server;

保存退出

[root@node1 dhcp]# cobbler sync

[root@node1 dhcp]# /etc/init.d/dhcpd status

dhcpd (pid  2652)is running...

dhcp服务是由cobbler来管理,所以每次修改dhcp.template并执行cobbler sync,就会自动更新到/etc/dhcpd.conf中,如果同步时发现服务关闭,会自动将其重启

 

启动tftp

[root@node1 cobbler]# yum install -y tftp tftp-server

[root@node1 cobbler]# chkconfig tftp on

[root@node1 cobbler]# /etc/init.d/xinetd restart

Stopping xinetd:                                          [  OK  ]

Starting xinetd:                                          [  OK  ]

查看监听端口

[root@node1 cobbler]# netstat -lntup | grep 69

tcp        0      0 :::873                      :::*                        LISTEN      9569/xinetd        

udp        0      0 0.0.0.0:69                  0.0.0.0:*                               9569/xinetd 

 

配置cobbler

挂载光盘,并导入其系统到本地

[root@node1 cobbler]# mount /dev/cdrom /media/ -r

[root@node1 cobbler]# df -h

Filesystem           Size  Used Avail Use% Mounted on

/dev/sda3             19G  3.7G   15G 21% /

tmpfs                939M     0  939M  0% /dev/shm

/dev/sda1            291M   33M  243M 12% /boot

/dev/sr0             4.1G  4.1G     0 100% /media

 

[root@node1 cobbler]# ls /media/

CentOS_BuildTag  GPL       Packages                  RPM-GPG-KEY-CentOS-6           RPM-GPG-KEY-CentOS-Testing-6

EFI             images   RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Debug-6    TRANS.TBL

EULA            isolinux  repodata                  RPM-GPG-KEY-CentOS-Security-6

 

将镜像导入到cobbler中

显示已经导入的distro的列表

[root@node1 cobbler]# cobbler distro list

同样使用profile list也可以显示

[root@node1 cobbler]# cobbler profile list

 

导入镜像

[root@node1 cobbler]# cobbler import -h

Usage: cobbler [options]

 

Options:

  -h, --help            show this help message and exit

  --arch=ARCH           OS architecture being imported                #指定os的architecture

 --breed=BREED         the breedbeing imported

 --os-version=OS_VERSION                                              #指定其版本号

                       the version being imported

  --path=PATH           local path or rsync location                  #指定安装树在什么位置

  --name=NAME           name, ex 'RHEL-5'                             #为导入的distro命名

 --available-as=AVAILABLE_AS

                       tree is here, don't mirror

 --kickstart=KICKSTART_FILE                                           #同时可以给其指定ks文件,但是ks配置文件主要是在定义profile中使用的,这里不用指定,而且我们也不打算去镜像,因此也不用定义rsync

                       assign this kickstart file

 --rsync-flags=RSYNC_FLAGS

                       pass additional flags to rsync

复制镜像

[root@node1 cobbler]# cobbler import--name=centos-6.4-x86_64 --path=/media/

它会将镜像全部复制到cobbler目录下,时间太少我们稍等片刻

过程中可以看到如下信息:

task started: 2014-08-11_211258_import

task started (id=Media import, time=Mon Aug 11 21:12:582014)

以上意为将文件全部复制到/var/www/cobbler 目录下

访问地址http://10.0.10.61/cobbler

wKiom1PqyKiTOvdJAAIyJKcY37M703.jpg 

定义kickstart

[root@node1 ~]# system-config-kickstart

制作过程略

修改ks文件

[root@node1 ~]# vim ks.cfg

将repo开头的行注释

#repo --name="CentOS" --baseurl=cdrom:sr0--cost=100

 

加入分区信息,但是centos6.cfg里没有其信息,所以我们将anaconda-ks.cfg 内的信息复制到ks.cfg,内容如下:

在clearpart参数下面开始复制

part /boot --fstype=ext4 --size=300
part swap --size=512
part / --fstype=ext4 --grow --size=200

关键的参数:

url--url="http://10.0.10.61/cobbler/ks_mirror/centos-6.4-x86_64/"

 本文出自http://yijiu.blog.51cto.com/  转载请注明

为cobbler添加profile

拷贝镜像完毕后,查看其distro列表

[root@node1 cobbler]# cobbler distro list

  centos-6.4-x86_64

[root@node1 cobbler]# cobbler profile list

  centos-6.4-x86_64

如果distro要想真正的去使用还需要定义profile

 

添加profile

profile一定是继承distro的,所以定义任何profile必须明确说明指定哪个distro

#指定自定义名称

#指定distro是哪个

#指定kickstart文件

[root@node1 ~]# cobbler profile add--name=centos-6.4-x86_64-basic --distro=centos-6.4-x86_64--kickstart=/root/ks.cfg      

查看profile

[root@node1 ~]# cobbler profile list

  centos-6.4-x86_64

  centos-6.4-x86_64-basic

确保无误,将cobbler同步

[root@node1 ~]# cobbler sync

同步过程中,可以看到以下信息:

trying hardlink/var/www/cobbler/ks_mirror/centos-6.4-x86_64/images/pxeboot/vmlinuz ->/var/www/cobbler/images/centos-6.4-x86_64/vmlinuz

trying hardlink/var/www/cobbler/ks_mirror/centos-6.4-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos-6.4-x86_64/initrd.img

将其路径下的vmlinuz initrd 链接至cobbler的目录下,明确说明其引导的时候指定的内核和initrd

 

然后我们查看其配置

[root@node1 ~]# cd /var/lib/tftpboot/pxelinux.cfg/

[root@node1 pxelinux.cfg]# ll

total 4

-rw-r--r--. 1 root root 806 Aug 12 14:33 default

 

[root@node1 pxelinux.cfg]#  cat default

DEFAULT menu

PROMPT 0

MENU TITLE Cobbler | http://www.cobblerd.org/

TIMEOUT 200

TOTALTIMEOUT 6000

ONTIMEOUT local

 

LABEL local

        MENU LABEL(local)

        MENUDEFAULT

        LOCALBOOT-1

 

LABEL centos-6.4-x86_64

        kernel/images/centos-6.4-x86_64/vmlinuz

        MENU LABELcentos-6.4-x86_64

        appendinitrd=/images/centos-6.4-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://10.0.10.61/cblr/svc/op/ks/profile/centos-6.4-x86_64

        ipappend 2

 

#以下为我们自生成的label配置信息

LABEL centos-6.4-x86_64-basic

       kernel /images/centos-6.4-x86_64/vmlinuz

       MENU LABEL centos-6.4-x86_64-basic

       append initrd=/images/centos-6.4-x86_64/initrd.img ksdevice=bootiflang=  kssendmac text  ks=http://10.0.10.61/cblr/svc/op/ks/profile/centos-6.4-x86_64-basic

       ipappend 2

 

MENU end

http://10.0.10.61/cblr/svc/op/ks/profile/centos-6.4-basic此路径是专门为ks存放ks文件的路径,而这个文件将会被附加在pxe对应lebel的对应内核的内核参数上

 

确保配置无误,我们新建一虚机,网卡模式与其一致,并开机观察,如下所示

 

wKioL1Pqyd3SID6BAADmtHIDvAo894.jpg

 

 wKioL1PqyfWiZrb6AAEb8fzCEHE259.jpg

使用koan实现重装系统

    koan是需要安装在物理节点上,而非cobbler的节点,而后来引导其虚拟机启动的时候会自动连接对应的cobbler来实现启动系统安装过程

    由于楼主也没太多研究,所以这里先一笔带过

 

在客户端安装koan

[root@node2 ~]# yum install koan -y

 

查看cobbler服务端有哪些profiles

[root@node2 ~]# koan --server=10.0.10.61 --list=profiles

- looking for Cobbler at http://10.0.10.61:80/cobbler_api

centos-6.4-x86_64-basic

centos-6.4-x86_64

查看profile的具体信息

[root@node2 ~]# koan --server=10.0.10.61 --display--profile=centos-6.4-x86_64-basic

- looking for Cobbler at http://10.0.10.61:80/cobbler_api

- reading URL:http://10.0.10.61/cblr/svc/op/ks/profile/centos-6.4-x86_64-basic

install_tree:http://10.0.10.61/cobbler/ks_mirror/centos-6.4-x86_64/

               name  : centos-6.4-x86_64-basic

             distro  : centos-6.4-x86_64

          kickstart  :http://10.0.10.61/cblr/svc/op/ks/profile/centos-6.4-x86_64-basic

             ks_meta : tree=http://@@http_server@@/cblr/links/centos-6.4-x86_64

       install_tree  :http://10.0.10.61/cobbler/ks_mirror/centos-6.4-x86_64/

             kernel  :/var/www/cobbler/ks_mirror/centos-6.4-x86_64/images/pxeboot/vmlinuz

              initrd : /var/www/cobbler/ks_mirror/centos-6.4-x86_64/images/pxeboot/initrd.img

     kernel_options  :ks=http://10.0.10.61/cblr/svc/op/ks/profile/centos-6.4-x86_64-basicksdevice=link kssendmac

              repos  :

            virt_ram  : 512

   virt_disk_driver  : raw

          virt_type  : xenpv

          virt_path  :

     virt_auto_boot  : 1

将node2设置在下次重启后安装其系统

[root@node2 ~]# koan --server=10.0.10.61 --replace-self--profile=centos-6.4-x86_64-basic

 

- looking for Cobbler at http://10.0.10.61:80/cobbler_api

- reading URL:http://10.0.10.61/cblr/svc/op/ks/profile/centos-6.4-x86_64-basic

install_tree:http://10.0.10.61/cobbler/ks_mirror/centos-6.4-x86_64/

downloading initrd initrd.img to /boot/initrd.img_koan

url=http://10.0.10.61/cobbler/images/centos-6.4-x86_64/initrd.img

- reading URL:http://10.0.10.61/cobbler/images/centos-6.4-x86_64/initrd.img

downloading kernel vmlinuz to /boot/vmlinuz_koan

url=http://10.0.10.61/cobbler/images/centos-6.4-x86_64/vmlinuz

- reading URL: http://10.0.10.61/cobbler/images/centos-6.4-x86_64/vmlinuz

- ['/sbin/grubby', '--add-kernel', '/boot/vmlinuz_koan','--initrd', '/boot/initrd.img_koan', '--args','"ks=http://10.0.10.61/cblr/svc/op/ks/profile/centos-6.4-x86_64-basicksdevice=link kssendmac "', '--copy-default', '--make-default','--title=kick1407895197']

reboot to apply changes        #提示重启即可

 

重启系统

[root@node2 ~]# reboot

稍等片刻,我们可以看到如下所示的信息:

wKioL1Pqyh-y_qBRAAEaXfgHdSQ855.jpg

以上,为cobbler常用基础配置的方法,

END,感谢各位支持!

 

本文转自zuzhou 51CTO博客,原文链接:http://blog.51cto.com/yijiu/1539245

相关文章
|
Linux
CentOS7下部署Cobbler实现PXE+Kickstart自动化安装【脚本版】
CentOS7下部署Cobbler实现PXE+Kickstart自动化安装【脚本版】
213 0
CentOS7下部署Cobbler实现PXE+Kickstart自动化安装【脚本版】
|
安全 Linux 网络安全
搭建PXE实现Kickstart无人值守安装(二)
1、搭建PXE远程安装服务器 2、实现kicstart无人值守安装
搭建PXE实现Kickstart无人值守安装(二)
|
存储 网络协议 Linux
搭建PXE实现Kickstart无人值守安装(一)
1、搭建PXE远程安装服务器 2、实现kicstart无人值守安装
搭建PXE实现Kickstart无人值守安装(一)
|
Linux 网络安全 开发工具
cobbler 无人值守-安装
环境准备 准备两台主机,如centos6和centos7 centos7当作server服务器 关闭selinux 关闭防火墙 安装 cobbler包光盘里是没有的,要配置epel源,这里就说怎么配置epel源了,在yum.
1191 0
|
网络协议 API 机器学习/深度学习
cobbler 无人值守-介绍
cobbler 介绍 快速网络安装linux操作系统的服务,支持众多的Linux版本,也支持网络安装windows系统 PXE的二次封装,将多种安装参数封装到一个菜单 它是由Python编写的 还可以用CLI和WEB来管理 cobbler 配置目录说明 安装:yum in...
2061 0
|
存储 开发工具 数据安全/隐私保护
|
数据安全/隐私保护