cobbler批量安装操作

 

 


打开mirrors.aliyun.com/epel
http://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.rpm

rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.rpm

Centos-7 minimal安装之后,缺少命令,可以通过yum search 进行查找,然后安装对应的软件包就行
  1. 手动创建repo,http://mirrors.aliyun.com/epel/6/x86_64/ 在该目录下有repodata/repomd.xml,直接配置就可以用/etc/yum.repo.d/下

  2. 开始安装cobbler,对应安装的软件有cobbler ,cobbler-web ,httpd,tftp,xinetd,pykickstart,dhcp

    安装官方仓库,主要是两个,一个是系统自己的安装仓库,一个是外部扩展仓库,两个仓库配合安装,就可以安装cobbler了
    curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
    安装完成后,直接就可以安装cobbler了
    yum install -y cobbler cobbler-web pykickstart debmirror httpd dhcp tftp-server xinetd syslinux
    安装所有软件后,查看配置
    
  3. 启动httpd和cobblerd

    systemctl start httpd
    systemctl start cobblerd
    
    [root@localhost httpd]# 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 : 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
    4 : change 'disable' to 'no' in /etc/xinetd.d/tftp
    5 : 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.
    6 : enable and start rsyncd.service with systemctl
    7 : comment out 'dists' on /etc/debmirror.conf for proper debian support
    8 : comment out 'arches' on /etc/debmirror.conf for proper debian support
    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
    10 : 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.
    

    /etc/cobbler/settings该文件是,cobbler的主要配置文件

    1、修改272行next_server和384行server,为cobbler的地址
    2、关闭selinux
    3、修改tftp的配置,启用tftp
    4、生成默认密码openssl passwd -1 -salt 'cobbler' '123456',将结果写入到/etc/cobbler/settings中的default_passwrord_crypted中
    5、下载loaders,使用命令cobbler get-loaders或者是直接将本地的loaders拷贝到/etc/lib/cobbler/loaders目录中
        cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders
        cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
        [root@localhost ~]# cobbler get-loaders
        task started: 2019-03-23_165526_get_loaders
        task started (id=Download Bootloader Content, time=Sat Mar 23 16:55:26 2019)
        path /var/lib/cobbler/loaders/README already exists, not overwriting existing content, use --force if you wish to update
        downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
        downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
        downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
        downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
        downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
        path /var/lib/cobbler/loaders/pxelinux.0 already exists, not overwriting existing content, use --force if you wish to update
        path /var/lib/cobbler/loaders/menu.c32 already exists, not overwriting existing content, use --force if you wish to update
        downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
        downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
        *** TASK COMPLETE ***
        [root@localhost ~]# ls /var/lib/cobbler/loaders/
        COPYING.elilo  COPYING.syslinux  COPYING.yaboot  elilo-ia64.efi  grub-x86_64.efi  grub-x86.efi  menu.c32  pxelinux.0  README  yaboot
    
  4. 管理DHCP

    1、242,manage_dhcp : 1
    2、修改dhcp的模板文件,/etc/cobbler/dhcp.template
        subnet 192.168.64.0 netmask 255.255.255.0 {
         option routers             192.168.64.2;
         option domain-name-servers 192.168.64.2;
         option subnet-mask         255.255.255.0;
         range dynamic-bootp        192.168.64.150 192.168.64.175;
         default-lease-time         21600;
         max-lease-time             43200;
         next-server                $next_server;
    
  5. 配置完成后,重启所有服务,包含httpd cobblerd rsyncd xinetd,然后执行cobbler sync同步

    [root@localhost ~]# systemctl start httpd
    [root@localhost ~]# systemctl start cobblerd
    [root@localhost ~]# systemctl start rsyncd
    [root@localhost ~]# systemctl start xinetd
    [root@localhost ~]# cobbler sync
    task started: 2019-03-22_075324_sync
    task started (id=Sync, time=Fri Mar 22 07:53:24 2019)
    running pre-sync triggers
    
  6. 开始导入镜像,将需要通过网络安装的镜像导入到cobbler中管理。导入之后的镜像,存放在/var/www/cobbler/ks-mirror,目录名称就是--name定义的名字

    [root@localhost ~]# cobbler import --path=/mnt --name=CentOS-7 --arch=x86_64
    task started: 2019-03-22_080226_import
    task started (id=Media import, time=Fri Mar 22 08:02:26 2019)
    Found a candidate signature: breed=redhat, version=rhel6
    Found a matching signature: breed=redhat, version=rhel6
    Adding distros from path /var/www/cobbler/ks_mirror/CentOS-7-x86_64:
    creating new distro: CentOS-7-x86_64
    trying symlink: /var/www/cobbler/ks_mirror/CentOS-7-x86_64 -> /var/www/cobbler/links/CentOS-7-x86_64
    creating new profile: CentOS-7-x86_64
    associating repos
    checking for rsync repo(s)
    checking for rhn repo(s)
    checking for yum repo(s)
    starting descent into /var/www/cobbler/ks_mirror/CentOS-7-x86_64 for CentOS-7-x86_64
    processing repo at : /var/www/cobbler/ks_mirror/CentOS-7-x86_64
    need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS-7-x86_64
    looking for /var/www/cobbler/ks_mirror/CentOS-7-x86_64/repodata/*comps*.xml
    Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS-7-x86_64/repodata
    *** TASK COMPLETE ***
    
  7. 开始创建kickstart,新安装的系统使用kickstarte进行安装,kickstart存放在/var/lib/cobbler/kickstarts/目录下,在kickstart里面可以将所有需要安装的软件、系统优化参数等信息,全部安装进去,做到统一的定制化。

    建议在kickstart文件中,不要写中文
    # Kickstart Configurator for CentOS 7 
    #告知安装程序,这是一次全新安装,而不是升级,通过cobbler setting 中的tree来自动定义镜像位置,实际上也就是http://cobbler_server/cobbler/ks_mirror/*/这个目录
    install
    url --url=$tree
    #以文本格式安装
    text
    #设置字符集格式
    lang en_US.UTF-8
    #设置键盘类型和时区格式
    keyboard us
    timezone --utc Asia/Shanghai
    #指定引导记录被写入的位置
    bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
    #清除mbr引导
    zerombr
    #创建分区
    clearpart --all --initlabel
    part /boot --fstype xfs --size 1024 --ondisk sda
    part swap --size 16384 --ondisk sda
    part / --fstype xfs --size 1 --grow --ondisk sda
    #配置eth0网卡
    #network  --bootproto=static --device=eth0 --gateway=192.168.64.2 --ip=192.168.64.132 --nameserver=192.168.64.2 --netmask=255.255.255.0 --activate
    #设置主机名
    #network  --hostname=Cobbler.client
    #设置密码格式
    authconfig --enableshadow --passalgo=sha512
    rootpw  123456
    
    firstboot --disable
    #关闭selinux
    selinux --disabled
    #关闭防火墙
    firewall --disabled
    #设置日志级别
    logging --level=info
    #安装完成重启
    reboot
    
    %packages #包组段   @表示包组
    @^minimal
    @compat-libraries
    @debugging
    @development
    tree
    nmap
    sysstat
    lrzsz
    dos2unix
    telnet
    net-tools
    wget
    vim
    bash-completion
    %end
    
    %post #脚本段,可以放脚本或命令
    systemctl disable postfix.service   #关闭邮件服务开机自启动
    %end
    
  8. 创建了镜像之后,就可以编辑该镜像安装对应的profile文件,通过cobbler profile list/report/edit可以编辑对应profile文件。对于CentOS7主要修改启动网卡的名称。

    [root@localhost kickstarts]# cobbler profile edit --name=CentOS-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.cfg 
    [root@localhost kickstarts]# cobbler profile edit --name=CentOS-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'
    [root@localhost kickstarts]# cobbler sync
    [root@localhost kickstarts]# cobbler profile report
    Name                           : CentOS-7-x86_64
    TFTP Boot Files                : {}
    Comment                        : 
    DHCP Tag                       : default
    Distribution                   : CentOS-7-x86_64
    Enable gPXE?                   : 0
    Enable PXE Menu?               : 1
    Fetchable Files                : {}
    Kernel Options                 : {'biosdevname': '0', 'net.ifnames': '0'}
    Kernel Options (Post Install)  : {}
    Kickstart                      : /var/lib/cobbler/kickstarts/CentOS-7.cfg
    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
    
  9. 配置完成后,就可以开始创建虚拟机,在cobbler server上启用httpd,cobberd,xinet.d,tftp,rsync服务之后。创建一个新的虚拟机,和之前cobbler

    启动所有的服务,并检查状态
    for services in httpd cobblerd xinetd tftpd rsyncd;do systemctl start $services ;done
    for services in httpd cobblerd xinetd tftpd rsyncd;do systemctl status $services|grep Active ;done
    启动同步,实际上是要启动dhcpd服务
    cobbler sync
    创建的虚拟机内存太小,将会出现无法启动的情况,建议虚拟机的内存大小在4GB左右。保证能顺利安装。
    
  10. koan重装操作系统,登录到clinet上,安装koan工具,然后通过客户端指定需要重装的profile,完成重装即可。

定制化安装客户机

当有很多机器需要安装时,在提前做好了规划之后,避免在系统安装完成之后,又需要再进行一台一台的进行配置,最好是将一些基本属性,在自动安装的时候就直接安装上去,比如需要的组件,设置主机名、IP地址等信息。

为了能直接安装这些系统,需要对每台机器进行区别,唯一能区别的就是MAC地址,所以在规划的时候,需要知道主机的MAC地址,然后开始规划,主机名、IP地址、参数等一些其他信息。

在cobbler中,一个system就是一个主机,如果没有设置system主机,默认使用profile直接进行安装,如果能匹配上某一个system,则按照该system进行安装。

[root@localhost ~]# cobbler system add --name=cobblerclient --mac=00:0C:29:62:A6:92 --profile=CentOS7.0-x86_64 --ip-address=192.168.64.132 --subnet=255.255.255.0 --gateway=192.168.64.2 --interface=eth0 --static=1 --hostname=cobblerclient --name-servers="192.168.64.2"
[root@localhost ~]# cobbler system report
Name                           : cobblerclient
TFTP Boot Files                : {}
Comment                        : 
Enable gPXE?                   : <<inherit>>
Fetchable Files                : {}
Gateway                        : 192.168.64.2
Hostname                       : cobblerclient
Image                          : 
IPv6 Autoconfiguration         : False
IPv6 Default Device            : 
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : <<inherit>>
Kickstart Metadata             : {}
LDAP Enabled                   : False
LDAP Management Type           : authconfig
Management Classes             : <<inherit>>
Management Parameters          : <<inherit>>
Monit Enabled                  : False
Name Servers                   : ['192.168.64.2']
Name Servers Search Path       : []
Netboot Enabled                : True
Owners                         : <<inherit>>
Power Management Address       : 
Power Management ID            : 
Power Management Password      : 
Power Management Type          : ipmitool
Power Management Username      : 
Profile                        : CentOS7.0-x86_64
Internal proxy                 : <<inherit>>
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Repos Enabled                  : False
Server Override                : <<inherit>>
Status                         : production
Template Files                 : {}
Virt Auto Boot                 : <<inherit>>
Virt CPUs                      : <<inherit>>
Virt Disk Driver Type          : <<inherit>>
Virt File Size(GB)             : <<inherit>>
Virt Path                      : <<inherit>>
Virt PXE Boot                  : 0
Virt RAM (MB)                  : <<inherit>>
Virt Type                      : <<inherit>>
Interface =====                : eth0
Bonding Opts                   : 
Bridge Opts                    : 
CNAMES                         : []
InfiniBand Connected Mode      : False
DHCP Tag                       : 
DNS Name                       : 
Per-Interface Gateway          : 
Master Interface               : 
Interface Type                 : 
IP Address                     : 192.168.64.132
IPv6 Address                   : 
IPv6 Default Gateway           : 
IPv6 MTU                       : 
IPv6 Prefix                    : 
IPv6 Secondaries               : []
IPv6 Static Routes             : []
MAC Address                    : 00:0C:29:62:A6:92
Management Interface           : False
MTU                            : 
Subnet Mask                    : 255.255.255.0
Static                         : True
Static Routes                  : []
Virt Bridge                    : 

在一个system中可以配置很多参数,比如代理设置,比如网卡,比如相关管理和kickstart文件。默认都是继承于profile中的参数。

添加一个system,就是在cobbler的启动项中,增加了一项。/var/lib/cobbler/config/system.d/下,增加了一个以名字命名的json文件。

做了system之后,直接会跳过grub页面,然后直接开始自定义安装程序。

在/etc/cobbler/pxe/pxedefault.template中可以修改默认的grub顺序,默认是20s之后从local启动

cobbler目录

1. /var/www/cobbler/ks_mirror:存放的是客户机的镜像文件
2. /var/www/cobbler/repo_irror:存放的是客户机的仓库镜像
3. /var/lib/cobbler/kickstarts:存放kickstart文件
4. /etc/cobbler/settings:主配置文件

创建一个私有的yum仓库,在cobbler自动化安装的时候,将所有的客户机上都安装该yum仓库。

添加yum源
cobbler repo add --name=OpenStack-mitaka --mirror=http://*** --arch=x86_64 --breed=yum

执行同步,从网络上自动将所需要的yum源仓库全部下载下来,自动创建repo文件,cobbler reposync

将repo文件添加到profile中,则在自动安装的时候,会自动将repo仓库信息,添加进自动化安装中。

cobbler profile edit --name=*** --repos=****

在kickstart中添加一个$yumconfigstanza,则就会将profile中的repo信息添加进行客户机中。添加的位置在%post和%end之间

 

cobbler API

在cobbler平台上,提供了很多API端口,可以通过写脚本的形式,完成这些命令行的操作。cobbler api默认也是web页面的操作。默认的用户名和密码都是cobbler

 

cobbler CentOS7 de kickstart

# Cobbler for Kickstart Configurator for CentOS 7.1
install
url --url=$tree  # 这些$开头的变量都是调用配置文件里的值。
text
lang en_US.UTF-8
keyboard us
zerombr
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
# 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 1024  # CentOS7系统磁盘默认格式xfs
part swap --size 1024
part / --fstype xfs --size 1 --grow
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

 

posted @ 2019-03-27 20:51  波波波波波  阅读(174)  评论(0编辑  收藏  举报