CentOS7下利用Cobbler安装部署CentOS

Cobbler是一款快速的网络系统部署工具,其最大的特点是集合了所有系统部署所需服务,如DHCP、DNS、TFTP,这样你在部署一台操作系统的时候不需要在各个服务之前协调切换,Cobbler都可以替你来管理,Cobbler内部集成了一个镜像版本仓库,你可以自定义相关配置文件,实现不同系统不同安装需求的选择;当然,Cobbler还提供了包括yum源管理、Web界面管理、API接口、电源管理等功能,方便你自定义开发管理。

关闭selinux和防火墙
[root@cobbler ~]# setenforce 0
[root@cobbler ~]# vim /etc/selinux/config
[root@cobbler ~]# systemctl stop firewalld

1)安装epel源和cobbler
[root@cobbler ~]# yum -y install http://mirrors.163.com/centos/7/extras/x86_64/Packages/epel-release-7-9.noarch.rpm
[root@cobbler ~]# yum install cobbler cobbler-web dhcp tftp-server pykickstart httpd xinetd -y
[root@cobbler ~]# systemctl start xinetd.service
[root@cobbler ~]# systemctl enable xinetd.service
[root@cobbler ~]# systemctl start httpd
[root@cobbler ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@cobbler ~]# systemctl start cobblerd.service
[root@cobbler ~]# systemctl enable cobblerd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.

2)配置cobbler

检查cobbler:
[root@cobbler ~]# 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.

修改cobbler的配置文件:
[root@cobbler ~]# vi  /etc/cobbler/settings 
next_server: 192.168.1.34         替换本机IP地址 (DHCP服务地址)
server:  192.168.1.34                 替换本机IP地址(cobbler服务地址)
pxe_just_once: 1                     ks脚本关闭 pxe ,这样就不会重复安装
manage_dhcp: 1                    替换为 1(cobbler管理dhcp,后面用于同步更新配置信息[cobbler sync])
manage_rsync: 1                    替换为 1 (cobbler管理rsync功能)
manage_tftpd: 1                    替换为 1 (cobbler管理tftp功能)


随机生成一个密码:
[root@cobbler ~]# openssl passwd -1 -salt 'random-phrase-here' ' 123456 '
$1$random-p$mzxQ/Sx848sXgvfwJCoZM0
注意: 这里保存的密码,将会用于批量部署机器中,root账户的登录密码。
修改cobbler默认的密码:
[root@cobbler ~]# vi  /etc/cobbler/settings 
将“default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac."”修改为“default_password_crypted:
"$1$random-p$mzxQ/Sx848sXgvfwJCoZM0”
[root@cobbler ~]# vim /etc/xinetd.d/tftp
将“disable = yes”修改为“disable = no”

重启rsync服务:

[root@cobbler ~]# systemctl start rsyncd.service
[root@cobbler ~]# systemctl enable rsyncd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.

下载cobbler相关的包:
[root@cobbler ~]# cobbler get-loaders

[root@cobbler ~]# systemctl restart cobblerd.service
[root@cobbler ~]# cobbler check

[root@cobbler ~]# cd /etc/cobbler/
[root@cobbler cobbler]# ls
auth.conf dhcp.template ldap power rsync.template users.conf zone_templates
cheetah_macros dnsmasq.template modules.conf pxe secondary.template users.digest
cobbler_bash import_rsync_whitelist mongodb.conf reporting settings version
completions iso named.template rsync.exclude tftpd.template zone.template

3)配置服务

[root@cobbler cobbler]# vim dhcp.template
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.254;
option domain-name-servers 8.8.8.8;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.1.34 192.168.1.35;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
class "pxeclients" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
if option pxe-system-type = 00:02 {
filename "ia64/elilo.efi";
} else if option pxe-system-type = 00:06 {
filename "grub/grub-x86.efi";
} else if option pxe-system-type = 00:07 {
filename "grub/grub-x86_64.efi";
} else {
filename "pxelinux.0";
}
}
}
备注:主要修改网段、DNS、网关等信息
[root@cobbler cobbler]# cobbler sync
通过cobbler管理的dhcp的配置文件
挂载并导入数据:
[root@cobbler ~]#rz CentOS-7.4-x86_64-Minimal-1708.iso
[root@cobbler ~]#mount -o loop /opt/CentOS-7.4-x86_64-Minimal-1708.iso /mnt/
mount: /dev/loop2 is write-protected, mounting read-only
[root@cobbler ~]# df -h
[root@cobbler opt]# cd /var/lib/cobbler/kickstarts
[root@swarm02 kickstarts]# vim centos7.4.ks
[root@cobbler opt]# cobbler import --path=/mnt --name=centos7.4 --arch=x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.4.ks
默认ks文件为 /var/lib/cobbler/kickstarts/sample_end.ks 文件


说明:cobbler导入的镜像放在:/var/www/cobbler/ks_mirror/

[root@cobbler ks_mirror]# pwd
/var/www/cobbler/ks_mirror
[root@cobbler ks_mirror]# ls
CentOS-7.4-x86_64 config

默认kickstart文件存放位置:/var/lib/cobbler/kickstarts/

[root@cobbler ~]# cd /var/lib/cobbler/kickstarts/
[root@cobbler kickstarts]# ll
[root@cobbler ~]# cobbler list
[root@cobbler ~]# cobbler profile report

查看cobbler profile的帮助:
[root@cobbler ~]# cobbler profile edit --help
Usage: cobbler [options]
Options:
-h, --help show this help message and exit
--name=NAME Name (Ex: F10-i386-webserver)
--uid=UID
--owners=OWNERS Owners (Owners list for authz_ownership (space
delimited))
--distro=DISTRO Distribution (Parent distribution)
--parent=PARENT Parent Profile
--enable-gpxe=ENABLE_GPXE
Enable gPXE? (Use gPXE instead of PXELINUX for
advanced booting options)
--enable-menu=ENABLE_MENU
Enable PXE Menu? (Show this profile in the PXE menu?)
--kickstart=KICKSTART
Kickstart (Path to kickstart template)
--kopts=KERNEL_OPTIONS
Kernel Options (Ex: selinux=permissive)
--kopts-post=KERNEL_OPTIONS_POST
Kernel Options (Post Install) (Ex: clocksource=pit
noapic)
--ksmeta=KS_META Kickstart Metadata (Ex: dog=fang agent=86)
--proxy=PROXY Internal proxy (Internal proxy URL)
--repos=REPOS Repos (Repos to auto-assign to this profile)
--comment=COMMENT Comment (Free form text description)
--virt-auto-boot=VIRT_AUTO_BOOT
Virt Auto Boot (Auto boot this VM?)
--virt-cpus=VIRT_CPUS
Virt CPUs (integer)
--virt-file-size=VIRT_FILE_SIZE
Virt File Size(GB)
--virt-disk-driver=VIRT_DISK_DRIVER
Virt Disk Driver Type (The on-disk format for the
virtualization disk)
--virt-ram=VIRT_RAM Virt RAM (MB)
--depth=DEPTH
--virt-type=VIRT_TYPE
Virt Type (Virtualization technology to use) (valid
options: xenpv,xenfv,qemu,kvm,vmware,openvz,SETTINGS:d
efault_virt_type)
--virt-path=VIRT_PATH
Virt Path (Ex: /directory OR VolGroup00)
--virt-bridge=VIRT_BRIDGE
Virt Bridge
--dhcp-tag=DHCP_TAG DHCP Tag (See manpage or leave blank)
--server=SERVER Server Override (See manpage or leave blank)
--ctime=CTIME
--mtime=MTIME
--name-servers=NAME_SERVERS
Name Servers (space delimited)
--name-servers-search=NAME_SERVERS_SEARCH
Name Servers Search Path (space delimited)
--mgmt-classes=MGMT_CLASSES
Management Classes (For external configuration
management)
--mgmt-parameters=MGMT_PARAMETERS
Management Parameters (Parameters which will be handed
to your management application (Must be valid YAML
dictionary))
--boot-files=BOOT_FILES
TFTP Boot Files (Files copied into tftpboot beyond the
kernel/initrd)
--fetchable-files=FETCHABLE_FILES
Fetchable Files (Templates for tftp or wget/curl)
--template-files=TEMPLATE_FILES
Template Files (File mappings for built-in config
management)
--redhat-management-key=REDHAT_MANAGEMENT_KEY
Red Hat Management Key (Registration key for RHN,
Spacewalk, or Satellite)
--redhat-management-server=REDHAT_MANAGEMENT_SERVER
Red Hat Management Server (Address of Spacewalk or
Satellite Server)
--template-remote-kickstarts=TEMPLATE_REMOTE_KICKSTARTS
--clobber allow add to overwrite existing objects
--in-place edit items in kopts or ksmeta without clearing the
other items

修改kickstart文件

[root@cobbler ~]# cobbler profile edit --name=CentOS-7.3-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.3-x86_64.cfg

修改内核参数:

[root@cobbler ~]# cobbler profile edit --name=CentOS-7.3-x86_64 --kopts='net.ifnames=0 biosdevname=0'
[root@cobbler ~]# cobbler profile report
Name : CentOS-7.3-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : CentOS-7.3-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.3-x86_64.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
[root@cobbler ~]# cobbler sync
task started: 2017-03-20_135014_sync
task started (id=Sync, time=Mon Mar 20 13:50:14 2017)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/CentOS-7.3-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.3-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
copying: /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
copying: /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
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.3-x86_64
trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.3-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/CentOS-7.3-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.3-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/CentOS-7.3-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: CentOS-7.3-x86_64
trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.3-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/CentOS-7.3-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.3-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/CentOS-7.3-x86_64/initrd.img
Writing template files for CentOS-7.3-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.3-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.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值