zoukankan      html  css  js  c++  java
  • centos7+cobbler安装

                    cobbler工作流程

    1、安装软件包:

     yum -y install httpd dhcp tftp python-ctypes cobbler  xinetd cobbler-web pykickstart
    ip addr add dev ens3 10.0.0.101/24 配置文件目录:
    /etc/cobbler /etc/cobbler/settings : 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 : 模块的配置文件 数据目录: /var/lib/cobbler/config/: 用于存放distros,system,profiles 等信 息配置文件 /var/lib/cobbler/triggers/: 用于存放用户定义的cobbler命令 /var/lib/cobbler/kickstart/: 默认存放kickstart文件 /var/lib/cobbler/loaders/: 存放各种引导程序  镜像目录 /var/www/cobbler/ks_mirror/: 导入的发行版系统的所有数据 /var/www/cobbler/images/ : 导入发行版的kernel和initrd镜像用于 远程网络启动 /var/www/cobbler/repo_mirror/: yum 仓库存储目录 日志目录: /var/log/cobbler/installing: 客户端安装日志 /var/log/cobbler/cobbler.log : cobbler日志

    cobbler命令介绍:
    cobbler check 核对当前设置是否有问题
    cobbler list 列出所有的cobbler元素
    cobbler report 列出元素的详细信息
    cobbler sync 同步配置到数据目录,更改配置最好都要执行下
    cobbler reposync 同步yum仓库
    cobbler distro 查看导入的发行版系统信息
    cobbler system 查看添加的系统信息
    cobbler profile 查看配置信息

    2、配置cobbler:

    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 : 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 : 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
     8 : 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:
     sed -i 's/^server: 127.0.0.1/server: 10.0.0.101/' /etc/cobbler/settings   #修改server的ip地址为本机ip
    
     错误2:
     sed -i 's/^next_server: 127.0.0.1/next_server: 10.0.0.101/' /etc/cobbler/settings  #TFTP Server 的IP地址
     
     错误3:
     修改/etc/xinetd.d/tftp文件:
     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
     }
     
     错误4:
     cobbler get-loaders  # 下载缺失的文件
     
     错误5:
     添加rsync到自启动并启动rsync
     systemctl enable rsyncd
     systemctl start rsyncd 
    
     错误6: 跟debian 相关,可以忽略 
    
     错误7: 
     修改root密码为123456: 
     [root@localhost ~]# openssl passwd -1 -salt '123456' '123456' 
     $1$123456$wOSEtcyiP2N/IfIl15W6Z0 
     [root@localhost ~]# vi /etc/cobbler/settings #修改settings配置文件中下面位置,把新生成的密码加进去 
     default_password_crypted: "$1$123456$wOSEtcyiP2N/IfIl15W6Z0”
    
     错误8: 
     # fence设备相关,不用配置 
    
    2、 修改settings中参数,由cobbler控制dhcp:
    vi /etc/cobbler/settings 
    manage_dhcp: 1
    
    修改dhcp.templates配置文件
    vi /etc/cobbler/dhcp.template
    subnet 10.0.0.0 netmask 255.255.255.0 {
         option routers             10.0.0.2;
         option domain-name-servers 10.0.0.2;
         option subnet-mask         255.255.255.0;
         range dynamic-bootp        10.0.0.100 10.0.0.250;
    }
    3、重启服务并同步配置,改完dhcp必须要sync同步配置: systemctl restart cobblerd systemctl start httpd systemctl enable httpd systemct1 enable cobblerd cobbler sync #同步数据 cobbler check #再检查一遍 4、检查dhcp: netstat -lnup|grep dhcp

    3、导入镜像:

    1、挂载系统镜像:
    mount /dev/centos7.1.iso  /mnt
    2、导入系统镜像:
    cobbler import --path=/mnt/ --name=CentOS-7.1-x86_64 --arch=x86_64
    
    参数解释:
    # --path 镜像路径
    # --name 为安装源定义一个名字
    # --arch 指定安装源是32位、64位、ia64, 目前支持的选项有: x86│x86_64│ia64
    # 安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-7.1-x86_64,如果重复,系统会提示导入失败。
    
    cobbler distro list #查看镜像列表
    
    镜像存放目录:
    #cobbler会将镜像中的所有安装文件拷贝到本地一份,放在/var/www/cobbler/ks_mirror下的CentOS-7.1-x86_64目录下。因此/var/www/cobbler目录必须具有足够容纳安装文件的空间。
    
    3、指定ks.cfg文件及调整内核参数:
    cd /var/lib/cobbler/kickstarts/   #Cobbler的ks.cfg文件存放位置
    上传或编辑ks.cfg文件: CentOS-7.1-x86_64.cfg
    
    查看安装镜像文件信息:
    cobbler distro report --name=CentOS-7.1-x86_64
    查看所有的profile设置:
    cobbler profile report
    查看指定的profile设置:
    cobbler profile report --name=CentOS-7.1-x86_64
    
    # 编辑profile,修改关联的ks文件
    cobbler profile edit --name=CentOS-7.1-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.1-x86_64.cfg
    
    # 修改安装系统的内核参数,在CentOS7系统有一个地方变了,就是网卡名变成eno16777736这种形式,但是为了运维标准化,我们需要将它变成我们常用的eth0,因此使用下面的参数。但要注意是CentOS7才需要下面的步骤,CentOS6不需要。
    cobbler profile edit --name=CentOS-7.1-x86_64 --kopts='net.ifnames=0 biosdevname=0'
    cobbler profile report CentOS-7.1-x86_64
    
    # 每次修改完都要同步一次
    cobbler sync

    cobbler的web页面地址:https://10.0.0.101/cobbler_web
    之后就可以通过pxe安装系统

     4、cobbler-api

    cobbler也是通过restful-api来调用对应的接口,下面请看两个小脚本:
    都是采用opython2.7版本运行的

    [root@linux-node1 ~]# cat cobbler_list.py
    #!/usr/bin/python
    import xmlrpclib
    server = xmlrpclib.Server("http://192.168.56.11/cobbler_api")
    print server.get_distros()
    print server.get_profiles()
    print server.get_systems()
    print server.get_images()
    print server.get_repos()

    下面看看创建system模版的:

    [root@linux-node1 ~]# cat cobbler-api.py
    #!/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.56.11/cobbler_api","cobbler","123456")
        ret = cobbler.add_system(hostname='cobbler-api-test',ip_add='192.168.56.101',mac_add='00:50:56:21:65:78',profile='CentOS-7.0-1406-x86_64')
        print ret
    
    if __name__ == '__main__':
        main()

    通过这样api的方式,也能够创建system模版实现安装主机的功能。

  • 相关阅读:
    python基础-包
    python基础-模块
    python基础-面向过程与函数式
    python基础-二分法
    python基础-函数递归
    python基础-生成器
    QFNU-ACM 2020.11.6 Trating
    ACM 实验室2020.11.01天梯赛练习*4
    QFNU-ACM 2020.10.30 Trating
    QFNU-ACM 2020.10.23 Trating
  • 原文地址:https://www.cnblogs.com/chimeiwangliang/p/8279138.html
Copyright © 2011-2022 走看看