溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

大數(shù)據(jù)平臺一鍵安裝OS【定制化OS鏡像制作】

發(fā)布時間:2020-06-25 00:04:07 來源:網(wǎng)絡(luò) 閱讀:17377 作者:cs312779641 欄目:大數(shù)據(jù)

   定制化 大數(shù)據(jù)平臺一鍵安裝OS


大數(shù)據(jù)平臺一鍵安裝OS系列

大數(shù)據(jù)平臺一鍵安裝OS【搭建腳本篇】

定制化OS鏡像制作


1.操作環(huán)境

操作環(huán)境:VMware Workstarion 9 and vSphere client

系統(tǒng):CentOS -6.8-x86_64

工具:gconf-editor anaconda repodata createrepo mkisofs rsync


2.主要思路

定制化是通過kickstart腳本來實(shí)現(xiàn)的,linux系統(tǒng)安裝完畢后在root目錄下會生成anaconda-ks.cfg install.log等文件,anaconda-ks.cfg是自動安裝腳本,install.log是安裝包的一些信息記錄。在定制化中我們用到的主要是anaconda-ks.cfg這個kickstart腳本,這個腳本可以通過工具生成,也可以通過修改原來系統(tǒng)的anaconda-ks.cfg文件來實(shí)現(xiàn)。這里為了方便,采用的是原來系統(tǒng)的anaconda-ks.cfg來進(jìn)行修改,在kickstart腳本中我們可以自行設(shè)置在安裝過程中要實(shí)現(xiàn)的操作,實(shí)現(xiàn)自動化定制化安裝。


3.工具安裝

在定制過程中,需要安裝一些工具,這些工具用于生成我們需要的文件和最后制作鏡像文件,進(jìn)入centos,管理員模式下在命令行輸入如下命令:#掛載鏡像

[root@localhost ~]# mount /dev/sr0 /mnt/
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# df -TH
Filesystem           Type     Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                     ext4      38G   27G  9.5G  74% /
tmpfs                tmpfs    985M     0  985M   0% /dev/shm
/dev/sda1            ext4     500M   42M  433M   9% /boot
/dev/sr0             iso9660  5.8G  5.8G     0 100% /mnt

#制作本地源
touch /etc/yum.repos.d/vrv.repo
echo "
[vrv-local]
name=vrv-local
baseurl=file:///mnt/
gpgcheck=0
enabled=1
" >> /etc/yum.repos.d/vrv.repo
yum clean all && echo 'yum repository has been updated!'
#安裝工具
yum –y install anaconda repodata createrepo mkisofs rsync


大數(shù)據(jù)平臺一鍵安裝OS【定制化OS鏡像制作】


4.定制化過程

#建立系統(tǒng)制作目錄

mkdir /home/source

掛載鏡像centos6.8.iso

#復(fù)制除了Packages文件夾以外的所有文件到系統(tǒng)制作目錄

mount /dev/sr0 /mnt

cd /mnt

cp -rf * /home/source/

上傳ks.cfg 服務(wù)端腳本配置和ks-config.cfg客戶端腳本配置到isolinux文件夾下

執(zhí)行yum install dos2*

dos2unix isolinux/*.cfg

 

#復(fù)制原系統(tǒng)的anaconda-ks.cfg和install.log文件到系統(tǒng)制作目錄

[root@localhost ~]#cp /root/anaconda-ks.cfg /root/install.log /home/source

 

#參照當(dāng)前的系統(tǒng),復(fù)制相應(yīng)的軟件包到系統(tǒng)制作目錄,install.log記錄了本機(jī)安裝的軟件包的信息,參考install.log可以減少復(fù)制多余的軟件包。

[root@localhost ~]#mkdir /home/source/Packages

[root@localhost ~]#awk ‘/Installing/{print $2}’ /home/source/install.log | xargs –I cp /mnt/Packages/{}.rpm /home/source/Packages/

cp /mnt/.discinfo   /home/source/  #這一步很重要

 大數(shù)據(jù)平臺一鍵安裝OS【定制化OS鏡像制作】

#修改/制作kickstart腳本,修改這個腳本有兩種方法,第一種方法是通過修改原系統(tǒng)的anaconda-ks.cfg腳本,第二種方法是通過system-config-kickstart工具來制作。第一種較為簡單,修改的地方較少,而第二種方法是制作一個kickstart腳本,制作的過程由很多參數(shù)是需要手動設(shè)置的,容易出問題。

 

#對里面的參數(shù)進(jìn)行解釋

timezone Asia/Shanghai  #設(shè)置系統(tǒng)的時區(qū),在時區(qū)設(shè)置是前面不加—utc否則時區(qū)設(shè)置不生效

bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"  #auto rhgb quiet參數(shù)設(shè)置了系統(tǒng)的啟動方式,去掉rhgb則在開機(jī)的過程中不顯示開機(jī)動畫,而是以文本的形式打印出系統(tǒng)的啟動過程

 

# 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

 

#這里設(shè)置分區(qū)操作,如果不在kickstart腳本中設(shè)置,則在安裝過程中需要手動來進(jìn)行設(shè)置

clearpart --all –initlabel    

part /boot --fstype=ext4 --size=300

part / --fstype=ext4 --grow --size=37000  #硬盤大小根據(jù)具體的大小設(shè)置,一般我給虛擬機(jī)的大小為40G,所以這里設(shè)置為37000,剩余的空間用作boot和swap分區(qū)。

part swap --grow --maxsize=1984 --size=1984

 大數(shù)據(jù)平臺一鍵安裝OS【定制化OS鏡像制作】

#修改引導(dǎo)顯示畫面,引導(dǎo)顯示畫面的背景圖片在安裝光盤中的isolinux文件夾內(nèi)部只需要用其他圖片替換掉即可。修改系統(tǒng)名字(安裝ambari服務(wù)不能修改名字)

#echo " OS release 1.1" > /etc/centos-release

#echo " OS release 1.1" > /etc/redhat-release

#sed -i 's/CentOS release 6.8 (Final)/ OS release 1.1/g' /etc/issue

#sed -i 's/CentOS release 6.8 (Final)/ OS release 1.1/g' /etc/issue.net

#sed -i 's/localhost.localdomain/vasp.host/g' /etc/sysconfig/network

#sed -i 's/CentOS/OS/g' /etc/rc.d/rc.sysinit

#sed -i 's/CentOS/OS/' /etc/grub.conf


5.添加背景圖片

cd /home/source/Packages/isolinux/

#添加背景圖片

menu background splash.jpg

大數(shù)據(jù)平臺一鍵安裝OS【定制化OS鏡像制作】

替換成

大數(shù)據(jù)平臺一鍵安裝OS【定制化OS鏡像制作】


注意圖片大小和名字必須跟原圖片一樣

大數(shù)據(jù)平臺一鍵安裝OS【定制化OS鏡像制作】

#自定義的安裝選項(xiàng),并將這個選項(xiàng)設(shè)置為默認(rèn)選項(xiàng),并設(shè)置自定義的kickstart安裝腳本的文件路徑,實(shí)現(xiàn)以文本形式自動安裝。真重要,如果不變成一樣,會遇到圖片無法變過來的情況。

按格式添加并修改菜單選項(xiàng):

######################添加以下內(nèi)容

label menu os server install new system

  menu os server install new system

  kernel vmlinuz

  append ks=cdrom:/isolinux/ks.cfg initrd=initrd.img   

label menu os client install new system

  menu os client install new system

  kernel vmlinuz

  append ks=cdrom:/isolinux/ks-config.cfg initrd=initrd.img

label rescue

  menu label ^Rescue installed system

  kernel vmlinuz

  append initrd=initrd.img rescue

label Boot

  menu label Boot from ^local drive

  localboot 0xffff

label memtest86

  menu label ^Memory test

  kernel memtest

  append -


成果圖:

大數(shù)據(jù)平臺一鍵安裝OS【定制化OS鏡像制作】


6.生成新的鏡像

#生成新的repodata文檔

[root@localhost ~]#cd /home/source

[root@localhost ~]#cp repodata/*comps.xml ./comps.xml

[root@localhost ~]#rm –rf repodata

[root@localhost ~]#declare –x discinfo=`head –1 .discinfo`

[root@localhost ~]#createrepo –g comps.xml /home/source 

#或者,也可以通過以下命令來實(shí)現(xiàn),這個命令和上面區(qū)別在于它只更改那些在上次產(chǎn)生元數(shù)據(jù)之后被修改,添加或者刪除了的項(xiàng)目,所以這個命令一般是用于在修改了包或組之后重新生成repodata文檔,可以提高效率。

[root@localhost ~]#createrepo –u “media://$discinfo” –g comps.xml | /home/source


#為了方便,也可以通過腳本來進(jìn)行操作,具體的腳本如下:

#!/bin/bash
ISO_DIR=/home/source
cd ${ISO_DIR}
declare -x discinfo=$(head -1 .discinfo)
cp /mnt/repodata/*-c6-x86_64-comps.xml ${ISO_DIR}/comps.xml 
createrepo -g ${ISO_DIR}/comps.xml ${ISO_DIR}
createrepo -u "media://$discinfo" -g ${ISO_DIR}/comps.xm l ${ISO_DIR}

# sh 1.sh 

Spawning worker 0 with 3233 pkgs

Workers Finished

Gathering worker results


Saving Primary metadata

Saving file lists metadata

Saving other metadata

Generating sqlite DBs

Sqlite DBs complete

#如果修改了Packages文件夾內(nèi)的軟件包,則需要重新生成comps.xml文件,可以將以上腳本保存為一個.sh文件,放于/root目錄下隨時使用。到這里所有的準(zhǔn)備工作都已經(jīng)完成,接下來可以開始制作鏡像文件了。制作鏡像文件用到的工具有mkisofs和implantisomd5,前者用來制作鏡像,后者用來進(jìn)行md5校驗(yàn),檢測文件在傳輸過程中是否損壞。進(jìn)入系統(tǒng)制作目錄/home/source運(yùn)行一下命令:

[root@localhost ~]#mkisofs –o os.iso  –b isolinux/isolinux.bin –c isolinux/boot.cat –no-emul-boot –boot-load-size 4 –boot-info-table –R –J –v –T –joliet-long /home/source

#執(zhí)行上述命令之后,在/home/source目錄下會生成一個名為OS.iso的鏡像文件進(jìn)入/home/source目錄。

Using KRB5_001.RPM;1 for  /home/source/Packages/krb5-server-ldap-1.10.3-57.el6.x86_64.rpm (krb5-server-1.10.3-57.el6.x86_64.rpm)
Using PYTHO02T.RPM;1 for  /home/source/Packages/python-simplejson-2.0.9-3.1.el6.x86_64.rpm (python-suds-0.4.1-3.el6.noarch.rpm)
Using KDE_L01L.RPM;1 for  /home/source/Packages/kde-l10n-Korean-4.3.4-5.el6.noarch.rpm (kde-l10n-Maithili-4.3.4-5.el6.noarch.rpm)
Using XORG_021.RPM;1 for  /home/source/Packages/xorg-x11-drv-tdfx-1.4.6-1.el6.x86_64.rpm (xorg-x11-drv-vmmouse-13.1.0-1.el6.x86_64.rpm)
Using YUM_P005.RPM;1 for  /home/source/Packages/yum-plugin-verify-1.1.30-37.el6.noarch.rpm (yum-plugin-tmprepo-1.1.30-37.el6.noarch.rpm)
Using KDE_L01M.RPM;1 for  /home/source/Packages/kde-l10n-Maithili-4.3.4-5.el6.noarch.rpm (kde-l10n-Icelandic-4.3.4-5.el6.noarch.rpm)
Using CONTR001.RPM;1 for  /home/source/Packages/control-center-filesystem-2.28.1-40.el6.x86_64.rpm (control-center-2.28.1-40.el6.x86_64.rpm)
Using POSTG00A.RPM;1 for  /home/source/Packages/postgresql-libs-8.4.20-6.el6.x86_64.rpm (postgresql-plpython-8.4.20-6.el6.x86_64.rpm)
Using AUDIT001.RPM;1 for  /home/source/Packages/audit-libs-python-2.4.5-3.el6.x86_64.rpm (audit-libs-2.4.5-3.el6.x86_64.rpm)
Using ECLIP01R.RPM;1 for  /home/source/Packages/eclipse-valgrind-0.6.1-1.el6.x86_64.rpm (eclipse-rpm-editor-0.5.0-2.el6.x86_64.rpm)
Writing:   Initial Padblock                        Start Block 0
Done with: Initial Padblock                        Block(s)    16
Writing:   Primary Volume Descriptor               Start Block 16
Done with: Primary Volume Descriptor               Block(s)    1
Writing:   Eltorito Volume Descriptor              Start Block 17
Size of boot p_w_picpath is 4 sectors -> No emulation
Done with: Eltorito Volume Descriptor              Block(s)    1
Writing:   Joliet Volume Descriptor                Start Block 18
Done with: Joliet Volume Descriptor                Block(s)    1
Writing:   End Volume Descriptor                   Start Block 19
Done with: End Volume Descriptor                   Block(s)    1
Writing:   Version block                           Start Block 20
Done with: Version block                           Block(s)    1
Writing:   Path table                              Start Block 21
Done with: Path table                              Block(s)    4
Writing:   Joliet path table                       Start Block 25
Done with: Joliet path table                       Block(s)    4
Writing:   Directory tree                          Start Block 29
Done with: Directory tree                          Block(s)    326
Writing:   Joliet directory tree                   Start Block 355
Done with: Joliet directory tree                   Block(s)    239
Writing:   Directory tree cleanup                  Start Block 594
Done with: Directory tree cleanup                  Block(s)    0
Writing:   Extension record                        Start Block 594
Done with: Extension record                        Block(s)    1
Writing:   The File(s)                             Start Block 595
 0.16% done, estimate finish Tue Jun 20 00:20:32 2017

 99.96% done, estimate finish Tue Jun 20 00:23:09 2017
Total translation table size: 848976
Total rockridge attributes bytes: 384427
Total directory bytes: 660628
Path table size(bytes): 848
Done with: The File(s)                             Block(s)    3160548
Writing:   Ending Padblock                         Start Block 3161143
Done with: Ending Padblock                         Block(s)    150
Max brk space used 3aa000
3161293 extents written (6174 MB)


執(zhí)行命令:

[root@localhost source]#/usr/bin/implantisomd5 os.iso 

#向鏡像文件插入md5校驗(yàn)值,防止鏡像文件在復(fù)制過程中損壞,校驗(yàn)時在相應(yīng)文件目錄下輸入如下命令,即可對文件進(jìn)行校驗(yàn),校驗(yàn)文件沒問題后,可以通過xftp將鏡像文件復(fù)制出來,下一步就可以安裝測試了。

[root@localhost ]#checkisomd5 os.iso 

大數(shù)據(jù)平臺一鍵安裝OS【定制化OS鏡像制作】

生成鏡像命令:

yum install -y mkisofs

createrepo -g repodata/*x86_64-comps.xml /home/source/

declare -x discinfo=`head -1 .discinfo`

createrepo -u "media://$discinfo" -g repodata/*x86_64-comps.xml /home/source/

mkisofs -o os.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -T -joliet-long /home/source


7.生成HDP鏡像

跟上述一樣的操作

createrepo -g repodata/*x86_64-comps.xml /home/hdp

declare -x discinfo=`head -1 .discinfo`

createrepo -u "media://$discinfo" -g repodata/*x86_64-comps.xml /home/hdp

mkisofs -o hdp2.4.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -T -joliet-long /home/hdp

效果圖:

大數(shù)據(jù)平臺一鍵安裝OS【定制化OS鏡像制作】


————————————————————————————————————————————————

如果你覺得作者的文章寫的不錯,請通過“支付寶”或“微信”獎勵作者一些銀子~

不需要太多(0.1、1元、3元、5元就可),不獎勵就請點(diǎn)個贊吧,謝謝!

大數(shù)據(jù)平臺一鍵安裝OS【定制化OS鏡像制作】

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI