kickstart自动化系统安装_自动化运维之kickstart自动化部署安装操作系统
第1章 簡介
1.1 PXE簡介
qPXE是預(yù)啟動執(zhí)行環(huán)境,全名是Pre-boot Execution Environment
q通過網(wǎng)絡(luò)接口啟動計算機(jī),不需要依賴本地存儲設(shè)備或本地已安裝的操作系統(tǒng)
q由Intel和Systemsoft公司于1999年9月20日公布的技術(shù)
qC/S的工作模式
qPXE客戶端會調(diào)用網(wǎng)際協(xié)議(IP)、用戶數(shù)據(jù)協(xié)議(UDP)、動態(tài)主機(jī)分配協(xié)議(DHCP)、小型文件傳輸協(xié)議(TFTP)等網(wǎng)絡(luò)協(xié)議
1.2 kickstart簡介
kickstart是一種無人值守的安裝方式??? ,他的工作原理就是在安裝的過程中記錄人工干預(yù)填寫的各種參數(shù),并會生成一個名為ks.cfg的文件,如果在自動化安裝的過程中出現(xiàn)需要填寫參數(shù)的情況,安裝程序就會去找ks.cfg程序,如果找到合適的參數(shù),就采用所找到的參數(shù),若找不到則需要人工進(jìn)行填寫,所以如果ks.cfg文件中涵蓋了所有需要填寫的參數(shù),那么安裝者完全可以只需告訴安裝程序從何處下載ks.cfg文件,然后就可以等待安裝完畢,然后會根據(jù)ks.cfg
文件設(shè)置重啟/安裝系統(tǒng),最后結(jié)束安裝。
1.3 Cobbler簡介
Cobbler集中和簡化了通過網(wǎng)絡(luò)安裝操作系統(tǒng)需要使用的DHCP、TFTP、和DNS服務(wù)的配置,Cobbler不僅有一個命令行界面,還提供了一個web界面,大大降低了使用者的入門水平。Cobbler內(nèi)置了一個輕量級的配置管理系統(tǒng),但也支持和其他配置管理系統(tǒng)集成,例如Puppet,但是暫時還不支持SaltStack
1.4 Kickstart與Cobbler的區(qū)別
簡單的說就是Cobbler是對Kickstart的封裝,簡化了安裝步驟、使用流程、降低了使用者的門檻
1.5 PXE+Kickstart裝機(jī)流程圖
第2章 環(huán)境準(zhǔn)備
2.1 系統(tǒng)環(huán)境
[root@kisckstart ~]# cat /etc/redhat-release
CentOS release 6.9 (Final)
[root@kisckstart ~]# uname -m
x86_64
[root@kisckstart ~]# uname -r
2.6.32-696.el6.x86_64
[root@kisckstart ~]# ifconfig eth0|awk -F "[ :]+" 'NR==2{print $4}'
10.33.1.2
[root@kisckstart ~]# hostname
kisckstart
2.2 關(guān)閉安裝機(jī)制
[root@kisckstart ~]# /etc/init.d/iptables stop
[root@kisckstart ~]# chkconfig iptables off
[root@kisckstart ~]# setenforce 0
[root@kisckstart ~]# sed "s#SELINUX=enforcing#SELINUX=disabled#g" /etc/sysconfig/selinux
第3章 部署kickstart
3.1 安裝DHCP服務(wù)
[root@kisckstart ~]# yum install -y dhcp
[root@kisckstart ~]# rpm -ql dhcp|grep "dhcpd.conf"? ==》查找配置文件的位置
/etc/dhcp/dhcpd.conf
[root@kisckstart ~]# cat /etc/dhcp/dhcpd.conf
subnet 10.33.0.0 netmask 255.255.0.0 {
range 10.33.1.100 10.33.1.200;? ##分配的IP地址范圍
option subnet-mask 255.255.0.0;? ##設(shè)定netmask
default-lease-time 21600;?? ##設(shè)置默認(rèn)的IP租用期
max-lease-time 43200;? ##設(shè)置最大的IP最大的IP租用期
next-server 10.33.1.2;? ##TFTP服務(wù)器的IP地址
filename "/pxelinux.0";? ##告訴客戶端從根目錄下載pxelinux.0文件
}
[root@kisckstart ~]# /etc/init.d/dhcpd start
[root@kisckstart ~]# netstat -tunlp |grep dhcpd? ==》查看端口
3.2 安裝TFTP服務(wù)
[root@kisckstart ~]# yum install -y tftp-server
[root@kisckstart ~]# cat /etc/xinetd.d/tftp
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變?yōu)閚o
per_source???????????? = 11
cps???????????????? = 100 2
flags????????????? = IPv4
}
[root@kisckstart ~]# /etc/init.d/xinetd start
[root@kisckstart ~]# netstat -tnulp|grep "xinetd"
3.3 配置HTTP服務(wù)
[root@kisckstart ~]# yum install -y httpd
[root@kisckstart ~]#sed -i "277i ServerName 127.0.0.1:80" /etc/httpd/conf/httpd.conf
[root@kisckstart conf]# /etc/init.d/httpd start
3.4 上傳鏡像
[root@kisckstart ~]# mkdir /var/www/html/centos-6.9 ==》創(chuàng)建鏡像存放目錄
[root@kisckstart ~]# mount /dev/cdrom /var/www/html/centos-6.9/? ==》掛載
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@kisckstart ~]# df -h? ==》檢查
Filesystem????? Size? Used Avail Use% Mounted on
/dev/sda3??????? 19G? 1.8G?? 16G? 10% /
tmpfs?????????? 491M???? 0? 491M?? 0% /dev/shm
/dev/sda1?????? 190M?? 35M? 146M? 19% /boot
/dev/sr0?? ?????3.7G? 3.7G???? 0 100% /var/www/html/centos-6.9
注意:只要將鏡像通過web發(fā)布即可,所以不管你怎么弄都行!!!
3.5 瀏覽器訪問測試
3.6 配置支持PXE的啟動程序
3.6.1 PXE引導(dǎo)配置
qsyslinux是一個功能強(qiáng)大的引導(dǎo)加載程序,并且兼容各種介質(zhì)
qsyslinux是一個小型的linux操作系統(tǒng),目的是簡化linux首次安裝的時間,并建立維護(hù)或其他特殊用途的啟動盤
q如果沒有找到pxelinux.0這個文件,可以安裝下syslinux
[root@kisckstart ~]# yum install -y syslinux
[root@kisckstart ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@kisckstart ~]# cp -a /var/www/html/centos-6.9/isolinux/* /var/lib/tftpboot/
[root@kisckstart ~]# ls /var/lib/tftpboot/
boot.cat? grub.conf?? isolinux.bin? memtest???? splash.jpg? vesamenu.c32
boot.msg? initrd.img? isolinux.cfg? pxelinux.0? TRANS.TBL?? vmlinuz
[root@kisckstart ~]# mkdir? /var/lib/tftpboot/pxelinux.cfg? ==》創(chuàng)建一個pxelinux.cfg目錄,存放客戶端的配置文件
[root@kisckstart ~]# cp /var/www/html/centos-6.9/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
3.6.2 半自動安裝
3.6.2.1 新建一個虛擬機(jī)然后開機(jī)
3.6.2.2 然后選擇第一項
3.6.2.3 選擇英語
3.6.2.5 選擇美式英語
3.6.2.6 選擇URL安裝
3.6.2.7 禁用IPv6
3.6.2.8 輸入http地址
3.6.2.9 最后和U盤或光盤安裝的步驟一樣
3.6.3 創(chuàng)建ks.cfg文件
3.6.3.1 生成配置文件的方式
【法1】
每安裝好一臺Centos機(jī)器,Centos就會創(chuàng)建一個名字為anaconda-ks.cfg的kickstart文件,位于/root目錄下面,記錄你的真實安裝配置,如果希望實現(xiàn)和某系統(tǒng)類似的安裝,可以基于該系統(tǒng)的kickstart配置文件來生成你自己的kickstart配置文件
【法2】
閱讀kickstart配置文件手冊,用文本編輯器就可以創(chuàng)建屬于自己的kickstart文件
【法3】
Centos提供了一個圖形化的kickstart配置工具。在任何一個安裝好的Linux系統(tǒng)上運行該工具,就可以很容易地創(chuàng)建你自己的kickstart配置文件。kickstart配置工具命令為redhat-config-kickstart(RHEL3)或system-config-kickstart(RHEL4,RHEL5).網(wǎng)上有很多用CentOS桌面版生成ks文件的文章,如果有現(xiàn)成的系統(tǒng)就沒什么可說。但沒有現(xiàn)成的,也沒有必要去用桌面版,命令行也很簡單
3.6.3.2 編寫ks.cfg文件
mkdir -p /var/www/html/ks_config
cat /var/www/html/ks_config/CentOS-6.9-ks.cfg
#Kickstart Configurator for CentOS 6.9 by liuzhonghhe
install
url --url="http://172.16.1.200/centos-6.9"
text
lang en_US.UTF-8
keyboard us
zerombr
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
network --bootproto=dhcp --device=eth0 --onboot=yes --noipv6 --hostname=Centos6
timezone -utc Asia/Shanghai
authconfig --enableshadow --passalgo=sha512
rootpw --iscrypted $6$4/LtE7Epu9PGKS7B$FkjCppxcjDxfYJ6RAFU52W0JzPWYDjQmyt2sa8lydljECLrhGH6YwtKBNQtXqF59bDs2CSfSiFPLEzgy2EfPz0
clearpart --all --initlabel
part /boot --fstype=ext4 --asprimary --size=200
part swap --size=1024
part / --fstype=ext4 --grow --asprimary --size=200
firstboot --disable
selinux --disabled
firewall --disabled
logging --level=info
reboot
%packages
@base
@compat-libraries
@debugging
@development
tree
nmap
sysstat
lrzsz
dos2unix
telnet
%post
wget -O /tmp/optimization.sh http://172.16.1.200/ks_config/optimization.sh &>/dev/null
/bin/sh /tmp/optimization.sh
%end
3.6.3.3 開機(jī)優(yōu)化腳本
vim ?/var/www/html/ks_config/optimization.sh
cat?? /var/www/html/ks_config/optimization.sh
#!/bin/bash
##############################################################
# File Name: /var/www/html/ks_config/optimization.sh
# Version: V1.0
# Author: Liu Zhonghe
# Description: Linux system initialization
##############################################################
. /etc/init.d/functions
Ip=172.16.1.200
Port=80
ConfigDir=ks_config
# Judge Http server is ok?
PortNum=`nmap $Ip? -p $Port 2>/dev/null|grep open|wc -l`
[ $PortNum -lt 1 ] && {
echo "Http server is bad!"
exit 1
}
# Defined result function
function Msg(){
if [ $? -eq 0 ];then
action "$1" /bin/true
else
action "$1" /bin/false
fi
}
# Defined IP function
function ConfigIP(){
Suffix=`ifconfig eth1|awk -F "[ .]+" 'NR==2 {print $6}'`
cat >/etc/sysconfig/network-scripts/ifcfg-eth1 <
DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=172.16.1.$Suffix
PREFIX=24
GATEWAY=172.16.1.61
DNS1=10.0.0.2
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth1"
END
Msg "config eth1"
}
# Defined Yum source Functions
function yum(){
YumDir=/etc/yum.repos.d
[ -f "$YumDir/CentOS-Base.repo" ] && cp $YumDir/CentOS-Base.repo{,.ori}
wget -O $YumDir/CentOS-Base.repo http://$Ip:$Port/$ConfigDir/CentOS-Base.repo &>/dev/null &&\
wget -O $YumDir/epel.repo http://$Ip:$Port/$ConfigDir/epel.repo &>/dev/null &&\
Msg "YUM source"
}
# Defined Hide the system version number Functions
function HideVersion(){
[ -f "/etc/issue" ] && >/etc/issue
Msg "Hide issue"
[ -f "/etc/issue.net" ] && > /etc/issue.net
Msg "Hide issue.net"
}
# Defined OPEN FILES Functions
function openfiles(){
[ -f "/etc/security/limits.conf" ] && {
echo '*? -? nofile? 65535' >> /etc/security/limits.conf
Msg "open files"
}
}
# Defined Kernel parameters Functions
function kernel(){
KernelDir=/etc
[ -f "$KernelDir/sysctl.conf" ] && /bin/mv $KernelDir/sysctl.conf{,.ori}
wget -O $KernelDir/sysctl.conf http://$Ip:$Port/$ConfigDir/sysctl.conf &>/dev/null
Msg "Kernel config"
}
# Defined System Startup Services Functions
function boot(){
for oldboy in `chkconfig --list|grep "3:on"|awk '{print $1}'|grep -vE "crond|network|rsyslog|sshd|sysstat"`
do
chkconfig $oldboy off
done
Msg "BOOT config"
}
# Defined Time Synchronization Functions
function Time(){
echo "#time sync by zhangyao at $(date +%F)" >>/var/spool/cron/root
echo '*/5 * * * * /usr/sbin/ntpdate time.nist.gov &>/dev/null' >>/var/spool/cron/root
Msg "Time Synchronization"
}
# Defined main Functions
function main(){
ConfigIP
yum
HideVersion
openfiles
kernel
boot
Time
}
main
default ks
prompt 0
label ks
kernel vmlinuz
append initrd=initrd.img ks=http://172.16.1.200/ks_config/CentOS-6.7-ks.cfg ksdevice=eth1
3.6.3.4 ?整合配置文件
vim /var/lib/tftpboot/pxelinux.cfg/default
default ks
prompt 0
label ks
kernel vmlinuz
append initrd=initrd.img ks=http://172.16.1.200/ks_config/CentOS-6.7-ks.cfg ksdevice=eth1
3.6.4 無人值守自動安裝
過程截圖
第4章 ks.cfg文件詳解
4.1 Centos6官方參考文檔
4.2 ks.cfg文件可以分為3段
q命令段
用來配置鍵盤類型、語言、安裝方式等系統(tǒng)的配置,有必選項和可選項,若缺少必須項,在安裝的過程中會暫定,需手動指定
q軟件包段
2%packages
2@groupname:指定安裝的包組
2package_name:指定安裝的包
2-package_name:指定不安裝的包
q腳本段
2%pre:安裝系統(tǒng)前執(zhí)行的命令或腳本(由于只依賴于啟動鏡像,支持的命令很少)
2%post:安裝系統(tǒng)后執(zhí)行的命令或腳本(基本支持所有命令)
4.3 詳細(xì)解釋關(guān)鍵字含義install告知安裝程序,這是一次全新安裝,而不是升級upgrade。
url --url=" "通過FTP或HTTP從遠(yuǎn)程服務(wù)器上的安裝樹中安裝。
url --url="http://172.16.1.200/centOS-6.7/"
url --url ftp://:@/
nfs從指定的NFS服務(wù)器安裝。
nfs --server=nfsserver.example.com --dir=/tmp/install-tree
text使用文本模式安裝。
lang設(shè)置在安裝過程中使用的語言以及系統(tǒng)的缺省語言。lang en_US.UTF-8
keyboard設(shè)置系統(tǒng)鍵盤類型。keyboard ? us
zerombr清除mbr引導(dǎo)信息。
bootloader系統(tǒng)引導(dǎo)相關(guān)配置。
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto ? rhgb quiet"
--location=,指定引導(dǎo)記錄被寫入的位置.有效的值如下:mbr(缺省),partition(在包含內(nèi)核的分區(qū)的第一個扇區(qū)安裝引導(dǎo)裝載程序)或none(不安裝引導(dǎo)裝載程序)。
--driveorder,指定在BIOS引導(dǎo)順序中居首的驅(qū)動器。
--append=,指定內(nèi)核參數(shù).要指定多個參數(shù),使用空格分隔它們。
network為通過網(wǎng)絡(luò)的kickstart安裝以及所安裝的系統(tǒng)配置聯(lián)網(wǎng)信息。
network --bootproto=dhcp --device=eth0 --onboot=yes --noipv6 ? --hostname=CentOS6
--bootproto=[dhcp/bootp/static]中的一種,缺省值是dhcp。bootp和dhcp被認(rèn)為是相同的。
static方法要求在kickstart文件里輸入所有的網(wǎng)絡(luò)信息。
network --bootproto=static --ip=10.0.0.200 --netmask=255.255.255.0 ? --gateway=10.0.0.2 --nameserver=10.0.0.2
請注意所有配置信息都必須在一行上指定,不能使用反斜線來換行。
--ip=,要安裝的機(jī)器的IP地址.
--gateway=,IP地址格式的默認(rèn)網(wǎng)關(guān).
--netmask=,安裝的系統(tǒng)的子網(wǎng)掩碼.
--hostname=,安裝的系統(tǒng)的主機(jī)名.
--onboot=,是否在引導(dǎo)時啟用該設(shè)備.
--noipv6=,禁用此設(shè)備的IPv6.
--nameserver=,配置dns解析.
timezone設(shè)置系統(tǒng)時區(qū)。timezone ? --utc Asia/Shanghai
authconfig系統(tǒng)認(rèn)證信息。authconfig ? --enableshadow --passalgo=sha512
設(shè)置密碼加密方式為sha512?啟用shadow文件。
rootpwroot密碼
clearpart清空分區(qū)。clearpart ? --all --initlabel
--all?從系統(tǒng)中清除所有分區(qū),--initlable?初始化磁盤標(biāo)簽
part磁盤分區(qū)。
part /boot --fstype=ext4 --asprimary --size=200
part swap --size=1024
part / --fstype=ext4 --grow --asprimary --size=200
--fstype=,為分區(qū)設(shè)置文件系統(tǒng)類型.有效的類型為ext2,ext3,swap和vfat。
--asprimary,強(qiáng)迫把分區(qū)分配為主分區(qū),否則提示分區(qū)失敗。
--size=,以MB為單位的分區(qū)最小值.在此處指定一個整數(shù)值,如500.不要在數(shù)字后面加MB。
--grow,告訴分區(qū)使用所有可用空間(若有),或使用設(shè)置的最大值。
firstboot負(fù)責(zé)協(xié)助配置redhat一些重要的信息。
firstboot --disable
selinux關(guān)閉selinux。selinux --disabled
firewall關(guān)閉防火墻。firewall ? --disabled
logging設(shè)置日志級別。logging ? --level=info
reboot設(shè)定安裝完成后重啟,此選項必須存在,不然kickstart顯示一條消息,并等待用戶按任意鍵后才重新引導(dǎo),也可以選擇halt關(guān)機(jī)
總結(jié)
以上是生活随笔為你收集整理的kickstart自动化系统安装_自动化运维之kickstart自动化部署安装操作系统的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python中repr的用法_pytho
- 下一篇: Java 第十一届 蓝桥杯 省模拟赛