Linux操作文档——搭建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$RApM9yvA$DYr9bIYor/Mql9UwGxGvC/
# System language
lang en_US
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled


# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=ens33
# Reboot after installation
reboot
# System timezone
timezone Africa/Abidjan
# Use network installation
url --url="ftp://192.168.1.10/centos7"
# 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

猜你喜欢

转载自blog.csdn.net/g950904/article/details/104197780