设为首页 收藏本站
查看: 424|回复: 0

[经验分享] cobbler实现无人值守自动安装

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-8-14 17:25:52 | 显示全部楼层 |阅读模式
本帖最后由 3dwqe 于 2014-8-14 17:27 编辑

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源
[iyunv@node1 tools]# mkdir cobbler
[iyunv@node1 tools]# cd cobbler/
[iyunv@node1 cobbler]# rpm -ivh epel-release-6-8.noarch.rpm
[iyunv@node1 cobbler]# yum install cobbler cobbler-web pykickstart debmirror httpd –y
与此同时还需要确保web服务正常工作,因为cobbler高级功能是依赖于httpd
安装完后其路径位于 /etc/cobbler/ 目录下
[iyunv@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

启动cobbler
cobbler依赖于httpd,所以首先启动httpd再启动cobbler
[iyunv@node1 cobbler]# /etc/init.d/httpd start
[iyunv@node1 cobbler]# /etc/init.d/cobblerd start
查看监听端口
[iyunv@node1 cobbler]# ss -tunlp | grep cobb
tcp    LISTEN     0     5             127.0.0.1:25151                *:*     users:(("cobblerd",2568,9))

启动之前需检查环境配置
[iyunv@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:
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分别改为网络地址
[iyunv@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 等
需在联网的环境下执行
[iyunv@node1 ~]# cobbler get-loaders
如果不能联网则需要安装syslinux去复制pxelinux.0 memu.c32 这几个文件即可
查看是否下载成功
[iyunv@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
[iyunv@node1 ~]# chkconfig rsync on

6/7.将配置文件/etc/debmirror.conf 中dists和arches 注释掉
vim /etc/debmirror.conf
将以下参数注释
#@dists="sid";
#@arches="i386";

8.默认的密码,因为colbber配置文件中为每个装好操作系统的管理员用户都提供了默认密码,这里我们需要定义为自己所需要的密码
[iyunv@node1 cobbler]# openssl passwd -1 -salt `openssl rand -hex 4`
Password:
$1$faa927d5$mqa11pGo9/ILeHGm.sfNI1
复制粘贴至settings
[iyunv@node1 cobbler]# vim settings
找到参数default_password_crypted,并修改为:
default_password_crypted:"$1$e9ef99ab$kC3I.Be1E58r8xvbQ5KTA."

9.实现电源管理,如果想使用这种功能需要安装cman和face-agents才可以
这个没有太大关系如果介意的话可以使用yum安装
[iyunv@node1 cobbler]# yum -y install cman fence-agents
重启服务并重新检测配置
[iyunv@node1 cobbler]# /etc/init.d/cobblerd restart
Stopping cobbler daemon:                                   [  OK  ]
Starting cobbler daemon:                                   [  OK  ]
[iyunv@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:

Restart cobblerd and then run 'cobbler sync' to applychanges.
#PS:我的环境已将selinux关闭了,可check的时候依旧报出此条信息,目前暂时没有解决

同步cobbler
同步cobbler,将所数据都会同步到对应的目录下
[iyunv@node1 ~]# cobbler sync
同步过后,将会在/var/lib/tftpboot/会生成一堆文件
[iyunv@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
[iyunv@node1 ~]# cd /etc/cobbler/
[iyunv@node1 cobbler]# vim modules.conf
可以看到每个模块以及模块配置参数都以[XXX]为
如下所示:
[dns]
module = manage_bind      #mange_bind表示使用cobbler进行管理bind服务,如果使用dnsmasq则将后面注释去掉即可
[dhcp]
module = manage_isc      #如果使用cobbler进行管理的话需要改成manage_dnsmasq 因为manage_dnsmasq既可以管理dns服务也可以管理dhcp服务
#默认所有服务都是独立运行的,因为没有必要去管理独立服务,如果有必要的话修改文件:
[iyunv@node1 cobbler]# vim settings
找到相关参数,以tftp为例
manage_tftpd: 1     #将其默认值0改为1即可
我们这里不需要让其独立管理所以还是使用默认值

配置DHCP
[iyunv@node1 cobbler]# yum install -y dhcp
[iyunv@node1 cobbler]# cp/usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
这里我们想让cobbler帮我们管理dhcp服务,则需要以下操作
直接替换参数,1为使cobbler进行管理
[iyunv@node1 cobbler]# sed -i 's/manage_dhcp:0/manage_dhcp: 1/g' /etc/cobbler/settings
把manage_dhcp的值改为1 这样cobbler会根据dhcp.template 生成 dhcp.conf
[iyunv@node1 cobbler]# vim /etc/cobbler/dhcp.template
修改如下:
subnet 10.0.10.0 netmask 255.255.255.0 {
     optionrouters             10.0.10.61;
     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;
保存退出
[iyunv@node1 dhcp]# cobbler sync
[iyunv@node1 dhcp]# /etc/init.d/dhcpd status
dhcpd (pid  2652)is running...
dhcp服务是由cobbler来管理,所以每次修改dhcp.template并执行cobbler sync,就会自动更新到/etc/dhcpd.conf中,如果同步时发现服务关闭,会自动将其重启

启动tftp
[iyunv@node1 cobbler]# yum install -y tftp tftp-server
[iyunv@node1 cobbler]# chkconfig tftp on
[iyunv@node1 cobbler]# /etc/init.d/xinetd restart
Stopping xinetd:                                          [  OK  ]
Starting xinetd:                                          [  OK  ]
查看监听端口
[iyunv@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
挂载光盘,并导入其系统到本地
[iyunv@node1 cobbler]# mount /dev/cdrom /media/ -r
[iyunv@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

[iyunv@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的列表
[iyunv@node1 cobbler]# cobbler distro list
同样使用profile list也可以显示
[iyunv@node1 cobbler]# cobbler profile list

导入镜像
[iyunv@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
复制镜像
[iyunv@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 目录下
wKiom1PqyKiTOvdJAAIyJKcY37M703.jpg
定义kickstart
[iyunv@node1 ~]# system-config-kickstart
制作过程略
修改ks文件
[iyunv@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/"
为cobbler添加profile
拷贝镜像完毕后,查看其distro列表
[iyunv@node1 cobbler]# cobbler distro list
  centos-6.4-x86_64
[iyunv@node1 cobbler]# cobbler profile list
  centos-6.4-x86_64
如果distro要想真正的去使用还需要定义profile

添加profile
profile一定是继承distro的,所以定义任何profile必须明确说明指定哪个distro
#指定自定义名称
#指定distro是哪个
#指定kickstart文件
[iyunv@node1 ~]# cobbler profile add--name=centos-6.4-x86_64-basic --distro=centos-6.4-x86_64--kickstart=/root/ks.cfg      
查看profile
[iyunv@node1 ~]# cobbler profile list
  centos-6.4-x86_64
  centos-6.4-x86_64-basic
确保无误,将cobbler同步
[iyunv@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

然后我们查看其配置
[iyunv@node1 ~]# cd /var/lib/tftpboot/pxelinux.cfg/
[iyunv@node1 pxelinux.cfg]# ll
total 4
-rw-r--r--. 1 root root 806 Aug 12 14:33 default

[iyunv@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
[iyunv@node2 ~]# yum install koan -y

查看cobbler服务端有哪些profiles
[iyunv@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的具体信息
[iyunv@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
               name  : centos-6.4-x86_64-basic
             distro  : centos-6.4-x86_64
             ks_meta : tree=http://@@http_server@@/cblr/links/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设置在下次重启后安装其系统
[iyunv@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
downloading initrd initrd.img to /boot/initrd.img_koan
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
- ['/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        #提示重启即可

重启系统
[iyunv@node2 ~]# reboot
稍等片刻,我们可以看到如下所示的信息:
wKioL1Pqyh-y_qBRAAEaXfgHdSQ855.jpg
以上,为cobbler常用基础配置的方法,
END,感谢各位支持!



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-23806-1-1.html 上篇帖子: CentOS7网络配置和服务管理 下篇帖子: Linux系统手动格式化大于2TB数据盘操作指引
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表