自动化运维之–Cobbler

Cobbler

自动化

Cobbler简介

Cobbler是一个快速网络安装linux的服务,而且在经过调整也可以支持网络安装windows。该工具使用python开发,小巧轻便(才15k行python代码),使用简单的命令即可完成PXE网络安装环境的配置,同时还可以管理DHCP、DNS、TFTP、RSYNC以及yum仓库、构造系统ISO镜像。 Cobbler支持命令行管理,web界面管理,还提供了API接口,可以方便二次开发使用。 Cobbler客户端Koan支持虚拟机安装和操作系统重新安装,同时支持服务器的电源管理,使重装系统更便捷。更多内容可以查看cobbler官方网站! 
cobbler官方网站:http://cobbler.github.io/

Cobbler版本

distro 发行版 
面对不同的操作系统 
面对同一个操作系统不同的版本 
profile 
核心特性是通过kickstart来部署 
system 
主要目的配置网络接口

1.png-172kB

      图1   cobbler各主要组件关系图

Cobbler环境

我们使用的是Centos7进行安装,如果是Centos6也可以。只是有一些相关的目录不一致,可以查阅Centos6Centos7的区别来进行设置。 
Centos7下载链接 密码:xph6 
环境查看

 
 
  1. [root@localhost ~]# cat /etc/redhat-release
  2. CentOS Linux release 7.2.1511 (Core)
  3. [root@localhost ~]# uname -r
  4. 3.10.0-327.28.3.el7.x86_64

Cobbler部署

安装EPEL源

 
 
  1. [root@localhost ~]# rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm

yum安装cobbler

 
 
  1. [root@localhost ~]# yum install -y httpd dhcp tftp cobbler cobbler-web pykickstart

cobler是基于Python开发,安装操作界面也是Python写的 
cobbler都是通过Apache来提供服务的 
启动apache

 
 
  1. [root@localhost conf.d]# systemctl start httpd
  2. 启动cobber
  3. [root@localhost conf.d]# systemctl start cobblerd

如果没有需要安装,安装步骤不说了,直接yum就好了

安装cobber_web 产生的2个配置文件

 
 
  1. [root@localhost conf.d]# ll /etc/httpd/conf.d/
  2. total 36
  3. -rw-r--r-- 1 root root 2926 Jul 18 11:30 autoindex.conf
  4. -rw-r--r-- 1 root root 1087 Jan 24 2016 cobbler.conf
  5. -rw-r--r-- 1 root root 1165 Jan 24 2016 cobbler_web.conf
  6. -rw-r--r-- 1 root root 366 Jul 18 11:30 README
  7. -rw-r--r-- 1 root root 9438 Jul 18 11:22 ssl.conf
  8. -rw-r--r-- 1 root root 1252 Jul 18 11:22 userdir.conf
  9. -rw-r--r-- 1 root root 824 Jul 18 11:22 welcome.conf

配置文件说明

 
 
  1. [root@localhost conf.d]# cat cobbler.conf
  2. # This configuration file allows cobbler data
  3. # to be accessed over HTTP.
  4. AliasMatch ^/cblr(?!/svc/)(.*)?$ "/var/www/cobbler$1" #别名匹配
  5. AliasMatch ^/cobbler_track(.*)?$ "/var/www/cobbler$1"
  6. #AliasMatch ^/cobbler(.*)?$ "/var/www/cobbler$1"
  7. Alias /cobbler /var/www/cobbler #别名的目录
  8. Alias /cobbler_webui_content /var/www/cobbler_webui_content
  9. WSGIScriptAliasMatch ^/cblr/svc/([^/]*) /var/www/cobbler/svc/services.py
  10. <Directory "/var/www/cobbler"> #一个虚拟主机
  11. SetEnv VIRTUALENV
  12. Options Indexes FollowSymLinks
  13. Order allow,deny
  14. Allow from all
  15. </Directory>
  16. ProxyRequests off
  17. ProxyPass /cobbler_api http://localhost:25151/ #代理,类似于nginx的代理proxypass
  18. ProxyPassReverse /cobbler_api http://localhost:25151/
  19. BrowserMatch "MSIE" AuthDigestEnableQueryStringHack=On
  20. # the webui is now part of the "cobbler-web" package
  21. # and is visited at http://.../cobbler_web not this URL.
  22. # this is only a pointer to the new page.
  23. <Directory "/var/www/cobbler/web/">
  24. Options Indexes FollowSymLinks
  25. Order allow,deny
  26. Allow from all
  27. </Directory>
  28. <IfVersion >= 2.4>
  29. <Location /cblr>
  30. Require all granted
  31. </Location>
  32. </IfVersion>

执行cobbler check

 
 
  1. [root@localhost conf.d]# cobbler check #类似一个使用手册,来告诉我们需要完成以下内容
  2. The following are potential configuration items that you may want to fix:
  3. 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.
  4. 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.
  5. 3 : change 'disable' to 'no' in /etc/xinetd.d/tftp
  6. 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.
  7. 5 : enable and start rsyncd.service with systemctl
  8. 6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
  9. 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
  10. 8 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
  11. Restart cobblerd and then run 'cobbler sync' to apply changes.

下面是解释:本段参考徐博士博客http://www.xuliangwei.com/xubusi/446.html

 
 
  1. 1、修改/etc/cobbler/settings文件中的server参数的值为提供cobbler服务的主机相应的IP地址或主机名,如server: 10.0.0.101
  2. [root@cobbler-node1 ~]# sed -i 's/server: 127.0.0.1/server: 10.0.0.101/' /etc/cobbler/settings
  3. 2、修改/etc/cobbler/settings文件中的next_server参数的值为提供PXE服务的主机相应的IP地址,如next_server: 10.0.0.101
  4. [root@cobbler-node1 ~]# sed -i 's/next_server: 127.0.0.1/next_server: 10.0.0.101/' /etc/cobbler/settings
  5. 3、修改/etc/xinetd.d/tftp文件中的disable参数修改为 disable = no
  6. 4、执行 cobbler get-loaders 命令即可;否则,需要安装syslinux程序包,而后复制/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至/var/lib/cobbler/loaders/目录中;
  7. 5、执行 systemctl enable rsyncd命令即可;
  8. 6、如果有强迫症可以选择 yum y install debmirror 然后根据错误进行解决,一般错误如下。
  9. 注释/etc/dedmirror.conf文件中的 @dists=”sid”; @arches=”i386”;
  10. 7、[root@cobbler-node1 ~]# openssl passwd -1 -salt '$(openssl rand -hex 4)' 'xuliangwei'
  11. $1$$(openss$.wbDUBV/STL0YaNuAcusK/
  12. [root@cobbler-node1~]# grep "default_password_crypted" /etc/cobbler/settings #替换/etc/cobbler/setting内的default_password_crypted
  13. default_password_crypted:"$1$$(openss$.wbDUBV/STL0YaNuAcusK/"
  14. 8yum y install cman fence-agents
  15. 最后重启Cobblersystemctl restart cobblerd

以上操作我们可以不根据他说的进行操作 
要根据要求进行设置!—————————————— 
cobbler配置文件

 
 
  1. [root@localhost conf.d]# vim /etc/cobbler/settings #cobbler配置文件
  2. next_server: 192.168.56.11 #修改成我们本机的IP地址
  3. server: 192.168.56.11 #修改成服务的IP地方

设置tftp

 
 
  1. [root@localhost conf.d]# vim /etc/xinetd.d/tftp
  2. disable改成no
  3. # default: off
  4. # description: The tftp server serves files using the trivial file transfer \
  5. # protocol. The tftp protocol is often used to boot diskless \
  6. # workstations, download configuration files to network-aware printers, \
  7. # and to start the installation process for some operating systems.
  8. service tftp
  9. {
  10. socket_type = dgram
  11. protocol = udp
  12. wait = yes
  13. user = root
  14. server = /usr/sbin/in.tftpd
  15. server_args = -s /var/lib/tftpboot
  16. disable = no
  17. per_source = 11
  18. cps = 100 2
  19. flags = IPv4
  20. }

启动rsync

 
 
  1. [root@localhost conf.d]# systemctl start rsyncd

执行网络安装要下载的相关文件

 
 
  1. [root@localhost conf.d]# cobbler get-loaders
  2. task started: 2016-08-23_115402_get_loaders
  3. task started (id=Download Bootloader Content, time=Tue Aug 23 11:54:02 2016)
  4. downloading http://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
  5. downloading http://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
  6. downloading http://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
  7. downloading http://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
  8. downloading http://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
  9. downloading http://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
  10. downloading http://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
  11. downloading http://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
  12. downloading http://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
  13. downloading http://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
  14. *** TASK COMPLETE ***

设置账号密码

 
 
  1. [root@localhost conf.d]# openssl passwd -1 -salt 'cobler' 'cobler' 第一个是掩码,第二个是密码
  2. $1$cobler$XJnisBweZJlhL651HxAM00

复制到配置文件中

 
 
  1. [root@localhost conf.d]# vim /etc/cobbler/settings

按照上面的说明,我们需要重启一下cobbler

 
 
  1. [root@localhost conf.d]# systemctl restart cobblerd

我们在执行cobbler check查看还有什么需要我们继续操作的

 
 
  1. [root@localhost conf.d]# cobbler check
  2. The following are potential configuration items that you may want to fix:
  3. 1 : enable and start rsyncd.service with systemctl
  4. 2 : debmirror package is not installed, it will be required to manage debian deployments and repositories
  5. 3 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
  6. Restart cobblerd and then run 'cobbler sync' to apply changes.

现在cobbler已经安装完了,现在还缺一个DHCP 
cobbler可以管理DHCP,也可以不让他管

 
 
  1. [root@localhost ~]# vim /etc/cobbler/settings
  2. manage_dhcp: 1 #将dhcp 0修改为1表示管理dhcp

我们再修改dhcp模板文件

 
 
  1. [root@localhost ~]# vim /etc/cobbler/dhcp.template
  2. subnet 192.168.56.0 netmask 255.255.255.0 { #网段
  3. option routers 192.168.56.2; #网关
  4. option domain-name-servers 192.168.56.2; #DMS
  5. option subnet-mask 255.255.255.0; #子网掩码
  6. range dynamic-bootp 192.168.56.100 192.168.56.254; #分配的地址段
  7. default-lease-time 21600;
  8. max-lease-time 43200;
  9. next-server $next_server; #这个是cobbler配置文件里面的变量

修改完配置文件之后,重启服务

 
 
  1. [root@localhost ~]# systemctl restart cobblerd

使用cobbler sync 生成dhcp模板,自动帮我们重启dhcp 
cobbler sync 表示刷新,其实就是删除原来的文件,从新进行加载

 
 
  1. [root@localhost ~]# cobbler sync
  2. task started: 2016-08-23_180604_sync
  3. task started (id=Sync, time=Tue Aug 23 18:06:04 2016)
  4. running pre-sync triggers
  5. cleaning trees
  6. removing: /var/lib/tftpboot/grub/images
  7. copying bootloaders
  8. trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
  9. trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
  10. trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
  11. trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
  12. trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
  13. trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
  14. copying distros to tftpboot
  15. copying images
  16. generating PXE configuration files
  17. generating PXE menu structure
  18. rendering DHCP files
  19. generating /etc/dhcp/dhcpd.conf
  20. rendering TFTPD files
  21. generating /etc/xinetd.d/tftp
  22. cleaning link caches
  23. running post-sync triggers
  24. running python triggers from /var/lib/cobbler/triggers/sync/post/*
  25. running python trigger cobbler.modules.sync_post_restart_services
  26. running: dhcpd -t -q
  27. received on stdout:
  28. received on stderr:
  29. running: service dhcpd restart
  30. received on stdout:
  31. received on stderr: Redirecting to /bin/systemctl restart dhcpd.service
  32. running shell triggers from /var/lib/cobbler/triggers/sync/post/*
  33. running python triggers from /var/lib/cobbler/triggers/change/*
  34. running python trigger cobbler.modules.scm_track
  35. running shell triggers from /var/lib/cobbler/triggers/change/*
  36. *** TASK COMPLETE ***

我们可以查看一下dhcp,查看cobbler是否可以管理dhcp

 
 
  1. [root@localhost ~]# cat /etc/dhcp/dhcpd.conf
  2. # ******************************************************************
  3. # Cobbler managed dhcpd.conf file
  4. # generated from cobbler dhcp.conf template (Tue Aug 23 22:06:05 2016)
  5. # Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes
  6. # in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
  7. # overwritten.
  8. # ******************************************************************

上述意思是 dhcp是由cobbler进行管理,如果想进行设置 请修改/etc/cobbler/dhcp.template 然后/etc/dhcp/dhcpd.conf会被覆盖 
现在我们安装一台操作系统

挂载镜像 右击Centos64–>设置>CD/DVD 
1.png-67.3kB

Linux 上是需要挂载光盘,我们进行挂载

 
 
  1. [root@localhost ~]# mount /dev/cdrom /mnt/
  2. mount: /dev/sr0 is write-protected, mounting read-only

制作镜像,用于安装操作系统,使cobbler导入镜像

 
 
  1. [root@localhost ~]# cobbler import --path=/mnt/ --name=CentOS-6-x86_64 --arch=x86_64
  2. --path=从哪里导入
  3. --name=名称
  4. --arch=系统位数32 or 64

导入过程中yum仓库和其他的已经给我们做好了 
导入的位置

 
 
  1. [root@localhost ks_mirror]# pwd
  2. /var/www/cobbler/ks_mirror
  3. [root@localhost ks_mirror]# ls
  4. CentOS-7-x86_64 config

在导入一个centos.7的,首先我们先卸载7的

 
 
  1. [root@localhost ~]# umount /dev/cdrom

2.png-81.3kB
3.png-36.1kB

重新进行挂载

 
 
  1. [root@localhost ~]# mount /dev/cdrom /mnt/
  2. mount: /dev/sr0 is write-protected, mounting read-only

继续执行,代表制作一个centos7的镜像

 
 
  1. [root@localhost /]# cobbler import --path=/mnt/ --name=CentOS-7.1-x86_64 --arch=x86_64

具体参数请参考上面的内容 
查看cobbler都有哪些命令

 
 
  1. [root@localhost /]# cobbler profile
  2. usage
  3. =====
  4. cobbler profile add
  5. cobbler profile copy
  6. cobbler profile dumpvars
  7. cobbler profile edit
  8. cobbler profile find
  9. cobbler profile getks
  10. cobbler profile list
  11. cobbler profile remove
  12. cobbler profile rename
  13. cobbler profile report

例如:我们查看当前有几个镜像

 
 
  1. [root@localhost /]# cobbler profile list
  2. CentOS-6-x86_64
  3. CentOS-7-x86_64

查看我们2个系统的详细信息

 
 
  1. [root@localhost /]# cobbler profile report
  2. Name : CentOS-7.1-x86_64
  3. TFTP Boot Files : {}
  4. Comment :
  5. DHCP Tag : default
  6. Distribution : CentOS-7.1-x86_64
  7. Enable gPXE? : 0
  8. Enable PXE Menu? : 1
  9. Fetchable Files : {}
  10. Kernel Options : {}
  11. Kernel Options (Post Install) : {}
  12. Kickstart : /var/lib/cobbler/kickstarts/sample_end.ks
  13. Kickstart Metadata : {}
  14. Management Classes : []
  15. Management Parameters : <<inherit>>
  16. Name Servers : []
  17. Name Servers Search Path : []
  18. Owners : ['admin']
  19. Parent Profile :
  20. Internal proxy :
  21. Red Hat Management Key : <<inherit>>
  22. Red Hat Management Server : <<inherit>>
  23. Repos : []
  24. Server Override : <<inherit>>
  25. Template Files : {}
  26. Virt Auto Boot : 1
  27. Virt Bridge : xenbr0
  28. Virt CPUs : 1
  29. Virt Disk Driver Type : raw
  30. Virt File Size(GB) : 5
  31. Virt Path :
  32. Virt RAM (MB) : 512
  33. Virt Type : kvm
  34. Name : CentOS-7-x86_64
  35. TFTP Boot Files : {}
  36. Comment :
  37. DHCP Tag : default
  38. Distribution : CentOS-7-x86_64
  39. Enable gPXE? : 0
  40. Enable PXE Menu? : 1
  41. Fetchable Files : {}
  42. Kernel Options : {}
  43. Kernel Options (Post Install) : {}
  44. Kickstart : /var/lib/cobbler/kickstarts/sample_end.ks
  45. Kickstart Metadata : {}
  46. Management Classes : []
  47. Management Parameters : <<inherit>>
  48. Name Servers : []
  49. Name Servers Search Path : []
  50. Owners : ['admin']
  51. Parent Profile :
  52. Internal proxy :
  53. Red Hat Management Key : <<inherit>>
  54. Red Hat Management Server : <<inherit>>
  55. Repos : []
  56. Server Override : <<inherit>>
  57. Template Files : {}
  58. Virt Auto Boot : 1
  59. Virt Bridge : xenbr0
  60. Virt CPUs : 1
  61. Virt Disk Driver Type : raw
  62. Virt File Size(GB) : 5
  63. Virt Path :
  64. Virt RAM (MB) : 512
  65. Virt Type : kvm

修改ks的路径,自定义安装后,需要设置的一些东西,例如开启哪些服务,关闭哪些服务。安装什么东西等 
我们先上传已经设置好的cfg文件 
下载链接 密码:iq4t 
为了规范,我们把kickstarts文件放在/var/lib/cobbler/kickstarts下面

 
 
  1. [root@localhost ~]# cd /var/lib/cobbler/kickstarts/
  2. [root@localhost kickstarts]# rz -E
  3. rz waiting to receive.

检查一下路径是否正确

 
 
  1. [root@localhost kickstarts]# ll
  2. total 60
  3. -rw-r--r-- 1 root root 3704 Aug 24 2016 CentOS-6-x86_64.cfg
  4. -rw-r--r-- 1 root root 1355 Aug 25 2016 CentOS-7-x86_64.cfg
  5. -rw-r--r-- 1 root root 115 Jan 23 2016 default.ks
  6. -rw-r--r-- 1 root root 22 Jan 23 2016 esxi4-ks.cfg
  7. -rw-r--r-- 1 root root 22 Jan 23 2016 esxi5-ks.cfg
  8. drwxr-xr-x 2 root root 54 Aug 23 09:17 install_profiles
  9. -rw-r--r-- 1 root root 1424 Jan 23 2016 legacy.ks
  10. -rw-r--r-- 1 root root 292 Jan 23 2016 pxerescue.ks
  11. -rw-r--r-- 1 root root 2916 Jan 23 2016 sample_autoyast.xml
  12. -rw-r--r-- 1 root root 1825 Jan 23 2016 sample_end.ks
  13. -rw-r--r-- 1 root root 0 Jan 23 2016 sample_esx4.ks
  14. -rw-r--r-- 1 root root 324 Jan 23 2016 sample_esxi4.ks
  15. -rw-r--r-- 1 root root 386 Jan 23 2016 sample_esxi5.ks
  16. -rw-r--r-- 1 root root 1784 Jan 23 2016 sample.ks
  17. -rw-r--r-- 1 root root 3419 Jan 23 2016 sample_old.seed
  18. -rw-r--r-- 1 root root 5879 Jan 23 2016 sample.seed

自定义kickstarts文件 
我们使用cobbler profile report命令看到Kickstart默认在/var/lib/cobbler/kickstarts/sample_end.ks 
我们直接使用命令进行修改,我们修改6的kickstarts

 
 
  1. [root@localhost /]# cobbler profile edit --name=CentOS-6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-6-x86_64.cfg

修改7的kickstarts

 
 
  1. [root@localhost /]# cobbler profile edit --name=CentOS-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg

因为Centos7 默认的网卡不在/etc/init.d/network 
所以我们需要修改内核

 
 
  1. [root@localhost /]# cobbler profile report
  2. Kernel Options : {}

我们查看到这里可以定义内核参数

 
 
  1. [root@localhost /]# cobbler profile edit --name=CentOS-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'

这样我们在安装Centos7的时候就会默认给我们加上这个内核参数

 
 
  1. [root@localhost /]# cobbler profile report
  2. Name : CentOS-7.1-x86_64
  3. TFTP Boot Files : {}
  4. Comment :
  5. DHCP Tag : default
  6. Distribution : CentOS-7.1-x86_64
  7. Enable gPXE? : 0
  8. Enable PXE Menu? : 1
  9. Fetchable Files : {}
  10. Kernel Options : {'biosdevname': '0', 'net.ifnames': '0'}

提示:默认cobbler profile report会查看当前配置的所有,我们可以使用cobbler profile ”Cobbler 定义的名字“来查看 
执行cobbler sync会删除原来的文件,相当于从新进行加载

 
 
  1. [root@localhost /]# cobbler sync
  2. task started: 2016-08-24_001542_sync
  3. task started (id=Sync, time=Wed Aug 24 00:15:42 2016)
  4. running pre-sync triggers
  5. cleaning trees
  6. removing: /var/www/cobbler/images/CentOS-7-x86_64
  7. removing: /var/www/cobbler/images/CentOS-7.1-x86_64
  8. removing: /var/lib/tftpboot/pxelinux.cfg/default
  9. removing: /var/lib/tftpboot/grub/images
  10. removing: /var/lib/tftpboot/grub/grub-x86.efi
  11. removing: /var/lib/tftpboot/grub/grub-x86_64.efi
  12. removing: /var/lib/tftpboot/grub/efidefault
  13. removing: /var/lib/tftpboot/images/CentOS-7-x86_64
  14. removing: /var/lib/tftpboot/images/CentOS-7.1-x86_64
  15. removing: /var/lib/tftpboot/s390x/profile_list
  16. copying bootloaders
  17. trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
  18. trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
  19. copying distros to tftpboot
  20. copying files for distro: CentOS-7.1-x86_64
  21. trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.1-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/CentOS-7.1-x86_64/vmlinuz
  22. trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.1-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/CentOS-7.1-x86_64/initrd.img
  23. copying files for distro: CentOS-7-x86_64
  24. trying hardlink /var/www/cobbler/ks_mirror/CentOS-7-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/CentOS-7-x86_64/vmlinuz
  25. trying hardlink /var/www/cobbler/ks_mirror/CentOS-7-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/CentOS-7-x86_64/initrd.img
  26. copying images
  27. generating PXE configuration files
  28. generating PXE menu structure
  29. copying files for distro: CentOS-7.1-x86_64
  30. trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.1-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/CentOS-7.1-x86_64/vmlinuz
  31. trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.1-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/CentOS-7.1-x86_64/initrd.img
  32. Writing template files for CentOS-7.1-x86_64
  33. copying files for distro: CentOS-7-x86_64
  34. trying hardlink /var/www/cobbler/ks_mirror/CentOS-7-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/CentOS-7-x86_64/vmlinuz
  35. trying hardlink /var/www/cobbler/ks_mirror/CentOS-7-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/CentOS-7-x86_64/initrd.img
  36. Writing template files for CentOS-7-x86_64
  37. rendering DHCP files
  38. generating /etc/dhcp/dhcpd.conf
  39. rendering TFTPD files
  40. generating /etc/xinetd.d/tftp
  41. processing boot_files for distro: CentOS-7.1-x86_64
  42. processing boot_files for distro: CentOS-7-x86_64
  43. cleaning link caches
  44. running post-sync triggers
  45. running python triggers from /var/lib/cobbler/triggers/sync/post/*
  46. running python trigger cobbler.modules.sync_post_restart_services
  47. running: dhcpd -t -q
  48. received on stdout:
  49. received on stderr:
  50. running: service dhcpd restart
  51. received on stdout:
  52. received on stderr: Redirecting to /bin/systemctl restart dhcpd.service
  53. running shell triggers from /var/lib/cobbler/triggers/sync/post/*
  54. running python triggers from /var/lib/cobbler/triggers/change/*
  55. running python trigger cobbler.modules.scm_track
  56. running shell triggers from /var/lib/cobbler/triggers/change/*
  57. *** TASK COMPLETE ***

新建虚拟机进行安装 
提示:我们先打开系统日志,因为dhcp默认会将日志显示在/var/log/messages 
我们在新建虚拟机 
1.png-102.6kB
2.png-53.8kB
3.png-70.9kB
4.png-18.4kB
dhcp的4个步骤 
5.png-18.5kB
现在已经获取到了IP,TFTP没有开启 
6.png-9.9kB
我们安装tftp

 
 
  1. [root@localhost kickstarts]# yum install xinetd -y
  2. 启动
  3. [root@localhost kickstarts]# systemctl start xinetd

耐心等待,如果超时2次需要重新启动,因为开启了dhcp获取到了IP地址,但是无法下载文件 肯定会超时 
7.png-6.7kB

** 菜单解释:** 
1.本地硬盘 
2.CentOS-6 
3.CentOS-7 
提示:默认会计时,我们使用上下键不让它进行计时。有这个菜单的好处就是不会担心重启之后就把系统给重装了。 
我们选择7进行安装 
1.png-30.7kB
安装完成 
2.png-5.3kB
3.png-3kB
以上就是cobbler的基础安装部分!


自动重装系统

#提示:如果我们想重装那台系统,可以执行以下的步骤: 
使用koan工具,让cobbler自动化重装

 
 
  1. [root@localhost kickstarts]# yum install koan

查看我们可以安装的系统

 
 
  1. [root@localhost kickstarts]# koan --server=192.168.56.11 --list=profiles
  2. - looking for Cobbler at http://192.168.56.11:80/cobbler_api
  3. CentOS-6-x86_64
  4. CentOS-7-x86_64
  5. ##--server=此处是cobbler的IP地址

例子:我们使用koan安装centos6 
指定要重装的系统

 
 
  1. [root@localhost kickstarts]# koan --replace-self --server=192.168.56.11 --profile=CentOS-6-x86_64
  2. - looking for Cobbler at http://192.168.56.11:80/cobbler_api
  3. - reading URL: http://192.168.56.11/cblr/svc/op/ks/profile/CentOS-6-x86_64
  4. install_tree: http://192.168.56.11/cblr/links/CentOS-6-x86_64
  5. downloading initrd initrd.img to /boot/initrd.img_koan
  6. url=http://192.168.56.11/cobbler/images/CentOS-6-x86_64/initrd.img
  7. - reading URL: http://192.168.56.11/cobbler/images/CentOS-6-x86_64/initrd.img
  8. downloading kernel vmlinuz to /boot/vmlinuz_koan
  9. url=http://192.168.56.11/cobbler/images/CentOS-6-x86_64/vmlinuz
  10. - reading URL: http://192.168.56.11/cobbler/images/CentOS-6-x86_64/vmlinuz
  11. - ['/sbin/grubby', '--add-kernel', '/boot/vmlinuz_koan', '--initrd', '/boot/initrd.img_koan', '--args', '"ks=http://192.168.56.11/cblr/svc/op/ks/profile/CentOS-7-x86_64 ksdevice=link kssendmac lang= text "', '--copy-default', '--make-default', '--title=kick1472015796']
  12. - ['/sbin/grubby', '--update-kernel', '/boot/vmlinuz_koan', '--remove-args=root']
  13. - reboot to apply changes

重启之后直接加载centos6 
4.png-10kB
不需要我们选择,他自己进行选择。 
1.png-4.2kB
提示:在我们reboot,一定要确定我们要重启的服务器是哪一台。如果确实操作错了,需要赶紧关闭cobbler、断电

Cobbler_Web 界面设置

Cobbler提供了一个web界面,我们可以使用网页进行访问 
1.png-35.4kB
地址:https://192.168.56.11/cobbler_web 
这里的用户名和密码是cobbler 
如果我们想修改cobbler_web用户名可以到/etc/cobbler/users.conf

 
 
  1. [root@localhost cobbler]# cat /etc/cobbler/users.conf
  2. [admins]
  3. admin = ""
  4. cobbler = ""

cobbler是描述 
修改cobbler_web密码

 
 
  1. [root@localhost cobbler]# htdigest /etc/cobbler/users.digest "Cobbler" cobbler
  2. Changing password for user cobbler in realm Cobbler
  3. New password:
  4. Re-type new password:

Cobbler=用户的描述 
cobbler=用户名 
2.png-41.4kB
我们可以查看profiles,点击Edit可以修改系统的一些选项 
3.png-68.4kB
在kernel里面可以设置一些内核参数 
4.png-78.1kB
Kickstart Templates 可以查看我们的kickstarts文件 
5.png-70.8kB
我们还可以修改kickstart文件 
6.png-32.1kB
所有命令行操作cobbler,都可以在cobbler_web上面实现


高级设置

我们可以修改cobbler的选择系统的菜单 
1.png-7.1kB
编辑配置文件

 
 
  1. [root@localhost pxe]# cat /etc/cobbler/pxe/pxedefault.template
  2. DEFAULT menu
  3. PROMPT 0
  4. MENU TITLE Cobbler www.abcdocker.com| http://www.abcdocker.com
  5. TIMEOUT 200
  6. TOTALTIMEOUT 6000
  7. ONTIMEOUT $pxe_timeout_profile
  8. LABEL local_abcdocker
  9. MENU LABEL [ install abcdocker.com ]
  10. MENU DEFAULT
  11. LOCALBOOT -1
  12. $pxe_menu_items
  13. MENU end

我们修改完配置文件之后需要刷新,否则不生效

 
 
  1. [root@localhost pxe]# cobbler sync

我们可以在创建一台虚拟机测试(安装过程不说了,直接看结果) 
修改图如下: 
1.png-7.5kB
Cobbler重要的几个目录 
镜像存放目录

 
 
  1. [root@localhost cobbler]# ls /var/www/cobbler/ks_mirror/
  2. CentOS-7.1-x86_64 CentOS-7-x86_64 config

存放仓库镜像

 
 
  1. [root@localhost cobbler]# ls /var/www/cobbler/repo_mirror/

kickstarts配置文件存放路径

 
 
  1. [root@localhost cobbler]# ls /var/lib/cobbler/
  2. config kickstarts lock snippets web.ss
  3. distro_signatures.json loaders scripts triggers webui_sessions

存放启动引导程序的目录

 
 
  1. [root@localhost cobbler]# ls /var/lib/cobbler/loaders/
  2. COPYING.elilo COPYING.yaboot grub-x86_64.efi menu.c32 README
  3. COPYING.syslinux elilo-ia64.efi grub-x86.efi pxelinux.0 yaboot

一些相关配置的脚本

 
 
  1. [root@localhost cobbler]# ls /var/lib/cobbler/snippets/
  2. cobbler_register networking.xml
  3. download_config_files partition_select
  4. download_config_files_deb post_anamon
  5. func_install_if_enabled post_install_kernel_options
  6. func_register_if_enabled post_install_network_config
  7. hosts.xml post_install_network_config_deb
  8. kdump.xml post_koan_add_reinstall_entry
  9. keep_cfengine_keys post_run_deb
  10. keep_files post_s390_reboot
  11. keep_rhn_keys pre_anamon
  12. keep_ssh_host_keys pre_install_network_config
  13. kickstart_done pre_partition_select
  14. kickstart_start preseed_apt_repo_config
  15. koan_environment proxy.xml
  16. late_apt_repo_config puppet_install_if_enabled
  17. log_ks_post puppet_register_if_enabled
  18. log_ks_post_nochroot redhat_register
  19. log_ks_pre restore_boot_device
  20. main_partition_select rhn_certificate_based_register
  21. network_config save_boot_device
  22. network_config_esx suse_scriptwrapper.xml
  23. network_config_esxi

cobbler配置文件存放目录

 
 
  1. [root@localhost cobbler]# ll /etc/cobbler/
  2. total 108
  3. -rw-r--r-- 1 root root 40 Jan 23 2016 auth.conf
  4. -rw-r--r-- 1 root root 75 Jan 23 2016 cheetah_macros
  5. -rw-r--r-- 1 root root 2409 Jan 23 2016 cobbler_bash
  6. -rw-r--r-- 1 root root 11636 Jan 23 2016 completions
  7. -rw-r--r-- 1 root root 2951 Aug 23 18:05 dhcp.template
  8. -rw-r--r-- 1 root root 385 Jan 23 2016 dnsmasq.template
  9. -rw-r--r-- 1 root root 2014 Jan 23 2016 import_rsync_whitelist
  10. drwxr-xr-x 2 root root 30 Aug 23 09:17 iso
  11. drwxr-xr-x 2 root root 37 Aug 23 09:17 ldap
  12. -rw-r--r-- 1 root root 3076 Jan 23 2016 modules.conf
  13. -rw-r--r-- 1 root root 43 Jan 23 2016 mongodb.conf
  14. -rw-r--r-- 1 root root 680 Jan 23 2016 named.template
  15. drwxr-xr-x 2 root root 4096 Aug 23 09:17 power
  16. drwxr-xr-x 2 root root 4096 Aug 24 05:51 pxe
  17. drwxr-xr-x 2 root root 40 Aug 23 09:17 reporting
  18. -rw-r--r-- 1 root root 368 Jan 23 2016 rsync.exclude
  19. -rw-r--r-- 1 root root 1073 Jan 23 2016 rsync.template
  20. -rw-r--r-- 1 root root 754 Jan 23 2016 secondary.template
  21. -rw-r--r-- 1 root root 19654 Aug 23 17:59 settings
  22. -rw-r--r-- 1 root root 740 Jan 23 2016 tftpd.template
  23. -rw-r--r-- 1 root root 848 Jan 23 2016 users.conf
  24. -rw-r--r-- 1 root root 49 Aug 24 05:27 users.digest
  25. -rw-r--r-- 1 root root 117 Jan 24 2016 version
  26. -rw-r--r-- 1 root root 522 Jan 23 2016 zone.template
  27. drwxr-xr-x 2 root root 6 Jan 24 2016 zone_templates

主要的配置文件目录还是settings

 
 
  1. [root@localhost cobbler]# ll /etc/cobbler/settings
  2. -rw-r--r-- 1 root root 19654 Aug 23 17:59 /etc/cobbler/settings

构建yum仓库

我们每次安装都需要在指定阿里云的yum源那样会比较麻烦,可以直接在装机的时候进行设置 
例如:我们构建一个openstack的yum源 
第一步:添加repo

 
 
  1. [root@localhost ~]# cobbler repo add --name=openstack-mitaka --mirror=http://mirrors.aliyun.com/centos/7.2.1511/cloud/x86_64/openstack-mitaka/ --arch=x86_64 --breed=yum
  2. repo=构建yum仓库
  3. add=添加
  4. --name=源的名字
  5. --mirror=源的地址

第二部:刷新同步repo

 
 
  1. [root@localhost ~]# cobbler reposync
  2. #提示:他会将网站下面所有的包下载到本地,并且帮我们创建repo文件(/etc/yum.repos.d)

第三步:添加repo到对应的profile

 
 
  1. [root@localhost ~]# cobbler profile edit --name=CentOS-7-x86_64 --repos="openstack-mitaka"

默认情况下,在安装系统的时候会默认安装openstack-mitaka 
可以通过修改配置文件,1代表开启

 
 
  1. [root@localhost ~]# vim /etc/cobbler/settings
  2. yum_post_install_mirror: 1

第四步:修改kickstart文件

 
 
  1. 在我们的kickstarts的配置文件中加入$yum_config_stanaz,这样在安装的时候会自动调节yum仓库
  2. [root@localhost ~]# vim /var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg
  3. %post
  4. systemctl disable postfix.service
  5. $yum_config_stanaz
  6. %end

第五步:添加定时任务,定期同步repo

 
 
  1. [root@localhost ~]# echo "00 00 * * * /usr/bin/cobbler reposync --tries=3 --no-file" >>/var/spool/cron/root

自动化的一套流程(系统层面)

因为我们每次安装系统都会很麻烦,而且环境会不一致所以我们可以按照每个服务器的mac地址进行设置

profile 
操作系统 
分区 
预分配的Ip地址 
主机名 
子网 
网关 
dns 
角色

规划如下: 
1.png-8.7kB
mac地址生成方法:设置—>硬件—>网络–>高级—>生成 
2.png-48kB
cobbler设置

 
 
  1. cobbler system add --name=linux-node1.com --mac=00:0C:29:AD:F2:08 \
  2. --profile=CentOS-7.1-x86_64 \
  3. --ip-address=192.168.56.12 \
  4. --subnet=255.255.255.0 \
  5. --gateway=192.168.56.2 \
  6. --interface=eth0 --static=1 \
  7. --hostname=linux-node1.com \
  8. --name-servers="192.168.56.12" \
  9. --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg

结果如下:

 
 
  1. [root@localhost ~]# cobbler system list
  2. [root@localhost ~]# cobbler system add --name=linux-node1.com --mac=00:0C:29:AD:F2:08 \
  3. > --profile=CentOS-7-x86_64 \
  4. > --ip-address=192.168.56.12 \
  5. > --subnet=255.255.255.0 \
  6. > --gateway=192.168.56.2 \
  7. > --interface=eth0 --static=1 \
  8. > --hostname=linux-node1.com \
  9. > --name-servers="192.168.56.12" \
  10. > --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg

cobbler system list查看当前的规划 
如果不知道我们的本地镜像都有哪些可以通过下面的命令查看

 
 
  1. [root@localhost ~]# cobbler profile list
  2. CentOS-6-x86_64
  3. CentOS-7-x86_64

提示:要会看报错信息,根据报错信息进行排查 
我们设置完在查看一下

 
 
  1. [root@localhost ~]# cobbler system list
  2. linux-node1.com

我们执行刷新命令。

 
 
  1. [root@localhost ~]# cobbler sync

否则不生效 
此时我们可以查看dhcp的配置文件,已经帮我们定义好了一个

 
 
  1. [root@localhost ~]# cat /etc/dhcp/dhcpd.conf
  2. # group for Cobbler DHCP tag: default
  3. group {
  4. host generic1 {
  5. hardware ethernet 00:0C:29:AD:F2:08;
  6. fixed-address 192.168.56.12;
  7. option host-name "linux-node1.com";
  8. option subnet-mask 255.255.255.0;
  9. option routers 192.168.56.2;
  10. filename "/pxelinux.0";
  11. next-server 192.168.56.11;
  12. }
  13. }

温馨提示:MAC地址必须要和装系统的一样,生成见上方 
11.png-400.4kB
现在按照正常的情况下,我们新建一台虚拟机默认就会安装Centos7,不会让我们选择,帮我设置好主机名IP地址 
12.png-59kB
这样就会自动进行安装了 
提示:这里只有对应的mac地址匹配上了,才会执行自动安装,如果没有匹配上。会让我们 选择其他安装的选项 
13.png-15.9kB
安装完成! 
cobbler大多都是使用脚本实现的 
脚本路径:

 
 
  1. [root@localhost ~]# cat /var/lib/cobbler/snippets/post_install_network_config
  2. [root@localhost ~]# ll /var/lib/cobbler/snippets/
  3. total 208
  4. -rw-r--r-- 1 root root 431 Jan 23 2016 cobbler_register
  5. -rw-r--r-- 1 root root 645 Jan 23 2016 download_config_files
  6. -rw-r--r-- 1 root root 865 Jan 23 2016 download_config_files_deb
  7. -rw-r--r-- 1 root root 61 Jan 23 2016 func_install_if_enabled
  8. -rw-r--r-- 1 root root 448 Jan 23 2016 func_register_if_enabled
  9. -rw-r--r-- 1 root root 821 Jan 23 2016 hosts.xml
  10. -rw-r--r-- 1 root root 1310 Jan 23 2016 kdump.xml
  11. -rw-r--r-- 1 root root 2506 Jan 23 2016 keep_cfengine_keys
  12. -rw-r--r-- 1 root root 4316 Jan 23 2016 keep_files
  13. -rw-r--r-- 1 root root 2609 Jan 23 2016 keep_rhn_keys
  14. -rw-r--r-- 1 root root 3155 Jan 23 2016 keep_ssh_host_keys
  15. -rw-r--r-- 1 root root 4547 Jan 23 2016 kickstart_done
  16. -rw-r--r-- 1 root root 1524 Jan 23 2016 kickstart_start
  17. -rw-r--r-- 1 root root 191 Jan 23 2016 koan_environment
  18. -rw-r--r-- 1 root root 644 Jan 23 2016 late_apt_repo_config
  19. -rw-r--r-- 1 root root 40 Jan 23 2016 log_ks_post
  20. -rw-r--r-- 1 root root 62 Jan 23 2016 log_ks_post_nochroot
  21. -rw-r--r-- 1 root root 281 Jan 23 2016 log_ks_pre
  22. -rw-r--r-- 1 root root 46 Jan 23 2016 main_partition_select
  23. -rw-r--r-- 1 root root 3790 Jan 23 2016 network_config
  24. -rw-r--r-- 1 root root 1918 Jan 23 2016 network_config_esx
  25. -rw-r--r-- 1 root root 2276 Jan 23 2016 network_config_esxi
  26. -rw-r--r-- 1 root root 4454 Jan 23 2016 networking.xml
  27. -rw-r--r-- 1 root root 769 Jan 23 2016 partition_select
  28. -rw-r--r-- 1 root root 707 Jan 23 2016 post_anamon
  29. -rw-r--r-- 1 root root 561 Jan 23 2016 post_install_kernel_options
  30. -rw-r--r-- 1 root root 16340 Jan 23 2016 post_install_network_config
  31. -rw-r--r-- 1 root root 11545 Jan 23 2016 post_install_network_config_deb
  32. -rw-r--r-- 1 root root 204 Jan 23 2016 post_koan_add_reinstall_entry
  33. -rw-r--r-- 1 root root 69 Jan 23 2016 post_run_deb
  34. -rw-r--r-- 1 root root 1988 Jan 23 2016 post_s390_reboot
  35. -rw-r--r-- 1 root root 194 Jan 23 2016 pre_anamon
  36. -rw-r--r-- 1 root root 6601 Jan 23 2016 pre_install_network_config
  37. -rw-r--r-- 1 root root 773 Jan 23 2016 pre_partition_select
  38. -rw-r--r-- 1 root root 628 Jan 23 2016 preseed_apt_repo_config
  39. -rw-r--r-- 1 root root 263 Jan 23 2016 proxy.xml
  40. -rw-r--r-- 1 root root 65 Jan 23 2016 puppet_install_if_enabled
  41. -rw-r--r-- 1 root root 644 Jan 23 2016 puppet_register_if_enabled
  42. -rw-r--r-- 1 root root 836 Jan 23 2016 redhat_register
  43. -rw-r--r-- 1 root root 662 Jan 23 2016 restore_boot_device
  44. -rw-r--r-- 1 root root 620 Jan 23 2016 rhn_certificate_based_register
  45. -rw-r--r-- 1 root root 358 Jan 23 2016 save_boot_device
  46. -rw-r--r-- 1 root root 438 Jan 23 2016 suse_scriptwrapper.xml

官方帮助文档:http://cobbler.github.io/manuals/2.4.0/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值