cobbler实验

Cobbler 批量安装操作系统

1、安装 cobbler

[root@haproxy2 ~]# hostnamectl set-hostname cobbler
[root@cobbler ~]# yum install -y epel-release.noarch
[root@cobbler ~]# yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd

2、启动http与cobbler,检查

[root@haproxy2 ~]# systemctl start httpd.service
[root@haproxy2 ~]# systemctl start cobblerd.service 
[root@haproxy2 ~]# 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.
# 会有以上提示需修改

3、解决报错

1、批量排查命令集
[root@cobbler ~]# sed -i 's/server: 127.0.0.1/server: 192.168.203.214/' /etc/cobbler/settings
[root@cobbler ~]# sed -i 's/next_server: 127.0.0.1/next_server: 192.168.203.214/' /etc/cobbler/settings
[root@cobbler ~]# sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings
[root@cobbler ~]# sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings
[root@cobbler ~]# sed -ri "/default_password_crypted/s#(.*: ).*#\1\"`openssl passwd -1 -salt 'cobbler' '123456'`\"#" /etc/cobbler/settings
[root@cobbler ~]# sed -i 's#yes#no#' /etc/xinetd.d/tftp
[root@cobbler ~]# cobbler get-loaders
[root@cobbler ~]# systemctl start rsyncd
[root@cobbler ~]# systemctl enable rsyncd
[root@cobbler ~]# systemctl enable tftp.socket
[root@cobbler ~]# systemctl start tftp.socket
[root@cobbler ~]# systemctl restart cobblerd.service
[root@cobbler ~]# sed -i.ori 's#192.168.1#192.168.203#g;22d;23d' /etc/cobbler/dhcp.template
[root@cobbler ~]# cobbler sync
task started: 2020-07-11_092401_sync
task started (id=Sync, time=Sat Jul 11 09:24:01 2020)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
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 ***
2、启动rsync服务
[root@cobbler ~]# systemctl start rsyncd
3、修改安装完成后的root密码
[root@cobbler ~]# openssl passwd -1 -salt 'cobbler' '123.com'
$1$cobbler$rK3/2t1JZHrwohtqCqcmg.
[root@cobbler ~]# vim /etc/cobbler/settings 
default_password_crypted: "$1$cobbler$rK3/2t1JZHrwohtqCqcmg."
4、下载所需包
[root@cobbler ~]# yum install -y fence-agents
[root@cobbler ~]# yum -y install debmirror
[root@cobbler ~]# sed -i  's|@dists=.*|#@dists=|'  /etc/debmirror.conf
[root@cobbler ~]# sed -i  's|@arches=.*|#@arches=|'  /etc/debmirror.conf
5、管理dhcp
[root@cobbler ~]# sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings
[root@cobbler ~]# sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings
##修改
[root@cobbler ~]# cp /etc/cobbler/dhcp.template{,.bak}
[root@cobbler ~]# vim /etc/cobbler/dhcp.template
6、重启服务
[root@cobbler ~]# systemctl restart cobblerd.service 
[root@cobbler ~]# cobbler sync

4、验证配置

1、再次检查语法
[root@cobbler ~]# cobbler check
No configuration problems found.  All systems go.
2、重启所有服务
[root@cobbler ~]# systemctl restart httpd.service 
[root@cobbler ~]# systemctl restart cobblerd.service 
[root@cobbler ~]# systemctl restart dhcpd.service 
[root@cobbler ~]# systemctl restart rsyncd.service 
[root@cobbler ~]# systemctl restart tftp.socket 
3、脚本开机启动
[root@cobbler ~]# cat >>/etc/init.d/cobbler<<EOF
 #!/bin/bash
 # chkconfig: 345 80 90
 # description:cobbler
 
 case \$1 in
   start)
     /etc/init.d/httpd start
     /etc/init.d/xinetd start
     /etc/init.d/dhcpd start
     /etc/init.d/cobblerd start
     ;;
 
   stop)
     /etc/init.d/httpd stop
     /etc/init.d/xinetd stop
     /etc/init.d/dhcpd stop
    /etc/init.d/cobblerd stop
     ;;
 
   restart)
     /etc/init.d/httpd restart
     /etc/init.d/xinetd restart
     /etc/init.d/dhcpd restart
     /etc/init.d/cobblerd restart
     ;;
   status)
     /etc/init.d/httpd status
     /etc/init.d/xinetd status
     /etc/init.d/dhcpd status
     /etc/init.d/cobblerd status
     ;;
 
   sync)
     cobbler sync
     ;;
 
   *)
     echo "Input error,please in put 'start|stop|restart|status|sync'!"
     exit 2
     ;;
 
 esac
 EOF
[root@cobbler init.d]# chmod +x /etc/init.d/cobbler 
[root@cobbler init.d]# chkconfig cobbler on
4、Cobbler 的命令行管理
[root@cobbler ~]# cobbler import --help  # 导入镜像
[root@cobbler ~]# cobbler check    核对当前设置是否有问题
[root@cobbler ~]# cobbler list     列出所有的cobbler元素
[root@cobbler ~]# cobbler report   列出元素的详细信息
[root@cobbler ~]# cobbler sync     同步配置到数据目录,更改配置最好都要执行下
[root@cobbler ~]# cobbler reposync 同步yum仓库
[root@cobbler ~]# cobbler distro   查看导入的发行版系统信息
[root@cobbler ~]# cobbler system   查看添加的系统信息
[root@cobbler ~]# cobbler profile  查看配置信息

5、导入镜像

先自行下载一个centos7镜像,然后挂载到本地,之后导入到cobbler

[root@cobbler ~]# mkdir /mnt/centos7.6
[root@cobbler ~]# mount /dev/sr0  /mnt/centos7.6
[root@cobbler ~]# cobbler import --path=/mnt/centos7.6 --name=CentOS-7.6-1908 --arch=x86_64
task started: 2020-07-21_105906_import
task started (id=Media import, time=Tue Jul 21 10:59:06 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/CentOS-7.6-1908-x86_64:
creating new distro: CentOS-7.6-1908-x86_64
trying symlink: /var/www/cobbler/ks_mirror/CentOS-7.6-1908-x86_64 -> /var/www/cobbler/links/CentOS-7.6-1908-x86_64
creating new profile: CentOS-7.6-1908-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.6-1908-x86_64 for CentOS-7.6-1908-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS-7.6-1908-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS-7.6-1908-x86_64
looking for /var/www/cobbler/ks_mirror/CentOS-7.6-1908-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS-7.6-1908-x86_64/repodata
*** TASK COMPLETE ***
1、查看镜像列表
[root@localhost centos7.6]# cobbler distro list
   CentOS-7.6-1908-x86_64

镜像保存在http的目录内

[root@localhost centos7.6]# ls /var/www/cobbler/ks_mirror/
CentOS-7.6-1908-x86_64  config
[root@localhost centos7.6]# cobbler distro  report
Name                           : CentOS-7.6-1908-x86_64
Architecture                   : x86_64
TFTP Boot Files                : {}
Breed                          : redhat
Comment                        : 
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/ks_mirror/CentOS-7.6-1908-x86_64/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/CentOS-7.6-1908-x86_64/images/pxeboot/vmlinuz
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/CentOS-7.6-1908-x86_64'}
Management Classes             : []
OS Version                     : rhel7
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {}

6、kickstarts 文件配置

[root@localhost centos7.6]# cd /var/lib/cobbler/kickstarts/
[root@localhost kickstarts]# ls
default.ks    install_profiles  sample_autoyast.xml  sample_esxi4.ks  sample.ks        sample.seed.28
esxi4-ks.cfg  legacy.ks         sample_end.ks        sample_esxi5.ks  sample_old.seed
esxi5-ks.cfg  pxerescue.ks      sample_esx4.ks       sample_esxi6.ks  sample.seed
[root@localhost kickstarts]# mv sample_end.ks{,.bak}
[root@localhost kickstarts]# ls
default.ks    install_profiles  sample_autoyast.xml  sample_esxi4.ks  sample.ks        sample.seed.28
esxi4-ks.cfg  legacy.ks         sample_end.ks.bak    sample_esxi5.ks  sample_old.seed
esxi5-ks.cfg  pxerescue.ks      sample_esx4.ks       sample_esxi6.ks  sample.seed
[root@localhost kickstarts]# vim centos7u6-x64.ks   #最小化系统
#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 --fstype="swap" --size 2048 --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
%end
2、查看 kickstart 的配置
[root@localhost kickstarts]# cobbler profile  report  --name=CentOS-7.6-1908-x86_64
Name                           : CentOS-7.6-1908-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : CentOS-7.6-1908-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.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
3、修改指定的 kickstart 文件
[root@localhost kickstarts]# cobbler profile edit --name=CentOS-7.6-1908-x86_64  --kickstart=/var/lib/cobbler/kickstarts/centos7u6-x64.ks
[root@localhost kickstarts]# cobbler profile edit --name=CentOS-7.6-1908-x86_64 --kopts='net.ifnames=0 biosdevname=0'  #修改centos配置文件中的kickstart值
[root@localhost kickstarts]# cobbler sync   #执行rsync同步
task started: 2020-07-21_113700_sync
task started (id=Sync, time=Tue Jul 21 11:37:00 2020)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/CentOS-7.6-1908-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/CentOS-7.6-1908-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: CentOS-7.6-1908-x86_64
trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.6-1908-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/CentOS-7.6-1908-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.6-1908-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/CentOS-7.6-1908-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: CentOS-7.6-1908-x86_64
trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.6-1908-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/CentOS-7.6-1908-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.6-1908-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/CentOS-7.6-1908-x86_64/initrd.img
Writing template files for CentOS-7.6-1908-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: CentOS-7.6-1908-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 ***
4、 查看 kickstart 关联
[root@localhost kickstarts]# cobbler profile  report  --name=CentOS-7.6-1908-x86_64 | grep -i kickstart
Kickstart                      : /var/lib/cobbler/kickstarts/centos7u6-x64.ks
Kickstart Metadata             : {}
5、启动服务
[root@localhost kickstarts]# systemctl  restart dhcpd rsyncd cobblerd tftp
[root@localhost kickstarts]# ss -anutlp|egrep "httpd|rsync|rsyncd|dhcpd|25151"
udp    UNCONN     0      0         *:67                    *:*                   users:(("dhcpd",pid=24453,fd=7))
tcp    LISTEN     0      5         *:873                   *:*                   users:(("rsync",pid=24468,fd=4))
tcp    LISTEN     0      5      127.0.0.1:25151                 *:*                   users:(("cobblerd",pid=24459,fd=25))
tcp    LISTEN     0      5        :::873                  :::*                   users:(("rsync",pid=24468,fd=5))
tcp    LISTEN     0      128      :::80                   :::*                   users:(("httpd",pid=24311,fd=4),("httpd",pid=8466,fd=4),("httpd",pid=8465,fd=4),("httpd",pid=8464,fd=4),("httpd",pid=8463,fd=4),("httpd",pid=8462,fd=4),("httpd",pid=8460,fd=4))
tcp    LISTEN     0      128      :::443                  :::*                   users:(("httpd",pid=24311,fd=6),("httpd",pid=8466,fd=6),("httpd",pid=8465,fd=6),("httpd",pid=8464,fd=6),("httpd",pid=8463,fd=6),("httpd",pid=8462,fd=6),("httpd",pid=8460,fd=6))
6、修改启动菜单
[root@localhost kickstarts]# cat /etc/cobbler/pxe/pxedefault.template
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT $pxe_timeout_profile

LABEL local
        MENU LABEL (local)
        MENU DEFAULT
        LOCALBOOT -1

$pxe_menu_items

MENU end
[root@localhost kickstarts]# cobbler system add  --name=default --profile=CentOS-7.6-1908-x86_64
[root@localhost kickstarts]# cobbler  system list
   default
[root@localhost kickstarts]# cobbler sync
[root@localhost kickstarts]# cat /var/lib/tftpboot/pxelinux.cfg/default
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT CentOS-7.6-1908-x86_64

LABEL local
        MENU LABEL (local)
        MENU DEFAULT
        LOCALBOOT -1

LABEL CentOS-7.6-1908-x86_64
        kernel /images/CentOS-7.6-1908-x86_64/vmlinuz
        MENU LABEL CentOS-7.6-1908-x86_64
        append initrd=/images/CentOS-7.6-1908-x86_64/initrd.img ksdevice=bootif lang=  text net.ifnames=0 biosdevname=0 kssendmac  ks=http://192.168.203.214/cblr/svc/op/ks/profile/CentOS-7.6-1908-x86_64
        ipappend 2



MENU end
7、自动安装系统
[root@localhost kickstarts]# cobbler status
ip             |target              |start            |state   
8、cobbler的web及界面操作
https://192.168.203.214/cobbler_web
注意CentOS7中cobbler只支持https访问
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值