一、了解cobbler
定义:Cobbler 是一个系统安装与管理类工具,用来快速建立 Linux 网络安装环境。由python语言开发,是对PXE和Kickstart以及DHCP的封装。不仅可以安装物理机,同时也支持kvm、xen虚拟化、Guest OS的安装。实现自动化的管理。工作原理如下图:
PXE(preboot execute environment,预启动执行环境)让计算机通过网卡独立地使用数据设备(如硬盘)或者安装操作系统。通过使用像网际协议(IP)、用户数据报协议(UDP)、动态主机设定协定(DHCP)、小型文件传输协议(TFTP)等几种网络协议和全局唯一标识符(GUID)、通用网络驱动接口(UNDI)、通用唯一识别码(UUID)的概念并通过对客户机(通过PXE自检的电脑)固件扩展预设的API来实现目的。工作原理如下图:
Kickstart提供自动安装系统功能。组成:
Kickstart 安装选项,包含语言的选择,防火墙,密码,网络,分区的设置等;
%Pre 部分,安装前解析的脚本,通常用来生成特殊的ks配置,比如由一段程序决定磁盘分区等;
%Package 部分,安装包的选择,可以是 @core 这样的group的形式,也可以是这样 vim-* 包的形式;
%Post 部分,安装后执行的脚本,通常用来做系统的初始化设置。比如启动的服务,相关的设定等。
二、准备(本机环境:CentOS 6.4)
本机IP:192.168.0.2
1.安装epel
rpm -Uvh http://mirrors.hustunique.com/epel/6/x86_64/epel-release-6-8.noarch.rpm
2.安装httpd
yum install httpd
配置:vim /etc/httpd/conf/httpd.conf
修改: Listen 本机ip:监听端口 (eg:192.168.0.2:80)
ServerName ip地址 (eg:192.168.0.2)
/etc/init.d/httpd restart 在浏览器打开,测试httpd是否可用
3.安装dhcp
yum install dhcp
配置:vim /etc/dhcp/dhcpd.conf
ddns-update-style interim; allow booting; allow bootp; ignore client-updates; set vendorclass = option vendor-class-identifier; subnet 192.168.0.0 netmask 255.255.255.0 { range 192.168.0.4 192.168.0.200; #动态分配的IP地址范围 option domain-name-servers ns1.internal.example.org; option domain-name "192.168.0.2"; #本机的IP地址 option routers 192.168.0.1; #网关 option broadcast-address 192.168.0.255; #子网掩码 default-lease-time 600; max-lease-time 7200; } group{ } host cobbler { option host-name "cobbler"; ddns-hostname "cobbler"; hardware ethernet 00:0C:29:A7:00:9F; #本机的物理(MAC)地址 fixed-address 192.168.0.2; #本机IP allow booting; allow bootp; class "PXE" { match if substring(option vendor-class-identifier, 0, 9) = "PXEClient"; next-server 192.168.0.2; #本机IP filename "pxelinux.0"; } }
三、安装配置cobbler
1.安装:yum install cobbler
2.配置:vim /etc/cobbler/settings
1)修改:server:本机IP (eg:192.168.0.2)
next_server:本机IP (eg:192.168.0.2)
default_password_crypted:“ ”
使用openssl passwd -1 -salt 'random-phrase-here' 'your-password-here' 获得一串字符串替换default_password_crypted后面的字符串,此处“your-password-here"就为设置的开机密码。
2)编辑/etc/xinetd.d/tftp文件,将文件中的disable字段的配置由yes改为no
3)编辑/etc/xinetd.d/rsync文件,将文件中的disable字段的配置由yes改为no
四、防火墙设置
1.在iptables中将需要用到的端口(69,80,25151 )打开。如果仅仅只是在内部环境中使用,可以将防火墙关掉 /etc/init.d/iptables stop
2.SELinux的设置:vim /etc/selinux/config 设置SELINUX=disabled,并reboot一次(不想或者不能reboot时用setenforce 0)
五、启动服务
/etc/init.d/httpd start
/etc/init.d/xinetd start
/etc/init.d/dhcpd start
/etc/init.d/cobblerd start
设置开机自启: chkconfig httpd on
chkconfig xinetd on
chkconfig dhcpd on
chkconfig cobblerd on
六、检查
cobbler check
若出现如下错误重启cobbler
Traceback (most recent call last): File "/usr/bin/cobbler", line 36, in <module> sys.exit(app.main()) File "/usr/lib/python2.6/site-packages/cobbler/cli.py", line 655, in main rc = cli.run(sys.argv) File "/usr/lib/python2.6/site-packages/cobbler/cli.py", line 270, in run self.token = self.remote.login("", self.shared_secret) File "/usr/lib64/python2.6/xmlrpclib.py", line 1199, in __call__ return self.__send(self.__name, args) File "/usr/lib64/python2.6/xmlrpclib.py", line 1489, in __request verbose=self.__verbose File "/usr/lib64/python2.6/xmlrpclib.py", line 1253, in request return self._parse_response(h.getfile(), sock) File "/usr/lib64/python2.6/xmlrpclib.py", line 1392, in _parse_response return u.close() File "/usr/lib64/python2.6/xmlrpclib.py", line 838, in close raise Fault(**self._stack[0]) xmlrpclib.Fault: <Fault 1: "<class 'cobbler.cexceptions.CX'>:'login failed'">
若有其他的没有配置好的运行他可以提示你。只需要解决提示内容即可。直到运行出现
No configuration problems found. All systems go.
七、导入系统安装包
1、在/mnt/下新建文件夹
mkdir /mnt/cdrom/
2、挂载
mount /dev/cdrom /mnt/cdrom/
3、导入系统安装包
cobbler import --path=/mnt/cdrom --name=CentOS-6.3-x86_64-bin-DVD (name为安装系统时选择的名字,可以自主命名)
task started: 2015-01-26_164018_import task started (id=Media import, time=Mon Jan 26 16:40:18 2015) Found a candidate signature: breed=redhat, version=rhel6 Found a matching signature: breed=redhat, version=rhel6 Adding distros from path /var/www/cobbler/ks_mirror/CentOS-6.3-x86_64-bin-DVD: creating new distro: CentOS-6.3-bin-DVD-x86_64 trying symlink: /var/www/cobbler/ks_mirror/CentOS-6.3-x86_64-bin-DVD -> /var/www/cobbler/links/CentOS-6.3-bin-DVD-x86_64 creating new profile: CentOS-6.3-bin-DVD-x86_64 associating repos checking for rsync repo(s) checking for rhn repo(s) checking for yum repo(s) starting descent into /var/www/cobbler/ks_mirror/CentOS-6.3-x86_64-bin-DVD for CentOS-6.3-bin-DVD-x86_64 processing repo at : /var/www/cobbler/ks_mirror/CentOS-6.3-x86_64-bin-DVD need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS-6.3-x86_64-bin-DVD looking for /var/www/cobbler/ks_mirror/CentOS-6.3-x86_64-bin-DVD/repodata/*comps*.xml Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS-6.3-x86_64-bin-DVD/repodata *** TASK COMPLETE ***
八、测试
查看:
1.输入cobbler report 可以看到如下内容:
distros: ========== Name : CentOS-6.3-bin-DVD-x86_64 Architecture : x86_64 TFTP Boot Files : {} Breed : redhat Comment : Fetchable Files : {} Initrd : /var/www/cobbler/ks_mirror/CentOS-6.3-x86_64-bin-DVD/images/pxeboot/initrd.img Kernel : /var/www/cobbler/ks_mirror/CentOS-6.3-x86_64-bin-DVD/images/pxeboot/vmlinuz Kernel Options : {} Kernel Options (Post Install) : {} Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/CentOS-6.3-bin-DVD-x86_64'} Management Classes : [] OS Version : rhel6 Owners : ['admin'] Red Hat Management Key : <<inherit>> Red Hat Management Server : <<inherit>> Template Files : {} profiles: ========== Name : CentOS-6.3-bin-DVD-x86_64 TFTP Boot Files : {} Comment : DHCP Tag : default Distribution : CentOS-6.3-bin-DVD-x86_64 Enable gPXE? : 0 Enable PXE Menu? : 1 Fetchable Files : {} Kernel Options : {} Kernel Options (Post Install) : {} Kickstart : /var/lib/cobbler/kickstarts/sample_end.ks (自动安装时,安装选项的配置文件) Kickstart Metadata : {} Management Classes : [] Management Parameters : <<inherit>> Name Servers : [] Name Servers Search Path : [] Owners : ['admin'] Parent Profile : Proxy :
查看该配置文件:
#platform=x86, AMD64, or Intel EM64T # System authorization information auth --useshadow --enablemd5 #用户登录认证 # System bootloader configuration bootloader --location=mbr #mbr引导 # Partition clearing information clearpart --all --initlabel #默认清除所以分区 # Use text mode install text #默认以文本模式安装 # Firewall configuration firewall --enabled #防火墙默认开启 # Run the Setup Agent on first boot firstboot --disable #禁用启动代理 # System keyboard keyboard us #默认英文键盘 # System language lang en_US #默认语言英文 # Use network installation url --url=$tree #网络安装路径 # If any cobbler repo definitions were referenced in the kickstart profile, include them here. $yum_repo_stanza #默认的yum仓库 # Network information $SNIPPET('network_config') (可以改为 network --bootproto=dhcp --device=eth0 --netmask=255.255.255.0 --gateway=192.168.0.1 --nameserver=8.8.8.8) # Reboot after installation reboot #安装完成后重启 #Root password rootpw --iscrypted $default_password_crypted #密码是我们/etc/cobbler/settings设置密码 # SELinux configuration selinux --disabled #默认关闭selinux # Do not configure the X Window System skipx #默认没有安装图形界面 # System timezone timezone America/New_York #默认时区是美国/纽约 (可以改为亚洲/上海 --utc Asia/Shanghai) # Install OS instead of upgrade install #定义的是安装系统而不是升级系统 # Clear the Master Boot Record zerombr #默认清空所有的mbr # Allow anaconda to partition the system as needed autopart #默认自动分区 %pre $SNIPPET('log_ks_pre') $SNIPPET('kickstart_start') $SNIPPET('pre_install_network_config') # Enable installation monitoring $SNIPPET('pre_anamon') %packages $SNIPPET('func_install_if_enabled') $SNIPPET('puppet_install_if_enabled') %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('puppet_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
如果根据修改后的安装的虚拟机是ip自动分配,网关跟子网掩码都是配置的,还有nameserver也配置好了,可以直接联网了。