zoukankan      html  css  js  c++  java
  • Cobbler自动化部署系统

    1、cobbler简介

    ​ cobbler是一个LInux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等

    ​ cobbler可以使用命令行的方式来管理,也提供了基于web的界面管理工具(cobble-web),还提供了API接口,可以方便二次开发的使用。

    ​ Cobbler是早些年前的kickstart的升级版,优点是比较容易配置的,还自带web方便管理

    ​ Cobbler内置一个轻量级管理系统,但他也支持其他配置管理系统集成,如Puppet,暂时不支持SaltStack

    cobbler 集成的服务

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

    cobbler配置文件详解

    cobbler的所在目录:/etc/cobbler

    配置文件 作用
    /etc/cobbler/sttings cobbler主配置文件
    /etc/cobbler/iso iso模板配置文件
    /etc/cobbler/pxe pxe配置文件
    /etc/cobbler/power 电源配置文件
    /etc/cobbler/user.conf web授权配置文件
    /etc/cobbler/users.digest web的访问的用户名和密码
    /etc/cobbler/dhcp.template dhcp服务器的配置模板
    /etc/cobbler/dnsmasq.template dns服务器的配置模板
    /etc/cobbler/tftpd.template tftp服务的配置文件
    /etc/cobbler/modules.conf 模块配置文件

    cobbler的数据目录

    目录 作用
    /var/lib/cobbler/config/ 用于存放distros,system,profiles等信息文件
    /var/lib/cobbler/triggers/ 用于存放用户定义的cobber命令
    /var/lib/cobbler/kickstart/ 默认存放kickstart文件
    /var/lib/cobbler/loaders/ 存放各种引导程序以及镜像目录
    /var/www/cobbler/ks_mirror/ 导入发行版本系统的所有数据
    /var/www/cobbler/repo_mirror/ yum 仓库储存目录
    /var/www/cobbler/images/ 导入发行版本的kernel和initrd镜像用于远程网络启动

    cobbler日志文件

    日志文件路径 说明
    /var/log/cobbler/installing 客户端日志
    /var/log/cobbler/cobbler.log cobbler日志

    cobbler命令详解

    cobbler check //核对配置有没有问题

    cobbler list //列出所有的cobbler元素

    cobbler report //列出元素的详细信息

    cobbler sync //同步数据目录

    2、配置cobbler服务

    1、关闭防火墙和selinux

    # 关闭防火墙、selinux等
    [root@cobbler ~]# systemctl stop firewalld
    [root@cobbler ~]# systemctl disable firewalld
    [root@cobbler ~]# setenforce 0
    [root@cobbler ~]# sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/sysconfig/selinux
    

    2、下载cobbler和相关依赖

    # 配置epel源
    [root@cobbler ~]# yum -y install epel-release
    
    # 安装cobbler及dhcp httpd xinetd cobbler-web
    [root@cobbler ~]# yum -y install cobbler cobbler-web tftp-server dhcp httpd xinetd
    # 启动cobbler及httpd并加入开机启动
    [root@cobbler ~]# systemctl start httpd cobblerd
    [root@cobbler ~]# systemctl enable httpd cobblerd
    

    3、设置可以动态的配置文件

    [root@cobbler ~]# sed -ri '/allow_dynamic_settings:/callow_dynamic_settings: 1' /etc/cobbler/settings
    [root@cobbler ~]# grep allow_dynamic_settings /etc/cobbler/settings 
    allow_dynamic_settings: 1
    [root@cobbler ~]# systemctl restart cobblerd
    

    4、查看cobbler的相关配置

    #192.168.2.128为本机ip
    [root@cobbler ~]# cobbler setting edit --name=server --value=192.168.2.128
    [root@cobbler ~]# cobbler setting edit --name=next_server --value=192.168.2.128
    [root@cobbler ~]# sed -ri '/disable/cdisable = no' /etc/xinetd.d/tftp
    [root@cobbler ~]# systemctl enable xinetd
    [root@cobbler ~]# systemctl restart xinetd
    #下载某些cobbler插件
    [root@cobbler ~]# cobbler get-loaders
    #设置你的开机密码
    [root@cobbler ~]# openssl passwd -1 -salt `openssl rand -hex 4` 'admin'
    $1$675f1d08$oJoAMVxdbdKHjQXbGqNTX0
    [root@cobbler ~]# vim vim /etc/cobbler/settings 
    ......
    default_password_crypted: $1$675f1d08$oJoAMVxdbdKHjQXbGqNTX0
    ......
    [root@cobbler ~]# yum -y install fence-agents
    [root@cobbler ~]# cobbler check
    #检查是否有错误
    [root@cobbler ~]# 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
    [root@cobbler ~]# cobbler setting edit --name=manage_dhcp --value=1
    # 修改cobbler的dhcp模块,不要直接修改dhcp本身的配置文件,因为cobbler会覆盖
    [root@cobbler ~]# vim /etc/cobbler/dhcp.template
    ...
    subnet 192.168.2.0 netmask 255.255.255.0 { #这里改为分配的网段和掩码
         #option routers             192.168.1.5; #如果有网关,这里改为网关地址
         #option domain-name-servers 192.168.1.1; #如果有DNS,这里改为DNS地址
         option subnet-mask         255.255.255.0; #改为分配的IP的掩码
         range dynamic-bootp        192.168.2.100 192.168.2.254; #改为分配的IP的范围
    ...
    

    5、cobbler的同步设置

    [root@cobbler ~]#  cobbler sync
    task started: 2020-06-01_093828_sync
    task started (id=Sync, time=Mon Jun  1 09:38:28 2020)
    running pre-sync triggers
    cleaning trees
    removing: /var/www/cobbler/images/radhat7-x86_64
    removing: /var/lib/tftpboot/pxelinux.cfg/default
    removing: /var/lib/tftpboot/grub/images
    removing: /var/lib/tftpboot/grub/grub-x86.efi
    removing: /var/lib/tftpboot/grub/grub-x86_64.efi
    removing: /var/lib/tftpboot/grub/efidefault
    removing: /var/lib/tftpboot/images/radhat7-x86_64
    removing: /var/lib/tftpboot/s390x/profile_list
    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 files for distro: radhat7-x86_64
    trying hardlink /var/www/cobbler/ks_mirror/radhat7-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/radhat7-x86_64/vmlinuz
    trying hardlink /var/www/cobbler/ks_mirror/radhat7-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/radhat7-x86_64/initrd.img
    copying images
    generating PXE configuration files
    generating PXE menu structure
    copying files for distro: radhat7-x86_64
    trying hardlink /var/www/cobbler/ks_mirror/radhat7-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/radhat7-x86_64/vmlinuz
    trying hardlink /var/www/cobbler/ks_mirror/radhat7-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/radhat7-x86_64/initrd.img
    Writing template files for radhat7-x86_64
    rendering DHCP files
    generating /etc/dhcp/dhcpd.conf
    rendering TFTPD files
    generating /etc/xinetd.d/tftp
    processing boot_files for distro: radhat7-x86_64
    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: dhcpd -t -q
    received on stdout: 
    received on stderr: 
    running: service dhcpd restart
    received on stdout: 
    received on stderr: Redirecting to /bin/systemctl restart dhcpd.service
    
    running shell triggers from /var/lib/cobbler/triggers/sync/post/*
    running python triggers from /var/lib/cobbler/triggers/change/*
    running python trigger cobbler.modules.manage_genders
    running python trigger cobbler.modules.scm_track
    running shell triggers from /var/lib/cobbler/triggers/change/*
    *** TASK COMPLETE ***
    
    

    5、cobbler配置安装radhad7x

    1、创建挂载点,并且挂载

    [root@test2 ~]#  mount /dev/cdrom /radhat-7/
    

    2、导入挂载镜像

    [root@cobbler ~]# cobbler import --path=/centos6 --name=centos6.9 --arch=x86_64
    # --path 镜像路径
    # --name 为安装源定义一个名字
    # --arch 指定安装源是32位、64位、ia64, 目前支持的选项有: x86│x86_64│ia64
    # 安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:centos6.9,如果重复,系统会提示导入失败。
    

    3、查看导入镜像

    [root@cobbler ~]# cobbler distro report --name=radhat7-x86_64
    Name                           : radhat7-x86_64
    Architecture                   : x86_64
    TFTP Boot Files                : {}
    Breed                          : redhat
    Comment                        : 
    Fetchable Files                : {}
    Initrd                         : /var/www/cobbler/ks_mirror/radhat7-x86_64/images/pxeboot/initrd.img
    Kernel                         : /var/www/cobbler/ks_mirror/radhat7-x86_64/images/pxeboot/vmlinuz
    Kernel Options                 : {}
    Kernel Options (Post Install)  : {}
    Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/radhat7-x86_64'}
    Management Classes             : []
    OS Version                     : rhel7
    Owners                         : ['admin']
    Red Hat Management Key         : <<inherit>>
    Red Hat Management Server      : <<inherit>>
    Template Files                 : {}
    
    [root@cobbler ~]# 
    

    4、查看profile信息

    [root@cobbler ~]# cobbler profile report --name=radhat7-x86_64
    Name                           : radhat7-x86_64
    TFTP Boot Files                : {}
    Comment                        : 
    DHCP Tag                       : default
    Distribution                   : radhat7-x86_64
    Enable gPXE?                   : 0
    Enable PXE Menu?               : 1
    Fetchable Files                : {}
    Kernel Options                 : {}
    Kernel Options (Post Install)  : {}
    Kickstart                      : /var/lib/cobbler/kickstarts/radhat7.ks
    Kickstart Metadata             : {}
    Management Classes             : []
    Management Parameters          : <<inherit>>
    Name Servers                   : []
    Name Servers Search Path       : []
    Owners                         : ['admin']
    Parent Profile                 : 
    Internal proxy                 : 
    Red Hat Management Key         : <<inherit>>
    Red Hat Management Server      : <<inherit>>
    Repos                          : []
    Server Override                : <<inherit>>
    Template Files                 : {}
    Virt Auto Boot                 : 1
    Virt Bridge                    : xenbr0
    Virt CPUs                      : 1
    Virt Disk Driver Type          : raw
    Virt File Size(GB)             : 5
    Virt Path                      : 
    Virt RAM (MB)                  : 512
    Virt Type                      : kvm
    [root@cobbler ~]# 
    

    5、copy一份profile文件(ks),进行修改

    [root@cobbler ~]# cd /var/lib/cobbler/kickstarts/
    [root@cobbler kickstarts]# ls
    default.ks    install_profiles  sample_autoyast.xml  sample_esxi4.ks  sample.ks
    esxi4-ks.cfg  legacy.ks         sample_end.ks        sample_esxi5.ks  sample_old.seed
    esxi5-ks.cfg  pxerescue.ks      sample_esx4.ks       sample_esxi6.ks  sample.seed
    [root@cobbler kickstarts]# cp sample_end.ks radhat7.ks
    #修改内容如下
    # This kickstart file should only be used with EL > 5 and/or Fedora > 7.
    # For older versions please use the sample.ks kickstart file.
    # Install OS instead of upgrade
    install
    # Use text mode install
    text
    # System keyboard
    keyboard us
    # System language
    lang en_US
    # System timezone
    timezone  Asia/ShangHai
    #Root password
    rootpw --iscrypted $default_password_crypted
    # System authorization information
    auth  --useshadow  --enablemd5
    # Firewall configuration
    firewall --disabled
    # SELinux configuration
    selinux --disabled
    # Use network installation
    url --url=$tree
    
    # Clear the Master Boot Record
    zerombr
    # System bootloader configuration
    bootloader --location=mbr
    # Partition clearing information
    clearpart --all --initlabel
    #这是磁盘分区
    part /boot --fstype="ext4" --size=500
    part swap --fstype="swap" --size=4096
    part / --fstype="ext4" --grow --size=15000
    
    
    # If any cobbler repo definitions were referenced in the kickstart profile, include them here.
    $yum_repo_stanza
    # Network information
    $SNIPPET('network_config')
    # Do not configure the X Window System
    skipx
    # Run the Setup Agent on first boot
    firstboot --disable
    # Reboot after installation
    reboot
    
    
    %pre
    $SNIPPET('log_ks_pre')
    $SNIPPET('kickstart_start')
    $SNIPPET('pre_install_network_config')
    # Enable installation monitoring
    $SNIPPET('pre_anamon')
    %end
    
    %packages
    $SNIPPET('func_install_if_enabled')
    @core
    @base
    tree
    nmap
    wget
    lftp
    lrzsz
    telnet
    %end
    
    %post --nochroot
    $SNIPPET('log_ks_post_nochroot')
    %end
    
    %post
    $SNIPPET('log_ks_post')
    # Start yum configuration
    $yum_config_stanza
    # End yum configuration
    $SNIPPET('post_install_kernel_options')
    $SNIPPET('post_install_network_config')
    $SNIPPET('func_register_if_enabled')
    $SNIPPET('download_config_files')
    $SNIPPET('koan_environment')
    $SNIPPET('redhat_register')
    $SNIPPET('cobbler_register')
    # Enable post-install boot notification
    $SNIPPET('post_anamon')
    # Start final steps
    $SNIPPET('kickstart_done')
    # End final steps
    
    sed -ri "/^#UseDNS/cUseDNS no" /etc/ssh/sshd_config
    sed -ri "/^GSSAPIAuthentication/cGSSAPIAuthentication no" /etc/ssh/sshd_config
    %end
    

    编辑radhat7镜像所使用的kickstart文件

    # 动态编辑指定使用新的kickstart文件
    [root@cobbler ~]# cobbler profile edit --name=radhat7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/radhat7.ks
    
    # 验证是否更改成功
    [root@cobbler kickstarts]# cobbler profile report --name=radhat7-x86_64 |grep Kickstart
    Kickstart                      : /var/lib/cobbler/kickstarts/radhat7.ks
    #同步文件
    [root@cobbler ~]# cobbler sync
    

    效果


    3、自定制安装


    ![

  • 相关阅读:
    POJ 3904 Sky Code [数学]
    UVA 11542 Square [XOR方程组]
    CSS+DIV 设置圆角边框加阴影效果
    取消谷歌CHROME文本框(域)外边框高亮和缩放功能的办法
    IE和火狐CSS透明层兼容写法
    Ubuntu 12.04 amd64 搭建Apache+PHP+Mysql环境
    CSS样式表的优先级别
    css设置透明层
    卸载gnome的命令为
    ubuntu12.04 启动n卡独显方法
  • 原文地址:https://www.cnblogs.com/liuzhijun666/p/13056432.html
Copyright © 2011-2022 走看看