linux cobbler 自动安装centos6与centos7系统
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux cobbler 自动安装centos6与centos7系统相关的知识,希望对你有一定的参考价值。
1.1 Cobbler介绍
Cobbler 是一个免费开源系统安装部署软件,用于自动化网络安装操作系统。 Cobbler 集成了 DNS, DHCP, 软件包更新,带外管理以及配置管理,方便操作系统安装自动化。 Cobbler 可以支持PXE启动, 操作系统重新安装,以及虚拟化客户机创建,包括Xen, KVM or VMware. Cobbler 透过koan程序以支持虚拟化客户机安装。 Cobbler 可以支持管理复杂网路环境,如建立在链路聚合以太网的桥接环境。
1.2 cobbler 服务集成
1 pxe 服务 2 DHCP 3 Rsync 4 HTTP 5 DNS 6 Kickstart 7 IPMI 电源管理
1.3 cobbler的设计方式
发行版(distro) :表示一个操作系统,它承载了内核和initrd的信息,以及内核等其他数据 存储库 (repository):保存了一个yum或者rsync存储库的镜像信息 配置文件(profile):包含了一个发行版(distro),一个kickstart文件以及可能的存储库(repository),还包含了更多的内核参数等其他数据 系统(system):表示要配给的机器,它包含了一个配置文件或一个镜像,还包含了ip和mac地址,电源管理(地址,凭据,类型)以及更为专业的数据信息 镜像(image):可替换一个包含不属于此类别的文件的发行版对象(eg: 无法为内核和initrd的对象)
以上各个组件中, 发行版,存储库, 配置文件为必须配置项
只有在虚拟环境中,必须要用cobbler来引导虚拟机启动时候,才会用到系统组件
但事实上,在生产环境中需要大量的虚拟机实例的话,通常利用openstack等来实现虚拟机节点
1.4 cobbler 运行的流程
- DHCP - Client (从dhcp服务器获取地址,访问next_server的ip地址) - Next_server (获取启动内核,initrd等文件) - tftp (pxe引导文件 启动cobbler选择界面) - kickstart (确定加载项,根据nfs,http,ftp等共享)
1.5 cobbler units
- cobbler - cobbler-web
2.1 准备环境
1 安装cobbler 依据cobbler check检查结果,对setting主配置文件的设置,进行相关的修正设置
2 启动先相关的httpd cobbler服务,使用cobbler rsync 同步设置
3 配置 cobbler 所依赖的服务
dhcp: isc dhcpd , dnsmasq (必须服务,选择其一管理即可)
dns: bing , dnsmasq (可选)
rysnc: rsync (必须服务)
tftp: in,tftp(tftp-server) ,cobbler自带的tftp(必须服务 ,选择其中其一管理即可)
4 安装epel源
[[email protected] ~]# yum install -y wget [[email protected] ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
5 设置ip转发
[[email protected] ~]# echo 1 > /proc/sys/net/ipv4/ip_forward [[email protected] ~]# sed -i ‘s/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/‘ /etc/sysctl.conf [[email protected] ~]# sysctl -p
2.2 安装Cobbler
[[email protected] ~]#yum -y install cobbler dhcp httpd xinetd tftp-server syslinux pykickstart xinetd rsync cobbler-web
2.3 调整为动态配置Cobbler
动态更新配置
对于Cobbler2.4来说,有一个重要的功能,就是让你可以不需要手工去编辑setting配置文件,直接使用命令去修改,默认这个功能是不启用,你需要启用。
[[email protected] cobbler]# cp settings settings.bak [[email protected] cobbler]# sed -i ‘s/^[[:space:]]\+/ /‘ /etc/cobbler/settings [[email protected] cobbler]# sed -i ‘s/allow_dynamic_settings: 0/allow_dynamic_settings: 1/g‘ /etc/cobbler/settings [[email protected] cobbler]# /etc/init.d/cobblerd restart Stopping cobbler daemon: [ OK ] Starting cobbler daemon: [ OK ]
2.4 检查需要安装的配置
[[email protected] ~]# 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 : 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 : since iptables may be running, ensure 69, 80/443, and 25151 are unblocked 7 : reposync is not installed, need for cobbler reposync, install/upgrade yum-utils? 8 : debmirror package is not installed, it will be required to manage debian deployments and repositories 9 : 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 10 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
#解决方法 [[email protected] cobbler]# cobbler setting edit --name=server --value=10.10.10.10 2: [[email protected] cobbler]# cobbler setting edit --name=next_server --value=10.10.10.10 3: 可以忽略 4: [[email protected] loaders]# openssl passwd -1 -salt `openssl rand -hex 4` "budongshu" $1$557d907c$AmKQun9Jxitt1D6aQ8DUC. [[email protected] cobbler]# cobbler setting edit --name=default_password_crypted > --value="$1$557d907c$AmKQun9Jxitt1D6aQ8DUC." 5: [[email protected] cobbler]# yum install cman #安装电源管理工具 #开机启动 [[email protected] cobbler]# chkconfig tftp on [[email protected] cobbler]# chkconfig rsync on [[email protected] cobbler]# /etc/init.d/xinetd restart #下载启动菜单 [[email protected] cobbler]# cobbler get-loaders #防止误重装系统 选项 pxe_just_one [[email protected] cobbler]# cobbler setting edit --name=pxe_just_once --value=1 #开启cobbler 管理dhcp服务器 [[email protected] cobbler]# cobbler setting edit --name=manage_dhcp --value="1" 2.5 同步cobbler [[email protected] cobbler]# service cobblerd restart Stopping cobbler daemon: [ OK ] Starting cobbler daemon: [ OK ] [[email protected] 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 triggerscleaning treesremoving: /var/lib/tftpboot/grub/imagescopying 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 imagesgenerating PXE configuration files generating PXE menu structurerendering TFTPD files generating /etc/xinetd.d/tftpcleaning link caches running post-sync triggersrunning 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 *** 重启 [[email protected] cobbler]# service cobblerd restart Stopping cobbler daemon: [ OK ] Starting cobbler daemon: [ OK ] 再次检查 [[email protected] cobbler]# cobbler check The following are potential configuration items that you may want to fix: 1 : debmirror package is not installed, it will be required to manage debian deployments and repositoriesRestart cobblerd and then run ‘cobbler sync‘ to apply changes. #上面配置成功
2.6 配置dhcp服务
[[email protected] 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; ...... 此时的dhcpd的配置就被cobbler覆盖,由cobbler来管理配置文件,截取的一部分,后面还有内容 [[email protected] cobbler]# vim /etc/dhcp/dhcpd.conf # ****************************************************************** # 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 { ...... ...... ......
编写启动脚本 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
2.7 配置ks文件
[[email protected] ~]# cobbler #cobbler命令 usage ===== cobbler <distro|profile|system|repo|image|mgmtclass|package|file> ... [add|edit|copy|getks*|list|remove|rename|report] [options|--help] cobbler <aclsetup|buildiso|import|list|replicate|report|reposync|sync|validateks|version|signature|get-loaders|hardlink> [options|--help] [[email protected] ~]# 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 查看配置信息
2.8 导入系统到cobbler
centos6.5
[[email protected] cobbler]# mount /dev/cdrom /mnt [[email protected] cobbler]# cobbler import --path=/mnt/ --name=Centos-6.5-x86_64 --arch=x86_64 [[email protected] 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‘: ‘ Management Classes : [] OS Version : rhel6 Owners : [‘admin‘] Red Hat Management Key : <<inherit>> Red Hat Management Server : <<inherit>> Template Files : {}
centos7
[[email protected] ~]# umount /mnt [[email protected] cobbler]# cobbler import --path=/mnt/ --name=Centos-7-x86_64 --arch=x86_64 [[email protected] 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://@@[email protected]@/cblr/links/Centos-7-x86_64‘} Management Classes : [] OS Version : rhel7 Owners : [‘admin‘] Red Hat Management Key : <<inherit>> Red Hat Management Server : <<inherit>> Template Files : {}
[[email protected] cobbler]# cobbler distro list Centos-6.5-x86_64 Centos-7-x86_64
2.9 修改默认ks文件
#配置centos6.5 [[email protected] kickstarts]#cd /var/lib/cobbler/kickstarts/ [[email protected] kickstarts]#cp sample_end.ks CentOS-6.5-x86_64.cfg [[email protected] kickstarts]#cobbler profile edit --name=Centos-6.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-6.5-x86_64.cfg [[email protected] kickstarts]# cat CentOS-6.5-x86_64.cfg # kickstart template for Fedora 8 and later. # (includes %end blocks) # do not use with earlier distros #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 were referenced in the kickstart profile, include them here. $yum_repo_stanza # Network information $SNIPPET(‘network_config‘) # Reboot after installation reboot #Root password rootpw --iscrypted $default_password_crypted # 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 as needed autopart %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‘) %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
#配置centos7 [[email protected] kickstarts]#cobbler profile edit --name=Centos-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg [[email protected] 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
#修改centos7 网卡label # 修改安装系统的内核参数,在CentOS7系统有一个地方变了,就是网卡名变成eno16777736这种形式,但是为了运维标准化, #我们需要将它变成我们常用的eth0,因此使用下面的参数。但要注意是CentOS7才需要下面的步骤,CentOS6不需要。 [[email protected] kickstarts]# cobbler profile edit --name=CentOS-7.1-x86_64 --kopts=‘net.ifnames=0 biosdevname=0‘ [[email protected] 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 : <<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
#查看
[[email protected] kickstarts]# cobbler profile report Centos-7-x86_64 [[email protected] kickstarts]# cobbler profile report Centos-6.5-x86_64
[[email protected] 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:
#配置本地yum仓库 可以忽略
[[email protected] ~]# mkdir /tmp/rpms [[email protected] ~]# createrepo /tmp/rpms #放入rpm包,执行此步骤 [[email protected] ~]# cobbler repo add --mirror=/tmp/rpms --name=local [[email protected] ~]# cobbler reposync
#配置本地epel仓库 可以忽略
[[email protected] ~]# cobbler repo add --mirror=http://mirrors.aliyun.com/epel/6/x86_64/ --name=epel [[email protected] ~]# cobbler reposync --tries=3 --no-fail #同步epel仓库到本地,需要较长时间#查看已添加的repo [[email protected] ~]# cobbler repo list epel local
#添加repo到profile 可以忽略
[[email protected] ~]# cobbler profile edit --name=Centos-6.5-x86_64 --repos="epel local" [[email protected] ~]# cobbler sync
#绑定mac地址 ,实现开机自动选择
#配置绑定mac地址和IP地址 ,开机自动选择
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"
3.0 配置cobbler web界面
cobbler-web支持多种认证方式,如authn_configfil、authn_ldap或authn_pam等,下面我们基于authn_pam做认证 #修改认证方式 [[email protected] web]# vim /etc/cobbler/modules.conf [authentication] module = authn_pam 添加系统用户 [[email protected] web]# useradd cobbler [[email protected] web]# echo "cobbler" | passwd --stdin cobbler 添加用户到管理组 [[email protected] web]# vim /etc/cobbler/modules.conf [admins] admin = "cobbler" 重启服务 Stopping cobbler daemon: [ OK ] Starting cobbler daemon: [ OK ] [[email protected] web]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ]
本文出自 “胡三刀” 博客,请务必保留此出处http://bdstravel.blog.51cto.com/8870307/1760637
以上是关于linux cobbler 自动安装centos6与centos7系统的主要内容,如果未能解决你的问题,请参考以下文章