转载自:http://www.jianshu.com/p/a4bed77bf40d
版权声明:完全抄自 http://www.jianshu.com/p/a4bed77bf40d
PXE
cobbler
cfengine
chef
puppet
saltstack
func
fabric
ansible
Cacti
Nagios Core
Zabbix
Zenoss core
关闭Directory上一批服务器
关闭这些服务器要更新的应用
更新webapp代码至目标主机
启动目标应用 ,Dirtectory启动这批服务器
代码控制(csv,svn,git)检出要发布的代码,发布至预发布服务器上
预发布服务器: 预发布服务器跟线上服务器环境一致,但不加入线上机器中,实施详细的测试
自动化测试,使用webapp自动化测试工具(如thoughworks开发的selenium)可以进行完整的代码,浏览器兼容性的测试
自动化灰度发布,线上批量分批次更新代码
监控数据采集,用户行为日志,服务器性能监控,运行数据报告
监控管理 异常报警,失败转移,自动优雅降级
运维自动化在生产环境中占据着举足轻重的地位,尤其是面对几百台,几千台甚至几万台的服务器时,仅仅是安装操作系统,如果不通过自动化来完成,根本是不可想象的。记得前面我们探究了基于PXE实现系统全自动安装,但PXE同时只能提供单一操作系统的批量部署,面对生产环境中不同服务器的需求,该如何实现批量部署多版本的操作系统呢?Cobbler便可以的满足这一实际需求,本文带来的是基于Cobbler实现多版本操作系统批量部署。
Cobbler是一款自动化操作系统部署的实现工具,由Python语言开发,是对PXE的二次封装。融合多种特性,提供了CLI和Web的管理形式。同时,Cobbler也提供了API接口,方便二次开发使用。它不仅可以安装物理机,同时也支持kvm、xen虚拟化、Guest OS的安装。另外,它还能结合Puppet等集中化管理软件,实现自动化管理。
Cobbler的各主要组件间关系如图所示
pxe 服务
DHCP
Rsync
Http
DNS
Kickstart
IPMI 电源管理
发行版(distro) :表示一个操作系统,它承载了内核和initrd的信息,以及内核等其他数据
存储库 (repository):保存了一个yum或者rsync存储库的镜像信息
配置文件(profile):包含了一个发行版(distro),一个kickstart文件以及可能的存储库(repository),还包含了更多的内核参数等其他数据
系统(system):表示要配给的机器,它包含了一个配置文件或一个镜像,还包含了ip和mac地址,电源管理(地址,凭据,类型)以及更为专业的数据信息
镜像(image):可替换一个包含不属于此类别的文件的发行版对象(eg: 无法作为内核和initrd的对象)
以上各个组件中, 发行版,存储库, 配置文件为必须配置项
只有在虚拟环境中,必须要用cobbler来引导虚拟机启动时候,才会用到系统组件
但事实上,在生产环境中需要大量的虚拟机实例的话,通常利用openstack等来实现虚拟机节点
dhcp
client: 从dhcp中获取地址,访问next_server的ip地址
next_server : 获取启动内核,initrd等文件
tftp: pxe引导文件,启动cobbler选择界面
kickstart: 确定加载项,根据nfs,http,tfp等共享获取资源
cobbler
cobbler-web
1 安装cobbler,依据cobbler check检查结果,对setting主配置文件,进行相关的修正配置
2 启动相关的http,cobbler服务,使用cobbler sync同步设置
3 配置cobbler 所依赖的包
* dhcp
* dns
* rsync
* tftp
4 配置cobbler组件
针对步骤3 ,需要:
1 选定要使用的程序,选其一管理即可
2 确定是独立管理这些服务,还有由cobbler代为管理
注意事项:
cobbler本身是不提供对应的服务程序的,因此还是需要安装对应的程序服务的rpm包,并保证其开启动的状态,由cobbler管理这些服务
[root@kvm ~]# yum install -y wget
[root@kvm ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
[root@kvm ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
[root@kvm ~]# sed -i 's/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/' /etc/sysctl.conf
[root@kvm ~]# sysctl -p
[root@kvm ~]# yum -y install cobbler dhcp httpd xinetd tftp-server syslinux pykickstart xinetd rsync cobbler-web
配置文件目录 /etc/cobbler
/etc/cobbler/settings : cobbler 主配置文件
/etc/cobbler/iso/: iso模板配置文件
/etc/cobbler/pxe: pxe模板文件
/etc/cobbler/power: 电源配置文件
/etc/cobbler/user.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 : 模块的配置文件
数据目录
/var/lib/cobbler/config/: 用于存放distros,system,profiles 等信息配置文件
/var/lib/cobbler/triggers/: 用于存放用户定义的cobbler命令
/var/lib/cobbler/kickstart/: 默认存放kickstart文件
/var/lib/cobbler/loaders/: 存放各种引导程序
镜像目录
/var/www/cobbler/ks_mirror/: 导入的发行版系统的所有数据
/var/www/cobbler/images/ : 导入发行版的kernel和initrd镜像用于远程网络启动
/var/www/cobbler/repo_mirror/: yum 仓库存储目录
日志目录
/var/log/cobbler/installing: 客户端安装日志
/var/log/cobbler/cobbler.log : cobbler日志
import
sync
reposync
build iso (使用发行版,配置文件,制作系统镜像)
command line search
replication
valication kickstart
[root@note1 ~]# cobbler check
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 : 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
Restart cobblerd and then run 'cobbler sync' to apply changes.
解决:
vim /etc/cobbler/settings
next_server: 10.1.1.243
server: 10.1.1.243
manage_dhcp: 1
default_password_crypted: "$1$panpan52$CZn1h8wYDYvYIIMzjq7Vg/"
#openssl passwd -1 -salt 'panpan520' 'panwenbin'命令获得
cobbler get-loaders
grep "disable" /etc/xinetd.d/rsync #将yes改为no
disable = no
/etc/init.d/xinetd restart
/etc/init.d/cobblerd restart
防止误重装系统,选项pxe_just_one
[root@note1 cobbler]# cobbler setting edit --name=pxe_just_once --value=1
前面执行chkconfig rysnc on 和chkconfig tftp on,diable 应该就是yes了,配置文件/etc/xinetd.d/rsync
[root@note1 cobbler]# chkconfig --level 35 xinetd on
[root@note1 cobbler]# vim /etc/cobbler/dhcp.template
#其他暂时不需要动,只修改下面的几个内容
subnet 10.10.10.0 netmask 255.255.255.0 {
option routers 10.10.10.10;
option domain-name-servers 114.114.114.114 ;
option subnet-mask 255.255.255.0;
range dynamic-bootp 10.10.10.20 10.10.10.50;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
cobbler sync
[root@kvm cobbler]# service cobblerd restart
Stopping cobbler daemon: [ OK ]
Starting cobbler daemon: [ OK ]
[root@kvm cobbler]# cobbler sync
task started: 2015-11-06_094656_sync
task started (id=Sync, time=Fri Nov 6 09:46:56 2015)
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_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
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 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@note1 cobbler]# vim /etc/dhcp/dhcpd.conf #查看cobbler是否接管DHCP
# ******************************************************************
# Cobbler managed dhcpd.conf file
# generated from cobbler dhcp.conf template (Sun Jan 31 15:47:49 2016)
# Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes
# in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
# overwritten.
# *****************************************************************
ddns-update-style interim;
allow booting
allow bootp
ignore client-updates;
set vendorclass = option vendor-class-identifier
option pxe-system-type code 93 = unsigned integer 16;
subnet 10.10.10.0 netmask 255.255.255.0 {
--------
再次检查
[root@localhost ~]# 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.
#第一个是bug,不用管,第二个如果是Debian系统可以安装,第三是电源fencing工具,可以不安装
[root@kvm ~]# chkconfig httpd on
[root@kvm ~]# chkconfig cobblerd on
[root@kvm Data]# chkconfig tftp on
[root@kvm Data]# chkconfig rsync on
[root@kvm Data]# chkconfig xinetd on
[root@kvm Data]# service xinetd start
[root@kvm Data]# service cobblerd start
[root@kvm Data]# service httpd start
cat >>/etc/init.d/cobbler<<EOF
#!/bin/bash
# chkconfig: 345 80 90
# description:cobbler
case \$1 in
start)
/etc/init.d/httpd start
/etc/init.d/xinetd start
/etc/init.d/dhcpd start
/etc/init.d/cobblerd start ;;
stop)
/etc/init.d/httpd stop
/etc/init.d/xinetd stop
/etc/init.d/dhcpd stop
/etc/init.d/cobblerd stop ;;
restart)
/etc/init.d/httpd restart
/etc/init.d/xinetd restart
/etc/init.d/dhcpd restart
/etc/init.d/cobblerd restart ;;
status)
/etc/init.d/httpd status
/etc/init.d/xinetd status
/etc/init.d/dhcpd status
/etc/init.d/cobblerd status ;;
sync)
cobbler sync ;;
*)
echo "Input error,please in put 'start|stop|restart|status|sync'!"
exit 2 ;;
esac
EOF
# chmod +x /etc/init.d/cobbler
# chkconfig cobbler on
[root@linux-node1 ~]# cobbler
usage
=====
cobbler... -loaders|hardlink> [options|--help]
[add|edit|copy|getks*|list|remove|rename|report] [options|--help]
cobblerget
[root@linux-node1 ~]# cobbler import --help # 导入镜像
Usage: cobbler [options]
Options:
-h, --help show this help message and exit
--arch=ARCH OS architecture being imported
--breed=BREED the breed being imported
--os-version=OS_VERSION
the version being imported
--path=PATH local path or rsync location
--name=NAME name, ex 'RHEL-5'
--available-as=AVAILABLE_AS
tree is here, don't mirror
--kickstart=KICKSTART_FILE
assign this kickstart file
--rsync-flags=RSYNC_FLAGS
pass additional flags to rsync
cobbler check 核对当前设置是否有问题
cobbler list 列出所有的cobbler元素
cobbler report 列出元素的详细信息
cobbler sync 同步配置到数据目录,更改配置最好都要执行下
cobbler reposync 同步yum仓库
cobbler distro 查看导入的发行版系统信息
cobbler system 查看添加的系统信息
cobbler profile 查看配置信息
centos6.5:
[root@kvm cobbler]# mount /dev/cdrom /mnt
[root@note1 cobbler]# cobbler import --path=/mnt/ --name=Centos-6.5-x86_64 --arch=x86_64
[root@note1 cobbler]# cobbler distro report --name=Centos-6.5-x86_64
Name : Centos-6.5-x86_64
Architecture : x86_64
TFTP Boot Files : {}
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/ks_mirror/Centos-6.5-x86_64/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/ks_mirror/Centos-6.5-x86_64/images/pxeboot/vmlinuz
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/Centos-6.5-x86_64'}
Management Classes : []
OS Version : rhel6
Owners : ['admin']
Red Hat Management Key : <>
Red Hat Management Server : <>
Template Files : {}
centos7:
[root@note1 ~]# umount /mnt
[root@note1 cobbler]# cobbler import --path=/mnt/ --name=Centos-7-x86_64 --arch=x86_64
[root@note1 kickstarts]# cobbler distro report --name=Centos-7-x86_64
Name : Centos-7-x86_64
Architecture : x86_64
TFTP Boot Files : {}
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/ks_mirror/Centos-7-x86_64/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/ks_mirror/Centos-7-x86_64/images/pxeboot/vmlinuz
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/Centos-7-x86_64'}
Management Classes : []
OS Version : rhel7
Owners : ['admin']
Red Hat Management Key : <>
Red Hat Management Server : <>
Template Files : {}
查看:
[root@note1 cobbler]# cobbler distro list
Centos-6.5-x86_64
Centos-7-x86_64
centos6.6:
# kickstart template for Fedora 8 and later.
# (includes %end blocks)
# do not use with earlier distros
#platform=x86, AMD64, or Intel EM64T
# Install OS instead of upgrade
install
# Use network installation
url --url=$tree
# Use text mode install
text
# System language
lang en_US
# System keyboard
keyboard us
# Clear the Master Boot Record
zerombr
# System bootloader configuration
bootloader --location=mbr
# System timezone
timezone America/Shanghai
# System authorization information
auth --useshadow --enablemd5
#Root password
rootpw --iscrypted $default_password_crypted
# Network information
$SNIPPET('network_config')
# Partition clearing information
clearpart --all --initlabel
# Allow anaconda to partition the system as needed
part /boot --fstype ext4 --size 200
part swap --fstype swap --size 2000
part / --fstype ext4 --size 20000
part /data --fstype ext4 --size 1 --grow
# Firewall configuration
firewall --enabled
# Run the Setup Agent on first boot
firstboot --disable
# SELinux configuration
selinux --disabled
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Reboot after installation
reboot
# Do not configure the X Window System
skipx
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end
%packages
$SNIPPET('func_install_if_enabled')
lrzsz
tree
wget
curl
openssh
openssl
%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('cobbler_register')
# Enable post-install boot notification
$SNIPPET('post_anamon')
# Start final steps
$SNIPPET('kickstart_done')
# End final steps
mkdir /root/backup
sed -i "s/#UseDNS yes/UseDNS no/" /etc/ssh/sshd_config
sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
yum -y install git lrzsz
%end
到此centos6.5系统就可以装机了
centos7:
[root@note1 kickstarts]# cat CentOS-7-x86_64.cfg
#obbler for Kickstart Configurator for CentOS 7.1 by yao zhang
install
url --url=$tree
text
lang en_US.UTF-8
keyboard us
zerombr
bootloader --location=mbr
# Network information
$SNIPPET('network_config')
timezone --utc Asia/Shanghai
authconfig --enableshadow --passalgo=sha512
rootpw --iscrypted $default_password_crypted
clearpart --all --initlabel
part /boot --fstype xfs --size 500
part swap --size 2000
part / --fstype xfs --size 20000
part /data --fstype xfs --size 30000
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
iptraf
ncurses-devel
openssl-devel
zlib-devel
OpenIPMI-tools
screen
%end
%post
systemctl disable postfix.service
%end
# 修改安装系统的内核参数,在CentOS7系统有一个地方变了,就是网卡名变成eno16777736这种形式,但是为了运维标准化,
# 我们需要将它变成我们常用的eth0,因此使用下面的参数。但要注意是CentOS7才需要下面的步骤,CentOS6不需要。
[root@note1 kickstarts]# cobbler profile edit --name=CentOS-7.1-x86_64 --kopts='net.ifnames=0 biosdevname=0'
[root@note1 kickstarts]# cobbler profile report --name=CentOS-7-x86_64
Name : CentOS-7-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : Centos-7-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-x86_64.cfg
Kickstart Metadata : {}
Management Classes : []
Management Parameters : <>
Name Servers : []
Name Servers Search Path : []
Owners : ['admin']
Parent Profile :
Internal proxy :
Red Hat Management Key : <>
Red Hat Management Server : <>
Repos : []
Server Override : <>
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
查看:
[root@note1 kickstarts]# cobbler profile report Centos-7-x86_64
[root@note1 kickstarts]# cobbler profile report Centos-6.5-x86_64
[root@note1 kickstarts]# cobbler list
distros:
Centos-6.5-x86_64
Centos-7-x86_64
profiles:
Centos-6.5-x86_64
Centos-7-x86_64
systems:
budongshu
repos:
images:
mgmtclasses:
packages:
files
同步:
[root@note1 kickstarts]# cobbler sync
配置本地yum仓库 (选配,可以不配置)
[root@localhost ~]# mkdir /tmp/rpms
[root@localhost ~]# createrepo /tmp/rpms #放入rpm包,执行此步骤
[root@localhost ~]# cobbler repo add --mirror=/tmp/rpms --name=local
[root@localhost ~]# cobbler reposync
配置本地epel仓库(选配,可以不配置)
[root@localhost ~]# cobbler repo add --mirror=http://mirrors.aliyun.com/epel/6/x86_64/ --name=epel
[root@localhost ~]# cobbler reposync --tries=3 --no-fail #同步epel仓库到
本地,需要较长时间
查看已添加的repo(选配,可以不配置)
[root@localhost ~]# cobbler repo list
epel
local
添加repo到profile(选配,可以不配置)
[root@localhost ~]# cobbler profile edit --name=Centos-6.5-x86_64 --repos="epel local"
[root@localhost ~]# cobbler sync
[root@note1 kickstarts]# cobbler system add --name=budongshu --mac=00:0C:29:48:1D:75 --profile=Centos-7-x86_64 \
--ip-address=10.10.10.23 --subnet=255.255.255.0 --gateway=10.10.10.10 --interface=eth0 \
--static=1 --hostname=budongshu --name-servers="114.114.114.114 8.8.8.8"
[root@note1 kickstarts]# cobbler sync
到此cento7系统的也可以装机了,并且绑定了mac地址,固定了ip地址
cobbler-web支持多种认证方式,如authn_configfil、authn_ldap或authn_pam等,下面我们基于authn_pam做认证
修改认证方式
[root@note1 web]# vim /etc/cobbler/modules.conf
[authentication]
module = authn_pam
添加系统用户
[root@note1 web]# useradd cobbler
[root@note1 web]# echo "cobbler" | passwd --stdin cobbler
添加用户到管理组
[root@note1 web]# vim /etc/cobbler/modules.conf
[admins]
admin = "cobbler"
重启服务
[root@note1 web]# service cobblerd restart
Stopping cobbler daemon: [ OK ]
Starting cobbler daemon: [ OK ]
[root@note1 web]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]