Centos批量安装部署
一.安装epel源
[root@server1~]#
wget http://dl.Fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
(此安装包也可以到rpmsearch官网去下载)
[root@server1 ~]#rpm -ivh epel-release-5-4.noarch.rpm
warning:epel-release-5-4.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 217521f6
Preparing...########################################### [100%]
1:epel-release########################################### [100%]
1.安装cobbler和一些必须的包,并设置开机自动启动
[root@server1 ~]#yum -y install cobbler httpd rsync tftp-server xinetd dhcp python-ctypespykickstart cman
[root@server1 ~]#chkconfig httpd on
[root@server1 ~]#chkconfig cobblerd on
[root@server1 ~]#chkconfig dhcpd on
[root@server1 ~]#chkconfig xinetd on
[root@server1~]#/etc/init.d/iptables stop
[root@server1~]#chkconfig --level 35 iptables off
2.编辑vim/etc/cobbler/settings
[root@server1 ~]#vim /etc/cobbler/settings
next_server:127.0.0.1 修改为:next_server: 192.168.0.45(是cobbler服务器的地址)
server: 127.0.0.1 修改为: server: 192.168.0.45(是cobbler服务器的地址)
manage_dhcp: 0 修改为 manage_dhcp: 1 (1意思就是由cobbler自动管理dhcpd)
manage_rsync: 0 修改为 manage_rsync: 1 (1意思就是由cobbler自动管理rsync)
3.编辑/etc/httpd/conf/httpd.conf
[root@server1 ~]#vim /etc/httpd/conf/httpd.conf 在LoadModule附近添加以下行
LoadModulesuexec_module modules/mod_suexec.so
LoadModuledisk_cache_module modules/mod_disk_cache.so
LoadModulefile_cache_module modules/mod_file_cache.so
LoadModulemem_cache_module modules/mod_mem_cache.so
LoadModulecgi_module modules/mod_cgi.so
LoadModuleversion_module modules/mod_version.so
LoadModulewsgi_module modules/mod_wsgi.so <- 在这里添加这行
4.启动httpd和cobbler
[root@server1 ~]#service httpd start
启动 httpd: [确定]
[root@server1 ~]#service cobblerd start
Starting cobblerdaemon: [确定]
[root@server1 ~]#
5.编辑/etc/xinetd.d/rsync
[root@server1 ~]#vim /etc/xinetd.d/rsync
service rsync
{
disable = no 修改yes 为 no(就是启用)
socket_type = stream
wait = no
user = root
server =/usr/bin/rsync
server_args =--daemon
log_on_failure +=USERID
}
6.编辑/etc/xinetd.d/tftp
[root@server1 ~]#vim /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server =/usr/sbin/in.tftpd
server_args =-s /tftpboot
disable = no 修改yes 为 no(就是启用)
per_source = 11
cps = 100 2
flags = IPv4
}
7.编辑/etc/cobbler/dhcp.template
[root@server1 ~]#vim /etc/cobbler/dhcp.template
ddns-update-styleinterim;
allow booting;
allow bootp;
ignoreclient-updates;
set vendorclass = option vendor-class-identifier;
subnet 192.168.1.0netmask 255.255.255.0 {
option routers192.168.0.1;
optiondomain-name-servers 192.168.1.1;
option subnet-mask255.255.255.0;
rangedynamic-bootp 192.168.1.10 192.168.1.20;
filename"/pxelinux.0";
default-lease-time21600;
max-lease-time43200;
next-server$next_server;
}
8.执行检查
[root@server1 ~]#cobbler check
Thefollowing are potential configuration items that you may want to fix:
1 : somenetwork boot-loaders are missing from /var/lib/cobbler/loaders, you may run'cobbler get-loaders' to download them, or, if you only want to handlex86/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, shouldinclude pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders'command is the easiest way to resolve these requirements.
2 :debmirror package is not installed, it will be required to manage debiandeployments and repositories
3 : Thedefault 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
Restartcobblerd and then run 'cobbler sync' to apply changes.
修复第1条:
[root@server1 ~]#cobbler get-loaders
task started:2012-12-09_055900_get_loaders
taskstarted (id=Download Bootloader Content, time=Sun Dec 9 05:59:002012)
downloadinghttp://dgoodwin.Fedorapeople.org/loaders/README to/var/lib/cobbler/loaders/README
downloadinghttp://dgoodwin.fedorapeople.org/loaders/COPYING.elilo to/var/lib/cobbler/loaders/COPYING.elilo
downloadinghttp://dgoodwin.fedorapeople.org/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloadinghttp://dgoodwin.fedorapeople.org/loaders/COPYING.syslinux to/var/lib/cobbler/loaders/COPYING.syslinux
downloadinghttp://dgoodwin.fedorapeople.org/loaders/elilo-3.8-ia64.efi to/var/lib/cobbler/loaders/elilo-ia64.efi
downloadinghttp://dgoodwin.fedorapeople.org/loaders/yaboot-1.3.14-12 to/var/lib/cobbler/loaders/yaboot
downloadinghttp://dgoodwin.fedorapeople.org/loaders/pxelinux.0-3.61 to/var/lib/cobbler/loaders/pxelinux.0
downloadinghttp://dgoodwin.fedorapeople.org/loaders/menu.c32-3.61 to/var/lib/cobbler/loaders/menu.c32
downloadinghttp://dgoodwin.fedorapeople.org/loaders/grub-0.97-x86.efi to/var/lib/cobbler/loaders/grub-x86.efi
downloadinghttp://dgoodwin.fedorapeople.org/loaders/grub-0.97-x86_64.efi to/var/lib/cobbler/loaders/grub-x86_64.efi
*** TASKCOMPLETE *** <-看到这就代表成功完成
第2条不安装debian系统就不用修复
安装的话,下载debmirror这个对应版本的包进行安装
修复第3条:
[root@server1 ~]#openssl passwd -1 -salt 'thinkpad' '123456'
$1$thinkpad$NIq68XbeN51UgdtXiSOAE.
# thinkpad 这个是随机的数字或字母用来干扰以免被人看到 123456为root密码
然后再次编辑/etc/cobbler/settings,把以上生成的密码替换原有的密码(下面红色部分)
default_password_crypted:"$1$thinkpad$NIq68XbeN51UgdtXiSOAE."
9.导入镜像文件
镜像文件会存在/var/www/cobbler/ks_mirror/ 这个目录下
[root@server1log]# mkdir /mnt/CentOS5.6
[root@server1log]# mount /dev/cdrom /mnt/centos5.6/ (使用镜像也可以)
mount: block device/dev/cdrom is write-protected, mounting read-only
[root@server1log]# cobbler import --path=/mnt/centos5.6/ --name=centos5.6-i386 这个进行的时间比较长
taskstarted: 2012-12-09_064244_import
taskstarted (id=Media import, time=Sun Dec 9 06:42:44 2012)
Founda RedHat compatiblesignature: CentOS
addingdistros
creatingnew distro: centos5.6-xen-i386
creatingnew profile: centos5.6-xen-i386
creatingnew distro: centos5.6-i386
creatingnew profile: centos5.6-i386
associatingrepos
traversingdistro centos5.6-xen-i386
descentinto /var/www/cobbler/ks_mirror/centos5.6-i386
processingrepo at : /var/www/cobbler/ks_mirror/centos5.6-i386
need toprocess repo/comps: /var/www/cobbler/ks_mirror/centos5.6-i386
lookingfor /var/www/cobbler/ks_mirror/centos5.6-i386/repodata/*comps*.xml
running:createrepo -c cache -s sha --groupfile/var/www/cobbler/ks_mirror/centos5.6-i386/repodata/comps.xml/var/www/cobbler/ks_mirror/centos5.6-i386
2644/2644- CentOS/boost-doc-1.33.1-10.el5.i386.rpm pm86.rpm
SavingPrimary metadata
Savingfile lists metadata
Savingother metadata
receivedon stderr: This option is deprecated
traversingdistro centos5.6-i386
descentinto /var/www/cobbler/ks_mirror/centos5.6-i386
processingrepo at : /var/www/cobbler/ks_mirror/centos5.6-i386
need toprocess repo/comps: /var/www/cobbler/ks_mirror/centos5.6-i386
lookingfor /var/www/cobbler/ks_mirror/centos5.6-i386/repodata/*comps*.xml
running:createrepo -c cache -s sha --groupfile/var/www/cobbler/ks_mirror/centos5.6-i386/repodata/comps.xml/var/www/cobbler/ks_mirror/centos5.6-i386
2644/2644- CentOS/boost-doc-1.33.1-10.el5.i386.rpm pm86.rpm
SavingPrimary metadata
Savingfile lists metadata
Savingother metadata
receivedon stderr: This option is deprecated
associatingkickstarts
*** TASKCOMPLETE *** <-看到这就代表成功完成
10.修复之后重启cobblerd,然后做文件同步
[root@server1 ~]#service cobblerd restart
Stoppingcobbler daemon: [确定]
Startingcobbler daemon: [确定]
[root@server1 ~]#cobbler sync
taskstarted: 2012-12-09_070816_sync
taskstarted (id=Sync, time=Sun Dec 9 07:08:16 2012)
runningpre-sync triggers
cleaningtrees
removing:/var/www/cobbler/p_w_picpaths/centos5.6-i386
removing:/var/www/cobbler/p_w_picpaths/centos5.6-xen-i386
removing:/tftpboot/pxelinux.cfg/default
removing:/tftpboot/grub/efidefault
removing:/tftpboot/grub/grub-x86_64.efi
removing:/tftpboot/grub/p_w_picpaths
removing:/tftpboot/grub/grub-x86.efi
removing:/tftpboot/s390x/profile_list
copyingbootloaders
tryinghardlink /var/lib/cobbler/loaders/grub-x86_64.efi-> /tftpboot/grub/grub-x86_64.efi
tryinghardlink /var/lib/cobbler/loaders/grub-x86.efi-> /tftpboot/grub/grub-x86.efi
copyingdistros to tftpboot
copyingfiles for distro: centos5.6-xen-i386
tryinghardlink /var/www/cobbler/ks_mirror/centos5.6-i386/p_w_picpaths/xen/vmlinuz-> /tftpboot/p_w_picpaths/centos5.6-xen-i386/vmlinuz
tryinghardlink /var/www/cobbler/ks_mirror/centos5.6-i386/p_w_picpaths/xen/initrd.img-> /tftpboot/p_w_picpaths/centos5.6-xen-i386/initrd.img
copyingfiles for distro: centos5.6-i386
tryinghardlink /var/www/cobbler/ks_mirror/centos5.6-i386/p_w_picpaths/pxeboot/vmlinuz-> /tftpboot/p_w_picpaths/centos5.6-i386/vmlinuz
tryinghardlink /var/www/cobbler/ks_mirror/centos5.6-i386/p_w_picpaths/pxeboot/initrd.img-> /tftpboot/p_w_picpaths/centos5.6-i386/initrd.img
copyingp_w_picpaths
generatingPXE configuration files
generatingPXE menu structure
copyingfiles for distro: centos5.6-xen-i386
tryinghardlink /var/www/cobbler/ks_mirror/centos5.6-i386/p_w_picpaths/xen/vmlinuz-> /var/www/cobbler/p_w_picpaths/centos5.6-xen-i386/vmlinuz
tryinghardlink /var/www/cobbler/ks_mirror/centos5.6-i386/p_w_picpaths/xen/initrd.img-> /var/www/cobbler/p_w_picpaths/centos5.6-xen-i386/initrd.img
copyingfiles for distro: centos5.6-i386
tryinghardlink /var/www/cobbler/ks_mirror/centos5.6-i386/p_w_picpaths/pxeboot/vmlinuz-> /var/www/cobbler/p_w_picpaths/centos5.6-i386/vmlinuz
tryinghardlink /var/www/cobbler/ks_mirror/centos5.6-i386/p_w_picpaths/pxeboot/initrd.img-> /var/www/cobbler/p_w_picpaths/centos5.6-i386/initrd.img
renderingDHCP files
generating/etc/dhcpd.conf
renderingTFTPD files
generating/etc/xinetd.d/tftp
cleaninglink caches
renderingRsync files
runningpost-sync triggers
runningpython triggers from /var/lib/cobbler/triggers/sync/post/*
runningpython trigger cobbler.modules.sync_post_restart_services
running:dhcpd -t -q
receivedon stdout:
receivedon stderr:
running:service dhcpd restart
receivedon stdout: 关闭 dhcpd:[确定]
启动 dhcpd:[确定]
receivedon stderr:
runningshell triggers from /var/lib/cobbler/triggers/sync/post/*
runningpython triggers from /var/lib/cobbler/triggers/change/*
runningpython trigger cobbler.modules.scm_track
runningshell triggers from /var/lib/cobbler/triggers/change/*
*** TASKCOMPLETE *** <-看到这就代表成功完成
查看导入结果:
[root@server1 ~]# cobbler distro list
centos5.6-i386 <- 这是刚刚导入的镜像的名字
centos5.6-xen-i386
11.启动xinetd服务
[root@server1 ~]#service xinetd start
12.先使用默认的kickstart配置文件来新建虚拟机测试
/var/lib/cobbler/kickstarts/sample.ks这个是默认的,如果不为每个导入的镜像设置单独的配置,那么就默认会使用这个
虚拟机安装测试不多说
安装完成之后会自动重启,重启后系统安装好了。
13、添加定制系统安装软件包
1、在终端输入system-config-kickstart调出软件包定制工具
2、选择好要安装的软件包后点击文件预览软件包
3、复制选择软件包到kickstart目录
vim/var/lib/cobbler/kickstarts/sample.ks
#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth --useshadow --enablemd5
# System bootloader configuration
bootloader --location=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 werereferenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
# Reboot after installation
reboot
#Root password
rootpw 123456
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone America/New_York
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system asneeded
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')
@gnome-software-development
@base-x
@base
@chinese-support 所选软件包
@gnome-desktop
@graphical-internet
@admin-tools
@system-tools
@web-server
%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
###############################################################################
FAQ
1、dhcp错误
[root@server1 ~]# service dhcpd start
启动 dhcpd: [失败]
查看/var/log/message 看到启动dhcp的过程中发现以下错误,
Dec 9 06:19:23 server1dhcpd: ** You must add a global ddns-update-style statement to /etc/dhcpd.conf.
Dec 9 06:19:23 server1 dhcpd: To get the same behaviour as in 3.0b2pl11 andprevious
Dec 9 06:19:23 server1 dhcpd: versions, add a line that says"ddns-update-style ad-hoc;"
Dec 9 06:19:23 server1 dhcpd: Please read the dhcpd.conf manual page for moreinformation. **
主要原因是:
文件/etc/cobbler/settings里面
manage_dhcp: 0 没有修改为1 造成的
修改为1之后,
重启cobblerd,然后做一次 cobbler sync(cobbler会把dhcp.template里面的内容复制到了/etc/dhcpd.conf),就会自动的把dhcpd启动起来.
2.启动cobbler
[root@localhostserver1]# setenforce 0
[root@localhost server1]#getenforce
Permissive
[root@localhost server1]# service cobblerd start
Startingcobbler daemon: No module namedctypes
Traceback(most recent call last):
File "/usr/bin/cobblerd", line 76,in main
api = cobbler_api.BootAPI(is_cobblerd=True)
File"/usr/lib/python2.4/site-packages/cobbler/api.py", line127, in__init__
module_loader.load_modules()
File"/usr/lib/python2.4/site-packages/cobbler/module_loader.py",line 62,in load_modules
blip = __import__("modules.%s" % (modname), globals(), locals(),[modname])
File "/usr/lib/python2.4/site-packages/cobbler/modules/authn_pam.py",line53, in ?
from ctypes import CDLL, POINTER, Structure,CFUNCTYPE, cast, pointer,sizeof
ImportError:No module named ctypes
[ OK ]
解决:
yum install –y python-ctypes
#service cobblerd start
Startingcobbler daemon: [ OK ]
3、较验cobblercheck出错
Traceback (most recent call last):
File "/usr/bin/cobbler", line 35,in ?
sys.exit(app.main())
File "/usr/lib/python2.4/site-packages/cobbler/cli.py",line 558, in main
rc = cli.run(sys.argv)
File"/usr/lib/python2.4/site-packages/cobbler/cli.py", line 202, in run
self.token = self.remote.login("",self.shared_secret)
File"/usr/lib64/python2.4/xmlrpclib.py", line 1096, in __call__
return self.__send(self.__name, args)
File"/usr/lib64/python2.4/xmlrpclib.py", line 1383, in __request
verbose=self.__verbose
File"/usr/lib64/python2.4/xmlrpclib.py", line 1147, in request
return self._parse_response(h.getfile(),sock)
File"/usr/lib64/python2.4/xmlrpclib.py", line 1286, in _parse_response
return u.close()
File"/usr/lib64/python2.4/xmlrpclib.py", line 744, in close
raise Fault(**self._stack[0])
xmlrpclib.Fault:<Fault 1: "cobbler.cexceptions.CX:'login failed'">
解决方法:此为BUG,按下方操作执行即可。
service cobblerdrestart
cobblerget-loaders
4、cobblerd校验错误:
cobblerddoes not appear to be running/accessible
解决方法:
service cobblerdstart
service httpdstart
5、httpd、SELinux未运行:
httpddoes not appear to be running and proxying cobbler, or SELinux is in the way.Original traceback:
Traceback(most recent call last):
解决方法:
service httpdstart
vi/etc/sysconfig/selinux
SELINUX=enforcing更改为SELINUX=disabled,重启使之生效。
如有错误欢迎批评指正技术交流qq群:155596694