1. 程式人生 > >cobbler自動化安裝操作系統

cobbler自動化安裝操作系統

enc check client write baseurl 復制 cman 127.0.0.1 logging

cobbler自動化安裝操作系統

cobbler是快速網絡安裝linux操作系統的服務,支持眾多的Linux發行版:Red Hat、
Fedora、CentOS、Debian、Ubuntu和SuSE,也可以支持網絡安裝windows

一、配置yum源

cobbler所在的源是epel源所以先配置yum源

[[email protected] ~]# vim /etc/yum.repos.d/base.repo
[base]
name=base
baseurl=file:///mnt
gpgcheck=0
[epel]
name=epel
baseurl=http://mirrors.sohu.com/fedora-epel/7/x86_64
gpgcheck=0

二、安裝cobbler和dhcp服務

[[email protected] ~]# yum install cobbler dhcp -y

三、啟動相關服務並設置為開機啟動

[[email protected] ~]# systemctl enable rsyncd httpd tftp cobblerd dhcpd
[[email protected] ~]# systemctl start rsyncd httpd tftp cobblerd

四、配置cobbler

1.使用cobbler check查看所需配置的內容

[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 : 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.

2.在/etc/cobbler/setting文件中查找到以下幾項並進行修改

server: 192.168.73.120                  #cobbler的服務器地址
next_server: 192.168.73.120             #tftp服務器地址
default_password_crypted: "$1$JZoCUmJG$PaPdl.tq3OW6KEXZbUaBP."      #修改默認密碼
manage_dhcp: 1                          #dhcpg管理設置為1

3.下載boot-loaders

[[email protected] ~]# cobbler get-loaders

4.修改cobbler的dhcp模板文件

[[email protected] ~]# vim /etc/cobbler/dhcp.template
...上面省略...
subnet 192.168.73.0 netmask 255.255.255.0 {                       #修改網段
     option routers             192.168.73.254;                   #指定網關
     option domain-name-servers 1.1.1.1;                          #指定dns
     option subnet-mask         255.255.255.0;                    #指定子網掩碼
     range dynamic-bootp        192.168.73.1 192.168.73.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";
          }
     }

}
...下面省略...

5.將cobbler的DHCP文件進行同步

[[email protected] ~]# cobbler sync

6.重啟cobbler服務以及DHCP服務

[[email protected] ~]# systemctl restart cobblerd
[[email protected] ~]# systemctl start dhcpd

五、為cobbler配置系統鏡像文件

1.將光盤掛載至一個空目錄

[[email protected] ~]# mount /dev/sr0 /mnt

2.將光盤內文件復制入cobbler,此步驟是將光盤的的文件復制至/var/www/cobbler/ks_mirror/目錄下

[[email protected] ~]# cobbler import --path=/mnt --name=Centos-6.10 --arch=x86_64

由於cobbler自帶了KS文件,所以現在已經能夠實現自動化安裝系統了,若要實現使用自己定制的KS文件,來實現自動化安裝看下面的補充。


補充

在實際生產環境中可能需要安裝各種不同的定制化的系統,此時就需要準備各種不同的ks文件,並將文件與相對應的系統關聯起來。

一、準備ks文件

1.ks文件可以在圖形化界面通過system-config-kickstart進行生成,也手寫(不建議)或使用已經裝好的系統中,/root/anaconda-ks.cfg進行修改。此處以最小化安裝ks文件為例。
此處需要註意的是在ks文件中使用network安裝,要將url的路徑設置為cobbler的內置變量$tree

# Use network installation
url --url=$tree

2.ks6mini.cfg文件內容

[[email protected] ~]# vim ks6.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url=$tree
# Root password
rootpw --iscrypted $1$6oVXZR1R$QOASc6inirmHCZmQ.W9Hg0
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone  Asia/Shanghai
# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel 
# Disk partitioning information
part /boot --fstype="ext4" --size=200
part / --fstype="ext4" --size=20000
part swap --fstype="swap" --size=1024

%packages
@core

%end

二、將ks文件復制到cobbler的ks的倉庫中

cobbler有自帶的ks倉庫,其目錄在/var/lib/cobbler/kickstarts/,將所準備好的ks文件復制到此目錄下

[[email protected] ~]# cp ks6mini.cfg /var/lib/cobbler/kickstarts/

三、將ks文件與cobbler中的系統鏡像相關聯

1.首先查看下cobbler倉庫中的ks文件關聯列表以及cobbler中所存在的系統鏡像

[[email protected] ~]# cobbler profile list          #此命令可以查看ks關聯安裝列表
   Centos-6.10-x86_64                           #此為剛才創建的安裝列表
[[email protected] ~]# cobbler distro list           #此命令可以查看所存在的系統鏡像
   Centos-6.10-x86_64                           #此為剛才導入的鏡像

2.將ks6mini.cfg文件進行關聯

[[email protected] ~]# cobbler profile add --name=Centos-6.10-mini-x86_64 --distro=Centos-6.10-x86_64 --ks=/var/lib/cobbler/kickstarts/ks6mini.cfg
#--name:指定新的安裝列表的名稱
#--distro:指定所要關聯的鏡像名稱
#--ks:指定ks文件所在的路徑
[[email protected] ~]# cobbler profile list          #查看安裝列表
   Centos-6.10-mini-x86_64                      #此為剛才所關聯的項
   Centos-6.10-x86_64

3.刪除ks關聯
由於cobbler所自帶的關聯安裝方法,並不是我們想要的,所以我們需要將其從列表中刪除,刪除方法

[[email protected] ~]# cobbler profile remove --name=Centos-6.10-x86_64      #刪除列表
[[email protected] ~]# cobbler profile list
   Centos-6.10-mini-x86_64                                              #此時只剩下mini

基於web的cobbler管理

由於文本形式的cobbler的管理不太友好,我們也可以使用基於web的管理方法

一、安裝cobbler-web

[[email protected] mnt]# yum install cobbler-web -y

二、重啟httpd服務

[[email protected] mnt]# systemctl restart httpd

三、此時已經能訪問cobbler的web界面

cobbler_web是基於ssl的,所以需要使用https協議,訪問地址為:https://XXX.XXX.XXX.XXX/cobbler_web
技術分享圖片

cobbler_web的賬戶和密碼

cobbler默認賬戶和密碼都為cobbler,此密碼不夠安全,我們需要對其加以修改。

一、authn_configfile驗證方法

cobbler的驗證文件存放在/etc/cobbler/modules.conf內部詳細的說明了各種驗證方法,默認的驗證方法為configfile。

[[email protected] mnt]# cat /etc/cobbler/modules.conf
# cobbler module configuration file
# =================================

# authentication: 
# what users can log into the WebUI and Read-Write XMLRPC?
# choices:
#    authn_denyall    -- no one (default)
#    authn_configfile -- use /etc/cobbler/users.digest (for basic setups)
#    authn_passthru   -- ask Apache to handle it (used for kerberos)
#    authn_ldap       -- authenticate against LDAP
#    authn_spacewalk  -- ask Spacewalk/Satellite (experimental)
#    authn_pam        -- use PAM facilities
#    authn_testing    -- username/password is always testing/testing (debug)
#    (user supplied)  -- you may write your own module
# WARNING: this is a security setting, do not choose an option blindly.
# for more information:
# https://github.com/cobbler/cobbler/wiki/Cobbler-web-interface
# https://github.com/cobbler/cobbler/wiki/Security-overview
# https://github.com/cobbler/cobbler/wiki/Kerberos
# https://github.com/cobbler/cobbler/wiki/Ldap

[authentication]
module = authn_configfile

添加用戶和刪除用戶
auth_confile的用戶名和密碼存放在/etc/cobbler/users.digest中使用一下命令可以創建Cobbler的用戶和密碼

[[email protected] mnt]# htdigest /etc/cobbler/users.digest Cobbler admin   #註意此處Cobbler的C必須為大寫
Adding user admin in realm cobbler
New password: 
Re-type new password: 

Cobbler刪除用戶只需要在/etc/cobbler/users.digest中找到用戶相對應的行將其刪除。

二、authn_pam的驗證方法

1.修改驗證文件/etc/cobbler/modules.conf中的authentication項,pam驗證方法的用戶名和密碼存放在/etc/cobbler/users.conf文件中

[authentication]
module = authn_pam

2.基於pam驗證的用戶名和密碼的創建
創建一個Linux用戶

[[email protected] mnt]# useradd -s /sbin/nologin cobbleradmin
[[email protected] mnt]# echo 111111 | passwd --stdin cobbleradmin
Changing password for user cobbleradmin.
passwd: all authentication tokens updated successfully.

此時可以使用Linxu賬戶進行登陸cobbler_web

cobbler自動化安裝操作系統