1. Nginx提供目录浏览功能


1)安装Nginx,直接yum安装。

[root@qiudao ~]# yum install nginx -y


2)配置文件

[root@qiudao ~]# cat /etc/nginx/nginx.conf
worker_processes auto;
events {
worker_connections 1024;
}
http {
        include mime.types;
        charset utf-8;
        default_type application/octet-stream;
        sendfile on;
        autoindex on; #开启目录浏览功能


        keepalive_timeout 65;
    server {
        listen 80;
        listen [::]:80;
        server_name localhost;
        location / {
            root html;
            index index.html index.htm;
            }
    }
}
3)启动Nginx

[root@qiudao ~]# nginx -t
[root@qiudao ~]# systemctl start nginx
[root@qiudao ~]# systemctl enable nginx



2. 同步公网Yum源

同步了centos7基础源和epel源,有的同学担心,这样会特别占用空间!是的,如果不启用过滤,全部同步,确实很占用空间!


1)创建本地Yum源路径

[root@qiudao ~]# mkdir /usr/share/nginx/html/epel/7/x86_64/


[root@qiudao ~]# mkdir /usr/share/nginx/html/centos/7/x86_64/
2)下面编写Rsync里面的--exclude-from文件

[root@qiudao ~]# vim /usr/share/nginx/html/centos_exclude.txt    
EFI/
LiveOS/
images/
isolinux/
CentOS_BuildTag
EULA
GPL
RPM-GPG-KEY-CentOS-7
RPM-GPG-KEY-CentOS-Testing-7


[root@qiudao ~]#    vim /usr/share/nginx/html/epel_exclude.txt     debug/
drpms/
3)开始同步

#同步centos基础源,同步完成后,将其放到定时任务当中,每天进行一次同步。    
[root@qiudao ~]# /usr/bin/rsync -zaP --exclude-from=/usr/share/nginx/html/centos_exclude.txt rsync://rsync.mirrors.ustc.edu.cn/centos/7/os/x86_64/ /usr/share/nginx/html/centos/7/x86_64/    

#同步epel源,同步完成后,将其放到定时任务当中,每天进行一次同步    
[root@qiudao ~]# /usr/bin/rsync -zaP --exclude-from=/usr/share/nginx/html/epel_exclude.txt rsync://rsync.mirrors.ustc.edu.cn/epel/7/x86_64/ /usr/share/nginx/html/epel/7/x86_64/

#在这里我遇到了一个bug,我要排除的文件和目录没有排除掉。所以我就直接在命令行上面进行了排除

[root@qiudao ~]# /usr/bin/rsync -zaP --exclude={EFI/,LiveOS/,images/,isolinux/,CentOS_BuildTag,EULA,GPL,RPM-GPG-KEY-CentOS-7,RPM-GPG-KEY-CentOS-Testing-7} rsync://rsync.mirrors.ustc.edu.cn/centos/7/os/x86_64/ /usr/share/nginx/html/centos/7/x86_64/

[root@qiudao ~]# /usr/bin/rsync -zaP --exclude={debug/,drpms/} rsync://rsync.mirrors.ustc.edu.cn/epel/7/x86_64/ /usr/share/nginx/html/epel/7/x86_64/
最终2个源全部同步完成,到这里已经能提供yum服务了,但是无法为下游提供同步服务,于是有了第三步。

3. 部署Rsync


1)开启Rsync --daemon模式

[root@qiudao ~]# vim /etc/rsyncd.conf    
uid = nginx
gid = nginx
use chroot = no
max connections = 2000
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = true #只提供同步,只读足够

list = true #允许查看列表,认证的什么的不需要配置


hosts allow = 0.0.0.0/0
#####################################
[centos]
path = /usr/share/nginx/html/centos
[epel]
path = /usr/share/nginx/html/epel
2)启动Rsync

[root@qiudao ~]# systemctl start rsyncd
[root@qiudao ~]# systemctl enable rsyncd

到这里,一个公网yum该有的功能都有了!


3) 配置客户端,将其yum下载的源指向本地

①.将原来的源移动到别处

[root@qiudao ~]# cd /etc/yum.repos.d
[root@qiudao ~]# mkdir yum_bak && mv *repo yum_bak

②.清本地Yum缓存:

[root@qiudao ~]# yum clean all

③.创建新的Repo源

[root@qiudao ~]# vim oldboyedu.repo
[centos]
name=CentOS-$releasever - Base
baseurl=http://192.168.15.84/centos/7/$basearch
enable=1
gpgcheck=0

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://192.168.15.84/epel/7/$basearch
enabled=1
gpgcheck=0
④.或者在站点目录下面编写个Repo源文件

[root@qiudao ~]# vim /usr/share/nginx/html/oldboyedu.repo
[centos]
name=CentOS-$releasever - Base
baseurl=http://192.168.15.84/centos/7/$basearch
enable=1
gpgcheck=0

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://192.168.15.84/epel/7/$basearch
enabled=1
gpgcheck=0
⑤.下载到本地

[root@qiudao ~]# curl -o /etc/yum.repos.d/oldboyedu.repo http://192.168.15.84/oldboyedu.repo

⑥.显示Yum仓库源

[root@qiudao ~]# yum repolist

4.书写定时任务

[root@qiudao ~]# crontab -l
#sync Yum Base source
00 22 * * * /usr/bin/rsync -az --exclude={EFI/,LiveOS/,images/,isolinux/,CentOS_BuildTag,EULA,GPL,RPM-GPG-KEY-CentOS-7,RPM-GPG-KEY-CentOS-Testing-7} rsync://rsync.mirrors.ustc.edu.cn/centos/7/os/x86_64/ /usr/share/nginx/html/centos/7/x86_64/ &>/dev/null


#sync Yum epel source
00 23 * * * /usr/bin/rsync -az --exclude={debug/,drpms/} rsync://rsync.mirrors.ustc.edu.cn/epel/7/x86_64/ /usr/share/nginx/html/epel/7/x86_64/ &>/dev/null
Copyright © 高程程 all right reserved,powered by Gitbook修订于: 2021-05-18 21:15:10

results matching ""

    No results matching ""