设为首页 收藏本站
查看: 1029|回复: 0

[经验分享] 详解如何在Centos6和Centos7两个版本上,执行Cobbler无人值守安装!

[复制链接]

尚未签到

发表于 2019-2-16 08:24:42 | 显示全部楼层 |阅读模式
Cobbler介绍:
  Cobbler是一个Linux服务器快速网络安装的服务,而且在经过调整也可以支持网络安装windows。
该工具使用python开发,小巧轻便(才15k行python代码),可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS,TFTP、RSYNC以及yum仓库、构造系统ISO镜像。
Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。
Cobbler客户端Koan支持虚拟机安装和操作系统重新安装,使重装系统更便捷。

Cobbler可以干啥:
  使用Cobbler,您无需进行人工干预即可安装机器。Cobbler设置一个PXE引导环境(它还可以使用yaboot支持PowerPC),并 控制与安装相关的所有方面,比如网络引导服务(DHCP和TFTP)与存储库镜像。当希望安装一台新机器时,Cobbler可以:
1)使用一个以前定义的模板来配置DHCP服务(如果启用了管理DHCP)
2)将一个存储库(yum或rsync)建立镜像或解压缩一个媒介,以注册一个新操作系统
3)在DHCP配置文件中为需要安装的机器创建一个条目,并使用指定的参数(IP和MAC)
4)在TFTP服务目录下创建适当的PXE文件
5)重新启动DHCP服务来反应新的更改
6)重新启动机器以开始安装(如果电源管理已启动)

Cobbler支持的系统和功能:
  Cobbler支持众多的发行版:RedHat、Fedora、CentOS、Debian、Ubuntu和SUSE。当添加一个操作系统(通常通过使用ISO文件)时,Cobbler知道如何解压缩合适的文件并调整网络服务,以正确引导机器。
  Cobbler可以使用kickstart模板。基于Red Hat或 Fedora的系统使用kickstart文件来自动化安装流程。通过使用模板,就会拥有基本的kickstart模板,然后定义如何针对一种配置文件或 机器配置而替换其中的变量。
  例如,一个模板可能包含两个变量$domain和$machine_name.在Cobbler配置中,一个配置文件指定 domain=mydomain.com,并且每台使用该配置文件的机器在machine_name变量中指定其名称。该配置文件的所有机器都使用相同的 kickstart安装且针对domain=mydomain.com进行配置,但每台机器拥有其自己的机器名称。您仍然可以使用kickstart模板 在不同的域中安装其他机器并使用不同的机器名称。
  为了协助管理系统,Cobbler可通过fence scripts连接到各个电源管理环境。Cobbler支持apc_snmp、bladecenter、bullpap、drac、 ether_wake、ilo、integrity、ipmilan、ipmitool、lpar、rsa、virsh和wti。要重新安装一台机器,可 运行reboot system foo命令,而且Cobbler会使用必要的 和信息来为您运行恰当的fence scripts(比如机器插槽数)。
  除了这些特性,还可以使用一个配置管理系统(CMS)。你有两种选择:该工具内的一个内部系统,或者现成的外部CMS,比如Chef或 Puppet。借助内部系统,你可以指定文件模板,这些模板会依据配置参数进行处理(与kickstart模板的处理方式一样),然后复制到你指定的位 置。如果必须自动将配置文件部署到特定机器,那么此功能很有用
使用koan客户端,Cobbler可从客户端配置虚拟机并重新安装系统。
  主要目的配置网络接口:
Cobbler的配置结构基于一组注册的对象。每个对象表示一个与另一个实体相关联的实体(该对象指向另一个对象,或者另一个对象指向该对象)。当一个对象指向另一个对象时,它就继承了被指向对象的数据,并可覆盖或添加更多特定信息。以下对象类型的定义
Distros(发行版):表示一个操作系统,它承载了内核和initrd的信息,以及内核参数等其他数据
Profile(配置文件):包含一个发行版、一个kickstart文件以及可能的存储库,还包含更多特定的内核参数等其他数据
Systems(系统):表示要配给的额机器。它包含一个配置文件或一个景象,还包含IP和MAC地址、电源管理(地址、凭据、类型)、(网卡绑定、设置valn等)
Repository(镜像):保存一个yum或rsync存储库的镜像信息
Image(存储库):可替换一个包含不属于此类比的额文件的发行版对象(例如,无法分为内核和initrd的对象)。
基于注册的对象以及各个对象之间的关联,Cobbler知道如何更改文件系统以反应具体配置。因为系统配置的内部是抽象的,所以您可以仅关注想要执行的操作。

1、基础环境准备
  centos6系列:

[root@cobbler ~]# cat /etc/redhat-release    #系统版本               
CentOS release 6.5 (Final)
[root@cobbler ~]# uname -r    #内核版本
2.6.32-431.el6.x86_64
[root@cobbler ~]# getenforce    #检测selinux是否关闭(必须关闭)                          
Disabled
[root@cobbler ~]# /etc/init.d/iptables status    #检测防火墙是否关闭(必须关闭)
iptables: Firewall is not running.
[root@cobbler ~]# ifconfig eth0|awk -F '[ :]+' 'NR==2 {print $4}'    #查看IP地址
10.0.0.71
[root@cobbler ~]# hostname    #查看主机名
cobbler
[root@cobbler ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
--2016-05-23 21:10:51--  http://mirrors.aliyun.com/repo/epel-6.repo
Resolving mirrors.aliyun.com... 115.28.122.210, 112.124.140.210
Connecting to mirrors.aliyun.com|115.28.122.210|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1083 (1.1K) [application/octet-stream]
Saving to: “/etc/yum.repos.d/epel.repo”    #cobbler安装必须使用到epel源
100%[====================================================================================>] 1,083       --.-K/s   in 0s
  centos7系列:

[root@cobbler02 ~]# cat /etc/redhat-release     #系统版本
CentOS Linux release 7.2.1511 (Core)
[root@cobbler02 ~]# uname -r                #内核版本
3.10.0-327.18.2.el7.x86_64
[root@cobbler02 ~]# getenforce              #检测selinux是否关闭(必须关闭)
Disabled
[root@cobbler02 ~]# systemctl status firewalld    #检测防火墙是否关闭(必须关闭)
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
[root@cobbler02 ~]# ifconfig eth0|awk -F '[ :]+' 'NR==2{print $3}'
192.168.31.73
[root@cobbler02 ~]# hostname
cobbler02  
[root@cobbler02 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
--2016-05-30 07:55:52--  http://mirrors.aliyun.com/repo/epel-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 112.124.140.210, 115.28.122.210
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|112.124.140.210|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1084 (1.1K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/epel.repo’
100%[===============================================================================================>] 1,084       --.-K/s   in 0s      
2016-05-30 07:55:52 (270 MB/s) - ‘/etc/yum.repos.d/epel.repo’ saved [1084/1084]
  注意:
虚拟机网卡采用桥接模式,不使用NAT模式,我们会搭建DHCP服务器,在同一局域网多个DHCP服务会有冲突,所以最好把路由器的DHCP服务关闭t_0015.gif我搭建服务只喜欢用桥接模式

2.安装Cobbler
  centos6系列:

[root@cobbler ~]# yum install cobbler cobbler-web pykickstart httpd dhcp tftp-server-y
cobbler            #cobbler程序包
cobbler-web        #cobbler的web服务包
pykickstart        #cobbler检查kickstart语法错误
httpd              #Apache web服务
dhcp               #dhcp服务
tftp-server        #tftp服务
[root@cobbler ~]# rpm -ql cobbler  # 查看安装的文件,下面列出部分。
/etc/cobbler                  # 配置文件目录
/etc/cobbler/settings         # cobbler主配置文件,这个文件是yaml格式,cobbler是python写的程序。
/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日志
  centos7系列:

[root@cobbler02 ~]# yum install cobbler cobbler-web pykickstart httpd dhcp tftp-server -y
cobbler            #cobbler程序包
cobbler-web        #cobbler的web服务包
pykickstart        #cobbler检查kickstart语法错误
httpd              #Apache web服务
dhcp               #dhcp服务
tftp-server        #tftp服务
3. 检测Cobbler
  cobbler的运行依赖于dhcp、tftp、rsync及dns服务,其中dhcp可由dhcpd(isc)提供,也可由dnsmasq提供;tftp可由tftp-server程序包提供,也可由cobbler功能提供,rsync有rsync程序包提供,dns可由bind提供,也可由dnsmasq提供
  cobbler可自行管理这些服务中的部分甚至是全部,但需要配置文件/etc/cobbler/settings中的“manange_dhcp”、“manager_tftpd”、“manager_rsync”、“manager_dns”分别来进行定义,另外,由于各种服务都有着不同的实现方式,如若需要进行自定义,需要通过修改/etc/cobbler/modules.conf配置文件中各服务的模块参数的值来实现。
  centos6系列:

[root@cobbler cobbler]# /etc/init.d/httpd restart    #启动apache服务
Stopping httpd:                                            [  OK  ]
Starting httpd: httpd: apr_sockaddr_info_get() failed for cobbler
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
#遇见报错需要修改apache的配置文件,添加一行
[root@cobbler cobbler]# vim /etc/httpd/conf/httpd.conf  
ServerName localhost:80  
#再重启服务发现没有报错了
[root@cobbler cobbler]# /etc/init.d/httpd restart      
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]                                                        [  OK  ]
[root@cobbler cobbler]# /etc/init.d/cobblerd restart    #启动cobbler服务
Stopping cobbler daemon:                                   [  OK  ]
Starting cobbler daemon:
  centos7系列:

[root@cobbler02 ~]# systemctl start httpd
[root@cobbler02 ~]# systemctl status httpd    #查看httpd的状态,看有没有起来
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2016-05-30 08:06:08 CST; 9s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 2317 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
CGroup: /system.slice/httpd.service
├─2317 /usr/sbin/httpd -DFOREGROUND
├─2318 (wsgi:cobbler_w -DFOREGROUND
├─2319 /usr/sbin/httpd -DFOREGROUND
├─2320 /usr/sbin/httpd -DFOREGROUND
├─2321 /usr/sbin/httpd -DFOREGROUND
├─2322 /usr/sbin/httpd -DFOREGROUND
└─2323 /usr/sbin/httpd -DFOREGROUND
May 30 08:06:08 cobbler02 systemd[1]: Starting The Apache HTTP Server...
May 30 08:06:08 cobbler02 httpd[2317]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, u...message
May 30 08:06:08 cobbler02 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@cobbler02 ~]# systemctl status cobblerd    #查看cobblerd的状态,看有没有起来
● cobblerd.service - Cobbler Helper Daemon
Loaded: loaded (/usr/lib/systemd/system/cobblerd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
[root@cobbler02 ~]# systemctl start cobblerd #开启cobblerd服务
[root@cobbler02 ~]# systemctl status cobblerd    #再检查一下,发现确实起来了
● cobblerd.service - Cobbler Helper Daemon
Loaded: loaded (/usr/lib/systemd/system/cobblerd.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2016-05-30 08:06:39 CST; 1s ago
Process: 2349 ExecStartPost=/usr/bin/touch /usr/share/cobbler/web/cobbler.wsgi (code=exited, status=0/SUCCESS)
Main PID: 2348 (cobblerd)
CGroup: /system.slice/cobblerd.service
└─2348 /usr/bin/python2 /usr/bin/cobblerd -F
May 30 08:06:39 cobbler02 systemd[1]: Starting Cobbler Helper Daemon...
May 30 08:06:39 cobbler02 systemd[1]: Started Cobbler Helper Daemon.
4、检查配置文件,需要在cobblerd和httpd启动的情况下检查
  centos6系列:

[root@cobbler cobbler]# cobbler check    #检查cobbler配置存在的问题,逐一解决
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 : change 'disable' to 'no' in /etc/xinetd.d/rsync
6 : file /etc/xinetd.d/rsync does not exist
7 : debmirror package is not installed, it will be required to manage debian deployments and repositories
8 : 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
9 : 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参数的值为提供cobbler服务的主机相应的IP地址或主机名

如server: 192.168.31.71;
#备份原文件
[root@cobbler cobbler]# cp /etc/cobbler/settings{,.ori}
# server,Cobbler服务器的IP,修改384行server: 127.0.0.1
[root@cobbler cobbler]# sed -i 's/server: 127.0.0.1/server: 192.168.31.71/' /etc/cobbler/settings
  2、修改/etc/cobbler/settings文件中的next_server参数的值为提供PXE服务的主机相应的IP地址

如next_server: 192.168.31.71;
# server,pxe服务器的IP,由于这里使用的是同一台机器,所以填Cobbler服务器的IP,修改272行next_server: 127.0.0.1
[root@cobbler cobbler]# sed -i 's/next_server: 127.0.0.1/next_server: 192.168.31.71/' /etc/cobbler/settings
#由于sed的匹配规则的原因,上一步就已经把这里给修改了,检查下
[root@cobbler cobbler]# grep "server: 192.168.31.71" settings
next_server: 192.168.31.71
server: 192.168.31.71
  3、修改/etc/xinetd.d/tftp文件中的disable参数修改为 disable = no

#备份原文件
[root@cobbler cobbler]# cp /etc/xinetd.d/tftp{,.ori}
#修改替换
[root@cobbler cobbler]# sed -i 's/disable.*= yes/disable                 = no/g' /etc/xinetd.d/tftp
  4、执行 cobbler get-loaders 命令即可;否则,需要安装syslinux程序包,而后复制/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至/var/lib/cobbler/loaders/目录中

[root@cobbler cobbler]# cobbler get-loaders
task started: 2016-05-23_230908_get_loaders
task started (id=Download Bootloader Content, time=Mon May 23 23:09:08 2016)
downloading http://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading http://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading http://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading http://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading http://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading http://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
downloading http://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading http://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading http://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading http://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
  5、修改rsync配置文件

[root@cobbler xinetd.d]# sed -i s/"disable.*= yes"/"disable         = no"/g /etc/xinetd.d/rsync
[root@cobbler xinetd.d]# cat /etc/xinetd.d/rsync
# default: off
# description: The rsync server is a good addition to an ftp server, as it \
#       allows crc checksumming etc.
service rsync
{
disable         = no
flags           = IPv6
socket_type     = stream
wait            = no
user            = root
server          = /usr/bin/rsync
server_args     = --daemon
log_on_failure  += USERID
}
  6、安装debmirror

[root@cobbler cobbler]# yum install -y  debmirror
#安装后再check下会报如下错误
3 : comment out 'dists' on /etc/debmirror.conf for proper debian support4 : comment out 'arches' on /etc/debmirror.conf for proper debian support
#修改配置文件来征服报错,其实不碍事,但是报错有碍眼睛,遂除之
[root@cobbler cobbler]# vim /etc/debmirror.conf
28 #@dists="sid"; 30 #@arches="i386";
注释掉这两行,重新check后没有报错了
  7、生成密码来取代默认的密码,更安全

#try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one
#根据提示your-password-here,这里是自己的密码,random-phrase-here,这里是随机的干扰码
[root@cobbler cobbler]# openssl passwd -1 -salt 'renjunjie' '123456'
$1$renjunji$G7LpR5255qFguHrw7E0KP/
[root@cobbler cobbler]# sed -i s/'default_password_crypted:.*'/'default_password_crypted: "$1$renjunji$G7LpR5255qFguHrw7E0KP\/"'/g /etc/cobbler/settings
[root@cobbler cobbler]# grep -n default_pass /etc/cobbler/settings
101:default_password_crypted: "$1$renjunji$G7LpR5255qFguHrw7E0KP/"
  8、安装cman fence-agents

[root@cobbler cobbler]# yum install -y cman ence-agents
  9、其他一些没有提示报错的小修改

# 用cobbler管理DHCP,修改242行manage_dhcp: 0
[root@cobbler cobbler]# sed -i 's/manage_dhcp: 0/manage_dhcp: 1/g' /etc/cobbler/settings
# 防止循环装系统,适用于服务器第一启动项是PXE启动,修改292行pxe_just_once: 0
[root@cobbler cobbler]# sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings
  修改完后重启服务再进行一次检测,发现剩下这两个报错,请往下走

[root@cobbler cobbler]# /etc/init.d/httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@cobbler cobbler]# /etc/init.d/xinetd restart
Stopping xinetd:                                           [  OK  ]
Starting xinetd:                                           [  OK  ]
[root@cobbler cobbler]# /etc/init.d/cobblerd restart
Stopping cobbler daemon:                                   [  OK  ]
Starting cobbler daemon:                                   [  OK  ]
[root@cobbler cobbler]# check
checkmodule  checkpolicy  
[root@cobbler cobbler]# cobbler check
The following are potential configuration items that you may want to fix:
1 : service dhcpd is not running
2 : file /etc/xinetd.d/rsync does not exist
Restart cobblerd and then run 'cobbler sync' to apply changes.
  centos7系列:

[root@cobbler02 ~]# cobbler check    #检查cobbler配置存在的问题,逐一解决
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、修改/etc/cobbler/settings文件中的server参数的值为提供cobbler服务的主机相应的IP地址或主机名

如server: 192.168.31.73;
#备份原文件
[root@cobbler02 ~]# cp /etc/cobbler/settings{,.ori}
# server,Cobbler服务器的IP,修改384行server: 127.0.0.1
[root@cobbler02 ~]# sed -i 's/server: 127.0.0.1/server: 192.168.31.73/' /etc/cobbler/settings
  2、修改/etc/cobbler/settings文件中的next_server参数的值为提供PXE服务的主机相应的IP地址

如next_server: 192.168.31.73;
# server,pxe服务器的IP,由于这里使用的是同一台机器,所以填Cobbler服务器的IP,修改272行next_server: 127.0.0.1
[root@cobbler02 ~]# sed -i 's/next_server: 127.0.0.1/next_server: 192.168.31.73/' /etc/cobbler/settings
#由于sed的匹配规则的原因,上一步就已经把这里给修改了,检查下
[root@cobbler02 ~]# grep "server: 192.168.31.73" settings
next_server: 192.168.31.713
server: 192.168.31.73
  3、修改/etc/xinetd.d/tftp文件中的disable参数修改为 disable = no

#备份原文件
[root@cobbler02 ~]# cp /etc/xinetd.d/tftp{,.ori}
#修改替换
[root@cobbler02 ~r]# sed -i 's/disable.*= yes/disable                 = no/g' /etc/xinetd.d/tftp
  4、执行 cobbler get-loaders 命令即可;否则,需要安装syslinux程序包,而后复制/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至/var/lib/cobbler/loaders/目录中

[root@cobbler02 ~]# cobbler get-loaders
task started: 2016-05-30_082337_get_loaders
task started (id=Download Bootloader Content, time=Mon May 30 08:23:37 2016)
downloading http://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading http://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading http://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading http://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading http://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading http://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
downloading http://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading http://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading http://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading http://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***
  5、启动rsyncd服务

[root@cobbler02 ~]# systemctl status rsyncd    #检查rsyncd服务的状态,发现是关闭的
● rsyncd.service - fast remote file copy program daemon
Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
[root@cobbler02 ~]# systemctl enable rsyncd    #开启rsync的服务开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
[root@cobbler02 ~]# systemctl status rsyncd    #检查rsyncd服务的状态
● rsyncd.service - fast remote file copy program daemon
Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; vendor preset: disabled)
Active: inactive (dead)
[root@cobbler02 ~]# systemctl start rsyncd     #开启rsync的服务
[root@cobbler02 ~]# systemctl status rsyncd    #再次检查rsyncd服务的状态
● rsyncd.service - fast remote file copy program daemon
Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2016-05-30 08:27:12 CST; 3s ago
Main PID: 2455 (rsync)
CGroup: /system.slice/rsyncd.service
└─2455 /usr/bin/rsync --daemon --no-detach
May 30 08:27:12 cobbler02 systemd[1]: Started fast remote file copy program daemon.
May 30 08:27:12 cobbler02 systemd[1]: Starting fast remote file copy program daemon...
May 30 08:27:12 cobbler02 rsyncd[2455]: rsyncd version 3.0.9 starting, listening on port 873
  6、安装debmirror

[root@cobbler02 ~]# yum install debmirror
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
No package debmirror available.
Error: Nothing to do
#这个是提供给debian的管理用的,centos7我没有这个包
  7、生成密码来取代默认的密码,更安全

#try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one
#根据提示your-password-here,这里是自己的密码,random-phrase-here,这里是随机的干扰码
[root@cobbler02 ~]# openssl passwd -1 -salt 'renjunjie' '123456'
$1$renjunji$G7LpR5255qFguHrw7E0KP/
[root@cobbler02 ~]# sed -i s/'default_password_crypted:.*'/'default_password_crypted: "$1$renjunji$G7LpR5255qFguHrw7E0KP\/"'/g /etc/cobbler/settings
[root@cobbler02 ~]# grep -n default_pass /etc/cobbler/settings
101:default_password_crypted: "$1$renjunji$G7LpR5255qFguHrw7E0KP/"
  8、安装cman fence-agents

[root@cobbler02 ~]# yum install -y cman fence-agents
  9、其他一些没有提示报错的小修改

# 用cobbler管理DHCP,修改242行manage_dhcp: 0
[root@cobbler02 ~]# sed -i 's/manage_dhcp: 0/manage_dhcp: 1/g' /etc/cobbler/settings
[root@cobbler02 ~]# grep -n manage_dhcp /etc/cobbler/settings
242:manage_dhcp: 1
269:# if using cobbler with manage_dhcp, put the IP address
355:# Note that if manage_dhcp and manage_dns are disabled, the respective
# 防止循环装系统,适用于服务器第一启动项是PXE启动,修改292行pxe_just_once: 0
[root@cobbler02 ~]# sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings
[root@cobbler02 ~]# grep -n pxe_just_once /etc/cobbler/settings
292:pxe_just_once: 1
[root@cobbler02 ~]#
#修改完后重启服务再进行一次检测,发现这个报错,请往下走
[root@cobbler02 ~]# systemctl restart cobblerd.service
[root@cobbler02 ~]# 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
Restart cobblerd and then run 'cobbler sync' to apply changes.
[root@cobbler02 ~]# yum install -y debmirror    #再次安装centos7就是没得,求适用于centos7的rpm包或者适用于centos7的编译源码包
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
No package debmirror available.
Error: Nothing to do
5、配置DHCP
  centos6系列:

# 修改cobbler的dhcp模版,这个模板会覆盖dhcp本身的配置文件。
[root@linux-node1 ~]# vim /etc/cobbler/dhcp.template
#添加如下
subnet 192.168.31.0 netmask 255.255.255.0 {  
option domain-name-servers 223.5.5.5;
option routers 192.168.31.1;     
range dynamic-bootp 192.168.31.100 192.168.31.250;
option subnet-mask 255.255.255.0;
next-server 192.168.31.71;
filename "/data/sys/kickstart/ks.cfg";
next-server 192.168.31.71;
filename "pxelinux.0";
}
#同步cobbler的配置,可以看到同步干了哪些事
[root@cobbler cobbler]# cobbler sync
task started: 2016-05-27_145749_sync
task started (id=Sync, time=Fri May 27 14:57:49 2016)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
cleaning link caches
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout:
received on stderr:
running: service dhcpd restart
received on stdout: Starting dhcpd: [  OK  ]
received on stderr:
running shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***
  重新检测下发现,只剩下这一个报错,实际上这个文件是有的,无视这个错误

[root@cobbler cobbler]# cobbler check
The following are potential configuration items that you may want to fix:
1 : file /etc/xinetd.d/rsync does not exist
Restart cobblerd and then run 'cobbler sync' to apply changes.
  centos7系列:

# 修改cobbler的dhcp模版,这个模板会覆盖dhcp本身的配置文件。
[root@cobbler02 ~]# vim /etc/cobbler/dhcp.template
#添加如下
subnet 192.168.31.0 netmask 255.255.255.0 {
option domain-name-servers 223.5.5.5;
option routers 192.168.31.1;
range dynamic-bootp 192.168.31.100 192.168.31.250;
option subnet-mask 255.255.255.0;
next-server $next_server;
default-lease-time 43200;
max-lease-time 86400;
}
#同步cobbler的配置,可以看到同步干了哪些事
[root@cobbler02 ~]# cobbler sync                  
task started: 2016-05-30_092640_sync
task started (id=Sync, time=Mon May 30 09:26:40 2016)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
cleaning link caches
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout:
received on stderr:
running: service dhcpd restart
received on stdout:
received on stderr: Redirecting to /bin/systemctl restart  dhcpd.service
running shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***
6、设置开机自启动
  centos6系列:
  方法1:全部写到rc.local

[root@cobbler cobbler]# echo "/etc/init.d/httpd restart" >>/etc/rc.local
[root@cobbler cobbler]# echo "/etc/init.d/xinetd restart" >>/etc/rc.local      
[root@cobbler cobbler]# echo "/etc/init.d/cobblerd restart" >>/etc/rc.local      
[root@cobbler cobbler]# echo "/etc/init.d/dhcpd restart" >>/etc/rc.local
  方法2:写一个专门的cobbler开机脚本

cat >>/etc/init.d/cobbler

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-672908-1-1.html 上篇帖子: Centos 7 minimal 安装ifconfig 下篇帖子: VMware虚拟机安装 CentOS 6.9
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表