您好,登錄后才能下訂單哦!
通過網絡去裝系統,如何部署配置
前言
部署PXE遠程安裝服務
實現Kickstart無人值守安裝
裸機插網卡,沒有IP地址,所以服務器要先運行DHCP服務,給客戶機分配地址,即服務端第一步先安裝引導程序
引導程序,指導客戶機去服務端下載相關安裝文件
引導程序放在TFTP服務器上,UDP協議69端口,傳輸速度快,文本小 第二步
映像文件放在VSFTPD上,tcp21和20端口 第三步
openstack
daiwops
[root@localhost pxelinux.cfg]# yum install tftp-sever -y '安裝tftp服務軟件'
[root@localhost pxelinux.cfg]# vim /etc/xinetd.d/tftp '修改tftp配置'
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no '雙重否定啟用'
per_source = 11
cps = 100 2
flags = IPv4
[root@localhost pxelinux.cfg]# yum install dhcp '安裝dhcp服務'
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.1 192.168.100.200;
option routers 192.168.100.100;
option domain-name-servers 8.8.8.8;
next-server 192.168.100.100; '指定TFTP服務器地址'
filename "pxelinux.0"; '指定要下載的引導程序文件'
}
[root@localhost pxelinux.cfg]# systemctl start dhcpd '開啟'
[root@localhost pxelinux.cfg]# systemctl enable dhcpd '自啟動'
[root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default '編輯default'
default auto '默認共享'
prompt 1 '啟動時間'
label auto
kernel vmlinuz '內核'
append initrd=initrd.img method=ftp://192.168.100.100/centos7 ks=ftp://192.168.100.100/ks.cfg
追加 進程 初始化文件 方法 定位 kickstart 位置
label linux text '文本模式安裝'
kernel vmlinuz
append text initrd=initrd.img method=ftp://192.168.100.100/centos7
label linux rescue '進入救援模式'
kernel vmlinuz
append rescue initrd=initrd.img method=ftp://192.168.100.100/centos7
root@localhost ~]# vim /var/ftp/ks.cfg
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL6,
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$6qKSDsgs$eaNnQ18jrgccQjSX95B9Z.
# Use network installation
url --url="ftp://192.168.100.100/centos7" '網絡安裝源'
# System language
lang zh_CN
# Firewall configuration
firewall --disabled
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled
# Network information
network --bootproto=dhcp --device=ens33
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=none
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot --fstype="xfs" --size=512
part /home --fstype="xfs" --size=4096
part swap --fstype="swap" --size=4096
part / --fstype="xfs" --grow --size=1
%packages '定制的軟件包組'
@^gnome-desktop-environment
@base
@core
@desktop-debugging
@dial-up
@directory-client
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@java-platform
@multimedia
@network-file-system-client
@networkmanager-submodules
@print-client
@x11
chrony
%end
root@localhost ~]# cp /root/ks.cfg /var/ftp/ks.cfg
root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default '編輯default'
default auto '默認共享'
prompt 0 '取消用戶時間'
label auto
kernel vmlinuz '內核'
append initrd=initrd.img method=ftp://192.168.100.100/centos7 ks=ftp://192.168.100.100/ks.cfg
追加 進程 初始化文件 方法 定位 應答文件kickstart 位置
思路:pxe自動部署
DHCP
為客戶機自動獲取IP地址,引導定位TFTP文件位置
命令:
next-server TFTP的IP
fliename “pxelinux.0”
TFTP 安裝tftp-server包,第一個安裝syslinux(包含pxelinux.0)' 引導程序
? 第二個壓縮內核 vmlinxuz (iso鏡像文件中獲取)
? 第三個初始化文件 initrd.img (iso鏡像文件中獲取)
? 第四個默認配置文件 default (自建文件:三個模式,默認是auto,指引FTP鏡像系統文件位置)
vsftpd 系統鏡像 無人值守安裝配置模板 (ks.cfg)
新加一塊網卡,設置僅主機模式,主機網卡用來安裝服務端去連接裸機,NAT網卡用來下載軟件包
[root@localhost named]# ifconfig 查看網卡
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.139.131 netmask 255.255.255.0 broadcast 192.168.139.255 '可以上網的網卡'
inet6 fe80::413b:c9ad:e0e:1afc prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:d6:c0:8a txqueuelen 1000 (Ethernet)
RX packets 638059 bytes 939850586 (896.3 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 157948 bytes 9731567 (9.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 '新增加的網卡,需要重新配置'
inet6 fe80::351b:fad2:2b7c:7ac2 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:d6:c0:94 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 13 bytes 2334 (2.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost named]# cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens36
'把ens33的網卡作為模板復制修改為ens36'
[root@localhost named]# vim /etc/sysconfig/network-scripts/ifcfg-ens36
'修改配置'
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static" '網卡設置為靜態'
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens36" '名稱改為36'
DEVICE="ens36"
ONBOOT="yes"
IPADDR=192.168.100.100 '配置IP地址'
NETMASK=255.255.255.0 '配置子網掩碼'
GATEWAY=192.168.100.1 '配置網關'
[root@localhost named]# systemctl restart network '重啟網卡'
[root@localhost named]# ifconfig '再次查看'
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.139.131 netmask 255.255.255.0 broadcast 192.168.139.255
ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.100 netmask 255.255.255.0
'成功'
1.
[root@localhost named]# systemctl stop firewalld.service 關閉防火墻
[root@localhost named]# setenforce 0 '關閉增強'
[root@localhost named]# rpm -q dhcp '查看dhcp是否安裝'
dhcp-4.2.5-77.el7.centos.x86_64
[root@localhost named]# yum install dhcp -y '沒有安裝的使用這個命令'
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.zju.edu.cn
* extras: mirrors.zju.edu.cn
* updates: mirrors.zju.edu.cn
軟件包 12:dhcp-4.2.5-77.el7.centos.x86_64 已安裝并且是最新版本
無須任何處理
[root@localhost named]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
'復制模板到/etc/dhcp.dhcpd下'
[root@localhost named]# vim /etc/dhcp/dhcpd.conf '編輯'
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.1 192.168.100.200;
option routers 192.168.100.100;
option domain-name-servers 8.8.8.8;
next-server 192.168.100.100; '指定TFTP服務器'
filename "pxelinux.0"; '指定要下載的引導程序文件目錄'
}
2.安裝tftp服務
[root@localhost named]# yum install tftp-server -y '安裝TFTPd服務'
[root@localhost named]# rpm -ql tftp-server '查看tftp服務的所有文件'
/etc/xinetd.d/tftp '需要配置'
/usr/lib/systemd/system/tftp.service
/usr/lib/systemd/system/tftp.socket
/usr/sbin/in.tftpd
/usr/share/doc/tftp-server-5.2
/usr/share/doc/tftp-server-5.2/CHANGES
/usr/share/doc/tftp-server-5.2/README
/usr/share/doc/tftp-server-5.2/README.security
/usr/share/man/man8/in.tftpd.8.gz
/usr/share/man/man8/tftpd.8.gz
/var/lib/tftpboot
[root@localhost named]# vim /etc/xinetd.d/tftp '編輯/etc/xinetd.d/tftp'
14 disable = no '雙重否定為啟用'
[root@localhost named]# vim /var/lib/tftpboot 'tftpboot站點'
[root@localhost named]# cd /var/lib/tftpboot
[root@localhost tftpboot]# ls
[root@localhost tftpboot]#
[root@localhost tftpboot]# yum install syslinux -y '安裝syslinux'
[root@localhost tftpboot]# rpm -ql syslinux | grep pxelinux.0
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/pxelinux.0 '把pxelinux.0復制到tftpboot內'
[root@localhost tftpboot]#
[root@localhost tftpboot]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@localhost tftpboot]# ls /var/lib/tftpboot
pxelinux.0
[root@localhost tftpboot]# yum install vsftpd -y '安裝vsftpd服務'
[root@localhost tftpboot]# rpm -ql vsftpd |grep pub
/var/ftp/pub
[root@localhost tftpboot]# mkdir /var/ftp/centos7 '創建/var/ftp/centos7目錄'
[root@localhost tftpboot]# cd /var/ftp
[root@localhost ftp]# ls
centos7 pub
[root@localhost ftp]# ls centos7/
[root@localhost ftp]#
開啟光驅,使用對應系統的鏡像文件
[root@localhost ftp]# mount /dev/sr0 /var/ftp/centos7 '把鏡像文件掛載到centos7上'
mount: /dev/sr0 寫保護,將以只讀方式掛載
[root@localhost ftp]# ls centos7
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
[root@localhost ftp]# cd centos7/images '切換到鏡像文件下的images目錄'
[root@localhost images]# ls
efiboot.img pxeboot TRANS.TBL
[root@localhost images]# cd pxeboot '切換到pxeboot目錄'
[root@localhost pxeboot]# ls
initrd.img TRANS.TBL vmlinuz
[root@localhost pxeboot]# cp vmlinuz initrd.img /var/lib/tftpboot '把里面的兩個文件復制到var/lib/tftpboot'
[root@localhost pxeboot]# ls /var/lib/tftpboot
initrd.img pxelinux.0 vmlinuz
[root@localhost pxeboot]# cd /var/lib/tftpboot '切換到tfpboot目錄'
[root@localhost tftpboot]# mkdir pxelinux.cfg '創建pxelinux.cfg目錄'
[root@localhost tftpboot]# cd pxelinux.cfg
[root@localhost pxelinux.cfg]# vim default '在pxelinux.cfg目錄下創建default文件'
[root@localhost pxelinux.cfg]# ls
default
[root@localhost pxelinux.cfg]#
defalut auto '默認為自適應'
prompt 1 '等待時間'
label auto '標簽自適應'
kernel vmlinuz '內核'
append initrd=initrd.img method=ftp://192.168.100.100/centos7
'追加初始化進程' '路徑方法'
label linux text
kernel vmlinuz
append text initrd=initrd.img method=ftp://192.168.100.100/centos7
label linux rescue
kernel vmlinuz
append rescue initrd=initrd.img method=ftp://192.168.100.100/centos7
[root@localhost pxelinux.cfg]# systemctl start dhcpd '開啟dhcpd'
[root@localhost pxelinux.cfg]# systemctl start vsftpd '開啟vsftpd'
[root@localhost pxelinux.cfg]# systemctl start tftp '開啟tftp'
測試
此時測試的虛擬機的網卡需要是僅主機模式
進入4
boot 敲回車
自動引導結束
3.無人值守安裝
[root@localhost ~]# yum install system-config-kickstart -y '安裝系統配置工具kickstart'
[root@localhost ~]# cd /var/ftp '切換到/var/ftp目錄'
[root@localhost ftp]# ls
centos7 ks.cfg pub
[root@localhost ftp]# vim ks.cfg '修改ks.cfg配置文件'
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$6qKSDsgs$eaNnQ18jrgccQjSX95B9Z.
# Use network installation
url --url="ftp://192.168.100.100/centos7"
# System language
lang zh_CN
# Firewall configuration
firewall --disabled
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled
# Network information
network --bootproto=dhcp --device=ens33
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=none
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot --fstype="xfs" --size=512
part /home --fstype="xfs" --size=4096
part swap --fstype="swap" --size=4096
part / --fstype="xfs" --grow --size=1
[root@localhost ftp]# cd ~ '切換到root的家目錄'
[root@localhost ~]# ls
anaconda-ks.cfg 公共 視頻 文檔 音樂
initial-setup-ks.cfg 模板 圖片 下載 桌面
[root@localhost ~]# vim anaconda-ks.cfg '把里面的anaconda.ks.cfg文件內的'
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'
# System language
lang zh_CN.UTF-8
# Network information
network --bootproto=dhcp --device=ens33 --ipv6=auto --activate
network --hostname=localhost.localdomain
# Root password
rootpw --iscrypted $6$lZy/ZqchdBxv/dZ0$RUyTDADN9e2H0hJlb9J757GyZ0nxWhPKY1sDdyCtvBR2/Asw/CPCAFFIfJB.kO7qbicMQx1LeoP53Xq/YXJeC0
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc
user --name=gsy --password=$6$4r65p5GBvUZhGlnz$Cs.RsqZdbDij5eQeIxWRi3f4VERzZFsp1TSkgaURI3d0Beafr8TT//iBETmpgEsW//yoHoqfvL9k2BwmGQlx51 --iscrypted --gecos="gsy"
# X Window System configuration information
xconfig --startxonboot
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
autopart --type=lvm
bootloader --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel
%packages
@^gnome-desktop-environment
@base
@core
@desktop-debugging
@dial-up
@directory-client
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@java-platform
@multimedia
@network-file-system-client
@networkmanager-submodules
@print-client
@x11
chrony
%end
%addon com_redhat_kdump --disable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
~
[root@localhost ~]# vim /var/ftp/ks.cfg
%packages
@^gnome-desktop-environment
@base
@core
@desktop-debugging
@dial-up
@directory-client
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@java-platform
@multimedia
@network-file-system-client
@networkmanager-submodules
@print-client
@x11
chrony
%end
[root@localhost ~]# cd /var/lib/tftpboot/
[root@localhost tftpboot]# ls
initrd.img pxelinux.0 pxelinux.cfg vmlinuz
[root@localhost tftpboot]# cd pxelinux.cfg
[root@localhost pxelinux.cfg]# ls
default
[root@localhost pxelinux.cfg]# vim default
label auto
kernel vmlinuz
append initrd=initrd.img method=ftp://192.168.100.100/centos7 ks=ftp://192.168.100.100/ks.cfg
[root@localhost pxelinux.cfg]# systemctl restart dhcpd
[root@localhost pxelinux.cfg]# systemctl restart tftp
[root@localhost pxelinux.cfg]# systemctl restart vsftpd
再次驗證
選擇第四個,然后回車
systemctl stop firewalld.service
setenforce 0
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.1 192.168.100.200;
option routers 192.168.100.100; '在局域網絡配置裝機服務時,把網關指向自己'
option domain-name-servers 8.8.8.8;
next-server 192.168.100.100; '指定FTP服務器'
filename "pxelinux.0"; '指定要下載的引導程序文件目錄'
}
配置tftpd服務的配置文件/etc/xinetd.d/tftp
disable 改為no '開啟'
initrd.img和vmlinuz文件來源于鏡像文件:把鏡像文件下的images/pxeboot/目錄下的兩個initrd.img、vmlinuz文件拷貝到/var/lib/tftpboot目錄下
pxelinux.0文件:需要先安裝syslinux軟件,在其/usr/share/syslinux目錄下,把pxelinux.0文件直接復制到var/lib/tftpboot/目錄下
pxelinux.cfg目錄為新創建的目錄,然后再var/lib/tftpboot/pxelinux.cfg/目錄下新建default文件
? pxelinux.cfg/default文件配置
default auto '默認共享'
prompt 1 '啟動時間'
label auto
kernel vmlinuz '內核'
append initrd=initrd.img method=ftp://192.168.100.100/centos7 ks=ftp://192.168.100.100/ks.cfg
追加 進程 初始化文件 方法 定位 kickstart 位置
label linux text '文本模式安裝'
kernel vmlinuz
append text initrd=initrd.img method=ftp://192.168.100.100/centos7
label linux rescue '進入救援模式'
kernel vmlinuz
append rescue initrd=initrd.img method=ftp://192.168.100.100/centos7
然后開啟所有服務
systemctl start dhcpd '開啟dhcpd'
systemctl start vsftpd '開啟vsftpd'
systemctl start tftp '開啟tftp'
先安裝system-config-kickstart 系統配置kickstart軟件
然后再圖形化界面配置
安裝方法FTP 服務器ftp://192.168.100.100/
目錄centos7
引導裝載程序選開啟
分區設置,/boot512M /home 4096M swap 4096M / 剩余的所有都給他
添加網卡ens33
禁用防火墻
然后保存在vsftpd服務的/var/ftp/目錄下
腳本可以把~/anaconda.cfg中的數據%pac
kages到%end 復制到/var/ftp/ks.cfg中
此時再次重啟即可
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。