cobbler配置

时间:2023-03-08 20:44:30
cobbler配置

:ks脚本关闭pxe,这样就不会重复安装

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

6:TFTP服务器 IP地址

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

7:cobbler管理rsync

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

8:cobbler管理dhcp

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

9:cobbler管理dns (可选)

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

设置root默认密码

这个设置只针对centos有效。我默认的root密码是:fengyun299

# openssl passwd -1 -salt 'random-phrase-here' 'fengyun299'
$1$random-p$99lAzJZEl9uunSaThe9oM0

修改 /etc/cobbler/settings

#default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac."
default_password_crypted: "$1$random-p$SBOoxFrHGWHpvzS8BeGQ5/"

11: 启动相关服务

dhcp服务由于没有设置,所以无法启动。后面我们会对dhcp进行设置。另外启动named的服务时候,需要等待1,2分钟,生成一个key。

chkconfig httpd on 
chkconfig cobblerd on
chkconfig named on
chkconfig dhcpd on
/etc/init.d/httpd restart
/etc/init.d/cobblerd restart
/etc/init.d/named restart

12:设置debmirror

sed -i -e 's|@dists=.*|#@dists=|'  /etc/debmirror.conf
sed -i -e 's|@arches=.*|#@arches=|'  /etc/debmirror.conf

13:启动菜单

cobbler get-loaders

检查cobbler

cobbler提供一个工具,检查你的设置。看到提示,就表示全部工作都已经完成。

对cobbler所有修改,需要

cobbler sync

检查

# cobbler check
No configuration problems found.  All systems go.

四:web登陆

[root@kingserver111 opt]# cobbler list

distros:

CentOS6.0-x86_64

profiles:

CentOS6.0-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:

4.7 删除导入的系统

cobbler profile find --distro=centos6.3-x64-x86_64 #查看配置是否存在

centos6.3-x64-x86_64

cobbler profile remove --name=centos6.3-x64-x86_64 #删除配置文件

cobbler distro remove --name=centos6.3-x64-x86_64 #删除distro

cobbler profile find --distro=centos6.3-x64-x86_64 #再查看配置已无

4.8 自定义ks

更改kickstart文件,可为http等,具体cobbler --help查看,这里采用我们自定制ks文件

ks目录位置

/var/lib/cobbler/kickstarts/

默认的ks位置

/var/lib/cobbler/kickstarts/sample.ks

更改指定系统版本对应的ks配置文件

cobbler profile edit --name=centos5.8-x86_64    --kickstart=/var/lib/cobbler/kickstarts/centos5u8-x64.cfg

cobbler profile edit --name=centos6.3-x86_64    --kickstart=/var/lib/cobbler/kickstarts/centos6u3-x64.cfg

cobbler profile edit --name=centos6.4-x86_64    --kickstart=/var/lib/cobbler/kickstarts/centos6u4-x64.cfg

4.9 配置信息查看

cobbler report

distros:

==========

Name                           : centos5.8-xen-x86_64

Architecture                   : x86_64

TFTP Boot Files                : {}

Breed                          : redhat

Comment                        : rhel5.8

Fetchable Files                : {}

Initrd                         : /var/www/cobbler/ks_mirror/centos5.8-x86_64/images/xen/initrd.img

Kernel                         : /var/www/cobbler/ks_mirror/centos5.8-x86_64/images/xen/vmlinuz

Kernel Options                 : {}

Kernel Options (Post Install) : {}

Kickstart Metadata             : {'tree': '

参数:

·         path 是镜像所挂载的目录

·         name 是导入到cobbler里面显示的名字

·         arch 是32位系统还是64位系统

2.导入kickstart文件

命令:cobbler profile add --name=list名 --distro=镜像 --kickstart=路径

参数:

·         name是表示添加的ks 的名字,用cobbler report可以看到这个名字

·         distro 是用哪个镜像,list的distros里面选择一个,需要版本相对应

·         kickstart 是具体的 ks 文件路径

3.同步DHCP、HTTPD

命令:cobbler sync

注,每次修改完dhcp.template之类的配置文件需要执行一次使其生效。

4.查看Cobbler列表

命令:cobbler list

注,列出Cobbler所有的元素。

5.删除相关列表

命令:cobbler distro/profile remove --name=要删除的引导文件名

·         删除指定 distro , 也就是镜像

·         删除指定的 profile 文件,也就是 ks

四、Cobbler 各种目录说明(注,这里只介绍重点的文件或目录 )

1.cobbler配置文件目录/etc/cobbler

[root@node2 cobbler]# ls /etc/cobbler/

auth.conf    cobblerd.service    dnsmasq.template    mongodb.conf  rsync.exclude    users.conf

cheetah_macros  cobbler_web.conf    import_rsync_whitelist named.template rsync.template   users.digest

cobbler_bash   completions       iso           power      secondary.template version

cobbler.conf   dhcp.template      ldap          pxe       settings      zone.template

cobblerd_rotate distro_signatures.json modules.conf      reporting    tftpd.template   zone_templates

·         /etc/cobbler/settings cobbler主配置文件

·         /etc/cobbler/iso/ iso模板配置文件

·         /etc/cobbler/pxe pxe模板文件

·         /etc/cobbler/power 电源的配置文件

·         /etc/cobbler/users.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模块配置文件

2.cobbler数据目录/var/lib/cobbler

1

2

3

4

5

6

7

[root@node2 cobbler]# ls /var/lib/cobbler/

config distro_signatures.json kickstarts loaders lock scripts snippets triggers web.ss

[root@node2 config]# ls

distros.d files.d images.d mgmtclasses.d packages.d profiles.d repos.d systems.d

[root@node2 loaders]# ls

COPYING.elilo   COPYING.yaboot grub-x86_64.efi menu.c32  README

COPYING.syslinux elilo-ia64.efi grub-x86.efi   pxelinux.0 yaboot

·         /var/lib/cobbler/config/ 用于存放distros、systems、profiles等信息配置文件

·         /var/lib/cobbler/triggers 用于存放用户定义的cobbler 命令

·         /var/lib/cobbler/kickstarts/ 默认存放kickstart文件

·         /var/lib/cobbler/loaders 存放的各种引导程序

3.镜像数据目录/var/www/cobbler

1

2

[root@node2 cobbler]# ls

aux images ks_mirror links localmirror pub rendered repo_mirror svc

·         /var/www/cobbler/ks_mirror/ 导入的发行版系统的所有数据

·         /var/www/cobbler/images/ 导入发行版的Kernel和initrd镜像用于远程网络启动

·         /var/www/cobbler/repo_mirror/ yum仓库存储目录

4.日志目录 /var/log/cobbler/

1

2

3

4

5

[root@node2 cobbler]# ls

anamon cobbler.log install.log kicklog syslog tasks

[root@node2 cobbler]# cat install.log

profile  CentOS-5.5-x86_64  192.168.18.222  start  1384219313.49

profile  CentOS-5.5-x86_64  192.168.18.222  stop  1384219512.05

·         /var/log/cobbler/install.log 客户端的安装系统日志

·         /var/log/cobbler/cobbler.log cobbler日志

下面我们来具体看一下sample.ks的内容。

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

[root@node2 ~]# cat /var/lib/cobbler/kickstarts/sample.ks

#platform=x86, AMD64, or Intel EM64T

# System authorization information

auth --useshadow --enablemd5 #用户登录认证

# System bootloader configuration

bootloader --location=mbr #mbr引导

# Partition clearing information

clearpart --all --initlabel #默认清除所以分区

# Use text mode install

text #默认以文本模式安装

# Firewall configuration

firewall --enabled #防火墙默认开启

# Run the Setup Agent on first boot

firstboot --disable #禁用启动代理

# 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 #默认的yum仓库

# Network information

$SNIPPET('network_config')

# Reboot after installation

reboot #安装完成后重启

#Root password

rootpw --iscrypted $default_password_crypted #密码是我们/etc/cobbler/settings设置密码

# SELinux configuration

selinux --disabled #默认关闭selinux

# Do not configure the X Window System

skipx #默认没有安装图形界面

# System timezone

timezone America/New_York #默认时区是美国/纽约

# Install OS instead of upgrade

install #定义的是安装系统而不是升级系统

# Clear the Master Boot Record

zerombr #默认清空所有的mbr

# Allow anaconda to partition the system as needed

autopart #默认自动分区

#下面就是Cobbler自定执行的一些脚本,我就不解释了。

%pre

$SNIPPET('log_ks_pre')

$SNIPPET('kickstart_start')

$SNIPPET('pre_install_network_config')

# Enable installation monitoring

$SNIPPET('pre_anamon')

%packages

$SNIPPET('func_install_if_enabled')

$SNIPPET('puppet_install_if_enabled')

%post

$SNIPPET('log_ks_post')

# Start yum configuration

$yum_config_stanza

# End yum configuration

$SNIPPET('post_install_kernel_options')

$SNIPPET('post_install_network_config')

$SNIPPET('func_register_if_enabled')

$SNIPPET('puppet_register_if_enabled')

$SNIPPET('download_config_files')

$SNIPPET('koan_environment')

$SNIPPET('redhat_register')

$SNIPPET('cobbler_register')

# Enable post-install boot notification

$SNIPPET('post_anamon')

# Start final steps

$SNIPPET('kickstart_done')

# End final steps

7、 RPM 仓库管理 (根据需要自己决定吧)

相关阅读:、设置 profile 和 system (这个功能比较牛 P。需要深入研究哈)

profile可以理解为按角色进行分类。

cobbler profile add --name=webserver --distro=CentOS-5-i386 --repos=EPEL-5-i386 --kickstart=/var/lib/cobbler/kickstarts/webserver.ks

system是对待安装机器做具体设置,如设置主机名、 IP 地址、 hostname 等,这些设置根据 MAC 应用到具体机器上。

# cobbler system add --name=webserver1 --ip=192.168.0.110 --mac=00:0C:29:77:89:c7 --profile=webserver --kickstart=/var/lib/cobbler/kickstarts/webserver.ks --static=1

# cobbler system edit --name=webserver1 --dns-name=webserver1.grid.house.sina.com.cn --hostname=webserver1.grid.house.sina.com.cn

cobbler system edit --name=webserver1 --gateway=192.168.0.1 --subnet=255.255.255.0

cobbler system edit --name=webserver1 --interface=eth1 --static=0

可以通过访问、 Cobbler 命令说明

cobbler check - 核对当前设置是否有问题

cobbler list - 列出所有的 cobbler 元素

cobbler report - 详细的列出个元素

cobbler sync - 同步配置到 dhcp/pxe 和数据目录

cobbler reposync - 同步 yum 仓库

13、 Cobbler 配置文件说明

Cobbler配置文件存放在 /etc/cobbler 下。 /etc/cobbler/settings 为主配置文件;在 /etc/cobbler 下你还能看到 dhcp 、 dns 、 pxe 、 dnsmasq 的模板配置文件; /etc/cobbler/users.digest 为用于 web 访问的用户名密码配置文件; /etc/cobbler/modules.conf  为模块配置文件;/etc/cobbler/users.conf 为 Cobbler WebUI/Web service 授权配置文件。

Repo数据目录 /var/www/cobbler

导入的发行版,repos 镜像和 kickstart 文件都放置在 /var/www/cobbler 目录下。确保 /var 目录有足够的空间来存储这些文件。

images/ - 存储所有导入发行版的 Kernel 和 initrd 镜像用于远程网络启动

ks_mirror/ - 存储导入的发行版

repo_mirror/ - yum repos存储目录

/var/log/cobbler用于存放日志文件 /var/log/cobbler/cobbler.log

Cobbler数据目录 /var/lib/cobbler ,此目录存储和 Cobbler profiles 、 systems 、 distros 相关的配置。

configs/ - 此目录用于存储 distros 、 repos 、 systems 和 profiles 相关信息

backup/ - 备份目录

snippets/  - 用于放置一些可以在 kickstarts 导入的脚本小片段

triggers/  - 此目录用来放置一些可执行脚本

kickstarts/  - 此目录用来放置 kickstart 模板文件

与Puppet 整合进行配置管理: 这个功能后续在研究吧。先写到这里。感谢你的支持。

一个ks.cfg

1.    # Kickstart file automatically generated by anaconda.

2.    #Install OS instead of upgrade

3.    install

4.    #Use text mode install

5.    text

6.    #Use CDROM installation media

7.    cdrom

8.    lang en_US.UTF-8

9.    keyboard us

10.

11. #Skip the X Configuration

12. skipx

13. #Use network installation

14. url --url=http://192.168.9.230/cobbler/ks_mirror/kerryOS-1.0-i386

15. #Network information

16. #network --device eth0 --bootproto static --ip 192.168.9.226 --netmask 255.255.255.0 --gateway 192.168.9.1 --nameserver 192.168.9.1 --noipv6 --onboot=yes --hostname kerry-web-001

17. network --device eth0 --bootproto dhcp --noipv6 --hostname kerry-web-001

18. #root -- 1q2w3e

19. rootpw --iscrypted $1$n07CbCot$GP.VBeICPHj.QkJb5Y2C2.

20. firewall --disabled

21. #System authorization information

22. authconfig --enableshadow --enablemd5

23. selinux --disabled

24. timezone --utc Asia/Shanghai

25. #System bootloader configuration

26. bootloader --location=mbr

27. #Clear the Master Boot Record

28. zerombr yes

29.

30. # Set the Mouse

31. mouse generic3ps/2

32.

33. # The following is the partition information you requested

34. # Note that any partitions you deleted are not expressed

35. # here so unless you clear all partitions first, this is

36. # not guaranteed to work

37.

38. #Partition clearing information

39. clearpart --all --initlabel

40. part /boot --fstype ext3 --size=200 --asprimary

41. part / --fstype ext3 --size=10000

42. part swap --size=2048

43. part /data --fstype ext3 --size=1 --grow

44.

45. #--- Reboot the host after installation is done

46. reboot

47.

48. %packages

49. %packages

50. @base

51. @core

52. @development-libs

53. @development-tools

54. @editors

55. @text-internet

56. keyutils

57. trousers

58. fipscheck

59. device-mapper-multipath

60. imake

61.

62. %post --nochroot

63. # Mount CDROM

64. mkdir -p /mnt/cdrom

65. mount -r -t iso9660 /tmp/cdrom /mnt/cdrom

66. cp /mnt/cdrom/ipmod /mnt/sysimage/root/ipmod > /dev/null

67.

68. umount /mnt/cdrom

69.

70. %post

71. #vim syntax on

72. sed -i "8 s/^/alias vi='vim'/" /root/.bashrc 2>/dev/null

73. echo 'syntax on' > /root/.vimrc 2>/dev/null

74.

75. #init_ssh

76. ssh_cf="/etc/ssh/sshd_config"

77. sed -i -e '74 s/^/#/' -i -e '76 s/^/#/' $ssh_cf

78.         sed -i "s/#UseDNS yes/UseDNS no/" $ssh_cf

79.

80. #client

81. sed -i -e '44 s/^/#/' -i -e '48 s/^/#/' $ssh_cf

82.

83. # Remove the ISO File translation files

84. find / -name TRANS.TBL -exec rm {} \; /dev/null 2>/dev/null

85.

86. # Remove some unneeded services

87. #--------------------------------------------------------------------------------

88. cat << EOF

89. +--------------------------------------------------------------+

90. | === Welcome to Tunoff services === |

91. +--------------------------------------------------------------+

92. EOF

93. #---------------------------------------------------------------------------------

94. for i in `ls /etc/rc3.d/S*`

95. do

96.     CURSRV=`echo $i|cut -c 15-`

97. echo $CURSRV

98. case $CURSRV in

99.         crond | irqbalance | microcode_ctl | network | random | sshd | syslog | local )

100.                  echo "Base services, Skip!"

101.                  ;;

102.                  *)

103.                      echo "change $CURSRV to off"

104.                      chkconfig --level 235 $CURSRV off

105.                      service $CURSRV stop

106.                  ;;

107.              esac

108.              done

109.

110.              # file descriptors

111.              ulimit -HSn 65535

112.

113.              echo -ne "

114.              * soft nofile 65536

115.              * hard nofile 65536

116.              " >>/etc/security/limits.conf

117.

118.              #set sysctl

119.              true > /etc/sysctl.conf

120.              cat >> /etc/sysctl.conf << EOF

121.              net.ipv4.ip_forward = 0

  1. net.ipv4.conf.default.rp_filter = 1

123.              net.ipv4.conf.default.accept_source_route = 0

124.              kernel.sysrq = 0

125.              kernel.core_uses_pid = 1

126.              net.ipv4.tcp_syncookies = 1

127.              kernel.msgmnb = 65536

128.              kernel.msgmax = 65536

129.              kernel.shmmax = 68719476736

130.              kernel.shmall = 4294967296

131.              net.ipv4.tcp_max_tw_buckets = 6000

132.              net.ipv4.tcp_sack = 1

133.              net.ipv4.tcp_window_scaling = 1

134.              net.ipv4.tcp_rmem = 4096 87380 4194304

135.              net.ipv4.tcp_wmem = 4096 16384 4194304

136.              net.core.wmem_default = 8388608

137.              net.core.rmem_default = 8388608

138.              net.core.rmem_max = 16777216

139.              net.core.wmem_max = 16777216

140.              net.core.netdev_max_backlog = 262144

141.              net.core.somaxconn = 262144

142.              net.ipv4.tcp_max_orphans = 3276800

143.              net.ipv4.tcp_max_syn_backlog = 262144

144.              net.ipv4.tcp_timestamps = 0

145.              net.ipv4.tcp_synack_retries = 1

146.              net.ipv4.tcp_syn_retries = 1

147.              net.ipv4.tcp_tw_recycle = 1

148.              net.ipv4.tcp_tw_reuse = 1

149.              net.ipv4.tcp_mem = 94500000 915000000 927000000

150.              net.ipv4.tcp_fin_timeout = 1

151.              net.ipv4.tcp_keepalive_time = 1200

152.              net.ipv4.ip_local_port_range = 1024 65535

153.              EOF

154.

155.              /sbin/sysctl -p

156.

157.              #close ctrl+alt+del

158.              sed -i "s/ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/#ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/" /etc/inittab

159.

160.              #set purview

161.              chmod 600 /etc/passwd

162.              chmod 600 /etc/shadow

163.              chmod 600 /etc/group

164.              chmod 600 /etc/gshadow