您的位置:首页 > 运维架构 > Linux

自动化运维利器之cobbler安装centos7

2015-11-30 14:38 781 查看
一、cobbler简介和服务
Cobbler是一款自动化操作系统安装的实现,与PXE安装系统的区别就是可以同时部署多个版本的系统,而PXE只能选择一种系统。而如今的架构动辄就是上千台的服务器。而存在一些操作系统不统一的现象,例如最初的架构采用的是CentOS5系列的系统,而新出现了一些技术后,需要新的操作系统的支持,一方面是需要批量部署装机,而另一方面还需要考虑到如果老版本的服务器出现故障后还需要重新去部署。并且提供Web配置页面,可以只需要一些点击就可以完成一些操作。 注:下文来自http://cobbler.github.io
Cobbler is a Linux installation server that allows forrapid setup of network installation environments. It glues together andautomates many associated Linux tasks so you do not have to hop between manyvarious commands and applications when deploying new systems, and, in somecases, changing existing ones. Cobbler can help with provisioning, managing DNSand DHCP, package updates, power management, configuration managementorchestration, and much more.服务类型:DNS,DHCP,更新包,电源管理,配置管理(支持puppet)二、引入kickstart见本人博客链接:/article/4399348.html
三、cobbler实战
安装cobbler 等依赖服务
[root@linux-node1 ~]# yum install cobbler cobbler-web dhcp tftp-server pykickstart  httpd -y
启动httpd 和cobbler服务

[root@linux-node1 ~]# /etc/init.d/httpd restart
[root@linux-node1 ~]# /etc/init.d/cobblerd start
使用cobbler check(5、6、8三步并不需要执行)检查,检查后使用cobbler sync同步操作

After installing, run "cobbler check" to verify that cobbler’s ecosystem is configured
correctly. Cobbler check will direct you on how to modify it’s config files using a text
editor.
[root@linux-node1 ~]# 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 : 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.
4 : change 'disable' to 'no' in /etc/xinetd.d/rsync
5 : reposync is not installed, need for cobbler reposync, install/upgrade yum-utils?
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.
上述结果直接告诉了安装cobbler需要哪些步骤,一步步按照提示进行操作即可
第一步+第二步+第七步
vim /etc/cobbler/settings

server: 10.0.0.7

next_server: 10.0.0.7 (指定tftp所在的服务器)
manage_dhcp: 1 (使用cobbler管理dhcp)
使用openssl对密码加密(前面的chuck是加盐随机值,后面的chuck是密码)
[root@linux-node1 ~]# openssl passwd -1 -salt 'chuck' 'chuck'
$1$chuck$vVcMGy7s.o2XdXxFM4TLo1
修改password

default_password_crypted: "$1$chuck$vVcMGy7s.o2XdXxFM4TLo1"
保存文件并使用cobble check重新检查
第三步:some network boot-loaders are missing from /var/lib/cobbler/loaders
cobbler get-loaders
第四步:把disable选项改为no,并重新启动xinetd

[root@linux-node1 ~]# vim /etc/xinetd.d/rsync
change 'disable' to 'no'
[root@linux-node1 ~]# /etc/init.d/xinetd restart
重启cobbler,并重新cobbler check
修改/etc/cobbler/dhcp.template 文件,该文件通过cobbler sync可以管理/etc/dhcp/dhcpd.conf文件,所以在此不需要更高/etc/dhcp/dhcpd.conf文件。
[root@linux-node1 ~]# vim /etc/cobbler/dhcp.template
subnet 10.0.0.0 netmask 255.255.255.0 {
option routers             10.0.0.2;
option domain-name-servers 10.0.0.2;
option subnet-mask         255.255.255.0;
range dynamic-bootp        10.0.0.100 10.0.0.200;
执行cobbler sync
使用vmvare虚拟机的iso镜像挂载到/mnt 路径(如下图),并导入镜像



cobbler --name:倒进后的名字 --arch:镜像架构 --path:挂载路径

[root@linux-node1 ~]# mount /dev/cdrom /mnt
[root@linux-node1 ~]# cobbler import --path=/mnt/ --name=CentOS-7.1-x86_64 --arch=x86_64
导入后镜像所在位置:/var/www/cobbler/ks_mirror/
[root@linux-node1 ~]# ls /var/www/cobbler/ks_mirror/
CentOS-7.1-x86_64  config
给kickstart定义ks文件
[root@linux-node1 ~]# cat /var/lib/cobbler/kickstarts/CentOS-7.1-x86_64.cfg
#Kickstart Configurator by Jason Zhao
#platform=x86, AMD64, or Intel EM64T
#System  language
lang en_US
#System keyboard
keyboard us
#Sytem timezone
timezone Asia/Shanghai
#Root password
rootpw --iscrypted $default_password_crypted
#rootpw --iscrypted $1$ops-node$7hqdpgEmIE7Z0RbtQkxW20
#Use text mode install
text
#Install OS instead of upgrade
install
#Use NFS installation Media
url --url=$tree
#url --url=http://192.168.56.11/CentOS-7.1-x86_64
#System bootloader configuration
bootloader --location=mbr
#Clear the Master Boot Record
zerombr
#Partition clearing information
clearpart --all --initlabel
#Disk partitioning information
part /boot --fstype xfs --size 1024 --ondisk sda
part swap --size 16384 --ondisk sda
part / --fstype xfs --size 1 --grow --ondisk sda
#System authorization infomation
auth  --useshadow  --enablemd5
#Network information
$SNIPPET('network_config')
#network --bootproto=dhcp --device=eth0 --onboot=on
# Reboot after installation
reboot
#Firewall configuration
firewall --disabled
#SELinux configuration
selinux --disabled
#Do not configure XWindows
skipx
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end
#Package install information
%packages
@ base
@ core
sysstat
iptraf
ntp
lrzsz
ncurses-devel
openssl-devel
zlib-devel
OpenIPMI-tools
mysql
nmap
screen
%end
%post
systemctl disable postfix.service
%end
使用cobbler list 查看列表,具体信息和内容,后面会有执行
distros:承载了内核和initrd等的信息
profile:可以理解为是配置文件,可以定义了ks文件,内核参数,存储库的位置等,
详情请使用cobbler profile edit --help查看
systems:定义主机,ip,dns,网关等 ,详情请使用cobbler system add --help查看

repo:yum的存储库
packages:和puppet关联时使用
files和images不做详细说明

[root@linux-node1 ~]# cobbler list
distros:
CentOS-7.1-x86_64
profiles:
CentOS-7.1-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
使用cobbler profile report查看生成信息
[root@linux-node1 ~]# cobbler profile report
Name                           : CentOS-7.1-x86_64
TFTP Boot Files                : {}
Comment                        :
DHCP Tag                       : default
Distribution                   : CentOS-7.1-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {'biosdevname': '0', 'net.ifnames': '0'}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/CentOS-7.1-x86_64.cfg
Kickstart Metadata             : {}
Management Classes             : []
Management Parameters          : <<inherit>>
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 :
Internal proxy                 :
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Repos                          : []
Server Override                : <<inherit>>
Template Files                 : {}
Virt Auto Boot                 : 1
Virt Bridge                    : xenbr0
Virt CPUs                      : 1
Virt Disk Driver Type          : raw
Virt File Size(GB)             : 5
Virt Path                      :
Virt RAM (MB)                  : 512
Virt Type                      : kvm
使用cobbler profile指定ks文件位置和内核参数(net.ifnames=0和biosdevname=0代表更改网卡为eth0==》》运维标准化)
cobbler profile edit --name=CentOS-7.1-x86_64 --kickstart= \
/var/lib/cobbler/kickstarts/CentOS-7.1-x86_64.cfg
cobbler profile edit --name=CentOS-7.1-x86_64 --kopts='net.ifnames=0 biosdevname=0'
为安装的机器安装一个yum源,并同步。建议使用内网yum源,在这里使用aliyun
[root@linux-node1 ~]# cobbler repo add -name=openstack-liberty -mirror=http://mirrors.aliyun.com/centos/7.1.1503/cloud/x86_64/openstack-liberty/ --arch=x86_64 --breed=yum
[root@linux-node1 ~]# cobbler reposync
编辑porfile,装完机器自动就会生成刚才指定的yum源

[root@linux-node1 ~]# cobbler profile edit --name=xxx --repo="openstack-liberty"
根据机器的MAC地址,自动绑定IP,网关,dns等

cobbler system add --name=chuck--mac=00:0C:29:22:E1:9C --profile=CentOS-7.1-x86_64 \
--ip-address=10.0.0.111 --subnet=255.255.255.0 --gateway=10.0.0.2 --interface=eth0  \
--static=1 --hostname=oldboy.example.com --name-servers="114.114.114.114 8.8.8.8"
使用cobbler sync同步配置
注意:客户端机器装系统时,要先使用修改bios启动然后修改为网卡启动,如图,把network boot from Intel E1000调整为最上,F10保存




出现下图所示,代表开始从dhcp服务安装系统开始



修改cobbler提示
[root@linux-node1 ~]# vim /etc/cobbler/pxe/pxedefault.template
DEFAULT menu
PROMPT 0
MENU TITLE by chuck  | http://chuck.blog.51cto.com TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT $pxe_timeout_profile
LABEL local
MENU LABEL (local)
MENU DEFAULT
LOCALBOOT -1
$pxe_menu_items
MENU end
四、web界面管理cobbler
在最开始yum的时候安装了cobbler-web,当然也就可以使用web界面管理cobbler
新版cobbler的web界面使用的是https,登录https://10.0.0.7/cobbler_web

(默认情况下username和password都是cobbler,可以通过用户名所在文件: /etc/cobbler/users.conf 和 密码所在文件:/etc/cobbler/users.digest进行管理 管理)







待安装完后,关闭机器,否则会反复安装,因此也要注意生产环境,尽量不要从网卡启动,防止机器意外重装!

本文出自 “思想决定高度” 博客,谢绝转载!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: