zoukankan      html  css  js  c++  java
  • cobbler深入学习

    cobbler重要目录和cobbler各对象的关系

    /var/www/cobbler/ks_mirror 存放操作系统镜像
    /var/www/cobbler/repo_mirror 存放仓库镜像
    /var/lib/cobbler/kickstarts 存放kickstarts文件
    /var/lib/cobbler/loaders 存放启动时需要的文件
    /var/lib/cobbler/snippets 存放脚本
    /etc/cobbler 存放cobbler的配置文

    自定义yum源

    cobbler可以管理yum源,以使用阿里云的openstack为例

    http://mirrors.aliyun.com/centos/7.2.1511/cloud/x86_64/openstack-mitaka/

    1) 添加openstack仓库源

    cobbler repo add --name=openstack-mitaka --mirror=http://mirrors.aliyun.com/centos/7.2.1511/cloud/x86_64/openstack-mitaka/ --arch=x86_64 --breed=yum

    2) 同步 cobbler reposync

    3) 将openstack-mitaka在安装centos 7时,默认导入安装

    cobbler profile edit --name=CentOS-7.1-x86_64 --repos="openstack-mitaka"

    cobbler profile report CentOS-7.1-x86_64 查看仓库源

    vim /etc/cobbler/settings  可以查看到yum_post_install_mirror默认开启

    4) 修改kickstart文件

    vim /var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg

    #Kickstart Configurator for cobbler by Jason Zhao
    #platform=x86, AMD64, or Intel EM64T
    #System  language
    lang en_US
    #System keyboard
    keyboard us
    #Sytem timezone
    timezone Asia/Shanghai
    #Root password
    rootpw --iscrypted $default_password_crypted
    #Use text mode install
    text
    #Install OS instead of upgrade
    install
    #Use NFS installation Media
    url --url=$tree
    #System bootloader configuration
    bootloader --location=mbr
    #Clear the Master Boot Record
    zerombr
    #Partition clearing information
    clearpart --all --initlabel 
    #Disk partitioning information
    part /boot --fstype xfs --size 1024 --ondisk sda
    part swap --size 16384 --ondisk sda
    part / --fstype xfs --size 1 --grow --ondisk sda
    #System authorization infomation
    auth  --useshadow  --enablemd5 
    #Network information
    $SNIPPET('network_config')
    #network --bootproto=dhcp --device=em1 --onboot=on
    # Reboot after installation
    reboot
    #Firewall configuration
    firewall --disabled 
    #SELinux configuration
    selinux --disabled
    #Do not configure XWindows
    skipx
    #Package install information
    %pre
    $SNIPPET('log_ks_pre')
    $SNIPPET('kickstart_start')
    $SNIPPET('pre_install_network_config')
    # Enable installation monitoring
    $SNIPPET('pre_anamon')
    %end
    
    %packages
    @ base
    @ core
    sysstat
    iptraf
    ntp
    lrzsz
    ncurses-devel
    openssl-devel
    zlib-devel
    OpenIPMI-tools
    mysql
    nmap
    screen
    %end
    
    %post
    systemctl disable postfix.service
    
    $yum_config_stanza
    %end
    

    5) 添加定时任务,定期同步repo

    echo "1 3 * * * /usr/bin/cobbler reposync --tries=3 --no-fail" >> /var/spool/cron/root

    自动化装机

    之前通过cobbler操作的安装并没有完全的自动化,需要在页面进行选择,我们在实现真正的自动化安装前,需要清楚整体流程。

    下图参考

    在自动化安装操作系统,需要做的几件事:

    1、存在硬件设备,如果虚拟机要创建完一个虚拟机,分配好内存、CPU、硬盘等资源

    2、分配IP、域名、子网掩码、网关、DNS、MAC地址,以虚拟机为例

    获取MAC地址为:00:50:56:3F:1B:9E

    IP:192.168.137.51

    主机名:cobbler-auto

    子网掩码:255.255.255.0

    网关:192.168.137.2

    DNS:192.168.137.2

    备注:MAC地址必须是唯一的,通过配置MAC地址才能进行自动化安装。

    cobbler system list
    
    cobbler system add --name=cobbler-auto --mac=00:50:56:3F:1B:9E 
    --profile=CentOS-7.1-x86_64 
    --ip-address=192.168.137.51 --subnet=255.255.255.0 --gateway=192.168.137.2 --interface=eth0 
    --static=1 --hostname=cobbler-auto --name-servers="192.168.137.2 114.114.114.114" 
    --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg
    
    cobbler system list

    cobbler sync

     

     安装成功

    安装 成功的主机中已经添加了openstack-mitaka的yum源

    Cobbler API

    cd /etc/httpd/conf.d

    cat cobbler.conf

    通过上图标红处,可以看到cobbler API是通过http调用

    如下为python调用样例脚本

    #!/usr/bin/python
    import xmlrpclib
    import time
    server = xmlrpclib.Server("http://192.168.137.10/cobbler_api")
    print server.get_distros()
    time.sleep(1)
    print server.get_profiles()
    time.sleep(1)
    print server.get_systems()
    time.sleep(1)
    print server.get_images()
    time.sleep(1)
    print server.get_repos()
    time.sleep(10)
    

    实现上面命令的一个完整脚本

    #!/usr/bin/env python 
    # -*- coding: utf-8 -*-
    import xmlrpclib 
    
    class CobblerAPI(object):
        def __init__(self,url,user,password):
            self.cobbler_user= user
            self.cobbler_pass = password
            self.cobbler_url = url
        
        def add_system(self,hostname,ip_add,mac_add,profile):
            '''
            Add Cobbler System Infomation
            '''
            ret = {
                "result": True,
                "comment": [],
            }
            #get token
            remote = xmlrpclib.Server(self.cobbler_url) 
            token = remote.login(self.cobbler_user,self.cobbler_pass) 
    		
    		#add system
            system_id = remote.new_system(token) 
            remote.modify_system(system_id,"name",hostname,token) 
            remote.modify_system(system_id,"hostname",hostname,token) 
            remote.modify_system(system_id,'modify_interface', { 
                "macaddress-eth0" : mac_add, 
                "ipaddress-eth0" : ip_add, 
                "dnsname-eth0" : hostname, 
            }, token) 
            remote.modify_system(system_id,"profile",profile,token) 
            remote.save_system(system_id, token) 
            try:
                remote.sync(token)
            except Exception as e:
                ret['result'] = False
                ret['comment'].append(str(e))
            return ret
    
    def main():
        cobbler = CobblerAPI("http://192.168.137.10/cobbler_api","cobbler","cobbler")
        ret = cobbler.add_system(hostname='cobbler-api-test',ip_add='192.168.137.111',mac_add='00:50:56:25:C2:AA',profile='CentOS-7.1-x86_64')
        print ret
    
    if __name__ == '__main__':
        main()
    

    执行上面的脚本,通过cobbler system list命令可以看到多出cobbler-api-test这项,这是通过cobbler API实现添加

    电源管理

    增加

    cobbler system edit --name=cobbler-auto --power-address=192.168.138.51 
    --power-type='ipmilan' --power-user=ipmi -power-pass=ipmi
    

    常用命令

    cobbler system poweroff
    cobbler system powon
    cobbler system powerstatus
    cobbler system reboot
    

    重启服务器并从PXE引导启动,并指定安装的操作系统配置。

    cobbler system edit --name=cobbler-auto --netboot-enabled=1 --profile=CentOS-7.1-x86_64
    

      

    官网文档

    对于cobbler,如果要做一些个性化配置,可以参考官方文档进行实现。

    如下图是官网给出的示例,如何去实现双网卡绑定。

    http://cobbler.github.io/manuals/2.8.0/4/1/1_-_Bonding.html

  • 相关阅读:
    四则运算2
    大二第二学期阅读计划
    第一周课堂练习
    《人月神话》读后感
    软件工程概论总结第十一章
    软件工程概论总结第十章
    软件工程概论总结第九章
    软件工程概论总结第八章
    软件工程概论总结第七章
    第五章、软件过程中的形式化方法
  • 原文地址:https://www.cnblogs.com/shhnwangjian/p/5862202.html
Copyright © 2011-2022 走看看