1. 程式人生 > 實用技巧 >批量化無人值守安裝

批量化無人值守安裝

pxe + kickstart 工作概述

1、網絡卡上的pxe晶片有512位元組,存放了DHCP和TFTP的客戶端。

2、啟動計算機選擇網絡卡啟動。

3、pxe上的DHCP客戶端會向DHCP伺服器,申請IP

4、DHCP伺服器分配給它IP地址的同時通過以下欄位,告訴pxe,TFTP的地址和它要下載的檔案

如:next-server xxx.xxx.xxx.xxx

filename "pxelinux.0"

5、pxelinux.0告訴pxe要下載的配置檔案是pxelinux.cfg目錄下面的default

6、pxe下載並依據配置檔案的內容下載啟動必須的檔案,並通過ks.cfg開始系統安裝。

----------------------------------------

cobbler功能

使用一個以前定義的模板來配置DHCP服務(如果啟用了管理DHCP)

將一個儲存庫(yum或rsync)建立映象或者解壓縮一個媒介,以註冊一個新作業系統

在DHCP配置檔案中為需要安裝的機器建立一個條目,並 使用你指定的引數(IP和Mac地址)

在TFTP服務目錄下建立適當的pxe檔案

重新啟動DHCP服務以反映更改

重新啟動機器以開始安裝(如果電源管理已啟用)

1、安裝yum源

[[email protected] ~]# rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm

2、安裝對應的服務

[[email protected] yum.repos.d]# yum -y install ncurses-devel gcc gcc-c++

[[email protected] yum.repos.d]# yum install -y httpd dhcp tftp cobbler cobbler-web pykickstart

[[email protected] httpd]# yum install cobbler dhcp xinetd fence-agents pykickstart ed patch perl perl-Compress-Zlib perl-Digest-SHA perl-LockFile-Simple perl-libwww-perl

3、進入目錄

[[email protected] yum.repos.d]# cd /etc/httpd/conf.d/

4、啟動系統服務

[[email protected] httpd]# systemctl start httpd

[[email protected] httpd]# systemctl start cobblerd

5、檢視埠

[[email protected] httpd]# ss -ntlp

6、關閉防火牆

[[email protected] httpd]# iptables -F

[[email protected] httpd]# iptables -t nat -F

[[email protected] httpd]# systemctl stop firewalld

7、去掉提示

[[email protected] httpd]# echo "unset MAILCHECK">> /etc/profile


wKiom1lBXYXheMw9AAAh61GLx50937.png

8、修改防火牆

wKioL1lBXaSgIVMSAAB2gQNVLMA005.png-wh_50

9、執行命令cobbler check

根據提示修改配置檔案

[[email protected] httpd]# vi /etc/cobbler/settings



wKioL1lBXgryjwWaAAA7IbBVexs769.png-wh_50

wKiom1lBXj7girqhAAAr22xMIvI918.png-wh_50

vi 小技巧

當前游標刪除到行尾 直接大 D

修改第二個配置檔案

[[email protected] httpd]# vim /etc/xinetd.d/tftp


啟動rsyncd服務

[[email protected] httpd]# systemctl start rsyncd

10、執行命令下載網路安裝檔案

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

11、設定密碼

[[email protected] httpd]# openssl passwd -1 -salt 'cobler' 'qq******'

會生成一串隨機密碼



修改配置檔案

[[email protected] httpd]# vi /etc/cobbler/settings

將密碼替換成隨機生成的密碼串,替換引號部分,注意隨機密碼串,生成的全部都是密碼

wKiom1lBXryAB18UAAAkrTZhXpY138.png

11、重啟服務

[[email protected] httpd]# systemctl restart cobblerd

[[email protected] httpd]# cobbler check

12、修改DHCP引數

[[email protected] httpd]# vi /etc/cobbler/settings

wKiom1lBXnXim8zlAABkBvW0t6U378.png-wh_50


13、修改dhcp模板配置檔案

[[email protected] httpd]# vim /etc/cobbler/dhcp.template


重啟服務

[[email protected] httpd]# systemctl restart cobblerd

[[email protected] httpd]# cobbler sync

系統自動生成DHCP


14、執行掛載映象

[[email protected] httpd]# mount /dev/cdrom /mnt/

mount: /dev/sr0 is write-protected, mounting read-only

15、自動匯入映象

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

映象會匯入到這個目錄下

[[email protected] ~]# cd /var/www/cobbler/ks_mirror/

[[email protected] ks_mirror]# ls

Centos-7-x86_64 config

[[email protected] ks_mirror]#

匯入完成


執行解除安裝,切換映象,然後在匯入一個centos6的系統


檢視 cobbler命令

[[email protected] httpd]# cobbler profile

檢視映象列表

[[email protected] httpd]# cobbler profile list


自定義kickstart檔案

[[email protected] kickstarts]# cobbler profile edit --name=Centos-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos-7-x86_64.cfg

[[email protected] kickstarts]# vi centos-7-x86_64.cfg ##配置檔案內容

lang en_US

keyboard us

timezone Asia/Shanghai

rootpw --iscrypted $default_password_crypted

text

install

url --url=$tree

bootloader --location=mbr

zerombr

clearpart --all initlabel

part /boot --fstype xfs --size 1024 --ondisk sda

part swap --size 1024 --ondisk sda

part / --fstype xfs --size 1 --grow --ondisk sda

auth --useshadow --enablemd5

$SNIPPET('network_config')

reboot

firewall --disabled

selinux --disabled

skipx

%pre

$SNIPPET('log_ke_pre')

$SNIPPET('kickstart_start')

$SNIPPET('pre_install_network_config')

$SNIPPET('pre_anamon')

%end

%packages

@ base

@ core

sysstat

iptraf

ntp

lrzsz

ncurses-devel

openssl-devel

zlib-devel

OpenIPMI-tools

mysql

nmap

screen

%end

%post

systemctl disable postfix.service

%end

加上核心引數

[[email protected] kickstarts]# cobbler profile edit --name=Centos-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'

檢視加入的核心引數

[[email protected] kickstarts]# cobbler profile report Centos-7-x86_64


執行命令,重新生成檔案

更改檔案必須執行 cobbler sync

[[email protected] kickstarts]# cobbler sync

啟動服務

[[email protected] ks_mirror]# systemctl start xinetd



安裝完成


wKioL1lBXxSDFsfcAAC0kX7WaLU103.png-wh_50

wKiom1lBXxXiLVzWAAAiJ_N_oVU168.png-wh_50


詳情請見我的有道筆記http://note.youdao.com/noteshare?id=6ec7d30137f325166c75a7094ade473d&sub=CD35A519A1684BC497E66A3B6EDF0DBF

轉載於:https://blog.51cto.com/yibeishui/1936897