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

[经验分享] 自动化运维——CentOS7下利用Cobbler批量部署CentOS

[复制链接]

尚未签到

发表于 2019-2-16 12:20:03 | 显示全部楼层 |阅读模式
  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源:
[root@CentOS7-1 Desktop]# yum -y install http://mirrors.163.com/centos/7/extras/x86_64/Packages/epel-release-7-11.noarch.rpm   ##安装EPEL源
[root@CentOS7-1 ~]# yum install cobbler cobbler-web dhcp tftp-server pykickstart httpd rsync xinetd -y   ##安装系统部署所需所有服务  开启服务,设置开机自启动方便以后使用,关闭防火墙及增强安全功能:
[root@CentOS7-1 ~]# systemctl restart httpd
[root@CentOS7-1 ~]# systemctl restart cobblerd
[root@CentOS7-1 ~]# systemctl enable httpd.service
[root@CentOS7-1 ~]# systemctl enable cobblerd.service
[root@CentOS7-1 ~]# systemctl stop firewalld
[root@CentOS7-1 ~]# setenforce 0  执行cobbler check,检查需要优化的点,需要注意的是,优化完成后要重启服务使你的优化生效:
  
[root@CentOS7-1 ~]# 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配置文件:

  
[root@CentOS7-1 ~]# 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默认密码:
[root@CentOS7-1 ~]# openssl passwd -1 -salt '123123' '123123'     ##盐值加密
$1$abner$kDle2KnwbPHdm1UZEE79V.    ##得到一串密码
[root@CentOS7-1 ~]# vim /etc/cobbler/settings   ##回setting文件搜索默认密码
default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac."   ##将得到的密码复制到双撇号内

  •   下载引导操作系统文件:
[root@CentOS7-1 ~]# 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服务:
[root@CentOS7-1 ~]# 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模板:
[root@CentOS7-1 ~]# 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配置文件:
[root@CentOS7-1 ~]# 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 ***  ##显示配置成功!  重启服务使配置生效:

[root@CentOS7-1 ~]# systemctl restart cobblerd
[root@CentOS7-1 ~]# systemctl restart rsyncd
[root@CentOS7-1 ~]# systemctl enable rsyncd
[root@CentOS7-1 ~]# systemctl restart xinetd
[root@CentOS7-1 ~]# systemctl restart dhcpd  再次执行cobbler check检查:
[root@CentOS7-1 ~]# 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中:

  
[root@CentOS7-1 cobbler]# mount /dev/cdrom /mnt   ##挂载镜像光盘到mnt目录中
mount: /dev/sr0 is write-protected, mounting read-only
[root@CentOS7-1 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登录用户及密码:
  
[root@CentOS7-1 cobbler]# htdigest -c /etc/cobbler/users.digest Cobbler cobbler  ##设置用户名为cobbler
Adding password for cobbler in realm Cobbler.
New password:
Re-type new password:
[root@CentOS7-1 cobbler]# systemctl restart cobblerd.service
[root@CentOS7-1 cobbler]# systemctl restart httpd  
cobbler-web的登录界面:
  
  




运维网声明 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-673150-1-1.html 上篇帖子: CentOS7关于NFS的初学 下篇帖子: centos6.8安装xfce+vnc
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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