Linux-搭建内网yum源
部署要求:
服务器:CentOS7
YUM源:阿里云
空间要求:CentOS6+CentOS7 50G,考虑后期更新预留,LVS空间100G
1、在服务器配置CentOS7的yum源和CentOS6的yum源
#Centos7
[base7]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[updates7]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[extras7]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[epel7]
name=CentOS-7-epel-cmiot.local
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
gpgcheck=0
#Centos6
[base6]
name=CentOS-6 - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/6/os/x86_64/
        http://mirrors.aliyuncs.com/centos/6/os/x86_64/
        http://mirrors.cloud.aliyuncs.com/centos/6/os/x86_64/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
[updates6]
name=CentOS-6 - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/6/updates/x86_64/
        http://mirrors.aliyuncs.com/centos/6/updates/x86_64/
        http://mirrors.cloud.aliyuncs.com/centos/6/updates/x86_64/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
[extras6]
name=CentOS-6 - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/6/extras/x86_64/
        http://mirrors.aliyuncs.com/centos/6/extras/x86_64/
        http://mirrors.cloud.aliyuncs.com/centos/6/extras/x86_64/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
[epel6]
name=CentOS-6-epel-cmiot.local
baseurl=https://mirrors.aliyun.com/epel/6/x86_64/
gpgcheck=0
2、检查yum的可用性,并查看yum的repolist

3、安装repo同步工具和必要软件包
yum install -y wget make cmake gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel createrepo yum-utils
4、创建yum软件包目录并向阿里同步,时间较久。
mkdir -p /mirror/Aliyun/CentOS/6
reposync -n --repoid=extras6 --repoid=updates6 --repoid=base6 --repoid=epel6 -p /mirror/Aliyun/CentOS/6
mkdir -p /mirror/Aliyun/CentOS/7
reposync -n --repoid=extras7 --repoid=updates7 --repoid=base7 --repoid=epel7 -p /mirror/Aliyun/CentOS/7
5、创建索引
createrepo -po /mirror/Aliyun/CentOS/6/base6/ /mirror/Aliyun/CentOS/6/base6/
createrepo -po /mirror/Aliyun/CentOS/6/epel6/ /mirror/Aliyun/CentOS/6/epel6/
createrepo -po /mirror/Aliyun/CentOS/6/extras6/ /mirror/Aliyun/CentOS/6/extras6/
createrepo -po /mirror/Aliyun/CentOS/6/updates6/ /mirror/Aliyun/CentOS/6/updates6/
createrepo -po /mirror/Aliyun/CentOS/7/base7/ /mirror/Aliyun/CentOS/7/base7/
createrepo -po /mirror/Aliyun/CentOS/7/epel7/ /mirror/Aliyun/CentOS/7/epel7/
createrepo -po /mirror/Aliyun/CentOS/7/extras7 /mirror/Aliyun/CentOS/7/extras7
createrepo -po /mirror/Aliyun/CentOS/7/updates7/ /mirror/Aliyun/CentOS/7/updates7/
6、安装nginx并配置
user root;
worker_processes  auto;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        root         /mirror ;           #这里是yum源存放目录,访问以此目录为根目录。      
        location / {
            autoindex on;                #打开目录浏览功能
            autoindex_exact_size off;    # off:以可读的方式显示文件大小
            autoindex_localtime on;      # on、off:是否以服务器的文件时间作为显示的时间
            charset utf-8,gbk;           #展示中文文件名
            index index.html;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
7、创建更新软件包的定时任务
1 0 1 * * * /mirror/update.sh
#!/bin/bash
reposync -n --repoid=extras6 --repoid=updates6 --repoid=base6 --repoid=epel6 -p /mirror/Aliyun/CentOS/6
reposync -n --repoid=extras7 --repoid=updates7 --repoid=base7 --repoid=epel7 -p /mirror/Aliyun/CentOS/7
createrepo --update /mirror/Aliyun/CentOS/6/base6/
createrepo --update /mirror/Aliyun/CentOS/6/epel6/
createrepo --update /mirror/Aliyun/CentOS/6/extras6/
createrepo --update /mirror/Aliyun/CentOS/6/updates6/
createrepo --update /mirror/Aliyun/CentOS/7/base7/
createrepo --update /mirror/Aliyun/CentOS/7/epel7/
createrepo --update /mirror/Aliyun/CentOS/7/extras7/
createrepo --update /mirror/Aliyun/CentOS/7/updates7/
8、配置客户端yum文件使用
为方便客户端下载,可配置nginx支持从客户端直接下载yum配置文件,配置方法如下
- 配置nginx
[root@HLWHOST ~]# cat /etc/nginx/nginx.conf
user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
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 4096;
    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;
        listen       [::]:80;
        server_name  localhost;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        location / {
            root   /data/mirror/Aliyun/;
            autoindex on;
            autoindex_exact_size off;
            autoindex_localtime on;
            charset utf-8,gbk;
            index index.html;
        }
        location /repo {                                  #配置repo文件的位置
            alias   /data/repo/;
            autoindex on;
            autoindex_exact_size off;
            autoindex_localtime on;
            charset utf-8,gbk;
            index index.html;
        }
        error_page 404 /404.html;
        location = /404.html {
        }
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
}
- 客户端下载repo文件
curl -o /etc/yum.repos.d/centos7.repo http://192.67.0.67/repo/centos7.repo
[base]
name=CentOS-$releasever - Base
baseurl=http://192.67.0.67/Aliyun/CentOS/$releasever/base$releasever
gpgcheck=1
gpgkey=http://192.67.0.67/Aliyun/CentOS/RPM-GPG-KEY-CentOS-$releasever
[updates]
name=CentOS-$releasever - Updates
baseurl=http://192.67.0.67/Aliyun/CentOS/$releasever/updates$releasever
gpgcheck=1
gpgkey=http://192.67.0.67/Aliyun/CentOS/RPM-GPG-KEY-CentOS-$releasever
[extras]
name=CentOS-$releasever - Extras
baseurl=http://192.67.0.67/Aliyun/CentOS/$releasever/extras$releasever
gpgcheck=1
gpgkey=http://192.67.0.67/Aliyun/CentOS/RPM-GPG-KEY-CentOS-$releasever
[epel]
name=CentOS-$releasever - epel
baseurl=http://192.67.0.67/Aliyun/CentOS/$releasever/epel$releasever
gpgcheck=0
yum clean all
yum makecache
yum repolist
9、可能遇到的问题
404
如果出现404错误,大概率可能是配置文件出错。
有可能是location后多加一个左斜杠/
也有可以是指向的目录地址不存在
403
403 Forbidden 代表被禁止的,一般是三种情况导致的
1、目录权限不足
检查目录权限。权限不足就将权限加上
chmod -R 755 /home/files
2、nginx.conf用户权限问题
vim /etc/nginx/nginx.conf
把 user 用户名 改为 user root 或 其它有高权限的用户名称即可
3 、Centos中的selinux配置未关闭
查看SELinux状态:
如果SELinux status参数为enabled即为开启状态
/usr/sbin/sestatus -v
如何关闭?
1、临时关闭(不用重启机器):
setenforce 0
2、永久关闭(要重启机器)
vim /etc/selinux/config
将SELINUX=enforcing改为SELINUX=disabled
10、参考链接
https://www.cnblogs.com/vpandaxjl/p/12054227.html
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号