• 搭建本地仓库脚本


    这是一个脚本文件,把内容复制到sh文件里面,sh.123.sh即可

    脚本内容

    #在/root路径下创建123.sh文件,把此文件复制到123.sh里,  sh 123.sh
    #首选安装nginx,作为web展示
    
    #强力清除老版本残留
    rpm -e nginx --nodeps
    rm -rf  /etc/nginx
    
    #开始安装
    yum install -y nginx 
    
    #配置文件()
    cat > /etc/nginx/nginx.conf << EOF
    user nginx;
    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /run/nginx.pid;
    events {worker_connections 1024;}
    http {log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
        access_log  /var/log/nginx/access.log  main;
        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         on;
        keepalive_timeout   65;
        types_hash_max_size 2048;
        include             /etc/nginx/mime.types;
        default_type        application/octet-stream;
        server{
        listen              80;
        root                /var/ftp/pub/;
        autoindex on;}      }
    EOF
    
    #安装vsftpd
    yum install  vsftpd -y
    
    #启动自启nginx,ftp
    systemctl start nginx
    systemctl enable nginx
    systemctl start vsftpd
    systemctl enable vsftpd
    
    #创建yum源存放目录
    mkdir -p /var/ftp/pub/epel/7/
    mkdir -p /var/ftp/pub/centos/7/os/x86_64/
    mkdir -p /var/ftp/pub/centos/7/updates/x86_64/
    mkdir -p /var/ftp/pub/centos/7/extras/x86_64/
    mkdir -p /var/ftp/pub/centos/7/centosplus/x86_64/
    
    #把不同步的yum源写入到排除文件
    mkdir -p /var/ftp/pub/
    cat > /var/ftp/pub/exclude.list <<EOF
    SRPMS
    aarch64
    ppc64
    ppc64le
    debug
    repodata
    EFI
    LiveOS
    images
    isolinux
    CentOS_BuildTag
    EULA
    GPL
    RPM-GPG-KEY-CentOS-7
    RPM-GPG-KEY-CentOS-Testing-7
    drpms
    EOF
    
    #这里写一个同步清华大学源的脚本
    cat >  /var/ftp/pub/centos7-rsync.sh <<EOF
    #epel
    rsync -avz --exclude-from=/var/ftp/pub/exclude.list rsync://mirrors.tuna.tsinghua.edu.cn/epel/7/ /var/ftp/pub/epel/7/
    createrepo /var/ftp/pub/epel/7/
     
    #centos7-base
    rsync -avz --exclude-from=/var/ftp/pub/exclude.list rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/ /var/ftp/pub/centos/7/os/x86_64/
    createrepo /var/ftp/pub/centos/7/os/x86_64/
     
    #centos7-updates
    rsync -avz --exclude-from=/var/ftp/pub/exclude.list rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/updates/x86_64/ /var/ftp/pub/centos/7/updates/x86_64/
    createrepo /var/ftp/pub/centos/7/updates/x86_64/
     
    #centos7-extras
    rsync -avz --exclude-from=/var/ftp/pub/exclude.list rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/extras/x86_64/ /var/ftp/pub/centos/7/extras/x86_64/
    createrepo /var/ftp/pub/centos/7/extras/x86_64/
     
    #centos7-centosplus
    rsync -avz --exclude-from=/var/ftp/pub/exclude.list rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/centosplus/x86_64/ /var/ftp/pub/centos/7/centosplus/x86_64/
    createrepo /var/ftp/pub/centos/7/centosplus/x86_64/
    EOF
    
    #最后一步,执行脚本同步
    sh /var/ftp/pub/centos7-rsync.sh
    
    #做一个定时更新yum源的任务
    echo "#每天4点更新yum源
    00 04 * * *  /usr/bin/sh    /var/ftp/pub/centos7-rsync.sh  &> /dev/null" >> /var/spool/cron/root

     注:此脚本感谢雷虎同学

  • 相关阅读:
    纯JavaScripst的全选、全不选、反选 【转】
    Java 文件和byte数组转换
    nc命令使用详解
    mtr 命令详解
    Nginx主动检测方案---Tengine
    Apache相关安全设置
    tomcat APR的配置
    Vsftpd 配置详解
    FTP主动模式和被动模式的区别
    iptables配置详解
  • 原文地址:https://www.cnblogs.com/Mercury-linux/p/12400967.html
Copyright © 2020-2023  润新知