zoukankan      html  css  js  c++  java
  • Linux系统 自动化运维工具之cobbler

    自动化工具分为三大类
    #预备类(Os Provisioning)
    PXE
    cobbler
    #配置管理类(Os config & Devops )
    puppet
    saltstack
    ansible
    #监控类(Mointor)
    Cacti
    Nagios Core
    Zabbix
    #网站灰度发布(依赖于前端的lb实现)
    关闭Directory上一批服务器
    关闭这些服务器要更新的应用
    更新webapp代码至目标主机
    启动目标应用 ,Dirtectory启动这批服务器
    #发布大致流程
    代码控制(csv,svn,git)检出要发布的代码,发布至预发布服务器上
    预发布服务器: 预发布服务器跟线上服务器环境一致,但不加入线上机器中,实施详细的测试
    自动化测试,使用webapp自动化测试工具(如thoughworks开发的selenium)可以进行完整的代码,浏览器兼容性的测试
    自动化灰度发布,线上批量分批次更新代码
    #网站运行监控
    监控数据采集,用户行为日志,服务器性能监控,运行数据报告
    监控管理 异常报警,失败转移,自动优雅降级

    cobbler 服务集成
    pxe 服务
    DHCP
    Rsync
    Http
    DNS
    Kickstart
    IPMI 电源管理
    cobbler 设计方式


    发行版(distro) :表示一个操作系统,它承载了内核和initrd的信息,以及内核等其他数据

    存储库 (repository):保存了一个yum或者rsync存储库的镜像信息

    配置文件(profile):包含了一个发行版(distro),一个kickstart文件以及可能的存储库(repository),还包含了更多的内核参数等其他数据

    系统(system):表示要配给的机器,它包含了一个配置文件或一个镜像,还包含了ip和mac地址,电源管理(地址,凭据,类型)以及更为专业的数据信息

    镜像(image):可替换一个包含不属于此类别的文件的发行版对象(eg: 无法作为内核和initrd的对象)
    以上各个组件中, 发行版,存储库, 配置文件为必须配置项
    只有在虚拟环境中,必须要用cobbler来引导虚拟机启动时候,才会用到系统组件
    但事实上,在生产环境中需要大量的虚拟机实例的话,通常利用openstack等来实现虚拟机节点

    cobbler 运行流程

    dhcp

    client: 从dhcp中获取地址,访问next_server的ip地址

    next_server : 获取启动内核,initrd等文件

    tftp: pxe引导文件,启动cobbler选择界面

    kickstart: 确定加载项,根据nfs,http,tfp等共享获取资源


    cobbler units

    cobbler

    cobbler-web


    配置cobbler 步骤

    1 安装cobbler,依据cobbler check检查结果,对setting主配置文件,进行相关的修正配置
    2 启动相关的http,cobbler服务,使用cobbler sync同步设置
    3 配置cobbler 所依赖的包
    * dhcp
    * dns
    * rsync
    * tftp
    4 配置cobbler组件
    **针对步骤3 ,需要:
    1 选定要使用的程序,选其一管理即可
    2 确定是独立管理这些服务,还有由cobbler代为管理
    *注意事项:
    cobbler本身是不提供对应的服务程序的,因此还是需要安装对应的程序服务的rpm包,并保证其开启动的状态,由cobbler管理这些服务 *
    安装cobbler
    1.配置安装源
    2.设置ip转发
    sed -i 's/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/' /etc/sysctl.conf
    sysctl -p
    3.安装cobbler
    yum -y install cobbler dhcp httpd xinetd tftp-server syslinux pykickstart xinetd rsync cobbler-web
    4.cobbler 各种配置目录说明
    配置文件目录 /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/kickstarts/: 默认存放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 commands

    import

    sync

    reposync

    build iso (使用发行版,配置文件,制作系统镜像)

    command line search

    replication

    valication kickstart
    动态更新配置
    cp /etc/cobbler/settings /etc/cobbler/settings.bak 
    开启编辑setting配置文件,直接使用命令去修改
    sed -i 's/allow_dynamic_settings: 0/allow_dynamic_settings: 1/g' /etc/cobbler/settings
    systemctl start cobblerd
    检查需要安装的配置
    cobbler check
    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 : change 'disable' to 'no' in /etc/xinetd.d/rsync
    6 : since iptables may be running, ensure 69, 80/443, and 25151 are unblocked
    7 : reposync is not installed, need for cobbler reposync, install/upgrade yum-utils?
    8 : debmirror package is not installed, it will be required to manage debian deployments and repositories
    9 : 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

    #解决问题
    1.cobbler setting edit --name=server --value=10.10.10.10
    2.cobbler setting edit --name=next_server --value=10.10.10.10
    3.修改/etc/xinetd.d/tftp disable no 改成yes
    systemctl start httpd cobblerd tftp rsync xinetd
    systemctl enable httpd cobblerd tftp rsyncd xinetd
    4.下载启动菜单 cobbler get-loaders
    5.配置防火墙
    iptables -A INPUT -m state --state NEW -m tcp -p tcp -m multiport --dports 80,443,88,25151 -j ACCEPT
    iptables -A INPUT -m state --state NEW -m udp -p udp -m multiport --dports 53,67,68,25252 -j ACCEPT
    iptables -A INPUT -m state --state NEW -m udp -p udp --dport 69 -j ACCEPT
    6.配置repo仓库
    7.问题跟debian系统有关,如果有需要装一下即可,否则可以忽略 yum -y install debmirror
    8.openssl passwd -1 -salt 'nt2017123' 'nt2017123' 
    cobbler setting edit --name=default_password_crypted --value="$1$nt201712$F/kd8KCQKtgvqjoU40YJz0"
    9.安装电源管理 yum -y install cman fence-agents
    10.防止误重装系统,选项pxe_just_one
    cobbler setting edit --name=pxe_just_once --value=1
    配置dhcp服务由cobbler来管理(这里使用cobbler管理dhcp器,也可以使用dnsmasq来管理)
    配置dhcpd配置文件
    vim /etc/cobbler/dhcp.template
    #其他暂时不需要动,只修改下面的几个内容
    subnet 10.10.10.0 netmask 255.255.255.0 {
    option routers 10.10.10.10;
    option domain-name-servers 114.114.114.114 ;
    option subnet-mask 255.255.255.0;
    range dynamic-bootp 10.10.10.20 10.10.10.50;
    default-lease-time 21600;
    max-lease-time 43200;
    next-server $next_server;

    vim /etc/dhcp/dhcpd.conf 
    # ******************************************************************
    # Cobbler managed dhcpd.conf file
    # generated from cobbler dhcp.conf template (Sun Jan 31 15:47:49 2016)
    # Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes
    # in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
    # overwritten.
    # *****************************************************************
    ddns-update-style interim;
    allow booting
    allow bootp
    ignore client-updates;
    set vendorclass = option vendor-class-identifier
    option pxe-system-type code 93 = unsigned integer 16;
    subnet 10.10.10.0 netmask 255.255.255.0 {

    同步cobbler
    systemctl restart cobblerd
    cobbler sync
    systemctl restart cobblerd
    再次检查 
    cobbler check
    配置命令
    cobbler usage
    =====
    cobbler <distro|profile|system|repo|image|mgmtclass|package|file> ... 
    [add|edit|copy|getks*|list|remove|rename|report] [options|--help]
    cobbler <aclsetup|buildiso|import|list|replicate|report|reposync|sync|validateks|version|signature|get-loaders|hardlink> [options|--help]

    [root@linux-node1 ~]# cobbler import --help # 导入镜像
    Usage: cobbler [options]
    Options:
    -h, --help show this help message and exit
    --arch=ARCH OS architecture being imported
    --breed=BREED the breed being imported
    --os-version=OS_VERSION
    the version being imported
    --path=PATH local path or rsync location
    --name=NAME name, ex 'RHEL-5'
    --available-as=AVAILABLE_AS
    tree is here, don't mirror
    --kickstart=KICKSTART_FILE
    assign this kickstart file
    --rsync-flags=RSYNC_FLAGS
    pass additional flags to rsync
    cobbler check 核对当前设置是否有问题
    cobbler list 列出所有的cobbler元素
    cobbler report 列出元素的详细信息
    cobbler sync 同步配置到数据目录,更改配置最好都要执行下
    cobbler reposync 同步yum仓库
    cobbler distro 查看导入的发行版系统信息
    cobbler system 查看添加的系统信息
    cobbler profile 查看配置信息

    导入系统到cobbler
    mount /dev/cdrom /mnt 
    cobbler import --path=/mnt/ --name=Centos-6.5-x86_64 --arch=x86_64
    cobbler distro report --name=Centos-6.5-x86_64 
    查看
    cobbler distro list
    修改默认ks文件
    配置文件路径/var/www/cobbler/images/redhat-6.5-x86_64
    ks 路径/var/lib/cobbler/kickstarts

    #platform=x86, AMD64, 或 Intel EM64T #安装配置的系统cpu类型
    #version=DEVEL 
    # X Window System configuration information 图形化
    xconfig --startxonboot
    # Install OS instead of upgradea -->安装
    install
    # Use network installation
    url --url=http://192.168.1.20/wangfeng7399 -->引导程序所在的位置
    # Run the Setup Agent on first boot 
    firstboot --enable
    ignoredisk --only-use=sda
    # Root password 设置root的密码是否加密 -->加密写入的文件和加密算法,这里必须要和上面root密码的加密算法一致
    rootpw --iscrypted $6$CGsqab6d$Cd.PnnWtlL5XZAyr9J2zoMqyJH1QodcDp1pQp0uZ1f0Cq4eq9.TMkSQU6IfpvYZEYc32.lmF0lKuQwavnC49a0 -->root账户的密码
    # System authorization information 系统配置加密
    auth --useshadow --passalgo=sha512 
    # Keyboard layouts -->选择键盘类型
    keyboard 'us'
    # System language -->选择语言
    lang en_US.UTF-8 
    # System timezone -->选择时区
    timezone Asia/Shanghai --isUtc
    # Firewall configuration
    firewall --disabled -->防火墙的运行状态
    # SELinux configuration
    selinux --disabled -->selinux的运行状态
    # Reboot after installation 安装完成是否重新引导
    reboot
    # Network information
    network --onboot yes --device eth0 --bootproto dhcp --noipv6 -->网卡的信息,表示开机自启动,并通过dhcp过去ip地址,关闭ipv6功能
    # System bootloader configuration
    bootloader --location=mbr --driveorder=sda --append="crashkernel=auto crashkernel=auto rhgb rhgb quiet quiet" -->mbr表写入的磁盘,已经给内核传递的启动参数
    # The following is the partition information you requested
    # Note that any partitions you deleted are not expressed
    # here so unless you clear all partitions first, this is
    # not guaranteed to work

    # Clear the Master Boot Record
    clearpart --all -->格式化所有硬盘
    zerombr -->清空硬盘的mbr表
    text -->文本模式安装
    # Partition clearing information
    clearpart --none --initlabel

    # Disk partitioning information
    part /boot --fstype="ext4"--ondisk=sda --size=200 -->创建200M的ext4格式的/boot分区
    part pv.9009 --size=61440 -->创建lvm物理卷

    volgroup vg0 --pesize=8192 pv.9009 --> 创建lvm卷组,指定pe大小为8M
    logvol / --fstype=ext4 --name=root --vgname=vg0 --size=20480 -->创建逻辑卷
    logvol swap --name=swap --vgname=vg0 --size=2048
    logvol /usr --fstype=ext4 --name=usr --vgname=vg0 --size=10240
    logvol /var --fstype=ext4 --name=var --vgname=vg0 --size=20480

    repo --name="CentOS" --baseurl=http://192.168.1.20/wangfeng7399 -->指定repo的读取位置,即rpm包的读取位置

    %packages -->程序包段的开始
    @Base
    @Core
    @base
    @basic-desktop
    @chinese-support
    @client-mgmt-tools
    @core
    @desktop-platform
    @fonts
    @general-desktop
    @graphical-admin-tools
    @legacy-x
    @network-file-system-client
    @perl-runtime
    @remote-desktop-clients
    @x11
    ibus-table-cangjie
    ibus-table-erbi
    ibus-table-wubi
    lftp

    %end -->程序包段的

    %packages 

    ####### CentOS mini desktop packages ############ 
    @base 
    @basic-desktop 
    @chinese-support 
    @desktop-debugging 
    @desktop-platform 
    @directory-client 
    @fonts 
    @input-methods 
    @internet-browser 
    @java-platform 
    @legacy-x 
    @network-file-system-client 
    @remote-desktop-clients 
    @server-platform 
    @x11

    ######## graphic admin tools ############# 
    @graphical-admin-tools 
    audit-viewer 
    firstaidkit-gui 
    policycoreutils-gui 
    sabayon 
    setroubleshoot 
    system-config-kickstart 
    system-config-lvm 
    wireshark-gnome 

    ############ virtualization tools ######## 
    @virtualization 
    @virtualization-client 
    @virtualization-platform 
    @virtualization-tools 
    fence-virtd-libvirt 
    fence-virtd-multicast 
    fence-virtd-serial 
    libguestfs-java 
    libguestfs-tools 
    libvirt-cim 
    libvirt-java 
    libvirt-qmf 
    libvirt-snmp 
    perl-Sys-Virt 
    #qemu-guest-agent 
    qemu-kvm-tools 
    virt-v2v 

    %post --interpreter=/bin/bash


    配置centos7
    #cobbler for Kickstart Configurator for CentOS 7.1 by hetao
    install
    url --url=$tree 
    text
    lang en_US.UTF-8
    keyboard us
    zerombr
    bootloader --location=mbr 
    # Network information
    $SNIPPET('network_config')
    timezone --utc Asia/Shanghai
    authconfig --enableshadow --passalgo=sha512
    rootpw --iscrypted $default_password_crypted
    clearpart --all --initlabel
    part /boot --fstype xfs --size 500 
    part swap --size 2000
    part / --fstype xfs --size 20000 
    part /data --fstype xfs --size 30000 
    firstboot --disable
    selinux --disabled
    firewall --disabled
    logging --level=info
    reboot
    %pre
    $SNIPPET('log_ks_pre')
    $SNIPPET('kickstart_start')
    $SNIPPET('pre_install_network_config')
    # Enable installation monitoring
    $SNIPPET('pre_anamon')
    %end
    %packages
    @base
    @compat-libraries
    @debugging
    @development
    tree
    nmap
    sysstat
    lrzsz
    dos2unix
    telnet
    iptraf
    ncurses-devel
    openssl-devel
    zlib-devel
    OpenIPMI-tools
    screen
    %end
    %post
    systemctl disable postfix.service
    %end

    修改centos7 网卡label
    修改安装系统的内核参数,在CentOS7系统有一个地方变了,就是网卡名变成eno16777736这种形式,但是为了运维标准化,
    cobbler profile edit --name=CentOS-7.1-x86_64 --kopts='net.ifnames=0 biosdevname=0'
    cobbler profile report --name=CentOS-7-x86_64 
    查看
    cobbler profile report Centos-7-x86_64
    cobbler profile report Centos-6.5-x86_64
    cobbler list
    cobbler sync
    配置本地yum源
    mkdir /tmp/rpms
    createrepo /tmp/rpms #放入rpm包,执行此步骤
    cobbler repo add --mirror=/tmp/rpms --name=local
    cobbler reposync
    cobbler repo list

    配置绑定mac地址和IP地址 ,开机自动选择
    cobbler system add --name=budongshu --mac=00:0C:29:48:1D:75 --profile=Centos-7-x86_64
    --ip-address=10.10.10.23 --subnet=255.255.255.0 --gateway=10.10.10.10 --interface=eth0
    --static=1 --hostname=budongshu --name-servers="114.114.114.114 8.8.8.8"

    cobbler sync

    web界面配置
    cobbler-web支持多种认证方式,如authn_configfil、authn_ldap或authn_pam等,下面我们基于authn_pam做认证
    vim /etc/cobbler/modules.conf 
    [authentication]
    module = authn_pam

    添加系统用户

    useradd cobbler 
    echo "cobbler" | passwd --stdin cobbler

    添加用户到管理组
    vim /etc/cobbler/modules.conf
    [admins]
    admin = "cobbler"
    systemctl restart cobblerd httpd
    http://10.10.49.155/cobbler_web

     

  • 相关阅读:
    自制“低奢内”CSS3注册表单,包含JS验证哦。请别嫌弃,好吗?。
    自制“低奢内”CSS3登入表单,包含JS验证,请别嫌弃哦。
    到网上收集了一个“高大上”的CSS3登入表单和大家分享一下
    利用:before和:after伪类制作CSS3 圆形按钮 含demo
    Font Awesome 4.0.3 提供了369个网页常用的矢量字体图标,新浪、人人 的矢量图标也到其中哟
    CSS3无前缀脚本prefixfree.js与Animatable使用介绍
    JAVA 利用Dom4j实现英语六级词汇查询 含演示地址
    JAVA中 XML与数据库互转 学习笔记三
    JAVA与DOM解析器提高(DOM/SAX/JDOM/DOM4j/XPath) 学习笔记二
    JAVA与DOM解析器基础 学习笔记
  • 原文地址:https://www.cnblogs.com/devops-docker/p/11495788.html
Copyright © 2011-2022 走看看