自动化运维利器之cobbler安装centos7

一、cobbler简介和服务

Cobbler是一款自动化操作系统安装的实现,与PXE安装系统的区别就是可以同时部署多个版本的系统,而PXE只能选择一种系统。而如今的架构动辄就是上千台的服务器。而存在一些操作系统不统一的现象,例如最初的架构采用的是CentOS5系列的系统,而新出现了一些技术后,需要新的操作系统的支持,一方面是需要批量部署装机,而另一方面还需要考虑到如果老版本的服务器出现故障后还需要重新去部署。并且提供Web配置页面,可以只需要一些点击就可以完成一些操作。
注:下文来自http://cobbler.github.io
Cobbler is a Linux installation server that allows forrapid setup of network installation environments. It glues together andautomates many associated Linux tasks so you do not have to hop between manyvarious commands and applications when deploying new systems, and, in somecases, changing existing ones. Cobbler can help with provisioning, managing DNSand DHCP, package updates, power management, configuration managementorchestration, and much more.
服务类型:DNS,DHCP,更新包,电源管理,配置管理(支持puppet)

二、引入kickstart

见本人kickstart博文:http://chuck.blog.51cto.com/10232880/1718168

三、cobbler实战

装cobbler 等依赖服务

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

启动httpd 和cobbler服务

  1. [root@linux-node1 ~]# /etc/init.d/httpd restart
  2. [root@linux-node1 ~]# /etc/init.d/cobblerd start

使用cobbler check(5、6、8三步并不需要执行)检查,检查后使用cobbler sync同步操作
After installing, run “cobbler check” to verify that cobbler’s ecosystem is configured
correctly. Cobbler check will direct you on how to modify it’s config files using a text
editor.

  1. [root@linux-node1 ~]# 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
  4. localhost, or kickstarting features will not work. This should be a resolvable hostname
  5. or IP for the boot server as reachable by all machines that will use it.
  6. 2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set
  7. to something other than 127.0.0.1, and should match the IP of the boot server on the PXE
  8. network.
  9. 3 : some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run
  10. 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64
  11. netbooting, you may ensure that you have installed a *recent* version of the syslinux
  12. package installed and can ignore this message entirely. Files in this directory,
  13. should you want to support all architectures, should include pxelinux.0, menu.c32,
  14. elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve
  15. these requirements.
  16. 4 : change 'disable' to 'no' in /etc/xinetd.d/rsync
  17. 5 : reposync is not installed, need for cobbler reposync, install/upgrade yum-utils?
  18. 6 : debmirror package is not installed, it will be required to manage debian deployments
  19. and repositories
  20. 7 : The default password used by the sample templates for newly installed machines
  21. (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should
  22. be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to
  23. generate new one
  24. 8 : fencing tools were not found, and are required to use the (optional) power management
  25. features. install cman or fence-agents to use them
  26. Restart cobblerd and then run 'cobbler sync' to apply changes.

述结果直接告诉了安装cobbler需要哪些步骤,一步步按照提示进行操作即可
部署第一步+第二步+第七步

  1. vim /etc/cobbler/settings
  2. server: 10.0.0.7
  3. next_server: 10.0.0.7 #指定tftp所在的服务器
  4. manage_dhcp: 1 #使用cobbler管理dhcp

使用openssl对密码加密(前面的chuck是加盐随机值,后面的chuck是密码)

  1. [root@linux-node1 ~]# openssl passwd -1 -salt 'chuck' 'chuck'
  2. $1$chuck$vVcMGy7s.o2XdXxFM4TLo1

修改password

  1. default_password_crypted: "$1$chuck$vVcMGy7s.o2XdXxFM4TLo1"

保存文件并使用cobble check重新检查
部署第三步:some network boot-loaders are missing from /var/lib/cobbler/loaders

  1. [root@linux-node1 ~]#cobbler get-loaders

部署第四步:把disable选项改为no,并重新启动xinetd

  1. [root@linux-node1 ~]# vim /etc/xinetd.d/rsync
  2. change 'disable' to 'no'
  3. [root@linux-node1 ~]# /etc/init.d/xinetd restart

重启cobbler,并重新cobbler check
修改/etc/cobbler/dhcp.template 文件,该文件通过cobbler sync可以管理/etc/dhcp/dhcpd.conf文件,所以在此不需要更高/etc/dhcp/dhcpd.conf文件

  1. [root@linux-node1 ~]# vim /etc/cobbler/dhcp.template
  2. subnet 10.0.0.0 netmask 255.255.255.0 {
  3. option routers 10.0.0.2;
  4. option domain-name-servers 10.0.0.2;
  5. option subnet-mask 255.255.255.0;
  6. range dynamic-bootp 10.0.0.100 10.0.0.200;

执行cobbler sync
使用vmvare虚拟机的iso镜像挂载到/mnt 路径(如下图),并导入镜像

cobbler –name:倒进后的名字 –arch:镜像架构 –path:挂载路径

  1. [root@linux-node1 ~]# mount /dev/cdrom /mnt
  2. [root@linux-node1 ~]# cobbler import --path=/mnt/ --name=CentOS-7.1-x86_64 --arch=x86_64

导入后镜像所在位置:/var/www/cobbler/ks_mirror/

  1. [root@linux-node1 ~]# ls /var/www/cobbler/ks_mirror/
  2. CentOS-7.1-x86_64 config

给kickstart定义ks文件

  1. [root@linux-node1 ~]# 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'}
  11. Kernel Options (Post Install) : {}
  12. Kickstart : /var/lib/cobbler/kickstarts/CentOS-7.1-x86_64.cfg
  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

使用cobbler profile指定ks文件位置和内核参数(net.ifnames=0和biosdevname=0代表更改网卡为eth0==》》运维标准化)

  1. cobbler profile edit --name=CentOS-7.1-x86_64 --kickstart= \
  2. /var/lib/cobbler/kickstarts/CentOS-7.1-x86_64.cfg
  3. cobbler profile edit --name=CentOS-7.1-x86_64 --kopts='net.ifnames=0 biosdevname=0'

为安装的机器安装一个yum源,并同步。建议使用内网yum源,在这里使用aliyun

  1. [root@linux-node1 ~]# cobbler repo add -name=openstack-liberty -mirror=http://mirrors.aliyun.com/centos/7.1.1503/cloud/x86_64/openstack-liberty/ --arch=x86_64 --breed=yum
  2. [root@linux-node1 ~]# cobbler reposync

编辑porfile,装完机器自动就会生成刚才指定的yum源

  1. [root@linux-node1 ~]# cobbler profile edit --name=xxx --repo="openstack-liberty"

根据机器的MAC地址,自动绑定IP,网关,dns等

  1. cobbler system add --name=chuck--mac=00:0C:29:22:E1:9C --profile=CentOS-7.1-x86_64 \
  2. --ip-address=10.0.0.111 --subnet=255.255.255.0 --gateway=10.0.0.2 --interface=eth0 \
  3. --static=1 --hostname=oldboy.example.com --name-servers="114.114.114.114 8.8.8.8"

使用cobbler sync同步配置
注意:客户端机器装系统时,要先使用修改bios启动然后修改为网卡启动,如图,把network boot from Intel E1000调整为最上,F10保存

出现下图所示,代表开始从dhcp服务安装系统开始

修改cobbler提示

  1. [root@linux-node1 ~]# vim /etc/cobbler/pxe/pxedefault.template
  2. DEFAULT menu
  3. PROMPT 0
  4. MENU TITLE by chuck | http://chuck.blog.51cto.com
  5. TIMEOUT 200
  6. TOTALTIMEOUT 6000
  7. ONTIMEOUT $pxe_timeout_profile
  8. LABEL local
  9. MENU LABEL (local)
  10. MENU DEFAULT
  11. LOCALBOOT -1
  12. $pxe_menu_items
  13. MENU end

四、web界面管理cobbler

在最开始yum的时候安装了cobbler-web,当然也就可以使用web界面管理cobbler
新版cobbler的web界面使用的是https,登录https://10.0.0.7/cobbler_web

(默认情况下username和password都是cobbler,可以通过用户名所在文件: /etc/cobbler/users.conf 和 密码所在文件:/etc/cobbler/users.digest进行管理 管理)


待安装完后,关闭机器,否则会反复安装,因此也要注意生产环境,尽量不要从网卡启动,防止机器意外重装!

0
未经许可,不得转载,否则将受到作者追究,博主联系方式见首页右上角

该文章由 发布

这货来去如风,什么鬼都没留下!!!
发表我的评论
取消评论
代码 贴图 加粗 链接 删除线 签到