3.14 cobbler

1. cobbler简介

Cobbler官网:https://cobbler.github.io/
cobbler配置文件详解

  • 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 模块的配置文件

cobbler数据目录

目录 作用
/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仓库存储目录

cobbler日志文件

日志文件路径 说明
/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. 服务端部署

1.配置yum源
[root@130 ~]# curl -o /etc/yum.repos.d/CentOS7-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@130 ~]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@130 ~]# sed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@130 ~]# yum -y install epel-release

2.使用yum源安装cobbler以及相关软件
[root@130 ~]# yum -y install httpd dhcp tftp python-ctypes cobbler  xinetd cobbler-web pykickstart

3.启动服务并设置为开机自启
[root@130 ~]# systemctl start httpd
[root@130 ~]# systemctl start cobblerd
[root@130 ~]# systemctl enable httpd
[root@130 ~]# systemctl enable cobblerd

4.修改server的ip地址为本机ip
[root@130 ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.80.130/' /etc/cobbler/settings

5.设置tftp的ip地址为本机ip
[root@130 ~]#  sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.80.130/' /etc/cobbler/settings

6.开启tftp
[root@130 ~]# sed -i '/disable/s/yes/no/g' /etc/xinetd.d/tftp

7.下载缺失文件
[root@130 ~]# cobbler get-loaders
task started: 2020-01-05_233412_get_loaders
task started (id=Download Bootloader Content, time=Sun Jan  5 23:34:12 2020)
downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
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
downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
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 ***

8.启动rsync并设置开机自启
[root@130 ~]# systemctl start rsyncd
[root@130 ~]# systemctl enable rsyncd

9.生成加密的密码
[root@130 ~]# openssl passwd -1 -salt "$RANDOM" '123456'
$1$3082$hSmQcOVltmf.NTq4lPTij0

10.将生成密码加入到配置文件
[root@130 ~]# vim /etc/cobbler/settings
  default_password_crypted: "$1$3082$hSmQcOVltmf.NTq4lPTij0"

11.重启cobbler  
[root@130 ~]# systemctl restart cobblerd
[root@130 ~]# ss -anlt
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128             *:22                          *:*                  
LISTEN      0      5       127.0.0.1:25151                       *:*                  
LISTEN      0      5               *:873                         *:*                  
LISTEN      0      128            :::80                         :::*                  
LISTEN      0      128            :::22                         :::*                  
LISTEN      0      128            :::443                        :::*                  
LISTEN      0      5              :::873                        :::*

12.使用cobbler check命令核对当前设置是否有问题、以下两个是关于debian系统的错误,请忽略
[root@130 ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : debmirror package is not installed, it will be required to manage debian deployments and repositories
2 : 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.

13.配置cobbler dhcp
13.1 修改cobbler配置文件,开启cobbler控制dhcp
[root@130 ~]# sed -i '/^manage_dhcp/s/0/1/g' /etc/cobbler/settings
[root@130 ~]# sed -n '/^manage_dhcp/p' /etc/cobbler/settings

13.2 配置dhcp,修改dhcp模板
[root@130 ~]# vim /etc/cobbler/dhcp.template
 subnet 192.168.80.0 netmask 255.255.255.0 {		//ip地址网段
     option routers             192.168.80.130;		//主机ip
     option domain-name-servers 192.168.80.2;		//dhcp服务器ip
     option subnet-mask         255.255.255.0;		//掩码
     range dynamic-bootp        192.168.80.132 192.168.1.250;	//ip地址池:分配ip地址范围
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;

14.重启服务并同步
[root@130 ~]# systemctl restart cobblerd
[root@130 ~]# cobbler sync
task started: 2020-01-06_093615_sync
task started (id=Sync, time=Mon Jan  6 09:36:15 2020)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
cleaning link caches
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout: 
received on stderr: 
running: service dhcpd restart
received on stdout: 
received on stderr: Redirecting to /bin/systemctl restart dhcpd.service

running shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.manage_genders
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***

15.检查dhcp是否正常
[root@130 ~]# netstat -anulp|grep dhcp
udp        0      0 0.0.0.0:67              0.0.0.0:*                           1513/dhcpd

16.导入redhat镜像
[root@130 ~]# mount /dev/cdrom /mnt/		//挂载镜像至/mnt目录
mount: /dev/sr0 写保护,将以只读方式挂载		
[root@130 ~]# cobbler import --path=/mnt --name=redhat-7 --arch=x86_64		//将/mnt下的所有镜像文件拷贝至cobbler,作为其镜像文件,--path:镜像路径,--name:镜像名称,--arch:安装平台cpu位数
task started: 2020-01-06_101513_import
task started (id=Media import, time=Mon Jan  6 10:15:13 2020)
Found a candidate signature: breed=redhat, version=rhel6
Found a candidate signature: breed=redhat, version=rhel7
Found a matching signature: breed=redhat, version=rhel7
Adding distros from path /var/www/cobbler/ks_mirror/redhat-7-x86_64:
creating new distro: redhat-7-x86_64
trying symlink: /var/www/cobbler/ks_mirror/redhat-7-x86_64 -> /var/www/cobbler/links/redhat-7-x86_64
creating new profile: redhat-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/redhat-7-x86_64 for redhat-7-x86_64
processing repo at : /var/www/cobbler/ks_mirror/redhat-7-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/redhat-7-x86_64
looking for /var/www/cobbler/ks_mirror/redhat-7-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/redhat-7-x86_64/repodata
processing repo at : /var/www/cobbler/ks_mirror/redhat-7-x86_64/addons/HighAvailability
need to process repo/comps: /var/www/cobbler/ks_mirror/redhat-7-x86_64/addons/HighAvailability
looking for /var/www/cobbler/ks_mirror/redhat-7-x86_64/addons/HighAvailability/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/redhat-7-x86_64/addons/HighAvailability/repodata
processing repo at : /var/www/cobbler/ks_mirror/redhat-7-x86_64/addons/ResilientStorage
need to process repo/comps: /var/www/cobbler/ks_mirror/redhat-7-x86_64/addons/ResilientStorage
looking for /var/www/cobbler/ks_mirror/redhat-7-x86_64/addons/ResilientStorage/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/redhat-7-x86_64/addons/ResilientStorage/repodata
*** TASK COMPLETE ***

17.查看cobbler镜像列表
[root@130 ~]# cobbler list
distros:
   redhat-7-x86_64

profiles:
   redhat-7-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:


18.创建kickstarts自动安装脚本
[root@130 ~]# cat > /var/lib/cobbler/kickstarts/redhat-7-x86_64.ks <<'EOF'
auth --enableshadow --passalgo=sha512
bootloader --location=mbr
clearpart --all --initlabel
part /boot --asprimary --fstype="ext4" --size=500
part swap --fstype="swap" --size=4096
part / --fstype="ext4" --grow --size=15000
text
firewall --disabled
firstboot --disable
keyboard us
lang en_US
url --url=http://192.168.80.130/cobbler/ks_mirror/redhat-7-x86_64
$yum_repo_stanza
reboot

rootpw --iscrypted $6$LKDv4w/TK823Yz.n$5wLpRFwwrIKamZk8fayKtRuZ54dQkiXd45U2JzeRnxx.9Lb7Qm1Wf7Fl79G.x8xZrVOOQNNiR150.nh6evAhI/

selinux --disabled
skipx
timezone Asia/Shanghai --isUtc --nontp
install
zerombr

%packages
@^minimal
@core
kexec-tools

%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
EOF

19.检查ks文件语法是否有误
[root@130 ~]# cobbler validateks
task started: 2020-01-06_102552_validateks
task started (id=Kickstart Validation, time=Mon Jan  6 10:25:52 2020)
----------------------------
osversion: rhel7
checking url: http://192.168.80.130/cblr/svc/op/ks/profile/redhat-7-x86_64
running: /usr/bin/ksvalidator -v "rhel7" "http://192.168.80.130/cblr/svc/op/ks/profile/redhat-7-x86_64"
received on stdout: 
received on stderr: 
*** all kickstarts seem to be ok ***
*** TASK COMPLETE ***

20.查看当前cobbler有哪些配置文件
[root@130 ~]# cobbler profile list
   redhat-7-x86_64

21.修改profile,将新建的ks文件设为默认的kickstarts安装文件
[root@130 ~]# cobbler profile edit --name redhat-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/redhat-7-x86_64.ks 

22.配置网卡名称为传统网卡名称eth0
[root@130 ~]# cobbler profile edit --name redhat-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'

23.检查当前系统cobbler配置文件信息
[root@130 ~]# cobbler profile report
Name                           : redhat-7-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : redhat-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/redhat-7-x86_64.ks
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

24.同步cobbler
[root@130 ~]# cobbler sync
task started: 2020-01-06_103422_sync
task started (id=Sync, time=Mon Jan  6 10:34:22 2020)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/redhat-7-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/images/redhat-7-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying files for distro: redhat-7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/redhat-7-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/redhat-7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/redhat-7-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/redhat-7-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: redhat-7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/redhat-7-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/redhat-7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/redhat-7-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/redhat-7-x86_64/initrd.img
Writing template files for redhat-7-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: redhat-7-x86_64
cleaning link caches
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout: 
received on stderr: 
running: service dhcpd restart
received on stdout: 
received on stderr: Redirecting to /bin/systemctl restart dhcpd.service

running shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.manage_genders
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***

25.重启所有服务
[root@130 ~]# systemctl restart xinetd		//重启守护进程xinetd
[root@130 ~]# systemctl restart cobblerd
[root@130 ~]# systemctl restart httpd
[root@130 ~]# ss -anlt
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128             *:22                          *:*                  
LISTEN      0      5       127.0.0.1:25151                       *:*                  
LISTEN      0      5               *:873                         *:*                  
LISTEN      0      128            :::80                         :::*                  
LISTEN      0      128            :::22                         :::*                  
LISTEN      0      128            :::443                        :::*                  
LISTEN      0      5              :::873                        :::*

3.客户端安装

  1. 新建虚拟机,稍后安装系统,内存最少为2G
  2. 虚拟机从pxe启动,若出现以下界面则表示成功:
    在这里插入图片描述

3.定制安装

定制安装步骤:

  • 统计服务器mac地址
  • 配置cobbler
  • 安装

1. 在web页面配置cobbler
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
保存后生成的配置存储在/var/lib/cobbler/config/profiles.d/redhat-7-x86_64.json
2. 在服务器同步配置并重启相关服务:

[root@130 ~]# cobbler sync
[root@130 ~]# systemctl restart httpd
[root@130 ~]# systemctl restart cobblerd
[root@130 ~]# systemctl restart xinetd

3. 启动需要安装系统的主机(最小内存为2G),启动后自动安装

发布了50 篇原创文章 · 获赞 8 · 访问量 1883

猜你喜欢

转载自blog.csdn.net/Yusyang_/article/details/103848437
今日推荐