zoukankan      html  css  js  c++  java
  • 互联网同步yum服务器阿里云 reposync createrepo

    参考文章:

    https://www.cnblogs.com/lldsn/p/10479493.html

    系统版本centos 7.5 最小化安装

    修改主机名

    hostnamectl set-hostname yum.local

    安装wget软件包

    yum install wget -y

       

    修改yum源

    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

    wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

    验证阿里云是否正常

    yum repolist

    安装依赖包

    yum install -y wget make cmake gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel createrepo yum-utils

    创建本地目录

    mkdir /mirror

    同步rpm包到本地的

    reposync -p /mirror

    更新新的rpm包

    reposync -np /mirror

    创建索引

    createrepo -po /mirror/base/ /mirror/base/

    createrepo -po /mirror/extras/ /mirror/extras/

    createrepo -po /mirror/updates/ /mirror/updates/

    createrepo -po /mirror/epel/ /mirror/epel/

    createrepo -po /mirror/epel/ /mirror/centosplus/

    更新数据源

    createrepo --update /mirror/base

    createrepo --update /mirror/extras

    createrepo --update /mirror/updates

    createrepo --update /mirror/epel

    createrepo --update /mirror/centosplus

    安装nginx

    yum install nginx -y

    修改nginx的配置文件

    vi /etc/nginx/nginx.conf

    nginx.conf配置文件内容如下

    user nginx;

    worker_processes auto;

    error_log /var/log/nginx/error.log;

    pid /run/nginx.pid;

    include /usr/share/nginx/modules/*.conf;

    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;

    # Load modular configuration files from the /etc/nginx/conf.d directory.

    # See http://nginx.org/en/docs/ngx_core_module.html#include

    # for more information.

    include /etc/nginx/conf.d/*.conf;

    server {

    listen 80 default_server;

    listen [::]:80 default_server;

    server_name _;

    root /mirror; #修改未mirro目录

    # Load configuration files for the default server block.

    include /etc/nginx/default.d/*.conf;

    location / {

    autoindex on; #打开目录浏览功能

    autoindex_exact_size off; # off:以可读的方式显示文件大小

    autoindex_localtime on; # onoff:是否以服务器的文件时间作为显示的时间

    charset utf-8,gbk; #展示中文文件名

    index index.html;

    }

    error_page 404 /404.html;

    location = /40x.html {

    }

    error_page 500 502 503 504 /50x.html;

    location = /50x.html {

    }

    }

    }

       

    重启nginx服务

    systemctl restart nginx.service

    将nginx添加到开机启动

    systemctl enable nginx.service

    使用浏览器访问测试nginx是否能被成功访问。

       

    yum客户端配置

    cd /etc/yum.repos.d/

    备份系统自带的yum源

    tar -zcvf yum.bak.tar.gz /etc/yum.repos.d/CentOS-*

    删除系统自带的repo文件

    rm -rf CentOS-*

    创建yum配置文件

    vi local.repo

    local.repo配置文件的内容如下

    [base]

    name=CentOS-Base(GDS)

    baseurl=http://192.168.197.20/base

    path=/

    enabled=1

    gpgcheck=0

       

    [updates]

    name=CentOS-Updates(GDS)

    baseurl=http://192.168.197.20/updates

    path=/

    enabled=1

    gpgcheck=0

       

    [extras]

    name=CentOS-Extras(GDS)

    baseurl=http://192.168.197.20/extras

    path=/

    enabled=1

    gpgcheck=0

       

    [epel]

    name=CentOS-Epel(GDS)

    baseurl=http://192.168.197.20/epel

    path=/

    enabled=1

    gpgcheck=0

       

    清除

       

    测试安装一个rpm包

    yum install vim -y

       

    服务器端周期性的更新rpm包,手工命令如下

    更新rpm包

    reposync -np /mirror

    更新之后需要重新更新数据源

    createrepo --update /mirror/base

    createrepo --update /mirror/extras

    createrepo --update /mirror/updates

    createrepo --update /mirror/epel

       

    也可以创建定时更新的脚本

    #vim /mirror/script/centos_yum_update.sh

    #!/bin/bash

    echo 'Updating Aliyum Source'

    DATETIME=`date +%F_%T`

    exec > /var/log/aliyumrepo_$DATETIME.log

    reposync -np /mirror

    if [ $? -eq 0 ];then

    createrepo --update /mirror/base

    createrepo --update /mirror/extras

    createrepo --update /mirror/updates

    createrepo --update /mirror/epel

    echo "SUCESS: $DATETIME aliyum_yum update successful"

    else

    echo "ERROR: $DATETIME aliyum_yum update failed"

    fi

       

    将脚本加入到定时任务中

    # crontab -e

    # Updating Aliyum Source

    00 13 * * 6 [ $(date +%d) -eq $(cal | awk 'NR==3{print $NF}') ] && /bin/bash /mirror/script/centos_yum_update.sh

    每月第一个周六的13点更新阿里云yum

       

       

       

       

       

  • 相关阅读:
    解题报告:luogu P3853 [TJOI2007]路标设置
    解题报告:luogu P2678 跳石头
    SG函数
    解题报告:CF622F
    解题报告:luogu P1144 最短路计数
    树剖小结(简述)
    LCA之tarjan离线
    %你赛2020.2
    一个小证明(题解 P5425 Part1)
    科创版简介
  • 原文地址:https://www.cnblogs.com/withfeel/p/10635529.html
Copyright © 2011-2022 走看看