1、cobbler简介

  Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。
  Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
  Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
  Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。
  Cobbler官网http://cobbler.github.io
  在使用cobbler之前需要了解kickstart的使用: http://www.cnblogs.com/clsn/p/7833333.html

1.1 cobbler集成的服务

   PXE服务支持
   DHCP服务管理
   DNS服务管理(可选bind,dnsmasq)
  电源管理
  Kickstart服务支持
  YUM仓库管理
  TFTP(PXE启动时需要)
  Apache(提供kickstart的安装源,并提供定制化的kickstart配置)

2、安装cobbler

2.1 环境说明

  1. [root@Cobbler ~]# cat /etc/redhat-release
  2. CentOS Linux release 7.4.1708 (Core)
  3. [root@Cobbler ~]# uname -r
  4. 3.10.0-693.el7.x86_64
  5. [root@Cobbler ~]# getenforce
  6. Disabled
  7. [root@Cobbler ~]# systemctl status firewalld.service
  8. firewalld.service - firewalld - dynamic firewall daemon
  9. Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
  10. Active: inactive (dead)
  11. Docs: man:firewalld(1)
  12. [root@Cobbler ~]# hostname -I
  13. 10.0.0.202 172.16.1.202

yum源说明:

  1. curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  2. curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

2.2 使用yum安装cobbler

  1. yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd

说明:cobbler是依赖与epel源下载

2.3 cobbler语法检查前先启动http与cobbler

  1. systemctl start httpd.service
  2. systemctl start cobblerd.service
  3. cobbler check

2.4 进行语法检查

  1. [root@Cobbler ~]# 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.

2.5 解决当中的报错

命令集

  1. sed -i 's/server: 127.0.0.1/server: 172.16.1.202/' /etc/cobbler/settings
  2. sed -i 's/next_server: 127.0.0.1/next_server: 172.16.1.202/' /etc/cobbler/settings
  3. sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings
  4. sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings
  5. sed -ri "/default_password_crypted/s#(.*: ).*#\1\"`openssl passwd -1 -salt 'oldboy' '123456'`\"#" /etc/cobbler/settings
  6. sed -i 's#yes#no#' /etc/xinetd.d/tftp
  7. systemctl start rsyncd
  8. systemctl enable rsyncd
  9. systemctl enable tftp.socket
  10. systemctl start tftp.socket
  11. systemctl restart cobblerd.service
  12. sed -i.ori 's#192.168.1#172.16.1#g;22d;23d' /etc/cobbler/dhcp.template
  13. cobbler sync

详解
解决1、2

  1. cp /etc/cobbler/settings{,.ori}
  2. sed -i 's/server: 127.0.0.1/server: 172.16.1.202/' /etc/cobbler/settings
  3. sed -i 's/next_server: 127.0.0.1/next_server: 172.16.1.202/' /etc/cobbler/settings

问题3

  1. sed 's#yes#no#g' /etc/xinetd.d/tftp -i

4.下载包所需的软件包

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

5.启动rsync服务

  1. [root@Cobbler ~]# systemctl start rsyncd.service
  2. [root@Cobbler ~]# systemctl enable rsyncd.service

6.debian相关无需修改
7.修改安装完成后的root密码

  1. openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'
  2. random-phrase-here 随机字符串
  3. your-password-here 密码

示例

  1. [root@Cobbler ~]# openssl passwd -1 -salt 'CLSN' '123456'
  2. $1$CLSN$LpJk4x1cplibx3q/O4O/K/

管理dhcp

  1. sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings

防止重装

  1. sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings

修改dhcp模板

  1. sed -i.ori 's#192.168.1#172.16.1#g;22d;23d' /etc/cobbler/dhcp.template

cobbler组配置文件位置

  1. /etc/cobbler/settings

注意:修改完成之后要使用cobbler sync 进行同步,否则不生效。

2.6 修改之后

再次检查语法:

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

重启所有服务

  1. systemctl restart httpd.service
  2. systemctl restart cobblerd.service
  3. systemctl restart dhcpd.service
  4. systemctl restart rsyncd.service
  5. systemctl restart tftp.socket

到此cobbler就安装完成,下面进行web界面的操作。

3、cobbler的web及界面操作

浏览器访问https://10.0.0.202/cobbler_web
注意CentOS7中cobbler只支持https访问。
账号密码默认均为cobbler
使用cobbler批量安装操作系统(基于Centos7.x ) - 图1

3.1 操作说明—导入镜像

1)在虚拟机上添加上镜像
使用cobbler批量安装操作系统(基于Centos7.x ) - 图2
2)挂载上镜像

  1. [root@Cobbler ~]# mount /dev/cdrom /mnt/
  2. mount: /dev/sr0 is write-protected, mounting read-only
  3. [root@Cobbler ~]# df -h |grep mnt
  4. /dev/sr0 4.3G 4.3G 0 100% /mnt

3)进行导入镜像
选择Import DVD 输入Prefix(文件前缀),Arch(版本),Breed(品牌),Path(要从什么地方导入)
在导入镜像的时候要注意路径,防止循环导入。
信息配置好后,点击run,即可进行导入。
使用cobbler批量安装操作系统(基于Centos7.x ) - 图3
导入过程使用rsync进行导入,三个进程消失表示导入完毕

  1. [root@Cobbler mnt]# ps -ef |grep rsync
  2. root 12026 1 0 19:04 ? 00:00:00 /usr/bin/rsync --daemon --no-detach
  3. root 13554 11778 12 19:51 ? 00:00:06 rsync -a /mnt/ /var/www/cobbler/ks_mirror/CentOS7.4-x86_64 --progress
  4. root 13555 13554 0 19:51 ? 00:00:00 rsync -a /mnt/ /var/www/cobbler/ks_mirror/CentOS7.4-x86_64 --progress
  5. root 13556 13555 33 19:51 ? 00:00:17 rsync -a /mnt/ /var/www/cobbler/ks_mirror/CentOS7.4-x86_64 --progress
  6. root 13590 10759 0 19:52 pts/1 00:00:00 grep --color=auto rsync

查看日志可以发现右running进程
日志位于 Events
使用cobbler批量安装操作系统(基于Centos7.x ) - 图4
导入完成后生成的文件夹

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

3.2 创建一台空白虚拟机,进行测试网路安装

注意:虚拟机的内存不能小于2G,网卡的配置要保证网络互通
启动虚拟机
启动虚拟机即可发现会有cobbler的选择界面
使用cobbler批量安装操作系统(基于Centos7.x ) - 图5
选择CentOS7.4即可进行安装,安装过程与光盘安装一致,这里就不在复述。

4、定制化安装操作系统

4.1 添加内核参数

1)查看导入的镜像,点击edit
使用cobbler批量安装操作系统(基于Centos7.x ) - 图6
2)在内核参数中添加net.ifnames=0 biosdevname=0
能够让显示的网卡变为eth0 ,而不是CentOS7中的ens33
修改完成后点击保存
使用cobbler批量安装操作系统(基于Centos7.x ) - 图7

4.2 查看镜像属性

使用cobbler批量安装操作系统(基于Centos7.x ) - 图8

4.3 编写ks文件

1)创建新的ks文件
使用cobbler批量安装操作系统(基于Centos7.x ) - 图9
2)添加ks文件,并配置文件名
创建完成后点击Save进行保存
使用cobbler批量安装操作系统(基于Centos7.x ) - 图10
CentOS7 ks配置文件参考

  1. # Cobbler for Kickstart Configurator for CentOS 7 by clsn
  2. install
  3. url --url=$tree
  4. text
  5. lang en_US.UTF-8
  6. keyboard us
  7. zerombr
  8. bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
  9. #Network information
  10. $SNIPPET('network_config')
  11. #network --bootproto=dhcp --device=eth0 --onboot=yes --noipv6 --hostname=CentOS7
  12. timezone --utc Asia/Shanghai
  13. authconfig --enableshadow --passalgo=sha512
  14. rootpw --iscrypted $default_password_crypted
  15. clearpart --all --initlabel
  16. part /boot --fstype xfs --size 1024
  17. part swap --size 1024
  18. part / --fstype xfs --size 1 --grow
  19. firstboot --disable
  20. selinux --disabled
  21. firewall --disabled
  22. logging --level=info
  23. reboot
  24. %pre
  25. $SNIPPET('log_ks_pre')
  26. $SNIPPET('kickstart_start')
  27. $SNIPPET('pre_install_network_config')
  28. # Enable installation monitoring
  29. $SNIPPET('pre_anamon')
  30. %end
  31. %packages
  32. @^minimal
  33. @compat-libraries
  34. @core
  35. @debugging
  36. @development
  37. bash-completion
  38. chrony
  39. dos2unix
  40. kexec-tools
  41. lrzsz
  42. nmap
  43. sysstat
  44. telnet
  45. tree
  46. vim
  47. wget
  48. %end
  49. %post
  50. systemctl disable postfix.service
  51. %end

4.4 自定义安装系统

1)选择systems 创建一个新的系统
使用cobbler批量安装操作系统(基于Centos7.x ) - 图11
2)定义系统信息
使用cobbler批量安装操作系统(基于Centos7.x ) - 图12
3)配置全局网络信息
主机名、网关、DNS
使用cobbler批量安装操作系统(基于Centos7.x ) - 图13
4)配置网卡信息,eth0,eth1
需要注意,选择static静态,
使用cobbler批量安装操作系统(基于Centos7.x ) - 图14
以上的所有配置完成后,点击Save进行保存
附录:
VMware workstation中查看虚拟机mac地址的方法。在虚拟机设置中。
使用cobbler批量安装操作系统(基于Centos7.x ) - 图15
cobbler web 界面说明
使用cobbler批量安装操作系统(基于Centos7.x ) - 图16

5、安装虚拟机

5.1 开启虚拟机

如果之前的设置就显示安装进度
使用cobbler批量安装操作系统(基于Centos7.x ) - 图17

5.2 安装完成进行检查

使用cobbler批量安装操作系统(基于Centos7.x ) - 图18

6、cobbler使用常见错误

6.1 cobbler check报错

  1. [root@Cobbler ~]# cobbler sync
  2. Traceback (most recent call last):
  3. File "/usr/bin/cobbler", line 36, in <module>
  4. sys.exit(app.main())
  5. File "/usr/lib/python2.7/site-packages/cobbler/cli.py", line 662, in main
  6. rc = cli.run(sys.argv)
  7. File "/usr/lib/python2.7/site-packages/cobbler/cli.py", line 269, in run
  8. self.token = self.remote.login("", self.shared_secret)
  9. File "/usr/lib64/python2.7/xmlrpclib.py", line 1233, in __call__
  10. return self.__send(self.__name, args)
  11. File "/usr/lib64/python2.7/xmlrpclib.py", line 1587, in __request
  12. verbose=self.__verbose
  13. File "/usr/lib64/python2.7/xmlrpclib.py", line 1273, in request
  14. return self.single_request(host, handler, request_body, verbose)
  15. File "/usr/lib64/python2.7/xmlrpclib.py", line 1306, in single_request
  16. return self.parse_response(response)
  17. File "/usr/lib64/python2.7/xmlrpclib.py", line 1482, in parse_response
  18. return u.close()
  19. File "/usr/lib64/python2.7/xmlrpclib.py", line 794, in close
  20. raise Fault(**self._stack[0])
  21. xmlrpclib.Fault: <Fault 1: "<class 'cobbler.cexceptions.CX'>:'login failed'">

解决办法

systemctl restart httpd.service systemctl restart cobblerd.service cobbler check

6.2 No space left on device

使用cobbler批量安装操作系统(基于Centos7.x ) - 图19
出现这个错误的原因是虚拟机的内存不足2G,
将内存调为2G即可(这个错误只会出现在CentOS7.3之上)

7、附录cobbler_CentOS6.x_ks配置文件

  1. # Cobbler for Kickstart Configurator for CentOS 6 by clsn
  2. install
  3. url --url=$tree
  4. text
  5. lang en_US.UTF-8
  6. keyboard us
  7. zerombr
  8. bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
  9. $SNIPPET('network_config')
  10. timezone --utc Asia/Shanghai
  11. authconfig --enableshadow --passalgo=sha512
  12. rootpw --iscrypted $default_password_crypted
  13. clearpart --all --initlabel
  14. part /boot --fstype=ext4 --asprimary --size=200
  15. part swap --size=1024
  16. part / --fstype=ext4 --grow --asprimary --size=200
  17. firstboot --disable
  18. selinux --disabled
  19. firewall --disabled
  20. logging --level=info
  21. reboot
  22. %pre
  23. $SNIPPET('log_ks_pre')
  24. $SNIPPET('kickstart_start')
  25. $SNIPPET('pre_install_network_config')
  26. # Enable installation monitoring
  27. $SNIPPET('pre_anamon')
  28. %end
  29. %packages
  30. @base
  31. @compat-libraries
  32. @debugging
  33. @development
  34. tree
  35. nmap
  36. sysstat
  37. lrzsz
  38. dos2unix
  39. telnet
  40. %end
  41. %post --nochroot
  42. $SNIPPET('log_ks_post_nochroot')
  43. %end
  44. %post
  45. $SNIPPET('log_ks_post')
  46. # Start yum configuration
  47. $yum_config_stanza
  48. # End yum configuration
  49. $SNIPPET('post_install_kernel_options')
  50. $SNIPPET('post_install_network_config')
  51. $SNIPPET('func_register_if_enabled')
  52. $SNIPPET('download_config_files')
  53. $SNIPPET('koan_environment')
  54. $SNIPPET('redhat_register')
  55. $SNIPPET('cobbler_register')
  56. # Enable post-install boot notification
  57. $SNIPPET('post_anamon')
  58. # Start final steps
  59. $SNIPPET('kickstart_done')
  60. # End final steps
  61. %end

8、参考文档

http://blog.oldboyedu.com/autoinstall-cobbler/ http://www.zyops.com/autoinstall-cobbler