天天看點

Redhat7.4 同步阿裡雲鏡像rpm包并自建本地yum倉庫

作業系統

IP位址

主機名

備注

Redhat7.4

192.168.10.21

yum-server

192.168.10.22

jump01

[root@yum-server ~]# cat /etc/redhat-release 

Red Hat Enterprise Linux Server release 7.4 (Maipo)

[root@yum-server ~]# systemctl stop ebtables firewalld

[root@yum-server ~]# systemctl disable ebtables firewalld

[root@yum-server ~]# sed -i 's/enforcing/disabled/g' /etc/sysconfig/selinux 

[root@yum-server ~]# setenforce 0

[root@yum-server ~]# tar -zcvf Centos-bak.tar.gz /etc/yum.repos.d/*

[root@yum-server ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

[root@yum-server ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

或者

[root@yum-server ~]# curl -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

[root@yum-server ~]# curl -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo  

[root@yum-server ~]# yum install -y wget make cmake gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel createrepo yum-utils

yum-utils:reposync同步工具

createrepo:編輯yum庫工具

plugin-priorities:控制yum源更新優先級工具,這個工具可以用來控制進行yum源檢索的先後順序,建議可以用在client端。

注:由于很多人喜歡最小化安裝,上邊軟體是一些常用環境。

[root@yum-server ~]# mkdir /mirrors/

[root@yum-server ~]# reposync -r base -p /mirrors/

注:不用擔心沒有建立相關目錄,系統自動建立相關目錄,并下載下傳,時間較長請耐心等待。

可以用 repo -r --repoid=repoid指定要查詢的repo id,可以指定多個(# reposync -r base -p /mirror #這裡同步base目錄到本地)

createrepo文法:

格式:createrepo -po  源目錄  索引中繼資料的輸出位置目錄

[root@yum-server ~]# createrepo -po /mirrors/base/  /mirrors/base/

[root@yum-server ~]# createrepo -po /mirrors/epel/  /mirrors/epel/

[root@yum-server ~]# createrepo --update /mirrors/base

[root@yum-server ~]# createrepo --update /mirrors/epel

[root@yum-server ~]# createrepo --update /mirrors/extras

[root@yum-server ~]# createrepo --update /mirrors/updates

[root@yum-server ~]# vim /mirrors/centos_yum_update.sh

#!/bin/bash

echo 'Updating Aliyum Source'

DATETIME=`date +%F_%T`

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

     reposync -np /mirrors

if [ $? -eq 0 ];then

      createrepo --update /mirrors/base

      createrepo --update /mirrors/extras

      createrepo --update /mirrors/updates

      createrepo --update /mirrors/epel

      echo "SUCESS: $DATETIME aliyum_yum update successful"

  else

      echo "ERROR: $DATETIME aliyum_yum update failed"

fi

[root@yum-server ~]# chmod a+x /mirrors/centos_yum_update.sh

[root@yum-server ~]# crontab -e

# Updating Aliyum Source

00 22 * * 6  /bin/bash /mirrors/centos_yum_update.sh

解釋:每月第一個周六的22點更新阿裡雲yum源

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

[root@yum-server ~]# vim /etc/nginx/nginx.conf 

user nginx;

worker_processes auto;

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

pid /var/run/nginx.pid;

events {

    worker_connections 1024;

}

http {

    include /etc/nginx/mime.types;

    default_type application/octet-stream;

    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;

    keepalive_timeout 65;

    gzip on;

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

server {

    listen 80;

    server_name localhost;

    root /mirrors;

    index index.html index.htm;

    #charset koi8-r;

    #access_log /var/log/nginx/yum.access.log main;

    location / {

        autoindex on;

        autoindex_exact_size off;

        autoindex_localtime on;

        charset utf-8,gbk;

    }

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html

    #

    error_page 500 502 503 504 /50x.html;

    location = /50x.html {

        root /usr/share/nginx/html;

[root@yum-server ~]# systemctl restart nginx

[root@yum-server ~]# systemctl enable nginx

[root@jump01 ~]# vim /etc/yum.repos.d/centos_local.repo 

[base]

name=base

baseurl=http://192.168.10.21/base/

failovermethod=priority

enabled=1

gpgcheck=0

[extras]

name=extras

baseurl=http://192.168.10.21/extras/

[updates]

name=updates

baseurl=http://192.168.10.21/updates/

[epel]

name=epel

baseurl=http://192.168.10.21/epel/

[root@jump01 ~]# yum makecache 

[root@jump01 ~]# yum -y install memcached