私有yum源适合于公司内网用户进行软件安装,也适合自定义RPM安装,许多大型公司会有自己的yum源,废话不多说我们来搭建私有yum源

1)安装yum utils工具包:

yum install yum-utils

2)创建rpm包存放目录:

install -d /application/yum/centos7/x86_64/

3) 初始化repodata索引文件

createrepo -pdo /application/yum/centos7/x86_64/ /application/yum/centos7/x86_64/

完成初始化后会生成yum源的相关数据库文件和索引文件存放于repodata目录下面

4)这里我们采用nginx作为服务器提供http服务

1,nginx安装这里不做说明,想了解 更多可以参照我之前的nginx相关文章进行安装:

2,在nginx conf目录下新建文件repo.conf 内容如下:

#repo conf
server {
    listen 8080;
    server_name 192.168.56.6;
    access_log  /var/log/nginx/repo.log;
    error_log  /var/log/nginx/repoerr.log;
    location / {
        root  /application/yum/centos7/x86_64/;
        autoindex on;
    }
}

3,修改nginx主配置文件http 下面,包含此文件:

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    include     repo.conf;
    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #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   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

启动nginx

启动之后可以尝试去访问下看服务时候正常启动

5)生成私有仓库repo文件private.repo:

文件内容如下:

[privaterepo]
name=privaterepo
baseurl=http://192.168.56.6:8080
gpgcheck=0

6) 测试

上面步骤完成后,我们的私有yum源就搭建成功了 ,我们来测试下:

只下载不安装lrzsz 工具:

yumdownloader lrzsz #此工具在yum-utils下,请确保已经安装

下载之前请确保yum开启了缓存功能:

[root@bogon yum.repos.d]# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever  #缓存地址
keepcache=1    #开启缓存功能
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release


#  This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
#  It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

将下载的lrzsz rpm包从缓存文件夹拷贝到我们新建的私有仓库的文件件

cp /var/cache/yum/lrzsz-0.12.20-36.el7.x86_64.rpm /application/yum/centos7/x86_64/

完成后更新仓库索引文件:

这里每次新增都需要更新该文件,不然安装时是找不到响应的 安装包的

createrepo /application/yum/centos7/x86_64/

 

查看现有的yum源仓库:

yum repolist #显示激活的源

查看更详细信息可以用:

yum -v repolist

显示所有源,包含禁止的和激活的 

yum repolist all

显示某一个源的详细信息:

yum -v repolist base
[root@bogon yum.repos.d]# yum -v repolist base
加载 "fastestmirror" 插件
Config time: 0.008
Yum version: 3.4.3
Loading mirror speeds from cached hostfile
设置软件包群集
pkgsack time: 0.000
源ID     : base/7/x86_64
源名    : CentOS-7 - Base - mirrors.aliyun.com
源状态  : 禁用
源基本地址: http://mirrors.aliyun.com/centos/7/os/x86_64/, http://mirrors.aliyuncs.com/centos/7/os/x86_64/, http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/
源到期:21,600 秒(已持续:Mon Jan 11 14:01:30 2021)
  Filter     : read-only:present
源文件名:/etc/yum.repos.d/CentOS-Base.repo

repolist: 0
[root@bogon yum.repos.d]# 

 

 

禁用现有的仓库:

yum-config-manager --disable base epel extras updates docker-ce-stable

现在我们再看看那些仓库还在:

[root@bogon yum.repos.d]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
源标识                                                                                                                               源名称                                                                                                                               状态
privaterepo                                                                                                                          privaterepo                                                                                                                          1
repolist: 1
[root@bogon yum.repos.d]# 

可以看到只剩下我们自己的私有yum源了,再查看私有yum源中是否包含lrzsz rpm包:

 

下面我们来安装着个包

yum install lrzsz
[root@bogon yum.repos.d]# yum install lrzsz
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 lrzsz.x86_64.0.0.12.20-36.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

==============================================================================================================================================================================================================================================================================
 Package                                                      架构                                                          版本                                                                     源                                                                  大小
==============================================================================================================================================================================================================================================================================
正在安装:
 lrzsz                                                        x86_64                                                        0.12.20-36.el7                                                           privaterepo                                                         78 k

事务概要
==============================================================================================================================================================================================================================================================================
安装  1 软件包

总下载量:78 k
安装大小:181 k
Is this ok [y/d/N]: y
Downloading packages:
lrzsz-0.12.20-36.el7.x86_64.rpm                                                                                                                                                                                                                        |  78 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : lrzsz-0.12.20-36.el7.x86_64                                                                                                                                                                                                                               1/1 
  验证中      : lrzsz-0.12.20-36.el7.x86_64                                                                                                                                                                                                                               1/1 

已安装:
  lrzsz.x86_64 0:0.12.20-36.el7                                                                                                                                                                                                                                               

完毕!

到此说明安装成功

posted on 2021-01-11 11:22  EZgod  阅读(401)  评论(0编辑  收藏  举报