zoukankan      html  css  js  c++  java
  • Cobbler的使用

    什么是cobbler

    cobbler是一个基于pxe安装原理的使用python编写的实现自动化网络安装的软件,提供了多种安装参数和命令,可以实现批量安装操作系统,甚至有web管理界面。

    cobbler相关服务

    httpd,tftp,dhcp

    cobbler的使用

    1. cobbler及相关服务的安装

    yum -y install cobbler dhcp 
    

    安装cobbler会自动安装所依赖的httpd和tftp-server等其他包

    httpd: 提供安装包yum源

    tftp-server: 提供启动菜单和bootloader等相关文件

    dhcp: 自动获取IP服务

    2. 启动及配置cobbler

    1. 启动cobbler
    systemctl enable --now httpd
    systemctl enable --now tftp.socket
    systemctl enable --now cobblerd
    #启动cobblerd前最好先启动其他相关服务,否则可能会出现问题
    
    1. 使用 cobbler check 命令,根据命令提示,进行cobbler的配置
    [root@centos7 ~]#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 : change 'disable' to 'no' in /etc/xinetd.d/tftp
    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.
    5 : enable and start rsyncd.service with systemctl
    6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
    7 : ksvalidator was not found, install pykickstart
    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.
    
    #其中第1,2,4项为必须配置项,第8项可选,其他选项可以忽略。
    # 1:  http服务器ip地址
    # 2:  tftp服务器地址
    # 3:  为tftp启动xinetd守护进程,centos6及以下版本需要配置修改,7之后版本无需更改
    # 4:  下载tftp服务所需要的bootloader文件,启动菜单等相关文件
    # 5:  rsyncd.service,实现全量及增量的本地或远程数据同步备份服务,可根据需要自行配置
    # 6:  debian系有关系统配置,redhat系可以忽略
    # 7:  pykickstart包的ksvalidator命令可以检查ks文件语法错误
    # 8:  默认密码修改
    # 9:  配置电源项
    
    1. dncp服务配置
    #修改cobbler配置文件/etc/cobbler/settings,让cobbler来管理dhcp服务
    manage_dhcp: 1
    #修改dhcp配置模板文件/etc/cobbler/dhcp.template,生成dhcp配置文件
    subnet 10.0.0.0 netmask 255.255.255.0 {
         option routers             10.0.0.2;
         option domain-name-servers 223.5.5.5;
         option subnet-mask         255.255.255.0;
         range dynamic-bootp        10.0.0.160 10.0.0.190;
    #修改完配置后重启cobblerd服务,并同步
    systemctl restart cobblerd
    cobbler sync
    #同步后会将/etc/cobbler/dhcp.template复制到/etc/dhcp/dhcpd.conf中,并自动启动dhcp服务。
    
    1. 修改启动菜单标题(可选)
    [root@centos7 ~]#cat /etc/cobbler/pxe/pxedefault.template | grep TITLE
    MENU TITLE Cobbler | http://cobbler.github.io/
    
    sed -ri '/TITLE/s#(^[^/]+).*#1//www.wuvikr.top#' /etc/cobbler/pxe/pxedefault.template
    cobbler sync
    

    完成以上配置后,cobbler的初步配置就算是完成了,接下来是镜像源和KS文件的准备

    3. 导入需要安装的系统文件

    可以拷贝iso镜像文件到机器上,也可以使用镜像光盘

    1. 挂载镜像到目录
    mount /dev/sr0 /mnt/
    
    2. 导入镜像
    cobbler import --name=centos7.8-x86_64 --path=/mnt --arch=x86_64
    # --name表示安装源自定义的名字
    # --path表示镜像所挂载的目录
    # --arch表示指定安装源是32位还是64位,支持的选项有 x86,x86_64,ia64.
    
    #查看导入的镜像列表
    cobbler distro list
    
    #查看ks文件菜单列表
    cobbler profile list
    
    # 导入镜像后会自动生成一个最小化的安装ks文件菜单,如果觉得自带的ks文件可以满足需求的话就可以跳过下一步了
    # 存放ks文件的目录: /var/lib/cobbler/kickstarts/
    

    4. 准备kickstart文件,并关联到指定yum源

    1. 将自己准备好的ks文件放入/var/lib/cobbler/kickstarts/目录下
    
    2. 删除默认生成的ks文件菜单
    cobbler profile remove --name=centos7.8-x86_64
    
    3. 添加自己准备好的ks文件菜单
    cobbler profile add --name=centos7.8.my --distro=centos7.8-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg
    # --name 添加启动菜单的名字
    # --distro 关联导入的yum源
    # --kickstart 自己定制的ks文件路径
    
    # 查看菜单,ks文件,镜像源详细信息
    cobbler profile report --name=centos7.8.my
    
    # 也可以查看/var/lib/tftpboot/pxelinux.cfg/default文件,添加成功后会自动生成一个label
    cat /var/lib/tftpboot/pxelinux.cfg/default 
    LABEL centos7.8.my
            kernel /images/centos7.8-x86_64/vmlinuz
            MENU LABEL centos7.8.my
            append initrd=/images/centos7.8-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://10.0.0.71/cblr/svc/op/ks/profile/centos7.8.my
            ipappend 2
    
    

    到这里cobbler就可以开始使用了!

    ks文件相关

    1. 可以根据自己安装好机器后/root目录下anaconda-ks.cfg文件进行修改定制。
    2. 可以安装system-config-kickstart包,一个具有图形化的ks文件制作工具。

    附上自己实验使用的ks文件

    centos7.cfg

    #platform=x86, AMD64, or Intel EM64T
    #version=DEVEL
    # Install OS instead of upgrade
    install
    # Keyboard layouts
    keyboard --vckeymap=us --xlayouts='us'
    # Root password
    rootpw --iscrypted $6$Ow9n3A86WGKGv8tF$.Jm4iXJLnilU0q/miXxkFD56uF/ZaD6pRzyvNjxt3H55XgA70PpJoWNQZAv3zLTU6vF3RB2qevwpHuRVNzFrI/
    # System language
    lang en_US
    # System authorization information
    auth  --useshadow  --passalgo=sha512
    # Use text mode install
    text
    firstboot --disabled
    # SELinux configuration
    selinux --disabled
    
    ignoredisk --only-use=sda
    # Firewall configuration
    firewall --disabled
    # Network information
    network  --bootproto=dhcp --device=eth0
    # Reboot after installation
    reboot
    # System timezone
    timezone Asia/Shanghai --nontp
    
    
    # Use network installation
    url --url=http://10.0.0.81/centos/7/x86_64/os
    # url --url=$tree  cobbler使用这个
    
    # System bootloader configuration
    bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda
    # Clear the Master Boot Record
    zerombr
    # Partition clearing information
    clearpart --all --initlabel
    # Disk partitioning information
    part /boot --fstype="xfs" --size=1024
    part / --fstype="xfs" --size=10240
    part swap --fstype="xfs" --size=2048
    part /data --fstype="xfs" --size=5120
    
    # 创建用户wuvikr,密码744123
    user --name=wuvikr --password=$6$z96.c6bRe..qZRAi$sxHDL0HLf5vFPvayvSjS2uwMaC/zWFMN3oPokFC5Z2S.wD1X8PDkLShdoZxGDhN51bBn/v7QKvhumknH2Qpya0 --iscrypted --gecos="wuvikr"
    
    
    %packages
    @^minimal
    @core
    kexec-tools
    
    %end
    
    %post
    rm -rf /etc/yum.repos.d/*
    cat > /etc/yum.repos.d/CentOS8.repo <<EOF
    [Packages]
    name=Base
    baseurl=https://mirrors.aliyun.com/centos/7/os/x86_64/
            https://mirrors.huaweicloud.com/centos/7/os/x86_64/
            https://mirrors.163.com/centos/7/os/x86_64/
    gpgcheck=1
    gpgkey=https://mirrors.aliyun.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
    
    [epel]
    name=epel
    baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
    gpgcheck=1
    gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-7
    
    [extras]
    name=extras
    baseurl=https://mirrors.aliyun.com/centos/7/extras/x86_64/
    gpgcheck=1
    gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
    EOF
    %end
    
  • 相关阅读:
    ArcGIS Server 服务迁移、恢复
    发布(高程数据)服务,Service Editor界面无LERC格式选项
    汇总10.4版本ArcGIS Server与ArcMap 安装+SDE+注册数据源(非破解)
    ArcGIS Server 缓存服务增加新比例尺缓存
    ArcMap 标注、注记、图形文本
    ArcGIS Server 缓存服务切图范围
    Oracle 安装 INS-30131错误。
    JAVA经典算法40题(供面试所用)
    Java 之HashMap.values()方法误用
    Java中如何把两个数组合并为一个
  • 原文地址:https://www.cnblogs.com/wuvikr/p/13738186.html
Copyright © 2011-2022 走看看