自動化運維——CentOS7下利用Cobbler批量部署CentOS
Cobbler的配置文件位置及配置:
1.) Cobbler配置文件目錄:/etc/cobbler
/etc/cobbler/settings #cobbler主配置文件
/etc/cobbler/dhcp.template #DHCP服務的配置模板
/etc/cobbler/tftpd.template #tftp服務的配置模板
/etc/cobbler/rsync.template #rsync服務的配置模板
/etc/cobbler/iso #iso模板配置文件
/etc/cobbler/pxe #pxe模板文件
/etc/cobbler/power #電源的配置文件
/etc/cobbler/users.conf #Web服務授權配置文件
/etc/cobbler/users.digest #用於web訪問的用戶名密碼配置文件
/etc/cobbler/dnsmasq.template #DNS服務的配置模板
/etc/cobbler/modules.conf #Cobbler模塊配置文件
2.) Cobbler數據目錄:/var/lib/cobbler
/var/lib/cobbler/config #配置文件
/var/lib/cobbler/triggers #Cobbler命令
/var/lib/cobbler/kickstarts #默認存放kickstart文件
/var/lib/cobbler/loaders #存放的各種引導程序
3.) 系統安裝鏡像目錄:/var/www/cobbler
/var/www/cobbler/ks_mirror #導入的系統鏡像列表
/var/www/cobbler/images #導入的系統鏡像啟動文件
/var/www/cobbler/repo_mirror #yum源存儲目錄
4.) 日誌目錄:/var/log/cobbler
/var/log/cobbler/install.log #客戶端系統安裝日誌
/var/log/cobbler/cobbler.log #cobbler日誌
下面我們來完成Cobbler服務的搭建:
Cobbler環境是由EPEL源提供的,我們先到站點下載EPEL源:
[root@CentOS7-1 Desktop]# yum -y install http://mirrors.163.com/centos/7/extras/x86_64/Packages/epel-release-7-11.noarch.rpm ##安裝EPEL源 [root@CentOS7-1 ~]# yum install cobbler cobbler-web dhcp tftp-server pykickstart httpd rsync xinetd -y ##安裝系統部署所需所有服務
開啟服務,設置開機自啟動方便以後使用,關閉防火墻及增強安全功能:
[root@CentOS7-1 ~]# systemctl restart httpd [root@CentOS7-1 ~]# systemctl restart cobblerd [root@CentOS7-1 ~]# systemctl enable httpd.service [root@CentOS7-1 ~]# systemctl enable cobblerd.service [root@CentOS7-1 ~]# systemctl stop firewalld [root@CentOS7-1 ~]# setenforce 0
執行cobbler check,檢查需要優化的點,需要註意的是,優化完成後要重啟服務使你的優化生效:
[root@CentOS7-1 ~]# 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 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment: https://github.com/cobbler/cobbler/wiki/Selinux 4 : change 'disable' to 'no' in /etc/xinetd.d/tftp 5 : 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. 6 : enable and start rsyncd.service with systemctl 7 : debmirror package is not installed, it will be required to manage debian deployments and repositories 8 : 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 9 : 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.
此時,我們按照上面需要優化的點逐步去優化:
修改cobbler配置文件:
[root@CentOS7-1 ~]# vim /etc/cobbler/settings 將“next_server: 127.0.0.1”修改為“next_server: 192.168.117.130” ##指定PXE位置,這裏用的為本機地址 將“server: 127.0.0.1”修改為“server: 192.168.117.130” 將"manage_dhcp: 0"修改為"manage_dhcp: 1" ##管理dhcp啟動
修改cobbler默認密碼:
[root@CentOS7-1 ~]# openssl passwd -1 -salt '123123' '123123' ##鹽值加密 $1$abner$kDle2KnwbPHdm1UZEE79V. ##得到一串密碼 [root@CentOS7-1 ~]# vim /etc/cobbler/settings ##回setting文件搜索默認密碼 default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac." ##將得到的密碼復制到雙撇號內
下載引導操作系統文件:
[root@CentOS7-1 ~]# cobbler get-loaders task started: 2018-05-31_144102_get_loaders task started (id=Download Bootloader Content, time=Thu May 31 14:41: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 *** ##顯示任務完成
啟用tftp服務:
[root@CentOS7-1 ~]# vim /etc/xinetd.d/tftp # default: off # description: The tftp server serves files using the trivial file transfer # protocol. The tftp protocol is often used to boot diskless # workstations, download configuration files to network-aware printers, # and to start the installation process for some operating systems. service tftp { socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /var/lib/tftpboot disable = no ##修改為no啟用服務 per_source = 11 cps = 100 2 flags = IPv4
配置cobbler控制的dhcp模板:
[root@CentOS7-1 ~]# vim /etc/cobbler/dhcp.template ##省略部分信息 set vendorclass = option vendor-class-identifier; option pxe-system-type code 93 = unsigned integer 16; subnet 192.168.117.0 netmask 255.255.255.0 { //修改子網 option routers 192.168.117.1; //修改網關 option domain-name-servers 192.168.117.2; //修改DNS option subnet-mask 255.255.255.0; range dynamic-bootp 192.168.117.100 192.168.117.200; //指定地址池,和cobbler服務器在同一網段 default-lease-time 21600; max-lease-time 43200; next-server $next_server;
幫助生成DHCP配置文件:
[root@CentOS7-1 ~]# cobbler sync task started: 2018-05-31_145223_sync task started (id=Sync, time=Thu May 31 14:52:23 2018) running pre-sync triggers cleaning trees removing: /var/lib/tftpboot/grub/images copying bootloaders copying: /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0 copying: /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32 copying: /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot copying: /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk copying: /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi copying: /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 TFTPD files generating /etc/xinetd.d/tftp cleaning link caches running post-sync triggers running 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 *** ##顯示配置成功!
重啟服務使配置生效:
[root@CentOS7-1 ~]# systemctl restart cobblerd [root@CentOS7-1 ~]# systemctl restart rsyncd [root@CentOS7-1 ~]# systemctl enable rsyncd [root@CentOS7-1 ~]# systemctl restart xinetd [root@CentOS7-1 ~]# systemctl restart dhcpd
再次執行cobbler check檢查:
[root@CentOS7-1 ~]# cobbler check ##下面三條可以忽略不去處理 The following are potential configuration items that you may want to fix: 1 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment: https://github.com/cobbler/cobbler/wiki/Selinux 2 : debmirror package is not installed, it will be required to manage debian deployments and repositories 3 : 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.
導入iso鏡像文件到cobbler中:
[root@CentOS7-1 cobbler]# mount /dev/cdrom /mnt ##掛載鏡像光盤到mnt目錄中 mount: /dev/sr0 is write-protected, mounting read-only [root@CentOS7-1 cobbler]# cobbler import --path=/mnt/ --name=CentOS-7-x86_64 --arch=x86_64 ##導入iso鏡像 task started: 2018-05-31_150936_import task started (id=Media import, time=Thu May 31 15:09:36 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/CentOS-7-x86_64: creating new distro: CentOS-7-x86_64 trying symlink: /var/www/cobbler/ks_mirror/CentOS-7-x86_64 -> /var/www/cobbler/links/CentOS-7-x86_64 creating new profile: CentOS-7-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-7-x86_64 for CentOS-7-x86_64 processing repo at : /var/www/cobbler/ks_mirror/CentOS-7-x86_64 ##默認導入存放位置 need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS-7-x86_64 looking for /var/www/cobbler/ks_mirror/CentOS-7-x86_64/repodata/*comps*.xml Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS-7-x86_64/repodata *** TASK COMPLETE ***
cobbler安裝界面,選擇CentOS-7-x86_64即可完成安裝:
完成安裝後的CentOS 7:
Cobbler-Web,網絡訪問:
設置一個cobbler-web登錄用戶及密碼:
[root@CentOS7-1 cobbler]# htdigest -c /etc/cobbler/users.digest Cobbler cobbler ##設置用戶名為cobbler Adding password for cobbler in realm Cobbler. New password: Re-type new password: [root@CentOS7-1 cobbler]# systemctl restart cobblerd.service [root@CentOS7-1 cobbler]# systemctl restart httpd
cobbler-web的登錄界面:
自動化運維——CentOS7下利用Cobbler批量部署CentOS