首页 > 代码库 > CentOS6.9上安装cobbler2.6实现自动化安装Linux系统
CentOS6.9上安装cobbler2.6实现自动化安装Linux系统
CentOS6.9上安装cobbler2.6实现自动化安装Linux系统
cobbler可以批量部署Linux系统,并实现无人值守安装。
cobbler依赖的服务:dhcp,tftp,http,pxe,kickstart
服务对应的端口号为dhcp--67,68;tftp--69;http--80;cobbler--25151
1.环境准备:最小化安装centos6.9mini,配置固定IP和本地yum源,关闭防火墙和selinux
iptables -F
setenforce 0
chkconfig iptables off
vi /etc/selinux/config 更改为permissive
2.设置yum源和epel源
这里使用本地光盘作为yum源,也可以使用阿里源,如下
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
cobbler安装需要使用epel源,这里使用阿里的epel源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
3.安装对应上述服务的软件包
yum install -y cobbler cobbler-web pykickstart httpd dhcp tftp-server syslinux
cobbler #cobbler程序包
cobbler-web #cobbler的web服务包
pykickstart #cobbler检查kickstart语法错误
httpd #Apache web服务
dhcp #dhcp服务
tftp-server #tftp服务
syslinux#pxe相关文件,如pxelinux.0
4.编辑cobbler的配置文件
vi /etc/cobbler/settings 更改如下参数:
default_kickstart: /var/lib/cobbler/kickstarts/default.ks
default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac."
manage_dhcp: 1
manage_tftpd: 1
next_server: 192.168.10.24
server: 192.168.10.24
更改default_password默认密码,即设置root密码,格式为$1即md5加密,可以通过OpenSSL命令生成,如下:
openssl passwd -1 –salt centos
输入密码,如redhat
5.cobbler配置检查,根据说明逐步更改设置,设置过的选项可以忽略
[root@c69 ~]# 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 : change ‘disable‘ to ‘no‘ in /etc/xinetd.d/rsync
7 : file /etc/xinetd.d/rsync does not exist
8 : since iptables may be running, ensure 69, 80/443, and 25151 are unblocked
9 : debmirror package is not installed, it will be required to manage debian deployments and repositories
10 : 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
11 : 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.
如果不安装Debian系统也可以忽略9.debmirror...错误;
由于网络问题无法通过cobbler get-loaders命令下载文件的话,可以直接复制本机的文件。(这一步也可以省略,使用cobbler sync命令会自动执行如下的复制操作)
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/
重启cobblerd服务并执行同步操作
service cobblerd restart
cobbler sync
提示错误:2.service dhcpd is not running
6.配置dhcp服务,更改cobbler自带的dhcp模板文件,更改subnet地址网段和地址范围
vi /etc/cobbler/dhcp.template
subnet 192.168.10.0 netmask 255.255.255.0 {
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.10.100 192.168.10.254;
再次重启cobbler服务并执行sync同步操作,cobbler会自动同步dhcp配置
重启dhcpd服务,启动xinetd服务
service dhcpd restart
service xinetd start
7.设置服务开机启动
cobbler默认已设置开机启动,需设置httpd和dhcpd服务开机启动
chkconfig dhcpd on
chkconfig httpd on
检查所有服务是否正常启动,端口67,69,80,25151
netstat -tuanlp
或ss -tunlp
8.导入安装文件
导入安装光盘文件,因为要完全复制光盘文件,需要等待一段时间
cobbler import --path=/mnt/cdrom --name=centos6.9mini --arch=x86_64
ll /var/www/cobbler/ks_mirror/centos6.9mini-x86_64
更换光盘,导入centos6.9的安装光盘文件
cobbler import --path=/mnt/cdrom --name=centos7.3mini --arch=x86_64
ll /var/www/cobbler/ks_mirror/centos7.3mini-x86_64
导入成功后查询名称
cobbler list
distros:
centos6.9mini-x86_64
centos7.3mini-x86_64
profiles:
centos6.9mini-x86_64
centos7.3mini-x86_64
查看详细信息
cobbler distro report --name centos6.9mini-x86_64
cobbler profile report --name centos6.9mini-x86_64
导入成功后cobbler会自动生成ks文件和menu启动菜单文件,默认最小化安装系统。
/var/lib/cobbler/kickstarts/sample_end.ks
/var/lib/tftpboot/pxelinux.cfg/default
如果导入的是mini安装光盘,则需要更改ks文件一个参数,即%packages后边添加--nobase
vi /var/lib/cobbler/kickstarts/sample_end.ks
%packages --nobase
9.添加自定义的ks配置文件
更改自己的ks配置文件参数,更改url --url=$tree
增加配置文件,即启动菜单项,并指定自定义的ks文件
cobbler profile add --name=centos6.9-custom --kickstart=/var/lib/cobbler/kickstarts/ks-69mini.ks --distro=centos6.9mini-x86_64
查看新增菜单项
cobbler profile list
centos6.9-custom
centos6.9mini-x86_64
centos7.3mini-x86_64
删除启动菜单项
cobbler profile remove --name=centos7.3-x86_64
至此所有cobbler配置已完成,可以新建一个虚拟机测试网络无人值守安装Linux系统。
本文出自 “rackie” 博客,请务必保留此出处http://rackie386.blog.51cto.com/11279229/1950307
CentOS6.9上安装cobbler2.6实现自动化安装Linux系统