首页 > 代码库 > Cobbler无人值守安装

Cobbler无人值守安装

COBBLER无人值守安装
Cobbler是独立的,不需要先安装Kickstart然后再安装Cobbler,这是写给不了解Kickstart的人看的。

建议大家在平常不用安装系统的时候一定要关闭cobbler主机

1.1 Cobbler介绍
Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。

Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。

Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。

Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。

 

1.2 Cobbler集成的服务
PXE服务支持
DHCP服务管理
DNS服务管理(可选bind,dnsmasq)
电源管理
Kickstart服务支持
YUM仓库管理
TFTP(PXE启动时需要)
Apache(提供kickstart的安装源,并提供定制化的kickstart配置)

 

1.3 系统环境准备

1、 使用VM创建一台虚拟机 当做cobbler服务器使用  内网IP为172.16.1.101

操作系统:

CentOS release 6.8 (Final)

默认分区并最小化安装 软件选包

@base
@compat-libraries
@debugging
@development
[root@cobbler ~]# cat /etc/redhat-release 

CentOS release 6.8 (Final)

[root@cobbler ~]# uname -r 

2.6.32-642.el6.x86_64

[root@cobbler ~]# getenforce

Disabled

[root@cobbler ~]# /etc/init.d/iptables status

iptables: Firewall is not running.
### 更改yum源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup &&
wget -O /etc/yum.repos.d/CentOS-Base.repo 
http://mirrors.aliyun.com/repo/Centos-6.repo
 

wget -O /etc/yum.repos.d/epel.repo

 

###注意

虚拟机网卡采用NAT模式,不要使用桥接模式,因为稍后我们会搭建DHCP服务器,在同一局域网多个DHCP服务会有冲突。

VMware的NAT模式的dhcp服务也关闭,避免干扰。

 

1.4 安装cobbler

[root@CentOS6 yum.repos.d]# yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd

技术分享

 

1.5 检查安装
[root@CentOS6 yum.repos.d]# 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 : 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.6解决报错问题

[root@CentOS6 yum.repos.d]#  cp /etc/cobbler/settings{,.ori}
sed -i ‘s/server: 127.0.0.1/server: 172.16.1.101/‘ /etc/cobbler/settings
sed -i ‘s/next_server: 127.0.0.1/next_server: 172.16.1.101/‘ /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 -ri "/default_password_crypted/s#(.*: ).*#\1\"`openssl passwd -1 -salt ‘oldboy‘ ‘123456‘`\"#" /etc/cobbler/settings
sed -i ‘s#yes#no#‘ /etc/xinetd.d/rsync
sed -i ‘s#yes#no#‘ /etc/xinetd.d/tftp

上传解压cobbler_load.tar.gz
[root@CentOS6 opt]#  tar xfP cobbler_load.tar.gz
启动xinetd
[root@CentOS6 opt]# /etc/init.d/xinetd start
修改dhcp.template
### 替换
vim /etc/cobbler/dhcp.template 
:%s/192.168.1/172.16.1/g 
 
### 删除
删除22和 23行
 
[root@CentOS6 opt]#  /etc/init.d/cobblerd restart
[root@CentOS6 opt]# cobbler sync
 
/etc/init.d/xinetd restart
 
/etc/init.d/cobblerd restart
 
/etc/init.d/httpd restart
 
[root@CentOS6 opt]# cobbler check
The following are potential configuration items that you may want to fix:
1 : file /etc/xinetd.d/rsync does not exist
2 : debmirror package is not installed, it will be required to manage debian deployments and repositories
3 : 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.
有问题的话 看看这个文件有没有内容 不行的话重启下服务
 vim /etc/dhcp/dhcpd.conf
/etc/init.d/cobblerd restart
页面访问:账号密码默认均为cobbler

 

配置篇:

上传镜像

[root@cobbler ~]# mount /dev/cdrom /mnt/
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@cobbler ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        19G  1.5G   16G   9% /
tmpfs           491M     0  491M   0% /dev/shm
/dev/sda1       190M   34M  147M  19% /boot
/dev/sr0        3.7G  3.7G     0 100% /mn

 

技术分享

如果不写路径 会把根/导入进去
可以通过Events事件中查看 正在导入

 

等待看不到rsync进程则导入完成
[root@CentOS6 CentOS-6.8-x86_64]# ps -ef|grep rsync
root       2782   1389  0 00:25 pts/0    00:00:00 grep rsync

 

创建kickstart文件

技术分享

# Cobbler for Kickstart Configurator for CentOS 6.8
install
url --url=$tree
text
lang en_US.UTF-8
keyboard us
zerombr
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
$SNIPPET(‘network_config‘)
timezone --utc Asia/Shanghai
authconfig --enableshadow --passalgo=sha512
rootpw  --iscrypted $default_password_crypted
clearpart --all --initlabel
part /boot --fstype=ext4 --asprimary --size=200
part swap --size=1024
part / --fstype=ext4 --grow --asprimary --size=200
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
@base
@compat-libraries
@debugging
@development
tree
nmap
sysstat
lrzsz
dos2unix
telnet
%end
%post --nochroot
$SNIPPET(‘log_ks_post_nochroot‘)
%end
%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(‘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
%end

 

今后只要安装CerntOS镜像,就会去关联这个kickstart.cfg文件

### 每次改完配置文件 都要sync同步一下

技术分享

 

物理机安装 只要连接上网线 与 10.0.0.101同网段即可,dhcp服务器会自动识别到新服务器

虚拟机 需要新建虚拟机 添加网卡 eth1 并且配置同样的lan区段 然后开机

需要cobbler_load.tar.gz包的小伙帮可以留言并留下邮箱地址

### 开启虚拟机
### 并不能直接自动安装操作系统 这样不太安全 cobbler有一个安全错误 要先选择
### 选择local 就是从本地硬盘启动 防止误重装安全系统 尽量保留
### 选择下面则会开始自动安装 

技术分享

本文出自 “Cross Game” 博客,转载请与作者联系!

Cobbler无人值守安装