溫馨提示×

溫馨提示×

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

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

實現(xiàn)基于PXE的系統(tǒng)自動化安裝

發(fā)布時間:2020-08-02 20:51:32 來源:網(wǎng)絡(luò) 閱讀:179 作者:Planeta峰 欄目:系統(tǒng)運維

初始化:iptables|firewalld,selinux,ntp|chrony
環(huán)境:兩臺主機
一臺主機A:DHCP,TFTP,HTTP,ks,yum 源 vmnet15,10.10.10.10
一臺主機B:客戶端pxe vmnet15

在A上實現(xiàn)。
一、http服務(wù)上需要實現(xiàn)的功能。

1.實現(xiàn)http服務(wù),下載http服務(wù),并且開啟服務(wù),設(shè)置成開機自動啟動。(centos7)

yum install httpd 
systemctl start httpd 
systemctl enable httpd 

2.配置啟動文件yum源文件的掛載,yum源文件提前拷貝到機器上

[root@centos7 ]#cd /var/www/html
[root@centos7 html]#mkdir -pv centos/{6,7}/os/x86_64/
把拷貝好的光盤文件掛載上去,放的位置不同,掛載的位置也不同。在/etc/fstab添加下面2行
[root@centos7 html]#vim /etc/fstab
/data/CentOS-7-x86_64-Everything-1810.iso /var/www/html/centos/7/os/x86_64/ iso9660 defaults 0 0
/data/CentOS-6.10-x86_64-bin-DVD1.iso /var/www/html/centos/6/os/x86_64/ iso9660 defaults 0 0
自動掛載
[root@centos7 html]#mount -a

3.應(yīng)答文件的配置,在圖形化界面配置生成,必須可以打開圖形功能(centos7) 6和7的文件要在不同的機器上分別生成,6和7還是有一點點細微的差別的。

[root@centos7 ~]#yum install system-config-kickstart 
[root@centos7 ~]#system-config-kickstart 

實現(xiàn)基于PXE的系統(tǒng)自動化安裝

實現(xiàn)基于PXE的系統(tǒng)自動化安裝

實現(xiàn)基于PXE的系統(tǒng)自動化安裝
實現(xiàn)基于PXE的系統(tǒng)自動化安裝

分區(qū)要自己設(shè)置的,由于圖片原因,就不細寫了

實現(xiàn)基于PXE的系統(tǒng)自動化安裝

實現(xiàn)基于PXE的系統(tǒng)自動化安裝

下面這個地方要注意了。必須要在本機的yum倉庫中把一個yum名字改成development,不然不會出現(xiàn)下圖的包的選擇。需要什么包自己選擇,也可以不選擇,但是centos6必須選擇一個包,生成文件后也可以刪除,不選擇的話會把所有的包都安裝上。

實現(xiàn)基于PXE的系統(tǒng)自動化安裝

實現(xiàn)基于PXE的系統(tǒng)自動化安裝

安裝后腳本,可以自己寫個初始化腳本,圖片被吃了

實現(xiàn)基于PXE的系統(tǒng)自動化安裝

下面是應(yīng)答文件的保存

實現(xiàn)基于PXE的系統(tǒng)自動化安裝

實現(xiàn)基于PXE的系統(tǒng)自動化安裝

生成文件后還可以修改。具體情況自己選擇。

[root@centos7 ]#cd /var/www/html
[root@centos7 html]#mkdir ksdir

把生成ks文件拷貝到里面

[root@centos7 html]#cd ksdir/
[root@centos7 ksdir]#tree
.
├── ks6_desktop.cfg
└── ks7_mini.cfg

0 directories, 2 files

這里貼一個ks文件,可以照的修改修改。6和7是有區(qū)別的。需要自己生成。

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --plaintext magedu
# Use network installation
url --url="http://10.10.10.10/centos/7/os/x86_64"
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled

# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System timezone
timezone Africa/Abidjan
# System bootloader configuration
bootloader --append="net.ifnames=0" --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --fstype="xfs" --size=10000
part /boot --fstype="xfs" --size=1000
part swap --fstype="swap" --size=1024

%post
useradd wang 
echo 123456 | passwd --stdin wang &> /dev/null
mkdir /etc/yum.repos.d/backup
cd /etc/yum.repos.d/
mv *.repo backup/
cat >base.repo <<EOF
[base]
baseurl=file:///misc/cd
gpgcheck=0
EOF
systemctl enable autofs
%end

%packages
autofs
tree
vim-enhanced
%end  

最后的httpd的結(jié)構(gòu)目錄,這是沒有掛載光盤文件之前的。index.html這個是沒有什么用的文件。

[root@centos7 html]#tree
.
├── centos
│ ├── 6
│ │ └── os
│ │ └── x86_64
│ └── 7
│ └── os
│ └── x86_64
├── index.html
└── ksdir
    ├── ks6_desktop.cfg
    └── ks7_mini.cfg

8 directories, 3 files

二、dhcp服務(wù)需要實現(xiàn)的功能

[root@centos7 network-scripts]#yum install dhcp
把配置示例弄過來,然后在修改修改
[root@centos7 network-scripts]#cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf 
[root@centos7 ksdir]#vim /etc/dhcp/dhcpd.conf
主要修改如下,就不一一解釋了,截圖寫的詳細太累了,一一解釋實在是太多了。
default-lease-time 86400;
max-lease-time 864000;
subnet 10.10.10.0 netmask 255.255.255.0 {
 range 10.10.10.11 10.10.10.100;
 range 10.10.10.130 10.10.10.254;
 option routers 10.10.10.10;
 option domain-name-servers 114.114.114.114,8.8.8.8;
 option domain-name "yuming.org";
 next-server 10.10.10.10;
 filename "pxelinux.0";
}

host mysql {
  hardware ethernet 00:0c:29:ec:ab:e6;
  fixed-address 10.10.10.5;
}

配置好就可以啟動服務(wù)等,在另一臺機器上查看效果了,看看是否可以得到地址,注意一定要在同一個網(wǎng)段,看能否得到地址、網(wǎng)關(guān)等。

[root@centos7 dhcpd]#systemctl start dhcpd
[root@centos7 dhcpd]#systemctl enable dhcpd

三、tftp服務(wù)

[root@centos7 dhcpd]#yum install tftp-server
[root@centos7 dhcpd]#systemctl start tftp.service
[root@centos7 dhcpd]#systemctl enable tftp.service

客戶端包。測試的時候可以使用
[root@centos6 isolinux]#yum install tftp

四、相關(guān)PXE相關(guān)文件

[root@centos7 tftpboot]#yum install syslinux
[root@centos7 tftpboot]#cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@centos7 tftpboot]# cd /var/lib/tftpboot
安裝菜單的準備工作
[root@centos7 tftpboot]#mkdir /var/lib/tftpboot/pxelinux.cfg/
[root@centos7 tftpboot]#cp /misc/cd//isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
把光盤上的啟動文件拷貝過來
mkdir /var/lib/tftpboot/centos{6,7}
cp /var/www/html/centos/7/os/x86_64/isolinux/{vmlinux,initrd.img} /var/lib/tftpboot/centos7
cp /var/www/html/centos/6/os/x86_64/isolinux/{vmlinux,initrd.img} /var/lib/tftpboot/centos6

下面只是為了改一下開機的圖片顯示,改成簡易的風格,還有一些菜單選項需要修改。
kernel和append的路徑一定要寫對了。
[root@centos7 tftpboot]#cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot
 [root@centos7 tftpboot]#vim pxelinux.cfg/default
default menu.c32
timeout 600

menu title Auto Install CentOS

label linux7
  menu label Install ^Mini_CentOS 7
  menu default
  kernel centos7/vmlinuz
  append initrd=centos7/initrd.img ks=http://10.10.10.10/ksdir/ks7_mini.cfg

label linux6                                                                                 
  menu label Install Desktop_CentOS 6
  kernel centos6/vmlinuz
  append initrd=centos6/initrd.img ks=http://10.10.10.10/ksdir/ks6_desktop.cfg

label local
  menu label Boot from ^local drive
  localboot 0xffff

最后的目錄結(jié)構(gòu)是這樣的

[root@centos7 tftpboot]#tree
.
├── centos6
│ ├── initrd.img
│ └── vmlinuz
├── centos7
│ ├── initrd.img
│ └── vmlinuz
├── menu.c32
├── pxelinux.0
└── pxelinux.cfg
    └── default

3 directories, 7 files

五、A機器搭建完成。B機器配置同樣網(wǎng)段就可以測試使用了,效果圖如下。

實現(xiàn)基于PXE的系統(tǒng)自動化安裝

向AI問一下細節(jié)

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

AI