Linux操作技術文檔——搭建YUM倉庫服務與PXE網絡裝機

搭建YUM倉庫服務與PXE網絡裝機

一、搭建YUM倉庫服務

1、準備網絡安裝源(服務器端)

準備軟件倉庫目錄(系統安裝光盤)

[root@localhost ~]# mount /dev/cdrom /media/
[root@localhost ~]# mkdir -p /var/ftp/centos7
[root@localhost ~]# cp -rf /media/* /var/ftp/centos7/

非CentOS 7光盤自帶的更多其他軟件包(必須包括存在依賴關係的所有安裝文件)

[root@localhost ~]# mkdir /var/ftp/other
[root@localhost ~]# cd /var/ftp/other/
[root@localhost other]# cp -rf /media/* /var/ftp/other/
[root@localhost other]# createrepo -g /media/repodata/repomd.xml ./                 //創建repodata數據文件

安裝並啓用vsftpd服務

[root@localhost ~]# yum -y install vsftpd
[root@localhost ~]# systemctl start vsftpd
[root@localhost ~]# systemctl enable vsftpd

2、配置軟件倉庫位置(客戶端)

安裝ftp客戶端

[root@localhost ~]# yum -y install ftp

訪問ftp://1 92.168.1.10/centos7/,確保可以查看到已複製到軟件倉庫目錄
在這裏插入圖片描述
在這裏插入圖片描述
倉庫配置

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mkdir backup
[root@localhost yum.repos.d]# mv *.repo backup/
[root@localhost yum.repos.d]# vim /etc/yum.repos.d/centos7.repo
[base]
name=centos7
baseurl=ftp://192.168.1.10/centos7
gpgcheck=0

3、使用本地文件夾作爲軟件倉庫

[root@localhost ~]# vim /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///media
gpgcheck=0

二、使用yum工具管理軟件包

1、查詢軟件包

[root@localhost ~]# yum list           //查看獲得系統中的軟件安裝情況
[root@localhost ~]# yum list installed           //只列出系統中已安裝的軟件包
[root@localhost ~]# yum list available           //只列出軟件倉庫中可用(尚未安裝)的軟件包
[root@localhost ~]# yum list updates           //只列出可以升級版本的軟件包

2、yum info:查詢軟件包的描述信息

[root@localhost ~]# yum info vsftpd
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
已安裝的軟件包
名稱    :vsftpd
架構    :x86_64
版本    :3.0.2
發佈    :27.el7
大小    :353 k
源    :installed
來自源:base
簡介    : Very Secure Ftp Daemon
網址    :https://security.appspot.com/vsftpd.html
協議    : GPLv2 with exceptions
描述    : vsftpd is a Very Secure FTP daemon. It was written completely from
         : scratch.

3、yum search:查詢指定的軟件包

[root@localhost ~]# yum search all httpd
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
================================= 匹配:httpd ==================================
keycloak-httpd-client-install.noarch : Tools to configure Apache HTTPD as
                                     : Keycloak client
libmicrohttpd-doc.noarch : Documentation for libmicrohttpd
httpd-devel.x86_64 : Development interfaces for the Apache HTTP server
httpd-manual.noarch : Documentation for the Apache HTTP server
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
libmicrohttpd.i686 : Lightweight library for embedding a webserver in
                   : applications
libmicrohttpd.x86_64 : Lightweight library for embedding a webserver in
                     : applications
libmicrohttpd-devel.i686 : Development files for libmicrohttpd
libmicrohttpd-devel.x86_64 : Development files for libmicrohttpd
python2-keycloak-httpd-client-install.noarch : Tools to configure Apache HTTPD
                                             : as Keycloak client
httpd.x86_64 : Apache HTTP Server
mod_dav_svn.x86_64 : Apache httpd module for Subversion server
mod_auth_mellon.x86_64 : A SAML 2.0 authentication module for the Apache Httpd
                       : Server
mod_fcgid.x86_64 : FastCGI interface module for Apache 2
mod_ldap.x86_64 : LDAP authentication modules for the Apache HTTP Server
mod_lookup_identity.x86_64 : Apache module to retrieve additional information
                           : about the authenticated user
mod_proxy_html.x86_64 : HTML and XML content filters for the Apache HTTP Server
mod_session.x86_64 : Session interface for the Apache HTTP Server
mod_ssl.x86_64 : SSL/TLS module for the Apache HTTP Server

2、安裝、升級、卸載軟件包

下載並安裝net-snmp軟件包,並自動解決其依賴關係
在這裏插入圖片描述
卸載autofs軟件包,並自動解決其依賴關係
在這裏插入圖片描述

3、修改源的配置文件

修改源的配置文件 /etc/yum.repos.d/ ,將默認的一個文件做成一個備份,然後自己新建以 .repo 結尾的文件,用vim編輯器打開

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# pwd
/etc/yum.repos.d
[root@localhost yum.repos.d]# mkdir backup
[root@localhost yum.repos.d]# mv *.repo backup/

1、配置本地源

[root@localhost yum.repos.d]# vim my.repo
[myrepo]           //倉庫源名稱
name=NewRepo           //對yum的描述
baseurl=file:///media          //baseurl表示聲明yum可以管理並使用的rpm包路徑,
enable=1          //表示當前倉庫是否開啓,1爲開啓,0爲關閉,此項不寫默認爲開啓
gpgcheck=0           //gpgcheck表示安裝rpm包時,是否基於公私鑰對匹配包的安全信息,1表示開啓,0表示關閉,此項不寫默認爲驗證
[root@localhost yum.repos.d]# yum clean all           //清理yum緩存
[root@localhost yum.repos.d]# yum repolist           //啓用倉庫

2、配置網絡源
下載國內阿里的yum源

[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]# yum repolist 

國內其他yum源的地址
網易163yum源,安裝方法查看:http://mirrors.163.com/.help/
中科大的 yum源,安裝方法查看:https://lug.ustc.edu.cn/wiki/mirrors/help
清華大學的 yum源,安裝方法查看: https://mirrors.tuna.tsinghua.edu.cn/
浙江大學的 yum源,安裝方法查看: http://mirrors.zju.edu.cn/
中國科技大學yum源,安裝方法查看: http://centos.ustc.edu.cn/
3、拓展yum源
EPEL (Extra Packages for Enterprise Linux)是基於Fedora的一個項目,爲“紅帽系”的操作系統提供額外的軟件包,適用於RHEL、CentOS和Scientific Linux。
此處採用阿里yum擴展源

[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@localhost ~]# yum repolist 
[root@localhost ~]# yum makecache fast

三、部署PXE遠程安裝服務

若要搭建PXE網絡體系,必須滿足以下幾個前提條件

客戶機的網卡支持PXE協議(集成BOOTROM芯片),且主板支持網絡引導。 
網絡中有一臺DHCP服務器以便爲客戶機自動分配地址、指定引導文件位置。
服務器通過TFTP (Trivial File Transfer Protocol,簡單文件傳輸協議)提供引導鏡像文件的下載。

1、搭建PXE遠程安裝服務器

1、準備CentOS 7安裝源(同上)
2、安裝並啓用TFTP服務

[root@localhost ~]# yum -y install tftp-server
[root@localhost ~]# vim /etc/xinetd.d/tftp 
service tftp
{
        socket_type             = dgram
        protocol                = udp           //TFTP採用UDP傳輸協議
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot           //指定TFTP根目錄
        disable                 = no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}
[root@localhost ~]# systemctl start tftp
[root@localhost ~]# systemctl enable tftp

3、準備Linux內核、初始化鏡像文件

[root@localhost ~]# cd /var/ftp/centos7/images/pxeboot/
[root@localhost pxeboot]# cp vmlinuz initrd.img /var/lib/tftpboot/

4、準備PXE引導程序、啓動菜單文件

[root@localhost ~]# yum -y install syslinux
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
default auto  
prompt 1 
label auto
        kernel vmlinuz
        append initrd=initrd.img method=ftp://192.168.1.10/centos7
label linux text
        kernel vmlinuz
        append text initrd=initrd.img method=ftp://192.168.1.10/centos7
label linux rescue
        kernel vmlinuz
        append rescue initrd=initrd.img method=ftp://l92.l68.1.10/centos7

5、安裝並啓用DHCP服務

[root@localhost ~]# yum -y install dhcp
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf 
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;
option domain-name "csdn.com";
option domain-name-servers 114.114.114.114,223.5.5.5;
default-lease-time 21600;
max-lease-time 43200;
range 192.168.1.100 192.168.1.200;
next-server 192.168.1.10;
filename "pxelinux.0";  
}
[root@localhost ~]# systemctl start dhcpd
[root@localhost ~]# systemctl enable dhcpd

2、驗證PXE網絡安裝

使用虛擬機時,虛擬機內存至少需要2GB,否則在啓動安裝時會報錯
修改BIOS設置
在這裏插入圖片描述
在提示字串"boot:"後直接按Enter鍵(或執行"auto"命令),將會進入默認的圖形安裝入口; 若執行linux text”命令,則進入文本安裝入口;若執行"linux rescue"命令,則進入救援模式
在這裏插入圖片描述
進入圖形化安裝配置程序
在這裏插入圖片描述

四、實現Kickstart無人值守安裝

1、準備安裝應答文件

[root@localhost ~]# yum -y install system-config-kickstart
[root@localhost ~]# vim /etc/yum.repos.d/local.repo
[development]
name=my-centos7-dvd
baseurl=file:///var/ftp/centos7
enabled=1
gpgcheck=0

在這裏插入圖片描述

2、配置安裝應答參數

1、基本配置及安裝方法
基本配置
在這裏插入圖片描述
指定CentOS 7的安裝方法
在這裏插入圖片描述
指定硬盤分區方案
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
網絡配置及防火牆配置
在這裏插入圖片描述
在這裏插入圖片描述
選擇軟件包
在這裏插入圖片描述
在這裏插入圖片描述

rm -rf /etc/yum.repo.d/*
cat >> /etc/yum.repo.d/yum.repo << EOF
[centos7]
name=centos7
baseurl=ftp://192.168.1.10/centos7
gpgcheck=0
EOF

保存自動應答文件
在這裏插入圖片描述
在這裏插入圖片描述

3、實現批量自動裝機

1、啓用自動應答文件

[root@localhost ~]# cp /root/ks.cfg /var/ftp/ks.cfg
[root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default 
default auto
prompt 0                   //表示不等待用戶控制
label auto
        kernel vmlinuz
        append initrd=initrd.img method=ftp://192.168.1.10/centos7 ks=ftp://192.
168.1.10/ks.cfg                   //添加
label linux text
        kernel vmlinuz
        append text initrd=initrd.img method=ftp://192.168.1.10/centos7
label linux rescue
        kernel vmlinuz
        append rescue initrd=initrd.img method=ftp://l92.l68.1.10/centos7

2、驗證無人值守安裝
在這裏插入圖片描述
附件:ks.cfg安裝腳本

#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$R3WeI8np$p87QNYBUo5P6Ab5lEBd4q1
# Use network installation
url --url="ftp://192.168.1.10/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=500
part /home --fstype="xfs" --size=4096
part swap --fstype="swap" --size=2048
part / --fstype="xfs" --grow --size=1

%post --interpreter=/bin/bash
rm -rf /etc/yum.repo.d/*
cat >> /etc/yum.repo.d/yum.repo << EOF
[centos7]
name=centos7
baseurl=ftp://192.168.1.10/centos7
gpgcheck=0
EOF
%end

%packages
@development
@gnome-desktop

%end
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章