1.cobble简介
cobble
是一个linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理dhcp,dns等。
cobbler可以使用命令行方式管理,也提供了基于web的界面管理工具(Cobbler-web),还提供API接口,方便二次开发使用。
cobbler是加载的kickstart的升级搬,优点是比较容易配置,还自带web界面比较易于管理。
cobbler内置了一个轻量级位置管理系统,但它也支持和其他配置管理系统集成,如puppet,暂时不支持saltstack.
cobbler集成的服务
- PXE服务支持
- DHCP服务管理
- DNS服务管理
- 电源管理
- Kickstart服务支持
- TFTF(PXE启动时需要)
- Apache(提供kickstart的安装源,并提供定制化的kickstart的配置)
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 //查看配置信息
cobbler服务端部署
#关闭防火墙和selinux.selinux需重启生效
[root@localhost ~]# getenforce 0
Disabled
[root@localhost ~]# systemctl stop firewalld
配置yum源
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS7-Base-163.repo http://m/CentOS7-Base-163.repo
% Total % Received % Xferd Average Speed Time Time Time Cur
Dload Upload Total Spent Left Spe
100 1572 100 1572 0 0 1301 0 0:00:01 0:00:01 --:--:-- 1
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS7-Base-163.repo
[root@localhost yum.repos.d]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@localhost yum.repos.d]# sed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@localhost yum.repos.d]# yum -y install epel-release
安装cobbler及相关软件
yum -y install httpd dhcp tftp python-ctypes cobbler xinetd cobbler-web pykickstart
启动服务设置开机自启
[root@localhost yum.repos.d]# systemctl start httpd
[root@localhost yum.repos.d]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@localhost yum.repos.d]# systemctl start cobblerd
[root@localhost yum.repos.d]# systemctl enable cobblerd
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.
修改serverde ip 地址问你本机ip
[root@localhost ~]# sed -i 's/^server:127.0.0.1/server: 192.168.118.112/' /etc/cobbler/settings
[root@localhost ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.118.112/' /etc/cobbler/settings
[root@localhost ~]# sed -i '/disable/s/yes/no/g' /etc/xinetd.d/tftp #开启tftp
下载缺失文件
[root@localhost ~]# cobbler get-loaders
task started: 2018-10-28_165834_get_loaders
task started (id=Download Bootloader Content, time=Sun Oct 28 16:58:34 2018)
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 ***
启动rsync并设置开机自启
[root@localhost ~]# systemctl start rsyncd
[root@localhost ~]# systemctl enable rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
生成加密的密码
[root@localhost ~]# openssl passwd -1 -salt "$RANDOM" '123456'
$1$1913$qAOnxp08DfDnfBjSbjiq71 #加密后的密码
#将新生成的加密密码加入到配置文件
[root@localhost ~]# vi /etc/cobbler/settings
# openssl passwd -1
# and put the output between the "" below.
default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac."
###替换为
default_password_crypted: "$1$1913$qAOnxp08DfDnfBjSbjiq71"
# the default template type to use in the absence of any
#重启cobbler
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 5 127.0.0.1:25151 *:*
LISTEN 0 5 *:873 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 :::443 :::*
LISTEN 0 5 :::873 :::*
核对当前设置有无问题
[root@localhost ~]# cobbler check
#配置cobbler dhcp
Restart cobblerd and then run 'cobbler sync' to apply changes.
[root@localhost ~]# sed -i '/^manage_dhcp/s/0/1/g' /etc/cobbler/settings
[root@localhost ~]# sed -n '/^manage_dhcp/p' /etc/cobbler/settings
manage_dhcp: 1
配置dhcp
[root@localhost ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.118.0 netmask 255.255.255.0 { #本机网段
option routers 192.168.118.112; #改为本机ip
option domain-name-servers 192.168.118.112; #改为本机ip
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.118.100 192.168.118.254; #本机网段
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
重启服务并同步配置,改变dhcp必须要sync同步配置
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# cobbler sync
#检查dhcp是否正常
[root@localhost ~]# netstat -anlup|grep dhcp
udp 0 0 0.0.0.0:67 0.0.0.0:* 1708/dhcpd
导入redhat7镜像
[root@localhost ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# cobbler import --path=/mnt --name=rhel-7 --arch=x86_64
#说明:
--path #镜像路径
--name #为安装源定义一个名字
--arch #指定安装源平台
#查看cobbler镜像列表
[root@localhost ~]# cobbler list
distros:
rhel-7-x86_64
profiles:
rhel-7-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
创建kickstarts自动安装脚本
[root@localhost ~]# cat > /var/lib/cobbler/kickstarts/rhel-7-x86_64.ks <<'EO
F'
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://172.16.12.128/cobbler/ks_mirror/rhel-7-x86_64
$yum_repo_stanza
$SNIPPET('network_config')
reboot
rootpw --iscrypted $6$2WTFvfNvAMgCUPuC$MJgWGzhakgxrRObcEbAwSe8vkz0s//xyiTllG
wxRsHHruQhcskO69u2LVTU9u0eemHXH2pzcGawyAJ54R2E/x0
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
#检查ks文件语法是否有误
[root@localhost ~]# cobbler validateks
#查看当前cobbler有哪些配置文件
[root@localhost ~]# cobbler profile list
#修改profile,将我们新建的ks文件设为默认的kickstarts安装文件
[root@localhost ~]# cobbler profile edit --name rhel-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/rhel-7-x86_64.ks
#修改网卡名称为传统网卡名称eth0
[root@localhost ~]# cobbler profile edit --name rhel-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'
#检查当前cobbler配置文件信息
[root@localhost ~]# cobbler profile report
#同步cobbler
[root@localhost ~]# cobbler sync
为了保险,把服务端的所有服务重启
[root@localhost ~]# systemctl restart xinetd
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# systemctl restart httpd
客户端安装
新建虚拟机,自动装机
出现以下界面表示成功