cobbler命令_Cobbler部署详细教程基于Centos7.5

当前环境介绍:

当前系统Centos7.5,关闭selinux,关闭firewalld(或自行设置相应规则),关闭当前路由dhcp功能,如果是虚拟机安装则网络适配器要选择NAT模式(因为同一局域网多个DHCP服务会有冲突),本机IP地址192.168.50.101

前提:cobbler由epel源提供,所以需要事先配置epel的yum源。

一、安装epel源

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

1

wget-O/etc/yum.repos.d/epel.repohttp://mirrors.aliyun.com/repo/epel-7.repo

我这里使用的是阿里的epel源,你也可以直接yum install epel-release

二、安装cobbler

yum install cobbler cobbler-web pykickstart debmirror httpd dhcp tftp-server xinetd syslinux

1

yuminstallcobblercobbler-webpykickstartdebmirrorhttpddhcptftp-serverxinetdsyslinux

三、启动相关服务并设置开机自启

systemctl start httpd

systemctl enable httpd

systemctl start cobblerd

systemctl enable cobblerd

systemctl start rsyncd

systemctl enable rsyncd

systemctl enable dhcpd

1

2

3

4

5

6

7

systemctlstarthttpd

systemctlenablehttpd

systemctlstartcobblerd

systemctlenablecobblerd

systemctlstartrsyncd

systemctlenablersyncd

systemctlenabledhcpd

四、检查cobbler配置

通过cobbler自带的命令检查,而后逐一按提示解决。

cobbler check

1

cobblercheck

正常会看到如下内容:

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 : comment out 'dists' on /etc/debmirror.conf for proper debian support

6 : comment out 'arches' on /etc/debmirror.conf for proper debian support

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、修改/etc/cobbler/settings文件,将默认server的127.0.0.1替换为本机IP地址

sed -i 's#^server: 127.0.0.1#server: 192.168.50.101#' /etc/cobbler/settings

1

sed-i's#^server: 127.0.0.1#server: 192.168.50.101#'/etc/cobbler/settings

2、修改/etc/cobbler/settings文件,将默认next_server的127.0.0.1替换为本机IP地址

sed -i 's#^next_server: 127.0.0.1#next_server: 192.168.50.101#' /etc/cobbler/settings

1

sed-i's#^next_server: 127.0.0.1#next_server: 192.168.50.101#'/etc/cobbler/settings

3、将/etc/xinetd.d/tftp中disable改为no

disable = no

1

disable = no

4、执行“cobbler get-loaders”命令即可

cobbler get-loaders

1

cobblerget-loaders

task started: 2018-11-04_103455_get_loaders

task started (id=Download Bootloader Content, time=Sat Nov 4 10:34:55 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 ***

1

2

3

4

5

6

7

8

9

10

11

12

13

taskstarted:2018-11-04_103455_get_loaders

taskstarted(id=DownloadBootloaderContent,time=SatNov410:34:552018)

downloadinghttps://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README

downloadinghttps://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo

downloadinghttps://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot

downloadinghttps://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux

downloadinghttps://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi

downloadinghttps://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot

downloadinghttps://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0

downloadinghttps://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32

downloadinghttps://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi

downloadinghttps://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi

***TASKCOMPLETE ***

5、注释/etc/debmirror.conf文件中的@dists="sid";一行

sed -i 's/@dists="sid";/#@dists="sid";/' /etc/debmirror.conf

1

sed-i's/@dists="sid";/#@dists="sid";/'/etc/debmirror.conf

6、注释/etc/debmirror.conf文件中的@arches="i386";一行

sed -i 's/@arches="i386";/#@arches="i386";/' /etc/debmirror.conf

1

sed-i's/@arches="i386";/#@arches="i386";/'/etc/debmirror.conf

7、设置新系统默认的root密码,执行“openssl passwd -1 -salt $(openssl rand -hex 4)”生成密码,并用其替换/etc/cobbler/settings文件中default_password_crypted参数的值;

openssl passwd -1 -salt $(openssl rand -hex 4)

Password:whsir

$1$7cbbc3f6$NDKbP8HqfR4/p6S6g9Mzd/

1

2

3

opensslpasswd-1-salt$(opensslrand-hex4)

Password:whsir

$1$7cbbc3f6$NDKbP8HqfR4/p6S6g9Mzd/

vi /etc/cobbler/settings

1

vi/etc/cobbler/settings

default_password_crypted: "$1$7cbbc3f6$NDKbP8HqfR4/p6S6g9Mzd/"

1

default_password_crypted:"$1$7cbbc3f6$NDKbP8HqfR4/p6S6g9Mzd/"

8、安装相应的程序包

yum install fence-agents

1

yuminstallfence-agents

五、重启cobblerd并同步检查

systemctl restart cobblerd

cobbler sync

cobbler check

1

2

3

systemctlrestartcobblerd

cobblersync

cobblercheck

显示No configuration problems found. All systems go.(没有找到配置问题,一切正常)

六、通过cobbler来管理dhcp

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

1

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

七、配置dhcp服务

vi /etc/cobbler/dhcp.template

1

vi/etc/cobbler/dhcp.template

...

subnet 192.168.50.0 netmask 255.255.255.0 {

option routers             192.168.50.1;  #网关地址

option domain-name-servers 114.114.114.114; #DNS

option subnet-mask         255.255.255.0; #掩码

range dynamic-bootp        192.168.50.120 192.168.50.130; #网段

...

1

2

3

4

5

6

7

...

subnet 192.168.50.0 netmask 255.255.255.0 {

option routers             192.168.50.1;  #网关地址

option domain-name-servers 114.114.114.114;#DNS

option subnet-mask         255.255.255.0;#掩码

range dynamic-bootp        192.168.50.120 192.168.50.130;#网段

...

重启cobbler服务并同步配置

systemctl restart cobblerd

cobbler sync

1

2

systemctlrestartcobblerd

cobblersync

八、挂载导入镜像

我这里已经上传好了一个镜像在root目录下

mount -r CentOS-7-x86_64-Minimal-1804.iso /mnt/

1

mount-rCentOS-7-x86_64-Minimal-1804.iso/mnt/

导入镜像,cobbler会将镜像中所有安装文件拷贝到/var/www/cobbler/ks_mirror/NAME目录下,因此/var/www/cobbler目录必须具有足够的空间

cobbler import --path=/mnt/ --name=CentOS-7.5-x86_64 --arch=x86_64

1

cobblerimport--path=/mnt/--name=CentOS-7.5-x86_64--arch=x86_64

导入镜像完成后,可用下面命令查看到刚才导入的镜像

cobbler distro list

1

cobblerdistrolist

九、编辑kickstart文件

我这里已经提前准备好了一份kickstart文件,文件内容如下

vi /var/lib/cobbler/kickstarts/CentOS-7.5-x86_64.cfg

1

vi/var/lib/cobbler/kickstarts/CentOS-7.5-x86_64.cfg

# Centos7

# This kickstart file should only be used with EL > 5 and/or Fedora > 7.

# For older versions please use the sample.ks kickstart file.

#platform=x86, AMD64, or Intel EM64T

# System authorization information

auth --useshadow --passalgo=sha512

# System bootloader configuration

bootloader --location=mbr

# Partition clearing information

clearpart --all --initlabel

# Use text mode install

text

# Firewall configuration

firewall --disable

# Run the Setup Agent on first boot

firstboot --disable

ignoredisk --only-use=sda

# System keyboard

keyboard us

# System language

lang en_US

# Use network installation

url --url=$tree

# If any cobbler repo definitions were referenced in the kickstart profile, include them here.

$yum_repo_stanza

# Network information

$SNIPPET('network_config')

# Reboot after installation

reboot

#Root password

rootpw --iscrypted $default_password_crypted

# SELinux configuration

selinux --disabled

# Do not configure the X Window System

skipx

# System timezone

timezone Asia/Shanghai

# Install OS instead of upgrade

install

# Clear the Master Boot Record

zerombr

# Allow anaconda to partition the system as needed

part /boot --fstype="xfs" --size=300 --ondisk=sda

part swap --fstype="swap" --size=2048 --ondisk=sda

part / --fstype="xfs" --grow --size=1 --ondisk=sda

%pre

$SNIPPET('log_ks_pre')

$SNIPPET('kickstart_start')

$SNIPPET('pre_install_network_config')

# Enable installation monitoring

$SNIPPET('pre_anamon')

%end

%packages

@^minimal

@core

kexec-tools

%end

%post

systemctl disable postfix.service

%end

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

# Centos7

# This kickstart file should only be used with EL > 5 and/or Fedora > 7.

# For older versions please use the sample.ks kickstart file.

#platform=x86, AMD64, or Intel EM64T

# System authorization information

auth--useshadow--passalgo=sha512

# System bootloader configuration

bootloader--location=mbr

# Partition clearing information

clearpart--all--initlabel

# Use text mode install

text

# Firewall configuration

firewall--disable

# Run the Setup Agent on first boot

firstboot--disable

ignoredisk--only-use=sda

# System keyboard

keyboardus

# System language

langen_US

# Use network installation

url--url=$tree

# If any cobbler repo definitions were referenced in the kickstart profile, include them here.

$yum_repo_stanza

# Network information

$SNIPPET('network_config')

# Reboot after installation

reboot

#Root password

rootpw--iscrypted$default_password_crypted

# SELinux configuration

selinux--disabled

# Do not configure the X Window System

skipx

# System timezone

timezoneAsia/Shanghai

# Install OS instead of upgrade

install

# Clear the Master Boot Record

zerombr

# Allow anaconda to partition the system as needed

part/boot--fstype="xfs"--size=300--ondisk=sda

partswap--fstype="swap"--size=2048--ondisk=sda

part/--fstype="xfs"--grow--size=1--ondisk=sda

%pre

$SNIPPET('log_ks_pre')

$SNIPPET('kickstart_start')

$SNIPPET('pre_install_network_config')

# Enable installation monitoring

$SNIPPET('pre_anamon')

%end

%packages

@^minimal

@core

kexec-tools

%end

%post

systemctldisablepostfix.service

%end

十、修改kickstart文件为自定义的CentOS-7.5-x86_64.cfg

cobbler profile edit --name=CentOS-7.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.5-x86_64.cfg

1

cobblerprofileedit--name=CentOS-7.5-x86_64--kickstart=/var/lib/cobbler/kickstarts/CentOS-7.5-x86_64.cfg

用cobbler profile report查看,Kickstart已经改变

十一、重启xinetd服务

systemctl restart xinetd

1

systemctlrestartxinetd

至此为止配置完成,部分参数可根据情况自行进行修改

PS:

后续安装系统时如果提示TFTP timeout,请检查xinetd服务是否启动,netstat -lntpu是否可以看到69端口

如果出现/sbin/dmsquash-live-root: line 286: printf: write error: No space left on device因为内存不足2G的原因

4a18ecff2246c7a12593d607469add98.gif

~微信打赏~

c58088c0d056e1a064803d30fe483a9f.png

251b18b42e27e127937af3c2cec64d17.png

8772c142b46fd39a599192ad682d0bff.png

分享到:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值