cobbler批量安裝系統使用詳解-技術流ken
1.前言
cobbler是一個可以實現批量安裝系統的Linux應用程序。它有別於pxe+kickstart,cobbler可以實現同個服務器批量安裝不同操作系統版本。
2.系統環境準備及其下載cobbler
一.系統環境
系統版本:CentOS release 6.7 (Final)
內網IP:192.168.232.7/24 #用來對內通信,提供cobbler服務
外網IP:10.220.5.166/24 #連接外網
二. 關閉安全服務
[root@ken ~]# cat /etc/redhat-release #檢查系統版本 CentOS release6.7 (Final) [root@ken ~]# service iptables stop #關閉防火墻 [root@ken ~]# setenforce 0 #關閉selinux
三. 下載cobbler及其所需服務程序
[root@ken ~]# yum install cobbler dhcp tftp-server xinetd syslinux httpd pykickstart -y
yum安裝cobbler需要使用網絡yum源,大家可以復制下面的代碼到自己的yum倉庫保存即可
[epel] name=epel enabled=1 gpgcheck=0 baseurl=https://mirrors.aliyun.com/epel/6Server/x86_64/
3.配置dhcp
[root@ken ~]# vim /etc/dhcp/dhcpd.conf #配置dhcp配置文件,並寫入如下代碼 subnet 192.168.232.0 netmask 255.255.255.0 { range 192.168.232.10 192.168.232.20; option domain-name-servers 8.8.8.8; option routers 192.168.232.7; default-lease-time 600; max-lease-time 7200; filename "pxelinux.0"; } [root@ken ~]# service dhcpd restart #重啟dhcpd服務,使之配置生效 Starting dhcpd: [ OK ]
4.配置tftp
[root@ken ~]# 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 #把yes修改為no,即啟動tftp服務 per_source = 11 cps = 100 2 flags = IPv4 } [root@ken ~]# service xinetd restart #重啟xinetd,使之配置生效 Stopping xinetd: [FAILED] Starting xinetd: [ OK ] [root@ken ~]# chkconfig xinetd on #把xinetd加入系統啟動項,實現開機自動啟動 [root@ken ~]# chkconfig --list | grep tftp #檢查確認tftp是否已經成功開啟 tftp: on
5.配置cobbler
首先檢查cobbler配置
[root@ken ~]# 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.
根據如上反饋,需要一一進行修改才能繼續進行
問題一:
cobbler文件默認是127.0.0.1本地回環地址,需要更改為提供cobbler服務的ip地址 192.163.232.7
[root@ken ~]# sed -i ‘s/server: 127.0.0.1/server: 192.168.232.7/g‘ /etc/cobbler/settings
問題二:
netx_server也是默認本地127.0.0.1回環地址,需要修改為提供cobbler服務的ip地址 192.163.232.7
[root@ken ~]# sed -i ‘s/next_server: 127.0.0.1/next_server: 192.168.232.7/g‘ /etc/cobbler/settings
問題三:
可以忽略
問題四:
啟動rsync即可
[root@ken ~]# 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 #yes更改為no flags = IPv6 socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID } [root@ken ~]# service xinetd restart #重啟xinetd服務 Stopping xinetd: [ OK ] Starting xinetd: [ OK ] [root@ken ~]# chkconfig --list | grep rsync #檢查rsync是否已經啟動 rsync: on
問題五:
可以忽略
問題六:
更改密碼,並把新生成的加密數據填寫進/etc/cobbler/settings
[root@ken ~]# openssl passwd -1 -salt ‘123‘ ‘123456‘ $1$123$7mft0jKnzzvAdU4t0unTG1 [root@ken ~]# vim /etc/cobbler/settings 92 # cobbler has various sample kickstart templates stored 93 # in /var/lib/cobbler/kickstarts/. This controls 94 # what install (root) password is set up for those 95 # systems that reference this variable. The factory 96 # default is "cobbler" and cobbler check will warn if 97 # this is not changed. 98 # The simplest way to change the password is to run 99 # openssl passwd -1 100 # and put the output between the "" below. 101 default_password_crypted: "$1$123$7mft0jKnzzvAdU4t0unTG1" #把新生成的加密密碼填寫在101行處 102 103 # the default template type to use in the absence of any 104 # other detected template. If you do not specify the template 105 # with ‘#template=<template_type>‘ on the first line of your 106 # templates/snippets, cobbler will assume try to use the 107 # following template engine to parse the templates.
問題七:
可以忽略
以上問題解決之後,需要同步和重啟
[root@ken ~]# service cobblerd restart #重啟cobbler服務
[root@ken ~]# cobbler sync #進行同步
再次檢查是否已經更改完成
[root@ken ~]# cobbler check The following are potential configuration items that you may want to fix: 1 : 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. 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.
已經更改完畢!
6.掛載光盤並進行數據導入
掛載光盤
[root@ken ~]# mount /dev/cdrom /mnt
數據導入
[root@ken ~]# cobbler import --path=/mnt --name=centos6.7 #進行數據導入 task started: 2018-09-09_021922_import task started (id=Media import, time=Sun Sep 9 02:19:22 2018) Found a candidate signature: breed=redhat, version=rhel6 Found a matching signature: breed=redhat, version=rhel6 Adding distros from path /var/www/cobbler/ks_mirror/centos6.7: creating new distro: centos6.7-x86_64 trying symlink: /var/www/cobbler/ks_mirror/centos6.7 -> /var/www/cobbler/links/centos6.7-x86_64 creating new profile: centos6.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/centos6.7 for centos6.7-x86_64 processing repo at : /var/www/cobbler/ks_mirror/centos6.7 need to process repo/comps: /var/www/cobbler/ks_mirror/centos6.7 looking for /var/www/cobbler/ks_mirror/centos6.7/repodata/*comps*.xml Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos6.7/repodata *** TASK COMPLETE ***
查看distro
[root@ken ~]# cobbler distro list centos6.7-x86_64
查看profile
[root@ken ~]# cobbler profile list centos6.7-x86_64
7.自定義profile
[root@ken ~]# cobbler profile add --distro=centos6.7-x86_64 --name=centos6.7_ken --kickstart=/var/lib/cobbler/kickstarts/ks.cfg [root@ken ~]# cobbler sync
8. 準備ks文件
在root目錄下找到ks文件,並移動到/var/lib/cobbler/kickstarts/到目錄下改名為ks.cfg
[root@ken ~]# ls anaconda-ks.cfg install.log install.log.syslog [root@ken ~]# mv anaconda-ks.cfg /var/lib/cobbler/kickstarts/ks.cfg [root@ken ~]# vim /var/lib/cobbler/kickstarts/ks.cfg
# Kickstart file automatically generated by anaconda.
#version=DEVEL
install
# Kickstart file automatically generated by anaconda.
#version=DEVEL
install
url --url=http://192.168.232.7/cobbler/ks_mirror/centos6.7/ #這裏需要更改為repodata所在的http地址
lang en_US.UTF-8
keyboard us
network --onboot no --device eth0 --bootproto dhcp --noipv6
rootpw 123
reboot
firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone --utc Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
clearpart --all
zerombr
part /boot --fstype=ext4 --size=500
part pv.008002 --grow --size=1
volgroup VolGroup --pesize=4096 pv.008002
logvol / --fstype=ext4 --name=lv_root --vgname=VolGroup --grow --size=1024 --maxsize=51200
logvol swap --name=lv_swap --vgname=VolGroup --grow --size=2016 --maxsize=2016
repo --name="CentOS" --baseurl=http://192.168.232.7/cobbler/ks_mirror/centos6.7/ --cost=100 #這裏的地址和上面的url地址保持一致
%packages
@core
@server-policy
@workstation-policy
%end
9.重啟服務
[root@ken ~]# service httpd restart [root@ken ~]# service cobblerd restart [root@ken ~]# service dhcpd restart [root@ken ~]# service xinetd restart
10.測試
新建一個虛擬機,需要和cobbler服務器所在同一個虛擬網絡中(nat,橋接等)。
選擇第二個我們自定義的包即可進行自動化安裝。
開始安裝
安裝完成
接下來的博文將會介紹如何使用cobbler,實現在同一個服務器批量安裝不同版本系統。
以及pxe+kickstart的安裝。
因為熱愛 所以熾熱
--技術流ken
cobbler批量安裝系統使用詳解-技術流ken