自动化运维——CentOS7下利用Cobbler批量部署CentOS

Cobbler是一个使用Python开发的开源项目,通过将部署系统所涉及的所有服务集中在一起,来提供一个全自动批量快速建立Linux系统的网络安装环境,Cobbler最初支持Fedora、RedHat和衍生版(如CentOS和Scientific Linux),现在还支持Debian、Ubuntu、SuSE以及FreeBSD、ESXI等。Cobbler是一款快速的网络系统部署工具,其最大的特点是集合了所有系统部署所需服务,如DHCP、DNS、TFTP,这样你在部署一台操作系统的时候不需要在各个服务之前协调切换,Cobbler都可以替你来管理,Cobbler内部集成了一个镜像版本仓库,你可以自定义相关配置文件,实现不同系统不同安装需求的选择;当然,Cobbler还提供了包括yum源管理、Web界面管理、API接口、电源管理等功能,方便你自定义开发管理。



Cobbler的配置文件位置及配置:


1.) Cobbler配置文件目录:/etc/cobbler

/etc/cobbler/settings #cobbler主配置文件

/etc/cobbler/dhcp.template #DHCP服务的配置模板

/etc/cobbler/tftpd.template #tftp服务的配置模板

/etc/cobbler/rsync.template #rsync服务的配置模板

/etc/cobbler/iso #iso模板配置文件

/etc/cobbler/pxe #pxe模板文件

/etc/cobbler/power #电源的配置文件

/etc/cobbler/users.conf #Web服务授权配置文件

/etc/cobbler/users.digest #用于web访问的用户名密码配置文件

/etc/cobbler/dnsmasq.template #DNS服务的配置模板

/etc/cobbler/modules.conf #Cobbler模块配置文件

2.) Cobbler数据目录:/var/lib/cobbler

/var/lib/cobbler/config #配置文件

/var/lib/cobbler/triggers #Cobbler命令

/var/lib/cobbler/kickstarts #默认存放kickstart文件

/var/lib/cobbler/loaders #存放的各种引导程序

3.) 系统安装镜像目录:/var/www/cobbler

/var/www/cobbler/ks_mirror #导入的系统镜像列表

/var/www/cobbler/images #导入的系统镜像启动文件

/var/www/cobbler/repo_mirror #yum源存储目录

4.) 日志目录:/var/log/cobbler

/var/log/cobbler/install.log #客户端系统安装日志

/var/log/cobbler/cobbler.log #cobbler日志



下面我们来完成Cobbler服务的搭建:

Cobbler环境是由EPEL源提供的,我们先到站点下载EPEL源:

[[email protected] Desktop]# yum -y install http://mirrors.163.com/centos/7/extras/x86_64/Packages/epel-release-7-11.noarch.rpm   ##安装EPEL源
[[email protected] ~]# yum install cobbler cobbler-web dhcp tftp-server pykickstart httpd rsync xinetd -y   ##安装系统部署所需所有服务

开启服务,设置开机自启动方便以后使用,关闭防火墙及增强安全功能:

[[email protected] ~]# systemctl restart httpd
[[email protected] ~]# systemctl restart cobblerd
[[email protected] ~]# systemctl enable httpd.service
[[email protected] ~]# systemctl enable cobblerd.service
[[email protected] ~]# systemctl stop firewalld
[[email protected] ~]# setenforce 0

执行cobbler check,检查需要优化的点,需要注意的是,优化完成后要重启服务使你的优化生效:

[[email protected] ~]# cobbler check

The following are potential configuration items that you may want to fix:
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.
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.
3 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:
    https://github.com/cobbler/cobbler/wiki/Selinux
4 : change 'disable' to 'no' in /etc/xinetd.d/tftp
5 : 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.
6 : enable and start rsyncd.service with systemctl
7 : debmirror package is not installed, it will be required to manage debian deployments and repositories
8 : 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
9 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them Restart cobblerd and then run 'cobbler sync' to apply changes.

此时,我们按照上面需要优化的点逐步去优化:

  • 修改cobbler配置文件:
[[email protected] ~]# vim /etc/cobbler/settings 

将“next_server: 127.0.0.1”修改为“next_server: 192.168.117.130”   ##指定PXE位置,这里用的为本机地址
将“server: 127.0.0.1”修改为“server: 192.168.117.130”
将"manage_dhcp: 0"修改为"manage_dhcp: 1"   ##管理dhcp启动
  • 修改cobbler默认密码:
[[email protected] ~]# openssl passwd -1 -salt '123123' '123123'     ##盐值加密
$1$abner$kDle2KnwbPHdm1UZEE79V.    ##得到一串密码
[[email protected] ~]# vim /etc/cobbler/settings   ##回setting文件搜索默认密码

default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac."   ##将得到的密码复制到双撇号内
  • 下载引导操作系统文件:
[[email protected] ~]# cobbler get-loaders
task started: 2018-05-31_144102_get_loaders
task started (id=Download Bootloader Content, time=Thu May 31 14:41:02 2018)
downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***   ##显示任务完成
  • 启用tftp服务:
[[email protected] ~]# vim /etc/xinetd.d/tftp 
# default: off
# description: The tftp server serves files using the trivial file transfer #       protocol.  The tftp protocol is often used to boot diskless #       workstations, download configuration files to network-aware printers, #       and to start the installation process for some operating systems.
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot
        disable                 = no      ##修改为no启用服务
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
  • 配置cobbler控制的dhcp模板:
[[email protected] ~]# vim /etc/cobbler/dhcp.template 
##省略部分信息
set vendorclass = option vendor-class-identifier;
option pxe-system-type code 93 = unsigned integer 16;
subnet 192.168.117.0 netmask 255.255.255.0 {   //修改子网
     option routers             192.168.117.1;  //修改网关
     option domain-name-servers 192.168.117.2;  //修改DNS
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.117.100 192.168.117.200;  //指定地址池,和cobbler服务器在同一网段
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
  • 帮助生成DHCP配置文件:
[[email protected] ~]# cobbler sync

task started: 2018-05-31_145223_sync
task started (id=Sync, time=Thu May 31 14:52:23 2018)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
copying: /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
copying: /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
copying: /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
copying: /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
copying: /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
copying: /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering TFTPD files
generating /etc/xinetd.d/tftp
cleaning link caches
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***  ##显示配置成功!

重启服务使配置生效:

[[email protected] ~]# systemctl restart cobblerd
[[email protected] ~]# systemctl restart rsyncd
[[email protected] ~]# systemctl enable rsyncd
[[email protected] ~]# systemctl restart xinetd
[[email protected] ~]# systemctl restart dhcpd

再次执行cobbler check检查:

[[email protected] ~]# cobbler check
##下面三条可以忽略不去处理
The following are potential configuration items that you may want to fix:
1 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:
    https://github.com/cobbler/cobbler/wiki/Selinux
2 : debmirror package is not installed, it will be required to manage debian deployments and repositories
3 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
Restart cobblerd and then run 'cobbler sync' to apply changes.

导入iso镜像文件到cobbler中:

[[email protected] cobbler]# mount /dev/cdrom /mnt   ##挂载镜像光盘到mnt目录中
mount: /dev/sr0 is write-protected, mounting read-only
[[email protected] cobbler]# cobbler import --path=/mnt/ --name=CentOS-7-x86_64 --arch=x86_64  ##导入iso镜像
task started: 2018-05-31_150936_import
task started (id=Media import, time=Thu May 31 15:09:36 2018)
Found a candidate signature: breed=redhat, version=rhel6
Found a candidate signature: breed=redhat, version=rhel7
Found a matching signature: breed=redhat, version=rhel7
Adding distros from path /var/www/cobbler/ks_mirror/CentOS-7-x86_64:
creating new distro: CentOS-7-x86_64
trying symlink: /var/www/cobbler/ks_mirror/CentOS-7-x86_64 -> /var/www/cobbler/links/CentOS-7-x86_64
creating new profile: CentOS-7-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/ks_mirror/CentOS-7-x86_64 for CentOS-7-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS-7-x86_64    ##默认导入存放位置
need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS-7-x86_64
looking for /var/www/cobbler/ks_mirror/CentOS-7-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS-7-x86_64/repodata
*** TASK COMPLETE ***

cobbler安装界面,选择CentOS-7-x86_64即可完成安装:

完成安装后的CentOS 7:



Cobbler-Web,网络访问:

设置一个cobbler-web登录用户及密码:

[[email protected] cobbler]# htdigest -c /etc/cobbler/users.digest Cobbler cobbler  ##设置用户名为cobbler
Adding password for cobbler in realm Cobbler.
New password: 
Re-type new password: 
[[email protected] cobbler]# systemctl restart cobblerd.service
[[email protected] cobbler]# systemctl restart httpd

cobbler-web的登录界面:

原文地址:http://blog.51cto.com/13625676/2122512

时间: 2024-08-15 20:32:06

自动化运维——CentOS7下利用Cobbler批量部署CentOS的相关文章

Python自动化运维开发之paramiko(远程批量管理服务器)

一:简介 paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接.它仅需要在本地上安装相应的软件(python以及PyCrypto),对远程服务器没有配置要求,对于连接多台服务器,进行复杂的连接操作特别有帮助. 二:安装方法 安装paramiko有两个先决条件,python和另外一个名为PyCrypto的模块.唯一麻烦的就是安装PyCrypto时,需要GCC库编译,如果没有GCC库会报错,会导致PyCrypto以及paramiko无法安装

自动化运维之Ansible概述及Ansible部署|(持续更新中)

Ansible概述 由于互联网的快速发展导致产品更新换代速度逐渐加快,运维人员每天都要进行大量的维护操作,仍旧按照传统方式进行维护使得工作效率低下.这时,部署自动化运维就可以尽可能安全,高效地完成这些工作. 一般会把自动化运维工具划分为两类:一类是需要使用代理工具的,也就是基于专用的Agent程序来完成管理功能,如:Puppet.Func.Zabbix等:另外一类是不需要配置代理工具的,可以直接基于SSH服务来完成管理功能,如:Ansible.Fabric等. 1.Puppet Puppet基于

自动化运维之-PXE实现系统批量自动安装

本节索引 需求分析 PXE简介 整体方案 服务选择 功能实现 安装调试 错误分析 总结 1 需求分析 随着互联网技术的不断壮大,服务器数量也在不断的增加,IT运维已经成为IT服务内涵中重要的组成部分.面对越来越复杂的业务,面对越来越多样化的用户需求,不断扩展的IT应用需要越来越合理的模式来保障IT服务能灵活便捷.安全稳定地持续保障,这种模式中的保障因素就是IT运维.从初期的几台服务器发展到庞大的数据中心,单靠人工已经无法满足在技术.业务.管理等方面的要求,那么标准化.自动化.架构优化.过程优化等

CentOS7下利用cobbler搭建openstack本地源

前面提到了使用cobbler进行自动化部署系统,下面我们介绍下如何利用cobbler快速搭建openstack本地源(这里我以我的测试环境中的openstack的Mitaka版本为例). 操作步骤如下: 1.添加openstack源: [[email protected] ~]# cobbler repo add --name=openstack-mitaka --mirror=http://mirrors.163.com/centos/7.3.1611/cloud/x86_64/opensta

CentOS7下利用cobbler部署CentOS

1)安装epel源和cobbler [[email protected] ~]# yum -y install http://mirrors.163.com/centos/7/extras/x86_64/Packages/epel-release-7-9.noarch.rpm [[email protected] ~]# yum install cobbler cobbler-web dhcp tftp-server pykickstart httpd xinetd -y [[email pro

python自动化运维——OMserver平台Web服务端部署过程

1.下载源代码(简单不讲述) 2.安装pcre,pcre是一个轻量级的正则表达式函数库,nginx的HTTP Rewrite模块会用到. wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz tar -zxvf pcre-8.34.tar.gz cd pcre-8.34 ./configure make && make install 3.安装nginx. wget http://nginx.

企业自动化运维

from http://bbs.chinaunix.net/thread-3779206-1-1.html 系统安装是交给IDC人员,最小化安装有标准规范Nagios.Cacti生产用的最多ControlTier.Zabbix.Puppet--这些折腾和测试过目前批量改密是用的脚本主机统一管理和登录是买的第三方产品自己内部用python开发了一套运维管理系统php开发数据库备份检查工具 +++++++++++++++++++++++++++1.不部署(或者无需刻意部署)agent的ssh,ssh

自动化运维Ansible之Playbook剧本(持续更新)

附上前两篇关于Ansible的博客地址,以供查阅,欢迎学习交流!自动化运维之Ansible概述及Ansible部署Ansible命令应用之常用模块 Playbook简介 playbook是ansible用于配置,部署,和管理被控节点的剧本. 通过playbook的详细描述,执行其中的一系列tasks,可以让远端主机达到预期的状态.playbook就像Ansible控制器给被控节点列出的的一系列to-do-list,而被控节点必须要完成. 也可以这么理解,playbook 字面意思,即剧本,现实中

自动化运维(一):Cobbler批量部署操作系统

作者:独笔孤行@TaoCloud 前言 Cobbler是自动化运维的必备工具,可通过网络启动(PXE)方式实现操作系统快速批量安装.Cobbler快速安装操作系统基于kickstart实现,但Cobbler功能更完善,管理更加简便.高效.Cobbler通过将安装系统所涉及的服务(tftp.dhcp.kickstart)集中管理,提供全自动化批量快速安装系统的网络环境,以实现大规模机房设备的统一管理. 一.简介 Cobbler支持CLI与WEB两种管理方式.要求所有被安装系统的服务器与Cobble