Cobbler简介:Cobbler 可以用来快速建立 Linux 网络安装环境,
cobbler集成的服务
- PXE服务支持
- DHCP服务管理
- DNS服务管理(可选bind,dnsmasq)
- 电源管理
- Kickstart服务支持
- YUM仓库管理
- TFTP(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服务端部署
//配置yum源
[root@cobbler ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@cobbler ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@localhost ~]# yum -y install epel-release
//安装cobbler以及相关的软件
[root@localhost ~]# yum -y install httpd dhcp tftp python-ctypes cobbler xinetd cobbler-web pykickstart
//启动服务并设置开机自启
[root@localhost ~]# systemctl enable --now httpd cobblerd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.
//修改server的ip地址为本机ip
[root@localhost ~]# vim /etc/cobbler/settings
server: 192.168.236.141
//设置tftp的ip地址为本机ip
[root@localhost ~]# vim /etc/cobbler/settings
next_server: 192.168.236.141
//开启tftp
[root@localhost ~]# vim /etc/xinetd.d/tftp
disable = no
关闭防火墙和seliunx
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# vim /etc/selinux/config
//下载缺失文件
[root@localhost ~]# cobbler get-loaders
[root@localhost ~]# openssl passwd -1 -salt "$RANDOM" '123123'
$1$18320$vqTHcVGAViUy092JSxxfc/
//启动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 ~]# vim /etc/cobbler/settings
default_password_crypted: "$1$25656$oih3qq3LAdw9vMy/8eLkW0"
//重启cobble
[root@localhost ~]# systemctl restart cobblerd
//通过cobbler check 核对当前设置是否有问题
[root@localhost ~]# 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.
//以上两个是关于debian系统的错误,请忽略
//配置cobbler dhcp
//修改cobbler配置文件,让cobbler控制dhcp
[root@localhost ~]# vim /etc/cobbler/settings
manage_dhcp: 1
//配置dhcp
[root@localhost ~]# vim /etc/cobbler/dhcp.templat
subnet 192.168.236.0 netmask 255.255.255.0 {
option routers 192.168.236.141; //此处为系统安装好后指定的dns地址
option domain-name-servers 114.114.114.114;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.236.10 192.168.236.25;
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 ~]# ss -antulp|grep 67
udp UNCONN 0 0 *:67 *:* users:(("dhcpd",pid=1811,fd=7))
//导入redhat7镜像
[root@localhost ~]# mount /dev/cdrom /mnt/
[root@localhost ~]# cobbler profile edit --name centos-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos-7-x86_64.ks
//说明:
--path //镜像路径
--name //为安装源定义一个名字
--arch //指定安装源平台
//查看cobbler镜像列表
[root@localhost ~]# cobbler list
distros:
centos-7-x86_64
profiles:
centos-7-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
//创建kickstarts自动安装脚本
[root@localhost ~]# cat > /var/lib/cobbler/kickstarts/centos-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.236.141/cobbler/ks_mirror/centos-7-x86_64
$yum_repo_stanza
reboot
rootpw --iscrypted $6$2WTFvfNvAMgCUPuC$MJgWGzhakgxrRObcEbAwSe8vkz0s//xyiTllGwxRsHHruQhcskO69u2LVTU9u0eemHXH2pzcGawyAJ54R2E/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
centos-7-x86_64
//修改profile,将我们新建的ks文件设为默认的kickstarts安装文件
[root@localhost ~]# cobbler profile edit --name centos-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos-7-x86_64.ks
//配置网卡名称为传统网卡名称eth0
[root@localhost ~]# cobbler profile edit --name centos-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'
//检查当前系统cobbler配置文件信息
[root@localhost ~]# 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-x86_64.ks //使用的kicksta
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
//同步cobbler
[root@localhost ~]# cobbler sync
//为避免发生未知问题,先把服务端所有服务重启
[root@localhost ~]# systemctl restart xinetd
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# systemctl restart httpd
客户端安装
新建虚拟机从pxe启动,若出现以下界面则表示成功:
定制安装
定制安装步骤:
统计服务器mac地址
配置cobbler
安装
统计mac地址此处就不赘述了,直接最重要的配置
在 cobbler 的web界面上配置:
https://192.168.236.141/cobbler_web
同步配置并重启相关服务:
[root@localhost ~]# cobbler sync
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# systemctl restart xinetd
最后开机自动会安装系统
[root@localhost ~]# cd /var/lib/cobbler/config/packages.d/
//脚本
[root@localhost systems.d]# cat vm5.json
#!/bin/bash
cat> /var/lib/cobbler/config/systems.d/vm8.json <<EOF
{
"comment":"",
"status":"production",
"kickstart":"/var/lib/cobbler/kickstarts/centos-7-x86_64.ks",
"name_servers_search":[
],
"ks_meta":{
},
"kernel_options_post":{
"biosdevname":"0",
"net.ifnames":"0"
},
"image":"",
"redhat_management_key":"<<inherit>>",
"virt_path":"<<inherit>>",
"power_user":"",
"kernel_options":{
},
"ctime":1606202655.916096,
"name_servers":[
"114.114.114.114"
],
"mtime":1606203514.751194,
"enable_gpxe":false,
"template_files":{
},
"gateway":"192.168.236.2",
"uid":"MTYwNjIwMjY1NS45MzQwODY5NS4yNjg2NA",
"virt_auto_boot":0,
"power_type":"ipmitool",
"virt_cpus":"<<inherit>>",
"mgmt_parameters":"<<inherit>>",
"boot_files":{
},
"hostname":"node9.example.com",
"repos_enabled":false,
"mgmt_classes":[
],
"power_pass":"",
"netboot_enabled":true,
"ipv6_autoconfiguration":false,
"profile":"centos-7-x86_64",
"virt_type":"xenpv",
"interfaces":{
"eth0":{
"ipv6_address":"",
"interface_type":"",
"static":true,
"cnames":[
],
"bridge_opts":"",
"management":false,
"interface_master":"",
"mac_address":"00:50:56:2F:52:DC",
"ipv6_prefix":"",
"virt_bridge":"xenbr0",
"netmask":"255.255.255.0",
"bonding_opts":"",
"ip_address":"192.168.236.252",
"dhcp_tag":"",
"ipv6_mtu":"",
"static_routes":[
],
"ipv6_static_routes":[
],
"if_gateway":"",
"dns_name":"",
"mtu":"",
"connected_mode":false,
"ipv6_secondaries":[
],
"ipv6_default_gateway":""
}
},
"power_address":"",
"proxy":"<<inherit>>",
"fetchable_files":{
},
"virt_file_size":"<<inherit>>",
"ldap_enabled":false,
"monit_enabled":false,
"ipv6_default_device":"",
"virt_pxe_boot":0,
"virt_disk_driver":"<<inherit>>",
"owners":"<<inherit>>",
"name":"vm8",
"virt_ram":"<<inherit>>",
"power_id":"",
"server":"<<inherit>>",
"redhat_management_server":"<<inherit>>",
"depth":2,
"ldap_type":"authconfig",
"template_remote_kickstarts":0
}
{
"comment":"",
"status":"production",
"kickstart":"/var/lib/cobbler/kickstarts/centos-7-x86_64.ks",
"name_servers_search":{
},
"ks_meta":{
},
"kernel_options_post":{
"biosdevname":"0",
"net.ifnames":"0"
},
"image":"",
"redhat_management_key":"<<inherit>>",
"virt_path":"<<inherit>>",
"power_user":"",
"kernel_options":{
},
"ctime":1606202655.916096,
"name_servers":[
"114.114.114.114"
],
"mtime":1606203514.751194,
"enable_gpxe":false,
"template_files":{
},
"gateway":"192.168.236.2",
"uid":"MTYwNjIwMjY1NS45MzQwODY5NS4yNjg2NA",
"virt_auto_boot":0,
"power_type":"ipmitool",
"virt_cpus":"<<inherit>>",
"mgmt_parameters":"<<inherit>>",
"boot_files":{
},
"hostname":"node9.example.com",
"repos_enabled":false,
"mgmt_classes":{
},
"power_pass":"",
"netboot_enabled":true,
"ipv6_autoconfiguration":false,
"profile":"centos-7-x86_64",
"virt_type":"xenpv",
"interfaces":{
"eth0":{
"ipv6_address":"",
"interface_type":"",
"static":true,
"cnames":{
},
"bridge_opts":"",
"management":false,
"interface_master":"",
"mac_address":"00:50:56:2F:52:DC",
"ipv6_prefix":"",
"virt_bridge":"xenbr0",
"netmask":"255.255.255.0",
"bonding_opts":"",
"ip_address":"192.168.236.252",
"dhcp_tag":"",
"ipv6_mtu":"",
"static_routes":{
},
"ipv6_static_routes":{
},
"if_gateway":"",
"dns_name":"",
"mtu":"",
"connected_mode":false,
"ipv6_secondaries":{
},
"ipv6_default_gateway":""
}
},
"power_address":"",
"proxy":"<<inherit>>",
"fetchable_files":{
},
"virt_file_size":"<<inherit>>",
"ldap_enabled":false,
"monit_enabled":false,
"ipv6_default_device":"",
"virt_pxe_boot":0,
"virt_disk_driver":"<<inherit>>",
"owners":"<<inherit>>",
"name":"vm8",
"virt_ram":"<<inherit>>",
"power_id":"",
"server":"<<inherit>>",
"redhat_management_server":"<<inherit>>",
"depth":2,
"ldap_type":"authconfig",
"template_remote_kickstarts":0
}
EOF
//执行脚本
[root@localhost scripts]# bash create_cobbler_system.sh
[root@localhost systems.d]# systemctl restart cobblerd
[root@localhost systems.d]# cobbler sync