1.1 cobbler简介

  spacer.gifimage.png


1.1.1 cobbler集成的服务

    PXE服务支持

    DHCP服务管理

    DNS服务管理(可选bind,dnsmasq)

    电源管理

    Kickstart服务支持

    YUM仓库管理

    TFTP(PXE启动时需要)

    Apache(提供kickstart的安装源,并提供定制化的kickstart配置)

1.2 安装cobbler

1.2.1 环境说明

[[email protected] ~]# cat /etc/redhat-release

CentOS Linux release 7.2.1511 (Core)

[[email protected] ~]# uname -r

3.10.0-693.el7.x86_64

[[email protected] ~]# getenforceDisabled

[[email protected] ~]# systemctl status firewalld.service

● firewalld.service - firewalld - dynamic firewall daemon

Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)

Active: inactive (dead)

Docs: man:firewalld(1)

[[email protected] ~]# hostname -I

10.0.0.202 172.16.1.202

先配置好yum源:

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

1.2.2 使用yum安装cobbler

yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd

   说明:cobbler是依赖与epel源下载

1.2.3 cobbler语法检查前先启动http与cobbler

systemctl start httpd.service

systemctl start cobblerd.service

cobbler check

1.2.4 进行语法检查

[[email protected] ~]# 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.

1.2.5 解决当中的报错

命令集合

########################################################################################################

sed -i 's/server: 127.0.0.1/server: 172.16.1.63/' /etc/cobbler/settings

sed -i 's/next_server: 127.0.0.1/next_server: 172.16.1.63/' /etc/cobbler/settings

sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings

sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings

sed -i 's#yes#no#' /etc/xinetd.d/tftp


sed -ri "/default_password_crypted/s#(.*: ).*#\1\"`openssl passwd -1 -salt 'asasd' '123456'`\"#" /etc/cobbler/settings


systemctl start rsyncd

systemctl enable rsyncd

systemctl enable tftp.socket

systemctl start tftp.socket

systemctl restart cobblerd.service

sed -i.ori 's#192.168.1#172.16.1#g;22d;23d' /etc/cobbler/dhcp.template

cobbler sync

########################################################################################################

以上命令详解

解决1、2

#/etc/cobbler/setting中的server配置需要修改,将127.0.0.1修改为cobbler服务器ip

cp /etc/cobbler/settings{,.ori}

sed -i 's/server: 127.0.0.1/server: 172.16.1.202/' /etc/cobbler/settings

sed -i 's/next_server: 127.0.0.1/next_server: 172.16.1.202/' /etc/cobbler/settings

问题3

#让xinetd管理thtp服务

sed 's#yes#no#g' /etc/xinetd.d/tftp -i

4下载包所需的软件包

[[email protected] ~]# cobbler get-loaders

[[email protected] ~]# ls /var/lib/cobbler/loaders

COPYING.elilo elilo-ia64.efi menu.c32 yaboot

COPYING.syslinux grub-x86_64.efi pxelinux.0

COPYING.yaboot grub-x86.efi README

5启动rsync服务

[[email protected] ~]# systemctl start rsyncd.service

[[email protected] ~]# systemctl enable rsyncd.service

6 debian相关无需修改

7、修改安装完成后的root密码

openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'

random-phrase-here 随机字符串(不是用户名)

your-password-here 密码

示例

[[email protected] ~]# openssl passwd -1 -salt 'sdfsdf' '123456'

$1$CLSN$LpJk4x1cplibx3q/O4O/K/

管理dhcp

sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings

防止重装

sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings

修改dhcp模板(切记不可连续执行)

sed -i.ori 's#192.168.1#172.16.1#g;22d;23d' /etc/cobbler/dhcp.template

cobbler组配置文件位置

/etc/cobbler/settings

注意:修改完成之后要使用cobbler sync 进行同步,否则不生效。

1.2.6 修改之后

再次检查语法:

[[email protected] ~]# 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.

重启所有服务

systemctl restart httpd.service

systemctl restart cobblerd.service

systemctl restart dhcpd.service

systemctl restart rsyncd.service

systemctl restart tftp.socket

到此cobbler就安装完成,下面进行web界面的操作。

1.3 cobbler的web及界面操作

浏览器访问https://10.0.0.63/cobbler_web

   注意CentOS7中cobbler只支持https访问。

   账号密码默认均为cobbler

1190037-20171115171117046-397590980.png spacer.gif

1.3.1 操作说明--导入镜像

1)在虚拟机上添加上镜像

1190037-20171115171127546-900178910.png spacer.gif

2)挂载上镜像

[[email protected] ~]# mount /dev/cdrom /mnt/

mount: /dev/sr0 is write-protected, mounting read-only

[[email protected] ~]# df -h |grep mnt

/dev/sr0 4.3G 4.3G 0 100% /mnt

   3)进行导入镜像

   选择Import DVD  输入Prefix(文件前缀),Arch(版本),Breed(品牌),Path(要从什么地方导入)

   镜像路径在导入镜像的时候要注意路径,防止循环导入。

   信息配置好后,点击run,即可进行导入。

 spacer.gif1190037-20171115171154031-1223678363.png

导入过程使用rsync进行导入,三个进程消失表示导入完毕

[[email protected] mnt]# ps -ef |grep rsync

root 12026 1 0 19:04 ? 00:00:00 /usr/bin/rsync --daemon --no-detach

root 13554 11778 12 19:51 ? 00:00:06 rsync -a /mnt/ /var/www/cobbler/ks_mirror/CentOS7.4-x86_64 --progress

root 13555 13554 0 19:51 ? 00:00:00 rsync -a /mnt/ /var/www/cobbler/ks_mirror/CentOS7.4-x86_64 --progress

root 13556 13555 33 19:51 ? 00:00:17 rsync -a /mnt/ /var/www/cobbler/ks_mirror/CentOS7.4-x86_64 --progress

root 13590 10759 0 19:52 pts/1 00:00:00 grep --color=auto rsync

查看日志可以发现右running进程

      日志位于 Events

1190037-20171115171219140-820246395.png spacer.gif

导入完成后生成的文件夹

[[email protected] ks_mirror]# pwd

/var/www/cobbler/ks_mirror

[[email protected] ks_mirror]# ls

CentOS7.4-x86_64 config

1.3.2 创建一台空白虚拟机,进行测试网路安装

注意:虚拟机的内存不能小于2G,网卡的配置要保证网络互通

启动虚拟机

   启动虚拟机即可发现会有cobbler的选择界面

spacer.gif

1190037-20171115171242656-398272156.png

选择CentOS7.4即可进行安装,安装过程与光盘安装一致,这里就不在复述。

1.4 定制化安装操作系统

1.4.1 添加内核参数

1)查看导入的镜像,点击edit

1190037-20171115171258015-1494072420.pngspacer.gif

2)在内核参数中添加net.ifnames=0 biosdevname=0

   能够让显示的网卡变为eth0 ,而不是CentOS7中的ens33

   修改完成后点击保存

spacer.gif

1190037-20171115171309874-60725189.png

1.4.2 查看镜像属性

1190037-20171115171319609-343797442.pngspacer.gif

1.4.3 编写ks文件

另一种方法:

1)创建新的ks文件

1190037-20171115171338593-1336390307.pngspacer.gif

2)添加ks文件,并配置文件名

      创建完成后点击Save进行保存

spacer.gif

1190037-20171115171346874-1039121760.png

CentOS7  ks配置文件参考

# Cobbler for Kickstart Configurator for CentOS 7 by yao zhang

install

url --url=$tree

text

lang en_US.UTF-8

keyboard us

zerombr

bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"

#Network information

$SNIPPET('network_config')

#network --bootproto=dhcp --device=eth0 --onboot=yes --noipv6 --hostname=CentOS7

timezone --utc Asia/Shanghai

authconfig --enableshadow --passalgo=sha512

rootpw  --iscrypted $default_password_crypted

clearpart --all --initlabel

part /boot --fstype xfs --size 1024

part swap --size 1024

part / --fstype xfs --size 1 --grow

firstboot --disable

selinux --disabled

firewall --disabled

logging --level=info

reboot

%pre

$SNIPPET('log_ks_pre')

$SNIPPET('kickstart_start')

$SNIPPET('pre_install_network_config')

# Enable installation monitoring

$SNIPPET('pre_anamon')

%end

%packages

@^minimal

@compat-libraries

@core

@debugging

@development

bash-completion

chrony

dos2unix

kexec-tools

lrzsz

nmap

sysstat

telnet

tree

vim

wget

%end

%post

systemctl disable postfix.service

%end



1.4.4 自定义安装系统

1)选择systems 创建一个新的系统

spacer.gif

1190037-20171115171448749-413659574.png

2)定义系统信息

spacer.gif

1190037-20171115171500702-1774899020.png

3)配置全局网络信息

      可以配置主机名、网关、DNS等

        我这里面是双网卡,所以只配置主机名和DNS

spacer.gif

1190037-20171115171510515-1866830973.png

4)配置网卡信息,eth0,eth1

   需要注意,选择static静态,

1190037-20171115171519781-484237309.pngspacer.gif

   以上的所有配置完成后,点击Save进行保存

附录:

   VMware workstation中查看虚拟机mac地址的方法。在虚拟机设置中。

1190037-20171115171558437-2147316862.png 

 cobbler web 界面说明

1190037-20171115171610484-679767567.png

1.5 安装虚拟机

1.5.1 开启虚拟机

如果之前的设置就显示安装进度

1190037-20171115171637515-1915678553.png spacer.gif

1.5.2 安装完成进行检查spacer.gif


1190037-20171115171645890-120797278.png

1.6 cobbler使用常见错误

1.6.1 cobbler check报错

[[email protected] ~]# cobbler syncTraceback (most recent call last):

File "/usr/bin/cobbler", line 36, in <module>

sys.exit(app.main())

File "/usr/lib/python2.7/site-packages/cobbler/cli.py", line 662, in main

rc = cli.run(sys.argv)

File "/usr/lib/python2.7/site-packages/cobbler/cli.py", line 269, in run

self.token = self.remote.login("", self.shared_secret)

File "/usr/lib64/python2.7/xmlrpclib.py", line 1233, in __call__

return self.__send(self.__name, args)

File "/usr/lib64/python2.7/xmlrpclib.py", line 1587, in __request

verbose=self.__verbose

File "/usr/lib64/python2.7/xmlrpclib.py", line 1273, in request

return self.single_request(host, handler, request_body, verbose)

File "/usr/lib64/python2.7/xmlrpclib.py", line 1306, in single_request

return self.parse_response(response)

File "/usr/lib64/python2.7/xmlrpclib.py", line 1482, in parse_response

return u.close()

File "/usr/lib64/python2.7/xmlrpclib.py", line 794, in close

raise Fault(**self._stack[0])

xmlrpclib.Fault: <Fault 1: "<class 'cobbler.cexceptions.CX'>:'login failed'">

解决办法

systemctl restart httpd.service

systemctl restart cobblerd.service

cobbler check

1.6.2 No space left on device

1190037-20171115171739296-1920171628.png 

   出现这个错误的原因是虚拟机的内存不足2G,

   将内存调为2G即可(这个错误只会出现在CentOS7.3之上)


小伙伴们可以关注我的微信公众号:linux运维菜鸟之旅

qrcode_for_gh_5ecc48d3d14a_258.jpg

关注“中国电信天津网厅”公众号,首次绑定可免费领2G流量,为你的学习提供流量! 

qrcode_for_gh_d20dccd1c74b_258.jpg