服务器:172.16.5.241html
操做系统版本:centos7.4python
客户端:虚拟机客户端,内存最少2GBlinux
运维自动化在生产环境中占据着举足轻重的地位,尤为是面对几百台,几千台甚至几万台的服务器时,仅仅是安装操做系统,若是不经过自动化来完成,根本是不可想象的。面对生产环境中不一样服务器的需求,该如何实现批量部署多版本的操做系统呢?Cobbler即可以知足这一实际需求,实现多版本操做系统批量部署git
Cobbler是一个Linux服务器安装的服务,能够经过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还能够管理DHCP,DNS等。github
Cobbler可使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,能够方便二次开发使用。web
Cobbler是较早前的kickstart的升级版,优势是比较容易配置,还自带web界面比较易于管理。shell
Cobbler内置了一个轻量级配置管理系统。vim
Cobbler官网http://cobbler.github.iocentos
在使用cobbler以前须要了解kickstart的使用: http://www.cnblogs.com/clsn/p/7833333.htmlapi
cobbler集成的服务:
PXE服务支持
DHCP服务管理
DNS服务管理(可选bind,dnsmasq)
电源管理
Kickstart服务支持
YUM仓库管理
TFTP(PXE启动时须要)
Apache(提供kickstart的安装源,并提供定制化的kickstart配置)
1、服务器安装。
注意我这里使用虚拟机实现的,由于cobbler须要搭建dhcp服务,因此我这里先安装了全部的须要安装包,启动了全部应该启动的服务,除了dhcp。测试的时候我使用虚拟机nat网卡模式,并关闭了虚拟机自带的dhcp服务。
一、安装基本组件
yum -y install wget net-tools curl epel-release
二、更新
yum -y update
三、关闭iptables与selinux,下面的全部操做完成后,重启服务器,不然后面会报错。
vim /etc/selinux/config
SELINUX=disabled
关闭iptables或者firewalld,开机不启动。
一、安装全部依赖服务
yum -y install dhcp httpd xinetd tftp-server rsync fence-agents pykickstart
二、设置开机自启动,dhcpd服务咱们后面再启动。
systemctl enable xinetd dhcpd httpd rsyncd systemctl start xinetd httpd rsyncd
三、安装cobbler
yum -y install cobbler-web
设置开机启动:
systemctl enable cobblerd systemctl start cobblerd
四、效验cobbler安装条件,注意观察是否有报错
cobbler check
[root@localhost ~]# cobbler check httpd does not appear to be running and proxying cobbler, or SELinux is in the way. Original traceback: Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/cobbler/cli.py", line 251, in check_setup s.ping() File "/usr/lib64/python2.7/xmlrpclib.py", line 1233, in __call__ return self.__send(self.__name, args) File "/usr/lib64/python2.7/xmlrpclib.py", line 1591, in __request verbose=self.__verbose File "/usr/lib64/python2.7/xmlrpclib.py", line 1273, in request return self.single_request(host, handler, request_body, verbose) File "/usr/lib64/python2.7/xmlrpclib.py", line 1321, in single_request response.msg, ProtocolError: <ProtocolError for 127.0.0.1:80/cobbler_api: 404 Not Found>
五、随机生成一个密码,这个密码就是你待会儿自动安装完操做系统之后的开机密码。复制生成的密码,待会儿须要写到配置文件中。
openssl passwd -1 -salt "root" "yunwei.123"
六、更改cobbler配置文件
vim /etc/cobbler/settings
只须要改配置文件中的这几项便可。
.......... default_password_crypted: "$1$cobbler$zPOuqy9SLOb87DIQb3RbQ." #第三步生成的密码 manage_dhcp: 1 #dhcp服务 manage_tftpd: 1 #xinetd服务 manage_rsync: 1 #rsyncd服务 next_server: 172.16.5.241 #替换成本机IP地址,dhcp服务地址 server: 172.16.5.241 #替换为本机IP地址,cobber服务地址 ..........
七、更新load信息
cobbler get-loaders
[root@bogon ~]# cobbler get-loaders task started: 2018-08-07_103302_get_loaders task started (id=Download Bootloader Content, time=Tue Aug 7 10:33:02 2018) downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0 downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32 downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi *** TASK COMPLETE ***
八、vim /etc/xinetd.d/tftp,设置tftp配置文件,‘disable'为'no'
service tftp { disable = no socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -B 1380 -v -s /var/lib/tftpboot per_source = 11 cps = 100 2 flags = IPv4 }
九、修改dhcp配置文件,先不要启动dhcp。
vim /etc/cobbler/dhcp.template
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 172.16.5.0 netmask 255.255.255.0 { option routers 172.16.5.1; option domain-name-servers 202.96.209.5,202.96.209.133; option subnet-mask 255.255.255.0; range dynamic-bootp 172.16.5.60 172.16.5.100; default-lease-time 21600; max-lease-time 43200; next-server $next_server; class "pxeclients" { match if substring (option vendor-class-identifier, 0, 9) = "PXEClient"; if option pxe-system-type = 00:02 { filename "ia64/elilo.efi"; } else if option pxe-system-type = 00:06 { filename "grub/grub-x86.efi"; } else if option pxe-system-type = 00:07 { filename "grub/grub-x86_64.efi"; } else if option pxe-system-type = 00:09 { filename "grub/grub-x86_64.efi"; } else { filename "pxelinux.0"; } } }
十、同步Cobbler,这里会把/etc/cobbler/dhcp.template这个文件咱们配置好的内容同步到/etc/dhcp/dhcpd.conf文件中,不然dhcp不能正常使用。
cobbler sync
[root@bogon dhcp]# cobbler sync task started: 2018-08-07_120115_sync task started (id=Sync, time=Tue Aug 7 12:01:15 2018) 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.efi -> /var/lib/tftpboot/grub/grub-x86.efi trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi copying distros to tftpboot copying images generating PXE configuration files generating PXE menu structure rendering DHCP files generating /etc/dhcp/dhcpd.conf rendering TFTPD files generating /etc/xinetd.d/tftp cleaning link caches rendering Rsync files running post-sync triggers running python triggers from /var/lib/cobbler/triggers/sync/post/* running python trigger cobbler.modules.sync_post_restart_services running: dhcpd -t -q received on stdout: received on stderr: running: service dhcpd restart received on stdout: received on stderr: Redirecting to /bin/systemctl restart dhcpd.service 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 ***
allow booting; allow bootp; ignore client-updates; set vendorclass = option vendor-class-identifier; option pxe-system-type code 93 = unsigned integer 16; subnet 172.16.5.0 netmask 255.255.255.0 { option routers 172.16.5.1; option domain-name-servers 172.16.5.1; option subnet-mask 255.255.255.0; range dynamic-bootp 172.16.5.100 172.16.5.254; default-lease-time 21600; max-lease-time 43200; next-server 172.16.5.241; class "pxeclients" { match if substring (option vendor-class-identifier, 0, 9) = "PXEClient"; if option pxe-system-type = 00:02 { filename "ia64/elilo.efi"; } else if option pxe-system-type = 00:06 { filename "grub/grub-x86.efi"; } else if option pxe-system-type = 00:07 { filename "grub/grub-x86_64.efi"; } else if option pxe-system-type = 00:09 { filename "grub/grub-x86_64.efi"; } else { filename "pxelinux.0"; } } } # group for Cobbler DHCP tag: default group { }
一、建立操做系统文件夹,虚拟机添加对应的操做系统iso文件,而后挂载。
mkdir -p /data/iso/centos7.4 #挂载 mount /dev/cdrom /data/iso/centos7.4
二、把挂载光盘镜像的mnt目录中的内容导入到cobbler
cobbler import --path=/data/iso/centos7.4 --name=centos7.4
三、接着同步cobber report查看导入信息
cobbler report
[root@bogon centos7.4]# cobbler import --path=/data/iso/centos7.4 --name=centos7.4 task started: 2018-08-07_103802_import task started (id=Media import, time=Tue Aug 7 10:38:02 2018) Found a candidate signature: breed=redhat, version=rhel6 Found a candidate signature: breed=redhat, version=rhel7 Found a matching signature: breed=redhat, version=rhel7 Adding distros from path /var/www/cobbler/ks_mirror/centos7.4: creating new distro: centos7.4-x86_64 trying symlink: /var/www/cobbler/ks_mirror/centos7.4 -> /var/www/cobbler/links/centos7.4-x86_64 creating new profile: centos7.4-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/centos7.4 for centos7.4-x86_64 processing repo at : /var/www/cobbler/ks_mirror/centos7.4 need to process repo/comps: /var/www/cobbler/ks_mirror/centos7.4 looking for /var/www/cobbler/ks_mirror/centos7.4/repodata/*comps*.xml Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos7.4/repodata *** TASK COMPLETE ***
web界面查看,已经看到了咱们刚才生成的操做系统。
注意:
前面咱们不是执行cobbler check命令报错么,如今咱们在check一下,
cobbler check
[root@bogon centos7.4]# 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 : debmirror package is not installed, it will be required to manage debian deployments and repositories 4 : 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.
一、前面服务器都支直接链接互联网的,这里面是有dhcp服务器,若是我启动cobbler的dhcp,那同事就得“炸锅了”,因此这里我先把服务器网卡换NAT模式,并关闭vmware workstation里面的DHCP服务。
二、检查前面咱们安装的服务是否正常。
三、启动DHCP服务。
四、新建一个虚拟机,网卡选择NAT,不须要挂载操做系统光盘,直接开机便可。
五、启动客户端,这里若是等待时间很长的话,证实的你的tftp服务有问题,重启一下服务器,客户端在从新启动就OK了。
六、开始安装,刚才咱们生成的镜像,上下键选择要安装的操做系统,回车便可,剩下的只有等。
七、默认分区
https://服务器IP地址/cobbler_web默认用户名和密码是cobbler,在这里面咱们能看到刚才咱们建立的这个centos7的镜像。
若是想修改cobbler登陆密码使用以下命令:
htdigest /etc/cobbler/users.digest "Cobbler" cobbler
查看一下咱们的版本库列表
cobbler distro list
#report详细查看一下库信息
cobbler distro report
#查看配置的详细信息,这个就很是有用了,标红的文件是默认配置文件,。
cobbler profile report
参考地址:
一、https://www.linuxidc.com/Linux/2018-03/151347.htm
二、https://www.cnblogs.com/clsn/p/7839965.html?utm_source=debugrun&utm_medium=referral
设置安装密码,上面咱们设置了cobbler的页面密码,若是咱们有不少的操做系统,随便一个服务器启动后dhcp就能够安装操做系统,没有密码很危险。
一、建立密码
#生成密码(yunwei.123才是密码,前面的root随意) openssl passwd -1 -salt root yunwei.123
#生成的密码 $1$root$vQ5iF/QlePLjafcRq8lCw/
第二步:编辑文件pxedefault:
# vim /etc/cobbler/pxe/pxedefault.template
DEFAULT menu PROMPT 0 MENU TITLE Cobbler | http://cobbler.github.io/ #细心的同窗发现,http是安装界面的显示内容 MENU MASTER PASSWD $1$root$vQ5iF/QlePLjafcRq8lCw/ #加入这一行,把前面的密码加进来 TIMEOUT 200 TOTALTIMEOUT 6000 ONTIMEOUT $pxe_timeout_profile LABEL local MENU LABEL (local) MENU DEFAULT LOCALBOOT -1 $pxe_menu_items MENU end
第三步:配置pxeprofile:
#vim /etc/cobbler/pxe/pxeprofile.template
LABEL $profile_name MENU PASSWD #只须要加这一行便可 kernel $kernel_path $menu_label $append_line ipappend 2
第四步:检查、同步配置使其生效
#cobbler check
#cobbler sync
#/etc/init.d/cobblerd restart
第五步:PXE装机选择版本查看效果:
自定义配置和分区
这个功能咱们必须得会,由于默认操做系统会.ks文件加参数autopart,意思就是自动分区。咱们生产中哪怕是试验,也没有这么分区的(/var/lib/cobbler/kickstarts/sample_end.ks,我这里的centos7.4是这个默认安装配置文件)
一、首先咱们得知道咱们安装的这个操做系统默认用的是哪一个.ks文件,圈红色的全都是默认的ks文件。
那咱们的操做系统默认用的是哪一个呢?
我这里默认是这个配置文件
二、首先咱们点击sample_end.ks这个咱们默认的配置文件,而后全选里面的内容。最后按照以下,咱们新建一个本身ks文件,把刚才复制的内容所有粘贴到里面。
这里还设置了默认关闭selinux,固然,你还能够写默认要安装哪些软件。
# This kickstart file should only be used with EL > 5 and/or Fedora > 7. # For older versions please use the sample.ks kickstart file. #platform=x86, AMD64, or Intel EM64T # System authorization information auth --useshadow --enablemd5 # System bootloader configuration bootloader --location=mbr # Partition clearing information clearpart --all --initlabel part /boot --fstype xfs --size 500 part swap --size 2048 part / --fstype xfs --size 3000 part /data --fstype xfs --size 1 --grow # 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 firewall --disabled # Do not configure the X Window System skipx # System timezone timezone Asia/Shanghai # 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 %end
其它配置参考:https://www.cnblogs.com/clsn/p/7839965.html?utm_source=debugrun&utm_medium=referral#auto_id_15
一、No space left on device
客户端在安装操做系统的时候报下面这个错误,那是由于你的机器内存太少了,最少也得2GB内存。
将内存调为2G便可(这个错误只会出如今CentOS7.3之上)