一、环境部署:
1、安装源准备并安装
说明:基础源与epel源。
rpm -ivh http://download.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum -y install cobbler cobbler-web httpd rsync tftp-server xinetd dhcp python-ctypes debmirror pykickstart fence-agents
需安装软件:
[root@localhost ~]# yum install cobbler cobbler-web dhcp tftp-server pykickstart httpd -y
需要安装Django
wget http://springdale.math.ias.edu/data/puias/unsupported/6/x86_64//Django14-1.4.14-1.sdl6.noarch.rpm
rpm -ivf Django14-1.4.14-1.sdl6.noarch.rpm
[root@localhost ~]# /etc/init.d/httpd start
二、启动
[root@localhost ~]# /etc/init.d/cobblerd start
1 [root@nagios-client5-135-Python-Env loaders]# cobbler get-loaders 2 task started: 2016-02-08_214823_get_loaders 3 task started (id=Download Bootloader Content, time=Mon Feb 8 21:48:23 2016) 4 downloading http://cobbler.github.com/loaders/README to /var/lib/cobbler/loaders/README 5 6 Exception occured: <class 'urlgrabber.grabber.URLGrabError'> 7 Exception value: [Errno 12] Timeout on http://cobbler.github.com/loaders/README: (28, 'Operation too slow. Less than 1 bytes/sec transfered the last 300 seconds') 8 Exception Info: 9 File "/usr/lib/python2.6/site-packages/cobbler/remote.py", line 87, in run 10 rc = self._run(self) 11 File "/usr/lib/python2.6/site-packages/cobbler/remote.py", line 181, in runner 12 return self.remote.api.dlcontent(self.options.get("force",False), self.logger) 13 File "/usr/lib/python2.6/site-packages/cobbler/api.py", line 751, in dlcontent 14 return grabber.run(force) 15 File "/usr/lib/python2.6/site-packages/cobbler/action_dlcontent.py", line 73, in run 16 urlgrabber.grabber.urlgrab(src, filename=dst, proxies=proxies) 17 File "/usr/lib/python2.6/site-packages/urlgrabber/grabber.py", line 618, in urlgrab 18 return default_grabber.urlgrab(url, filename, **kwargs) 19 File "/usr/lib/python2.6/site-packages/urlgrabber/grabber.py", line 985, in urlgrab 20 return self._retry(opts, retryfunc, url, filename) 21 File "/usr/lib/python2.6/site-packages/urlgrabber/grabber.py", line 886, in _retry 22 r = apply(func, (opts,) + args, {}) 23 File "/usr/lib/python2.6/site-packages/urlgrabber/grabber.py", line 971, in retryfunc 24 fo = PyCurlFileObject(url, filename, opts) 25 File "/usr/lib/python2.6/site-packages/urlgrabber/grabber.py", line 1066, in __init__ 26 self._do_open() 27 File "/usr/lib/python2.6/site-packages/urlgrabber/grabber.py", line 1360, in _do_open 28 self._do_grab() 29 File "/usr/lib/python2.6/site-packages/urlgrabber/grabber.py", line 1490, in _do_grab 30 self._do_perform() 31 File "/usr/lib/python2.6/site-packages/urlgrabber/grabber.py", line 1290, in _do_perform 32 raise err 33 34 !!! TASK FAILED !!!
解决方法:
1 cd /var/lib/cobbler/loaders 2 cat filelist.txt 3 http://dgoodwin.fedorapeople.org/loaders/README 4 http://dgoodwin.fedorapeople.org/loaders/COPYING.elilo 5 http://dgoodwin.fedorapeople.org/loaders/COPYING.yaboot 6 http://dgoodwin.fedorapeople.org/loaders/COPYING.syslinux 7 http://dgoodwin.fedorapeople.org/loaders/elilo-3.8-ia64.efi 8 http://dgoodwin.fedorapeople.org/loaders/yaboot-1.3.14-12 9 http://dgoodwin.fedorapeople.org/loaders/pxelinux.0-3.61 10 http://dgoodwin.fedorapeople.org/loaders/menu.c32-3.61 11 http://dgoodwin.fedorapeople.org/loaders/grub-0.97-x86.efi 12 http://dgoodwin.fedorapeople.org/loaders/grub-0.97-x86_64.efi 13 wget -i filelist.txt
三、配置:
可运行以下命令有提示步骤:
[root@localhost mod_ssl-2.8.30-1.3.39]# 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 : debmirror package is not installed, it will be required to manage debian deployments and repositories 6 : 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 7 : 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.
[root@localhost httpd]# openssl passwd -1 -salt 'xuxuedong' 'P@ssw0rd' 配置加密秘钥
$1$xuxuedon$3HGeoHhjobMg8OgOmHZwz0
配置cobbler:
next_server: 127.0.0.1 server: 172.22.0.60 manage_dhcp: 1 default_password_crypted: "$1$xuxuedon$3HGeoHhjobMg8OgOmHZwz0"
[root@localhost mod_ssl-2.8.30-1.3.39]# cobbler get-loaders
配置/etc/xinetd.d/rsync
[root@localhost /]# vim /etc/xinetd.d/rsync # default: off # description: The rsync server is a good addition to an ftp server, as it \ # allows crc checksumming etc. service rsync { disable = no flags = IPv6 socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID } ~
重启服务:
[root@localhost /]# /etc/init.d/xinetd restart Stopping xinetd: [ OK ] Starting xinetd: [ OK ] [root@localhost /]# /etc/init.d/cobblerd restart Stopping cobbler daemon: [ OK ] Starting cobbler daemon:
编辑cobbler模板
[root@localhost loaders]# vi /etc/cobbler/dhcp.template subnet 172.22.0.0 netmask 255.255.255.0 { option routers 172.22.0.60; option domain-name-servers 172.22.0.60; option subnet-mask 255.255.255.0; range dynamic-bootp 172.22.0.200 172.22.0.240; default-lease-time 21600; max-lease-time 43200; next-server $next_server;
[root@localhost loaders]# cobbler sync 每次有修改必须执行
镜像导入:
[root@localhost ~]# mount /dev/cdrom /mnt [[root@localhost loaders]# cobbler import --path=/mnt/ --name=Centos-6.6-x86_64 --arch=x86_64 #导入镜像 [root@localhost Packages]# cd /var/www/cobbler/ks_mirror/ #镜像导入到此处
定义kickstart文件
[root@localhost ks_mirror]# cd /var/lib/cobbler/kickstarts/ [root@localhost kickstarts]# vi Centos-6.8-x86_64.cfg # Cobbler for Kickstart Configurator for CentOS 6.6 by xuxuedong install url --url=$tree #url --url=http://172.22.0.60/Centos-6.8_x86_64 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 --size=1024 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
列出cobbler元素的详细信息
[root@localhost kickstarts]# cobbler list distros: Centos-6.6-x86_64 profiles: Centos-6.6-x86_64 systems: repos: images: mgmtclasses: packages: files: [root@localhost kickstarts]# cobbler profile report Name : Centos-6.6-x86_64 TFTP Boot Files : {} Comment : DHCP Tag : default Distribution : Centos-6.6-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 : 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
编辑profile:
[root@localhost kickstarts]# cobbler profile edit --help Usage: cobbler [options] Options: -h, --help show this help message and exit --name=NAME Name (Ex: F10-i386-webserver) --uid=UID --owners=OWNERS Owners (Owners list for authz_ownership (space delimited)) --distro=DISTRO Distribution (Parent distribution) --parent=PARENT Parent Profile --enable-gpxe=ENABLE_GPXE Enable gPXE? (Use gPXE instead of PXELINUX for advanced booting options) --enable-menu=ENABLE_MENU Enable PXE Menu? (Show this profile in the PXE menu?) --kickstart=KICKSTART Kickstart (Path to kickstart template) --kopts=KERNEL_OPTIONS Kernel Options (Ex: selinux=permissive) --kopts-post=KERNEL_OPTIONS_POST Kernel Options (Post Install) (Ex: clocksource=pit noapic) --ksmeta=KS_META Kickstart Metadata (Ex: dog=fang agent=86) --proxy=PROXY Internal proxy (Internal proxy URL) --repos=REPOS Repos (Repos to auto-assign to this profile) --comment=COMMENT Comment (Free form text description) --virt-auto-boot=VIRT_AUTO_BOOT Virt Auto Boot (Auto boot this VM?) --virt-cpus=VIRT_CPUS Virt CPUs (integer) --virt-file-size=VIRT_FILE_SIZE Virt File Size(GB) --virt-disk-driver=VIRT_DISK_DRIVER Virt Disk Driver Type (The on-disk format for the virtualization disk) --virt-ram=VIRT_RAM Virt RAM (MB) --depth=DEPTH --virt-type=VIRT_TYPE Virt Type (Virtualization technology to use) (valid options: xenpv,xenfv,qemu,kvm,vmware,openvz,SETTINGS:d efault_virt_type) --virt-path=VIRT_PATH Virt Path (Ex: /directory OR VolGroup00) --virt-bridge=VIRT_BRIDGE Virt Bridge --dhcp-tag=DHCP_TAG DHCP Tag (See manpage or leave blank) --server=SERVER Server Override (See manpage or leave blank) --ctime=CTIME --mtime=MTIME --name-servers=NAME_SERVERS Name Servers (space delimited) --name-servers-search=NAME_SERVERS_SEARCH Name Servers Search Path (space delimited) --mgmt-classes=MGMT_CLASSES Management Classes (For external configuration management) --mgmt-parameters=MGMT_PARAMETERS Management Parameters (Parameters which will be handed to your management application (Must be valid YAML dictionary)) --boot-files=BOOT_FILES TFTP Boot Files (Files copied into tftpboot beyond the kernel/initrd) --fetchable-files=FETCHABLE_FILES Fetchable Files (Templates for tftp or wget/curl) --template-files=TEMPLATE_FILES Template Files (File mappings for built-in config management) --redhat-management-key=REDHAT_MANAGEMENT_KEY Red Hat Management Key (Registration key for RHN, Spacewalk, or Satellite) --redhat-management-server=REDHAT_MANAGEMENT_SERVER Red Hat Management Server (Address of Spacewalk or Satellite Server) --template-remote-kickstarts=TEMPLATE_REMOTE_KICKSTARTS --clobber allow add to overwrite existing objects --in-place edit items in kopts or ksmeta without clearing the other items
[root@localhost kickstarts]# cobbler profile edit --name=Centos-6.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/Centos-6.8-x86_64.cfg
[root@localhost kickstarts]# cobbler profile edit --name=Centos-6.6-x86_64 --kopts='net.ifnames=0 biosdevname=0' #网卡设置为ETH0
[root@localhost kickstarts]# cobbler sync
修改安装栏首页(/etc/cobbler/pxe/pxedefault.template ):
[root@localhost kickstarts]# vim /etc/cobbler/pxe/pxedefault.template DEFAULT menu PROMPT 0 MENU TITLE Cobbler By xuxuedong| http://cobbler.github.io TIMEOUT 200 TOTALTIMEOUT 6000 ONTIMEOUT $pxe_timeout_profile LABEL local MENU LABEL (local) MENU DEFAULT LOCALBOOT -1 $pxe_menu_items MENU end
四、定制化安装
[root@localhost kickstarts]# cobbler system add --name=xuxuedong --mac=00:50:56:20:7A:F1 --profile=Centos-7-x86_64 --ip-address=172.22.0.250 --subnet=255.255.255.0 --gateway=172.22.0.17 --interface=eth0 --static=1 --hostname=fqdb --name-servers="211.137.96.205 61.139.2.69"
安装完成后自动有网卡、IP地址、网关、DNS
修改:Cobbler-web配置文件:
[root@localhost httpd]# cd /etc/httpd/conf.d/
[root@localhost conf.d]#
[root@localhost conf.d]# ls
cobbler.conf cobbler_web.conf README welcome.conf wsgi.conf
修改Cobbler-web访问密码:
[root@localhost conf.d]# cd /etc/cobbler/ [root@localhost cobbler]# ls auth.conf cobbler_web.conf ldap rsync.exclude version cheetah_macros completions modules.conf rsync.template zone.template cobbler_bash dhcp.template mongodb.conf secondary.template zone_templates cobbler.conf distro_signatures.json named.template settings cobblerd dnsmasq.template power tftpd.template cobblerd_rotate import_rsync_whitelist pxe users.conf cobblerd.service iso reporting users.digest 以下两个文件为:users.conf users.digest 用户权限文件和密码文件
可用命令修改:
[root@localhost conf.d]#htdigest /etc/cobbler/users.digest "Cobbler" cobbler
web访问:
Web界面登录地址:
http://172.22.0.60/cobbler_web/do_login #为cobbler主机地址
如果web登录报错解决方法:
[Errno 13] Permission denied: '/var/lib/cobbler/webui_sessions/sessionidd886ab4b38127a9a21f9d8cfb831511a' [root@localhost cobbler]# yum install semanage chcon -R -t httpd_cobbler_rw_content_t /var/lib/cobbler/webui_sessions [root@localhost ~]# cd /var/lib/cobbler/webui_sessions/ [root@localhost cobbler]# chown apache webui_sessions
五、完成部署可实现自动化安装