上传Centos镜像
CentOS-7-x86_64-DVD-2207-02.iso
挂载iso镜像
mkdir -p /mnt/cdrom #创建挂载目录
mount -o loop CentOS-7-x86_64-DVD-2207-02.iso /mnt/cdrom/
挂载好的目录文件
总用量 698
-rw-rw-r--. 2 root root 14 10月 30 CentOS_BuildTag
drwxr-xr-x. 3 root root 2048 7月 26 22:39 EFI
-rw-rw-r--. 2 root root 227 8月 30 EULA
-rw-rw-r--. 2 root root 18009 12月 10 GPL
drwxr-xr-x. 3 root root 2048 7月 26 22:40 images
drwxr-xr-x. 2 root root 2048 7月 26 22:39 isolinux
drwxr-xr-x. 2 root root 2048 7月 26 22:39 LiveOS
drwxr-xr-x. 2 root root 675840 7月 26 00:51 Packages
drwxr-xr-x. 2 root root 4096 7月 26 00:51 repodata
-rw-rw-r--. 2 root root 1690 12月 10 RPM-GPG-KEY-CentOS-7
-rw-rw-r--. 2 root root 1690 12月 10 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--. 1 root root 2883 7月 26 23:09 TRANS.TBL
配置本地yum源
删除默认repo文件
rm -rf /etc/yum.repos.d/*
vi /etc/yum.repos.d/Centos7.repo
[Centos7.9]
baseurl = file:///mnt/cdrom
gpgcheck = 0
enabled=1
name = Base Yum Repo
编译安装nginx
yum install gcc gcc-c++ pcre pcre-devel openssl openssl-devel -y
上传nginx-1.22.0.tar,解压并编译安装
./configure --user=www --group=www --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf
此时可用nginx直接配置
cd /etc/nginx/conf.d/
cat local_yum.conf
server {
listen 99;
server_name 本机IP;
charset utf-8;
location /cdrom
{
autoindex on;
root /mnt/;
}
}
浏览器访问http://本机IP:99/cdrom
使用createrepo实现
yum install -y createrepo
mkdir -p /mnt/nginx-yum
cp -a /mnt/cdrom/Packages/ /mnt/nginx-yum/ # /mnt/cdrom/为只读目录,且不想展示过多内容,需先拷贝出来
cd /mnt/nginx-yum/
ll
总用量 292
drwxr-xr-x. 2 root root 229376 7月 26 00:51 Packages
#执行以下命令,利用挂载目录里的**comps.xml生成repodata,没有该文件将无法成功调用yum
#最终验证 直接拷贝/mnt/cdrom/repodata可直接使用,跟以下命令生成是一样的。这就很尴尬
createrepo -g /mnt/cdrom/repodata/cca56f3cffa18f1e52302dbfcf2f0250a94c8a37acd8347ed6317cb52c8369dc-comps.xml /mnt/nginx-yum/
...
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
ll
总用量 296
drwxr-xr-x. 2 root root 229376 7月 26 00:51 Packages
drwxr-xr-x. 2 root root 4096 11月 24 17:01 repodata
cd /etc/nginx/conf.d/
cat yum.conf
server {
listen 88;
server_name 本机IP;
charset utf-8;
location /nginx-yum
{
autoindex on;
root /mnt/;
}
}
浏览器访问http://本机IP:88/nginx-yum
配置局域网yum源
cat /etc/yum.repos.d/Centos7.repo
[Centos7.9]
baseurl = http://本地IP:88/nginx-yum/
enabled=1
gpgcheck = 0
name = Base Yum Repo
yum clean all
已加载插件:fastestmirror
正在清理软件源: Centos7.9
Cleaning up list of fastest mirrors
Other repos take up 18 M of disk space (use --verbose for details)
yum makecache
已加载插件:fastestmirror
Determining fastest mirrors
Centos7.9 | 3.0 kB 00:00:00
(1/3): Centos7.9/filelists_db | 3.3 MB 00:00:00
(2/3): Centos7.9/primary_db | 3.3 MB 00:00:00
(3/3): Centos7.9/other_db| 1.3 MB 00:00:00
元数据缓存已建立
原挂载的镜像此时也可以卸载,不影响使用
umount /mnt/cdrom/
rm -rf /mnt/cdrom/