Cobbler

Cobbler

 

0.0
0.0

 

1、配置yum源+epel源

[root@localhost ~]# rm -rf /etc/yum.repos.d/*
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]# yum install epel-release -y

2、安装Cobbler及相关的软件包

[root@localhost ~]# yum install httpd tftp-server dhcp xinetd pykickstart debmirror fence-agents cobbler cobbler-web -y

下面是COBBLER相关的配置文件

cobbler     #cobbler程序包
cobbler-web  #cobbler的web服务包
pykickstart  #cobbler检查kickstart语法错误
httpd       #Apache web服务
 
/etc/cobbler                   # 配置文件目录
/etc/cobbler/settings         # cobbler主配置文件
/etc/cobbler/dhcp.template    # DHCP服务的配置模板
/etc/cobbler/tftpd.template   # tftp服务的配置模板
/etc/cobbler/rsync.template   # rsync服务的配置模板
/etc/cobbler/iso              # iso模板配置文件目录
/etc/cobbler/pxe              # pxe模板文件目录
/etc/cobbler/power            # 电源的配置文件目录
/etc/cobbler/users.conf       # Web服务授权配置文件
/etc/cobbler/users.digest     # web访问的用户名密码配置文件
/etc/cobbler/dnsmasq.template # DNS服务的配置模板
/etc/cobbler/modules.conf     # Cobbler模块配置文件
/var/lib/cobbler               # Cobbler数据目录
/var/lib/cobbler/config       # 配置文件
/var/lib/cobbler/kickstarts   # 默认存放kickstart文件
/var/lib/cobbler/loaders      # 存放的各种引导程序
/var/www/cobbler               # 系统安装镜像目录
/var/www/cobbler/ks_mirror    # 导入的系统镜像列表
/var/www/cobbler/images       # 导入的系统镜像启动文件
/var/www/cobbler/repo_mirror  # yum源存储目录
/var/log/cobbler               # 日志目录
/var/log/cobbler/install.log  # 客户端系统安装日志
/var/log/cobbler/cobbler.log  # cobbler日志

3、关闭防火墙和SELINUX

[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce 
Permissive
[root@localhost ~]# sed 's/=enforcing/=permissive/g' /etc/selinux/config -i
[root@localhost ~]# grep ^SE /etc/selinux/config 
SELINUX=permissive
SELINUXTYPE=targeted

4、配置DHCP服务,并启动Cobbler及相关服务

cat /etc/dhcp/dhcpd.conf
ddns-update-style interim;
allow booting;
allow bootp;
ignore client-updates;
set vendorclass = option vendor-class-identifier;
option pxe-system-type code 93 = unsigned integer 16;
subnet 192.168.2.0 netmask 255.255.255.0 {
     option routers             192.168.2.254;
     option domain-name-servers 192.168.2.254;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.2.100 192.168.2.254;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                192.168.2.254;
     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 if option pxe-system-type = 00:09 {
                  filename "grub/grub-x86_64.efi";
          } else {
                  filename "pxelinux.0";
          }
     }

}
systemctl restart httpd cobblerd dhcpd xinetd
systemctl enable httpd xinetd tftp dhcpd cobblerd
systemctl list-unit-files | grep -E "httpd|dhcpd|xinetd|cobblerd"

方法二:使用COBBLER管理DHCP

修改settings中参数,由cobbler控制dhcp
[root@localhost ~]# sed -i 's#manage_dhcp: 0#manage_dhcp: 1#g' /etc/cobbler/settings
配置DHCP服务
[root@localhost ~]# sed 's/192.168.1/192.168.2/g' /etc/cobbler/dhcp.template -i

5、导入镜像和KS文件

KS文件可安装system-config-kickstart文件生成

[root@localhost ~]# cat /var/lib/cobbler/kickstarts/centos7.2.cfg
install
keyboard 'us'
#rootpw --iscrypted $1$MfnFwJ6q$kwpX7UtHeWuLoBZyWkjmk0
rootpw 1
url --url="http://192.168.2.254/cobbler/ks_mirror/Centos7-x86_84/"
lang en_US
auth  --useshadow  --passalgo=sha512
text
firstboot --disable
selinux --disabled
skipx
firewall --disabled
reboot
timezone Asia/Shanghai
bootloader --location=mbr
zerombr
clearpart --all --initlabel
part /boot --fstype="xfs" --size=500
part swap --fstype="swap" --size=1000
part / --fstype="xfs" --grow --size=1

%packages
# --nobase
@^minimal
@core

%end

提示:写完 ks 文件之后,先通过 validateks 测试一下有没有语法错误

[root@localhost ~]# cobbler validateks
[root@localhost ~]# ksvalidator /var/lib/cobbler/kickstarts/centos7.cfg
[root@localhost ~]# mount /dev/sr0 /media/
cobbler import --path /media --name Centos7-x86-64
cobbler distro rename --name Centos7-64-x86_64 --newname --newname Centos7-x86-64
cobbler profile rename --name Centos7-64-x86_64 --newname Centos7-x86-64
cobbler profile edit --name Centos7-x86-64 --kickstart /var/lib/cobbler/kickstarts/centos7.cfg
[root@localhost ~]# cobbler sync

6、cobbler check检测

[root@localhost network-scripts]# 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 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:
    https://github.com/cobbler/cobbler/wiki/Selinux
4 : change 'disable' to 'no' in /etc/xinetd.d/tftp
5 : 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.
6 : enable and start rsyncd.service with systemctl
7 : comment out 'dists' on /etc/debmirror.conf for proper debian support
8 : comment out 'arches' on /etc/debmirror.conf for proper debian support
9 : 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

Restart cobblerd and then run 'cobbler sync' to apply changes.

7、解决报警

修改server的ip地址为本机ip
sed -i 's/server: 127.0.0.1/server: 192.168.2.254/g' /etc/cobbler/settings

修改TFTP Server 的IP地址
sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.2.254/' /etc/cobbler/settings
sed '14s/yes/no/g' /etc/xinetd.d/tftp -i
systemctl restart xinetd

启动rsyncd服务并设置为开机启动
[root@localhost ~]# systemctl enable rsyncd
[root@localhost ~]# systemctl start rsyncd

下载缺失的文件
[root@localhost ~]# cobbler get-loaders

生成密码
openssl passwd -1 -salt $(openssl rand -hex 4) 123456
$1$3a96551b$ma1wWqgi0lHpKLugVhUC31

修改settings配置文件中下面位置,把新生成的密码加进去
grep -n \_password /etc/cobbler/settings 
101:default_password_crypted: "$1$3a96551b$ma1wWqgi0lHpKLugVhUC31"

注释2830行
grep -En "sid|i386" /etc/debmirror.conf
28:#@dists="sid";
30:#@arches="i386";

重启COBBLER服务
[root@localhost ~]# systemctl restart cobblerd

在用COBBLER检测一次,以下SELINUX可忽略
[root@localhost ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:
    https://github.com/cobbler/cobbler/wiki/Selinux

Restart cobblerd and then run 'cobbler sync' to apply changes.

[root@localhost ~]# cobbler sync
systemctl restart xinetd

8、测试

 

8-1
8-1

 

 

8-2
8-2

 

 

8-3
8-3

 

 

8-4
8-4

 

注意:

  • 防火墙和SELINUX要关闭
firewall-cmd --permanent --add-port=67/udp
firewall-cmd --permanent --add-port=68/udp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tc
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --reload
firewall-cmd --permanent --list-ports
  • KS文件URL一定要指定对

9、通过Cobbler-web来管理Cobbler

使用 authn_configfile 模块认证 cobbler_web 用户
首先修改 modules.conf 中 [authentication] 段的 module 参数的值为 authn_configfile。
接着创建其认证文件 / etc/cobbler/users.digest,并添加所需的用户即可。需要注意的是,添加第一个用户时,需要为 htdigest 命令使用 “-c” 选项,后续添加其他用户时不能再使用;另外,cobbler_web 的 realm 只能为 Cobbler

htdigest -c /etc/cobbler/users.digest Cobbler cobbler

 

9-1
9-1

 

 

9-2
9-2

 

posted @ 2018-10-18 12:33  Final233  阅读(463)  评论(0编辑  收藏  举报