资讯专栏INFORMATION COLUMN

2018年第12周-yum私库搭建

lk20150415 / 934人阅读

摘要:此实验过程仅在上实践过先顶一下角色,假设我有三台服务器,,。除了库,我们还可以将库,库等,私有化。

此实验过程仅在centos上实践过

先顶一下角色,假设我有三台服务器A,B,C。
服务器A是centos6.5版本,目标:我想把它当做yum私库
服务器B是centos7.2版本,目标:yum安装程序包时,不从internet上获取安装包信息,而是从服务器A获取安装包信息来安装
服务器C是centos6.5版本,目标:yum安装程序包时,不从internet上获取安装包信息,而是从服务器A获取安装包信息来安装

安装步骤

1.在服务器A备份

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2.在服务器A下载新的CentOS-Base.repo 到/etc/yum.repos.d/

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

在这里,我们只有6和7版本的centos,于是我们下载centos6和centos7的Centos-Base.repo,这时候需进去修改下centos7的名字

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

在服务器A修改CentOS-Base-7.repo,把$releasever都改为7

vim /etc/yum.repos.d/CentOS-Base-7.repo 
[base-7]
name=CentOS-7 - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/os/$basearch/
        http://mirrors.aliyuncs.com/centos/7/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates-7]
name=CentOS-7 - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/7/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras-7]
name=CentOS-7 - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/7/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus-7]
name=CentOS-7 - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/7/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

3.在服务器A安装apache http服务器,可参考文章https://segmentfault.com/a/11...
4.在服务器A下载所有程序安装包,到http服务器目录下,这过程要很久

reposync -r base-7 -p /var/www/html/

reposync命令不存在则需安装:

yum-utils   createrepo     yum-plugin-priorities -y

reposync命令是一个python脚本。包含在yum-utils包中。
此过程可能需要安装reposync
5.在服务器A创建base-7索引

createrepo -pdo /var/www/html/base-7/ /var/www/html/base-7/

6.这时候就能访问http://serverA/base-7 看到目录信息了

7.然后配置服务器B,在服务器B的/etc/yum.repos.d/下,删除(备份)其他repo文件,新建一个base.repo文件,内容如下:

[base] 
name=base
baseurl=http://server/base-7
enabled=1 
gpgcheck=0 

8.然后在服务器B清除yum缓存信息

yum clean all

9.在服务器B缓存yum库新信息,这时候就能看到新的base库信息

yum makecache
更新步骤

1.在服务器A更新base-7库的信息,在服务器A执行一下命令:

reposync -d -r base-7 -p /var/www/html/    #同步镜像源

2.在服务器A更新base-7库的索引信息,在服务器A执行一下命令:

createrepo --update  /var/www/html/epel   #每次添加新的rpm时,必须更新epel索引信息

3.在服务器A,上述步骤可以生成一个文件yum-update.sh,每周定时执行一下

#!/bin/bash

datetime=`date +"%Y-%m-%d"`
#exec > /var/log/epel.log  #同步日志输出
reposync -d -r epel -p /var/www/html/    #同步镜像源
if [ $? -eq 0 ];then
    createrepo --update  /var/www/html/epel   #每次添加新的rpm时,必须更新epel索引信息
    echo "SUCESS: $datetime epel update successful"
else
    echo "ERROR: $datetime epel update failed"
fi
reposync -d -r base -p /var/www/html/    #同步镜像源
if [ $? -eq 0 ];then
    createrepo --update  /var/www/html/base   #每次添加新的rpm时,必须更新epel索引信息
    echo "SUCESS: $datetime base update successful"
else
    echo "ERROR: $datetime base update failed"
fi

4.在服务器A,更改yum-update.sh文件权限,并添加定时任务

chmod u+x /root/yum-update.sh
crontab -e
0 3 * * 6 /bin/bash /root/yum-update.sh
举一反十

类似的,服务器C虽然是centos6.5,与服务器B不太一样,但服务器A的也可以继续创建base6的私库,由于服务器A的CentOS-Base.repo就已经是centos6的库,所以直接执行

reposync -r base -p /var/www/html/

然后后续过程就和上面的一样了。
除了base库,我们还可以将epel库,cdh库等,私有化。

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/10553.html

相关文章

  • 2018年第48-centos7下的docker的安装及常用命令

    摘要:下图是与其他虚拟技术的对比图。的目标是,基于这个目标,将你需要发布的应用组件及需要的环境配置都封装成一个镜像,然后基于镜像创建容器并启动运行。这样就可以达到组建级别的一次封装,多次运行。而默认情况下,属于用户,需要权限才能访问。 docker玩过很多次,但每次都是从零开始,所以这次而打算记录下来,方便后面查询。 docker的技术基础是LXC虚拟化技术,虚拟化技术有很多,有硬件层面和...

    lemon 评论0 收藏0
  • 2018年第49-dnsmasq的安装(docker方式)

    摘要:在开发或测试环境可能有大量服务器数据库应用服务器中间件服务器等特别大数据系统涉及的服务器很多的时候很难记就算修改本机但每次新增删除一个对于的域名都是很麻烦的于是搭建一个就非常必须了这里使用无侵入式的搭建服务不要时删除即可新建三个文件在宿主新 在开发或测试环境, 可能有大量服务器, 数据库, 应用服务器, 中间件服务器等. 特别大数据系统, 涉及的服务器很多的时候, ip很难记, 就算修...

    Yuanf 评论0 收藏0
  • 2018年第22-大数据的HDFS

    摘要:与大数据可以说是大数据的代名词。其实准确来说是家族是大数据的代名词,家族成员有等。于是通过网络管理多台机器存储的文件的系统,称为分布式文件系统。如文件系统的能够容忍节点故障且不丢失任何数据。 Hadoop与大数据 Hadoop可以说是大数据的代名词。 其实准确来说是Hadoop家族是大数据的代名词,家族成员有:Hadoop、Hive、Pig、HBase、Sqoop、Zookeeper...

    vspiders 评论0 收藏0
  • 2018年第28-Kafka环境搭建和其Java例子

    摘要:安装下载配置文件我部署在服务器都在目录修改文件的和,要集群上唯一如只能让内网访问,则需配置这个启动先在每个服务器启动再在每个服务器启动以下命令的例子项目配置项目使用和和,文件如下 安装kafka 下载 wget http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/1.1.0/kafka_2.11-1.1.0.tgz 配置文件 我部署在服务器...

    izhuhaodev 评论0 收藏0
  • 2018年第20-Flume概念(简单例子)

    摘要:两个发布版本和。用于暂存接受过来的事件,直到被消费。使用事务方法保证事件传递的可靠性。一个简单的例子以下是单节点的配置信息这配置可以让用户通过工具连接端口,发送文本,然后在和日志中输出。配置文件可以定一个多个,启动进程时可以指定启动。 Flume 1.8.0 简介 概要 Flume是一个分布式,可靠性和可用性的系统,此系统用于收集、聚合和移动大量数据日志数据,从各种各样的数据源将数据移...

    Nekron 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<