创建本地仓库centos7

创建本地仓库centos7

1安装创建本地仓库工具
首先肯定是要有一台服务器可以连接外网的,否则任何软件包都无法下载了。
createrepo工具可以帮助我们创建一个本地局域网的私有仓库
以下命令默认都是以root用户运行:

 yum install createrepo -y

2安装yum-utils包
yum-utils包含有reposync工具,可以方便的从远程同步仓库镜像到本地

yum install yum-utils -y

3安装配置nginx
安装nginx是用来方便内网其他服务器进行访问私有仓库,也用apache也可以

yum install epel-release
yum install nginx -y

将nginx配置成文件服务器,类似apache那种。编辑/etc/nginx/nginx.conf文件。

vim /etc/nginx/nginx.conf
找到server节点,添加以下内容即可。

server {

  listen 80 default_server;

  location / {
    root /var/www/html; #这里可以选择一个空间较大分区
    autoindex on;
    autoindex_exact_size off;
    autoindex_localtime on;
  }

之后执行以下命令,启动nginx,查看运行状态以及设置开机自启:

systemctl start nginx
systemctl status nginx   # 出现Active: active (running)表示启动成功
systemctl enable nginx

4配置HDP 2.5源
在可以访问外网的服务器上进行配置,执行以下命令:

yum -y install wget
wget -nv http://public-repo-1.hortonworks.com/ambari/centos7/2.x/updates/2.4.2.0/ambari.repo -O /etc/yum.repos.d/ambari.repo

这个命令是配置ambari仓库的,Ambari是一种基于Web的工具,支持Apache Hadoop集群的供应、管理和监控。目前也是Apache的顶级项目。

继续配置hdp仓库,执行以下命令:

wget -nv http://public-repo-1.hortonworks.com/HDP/centos7/2.x/updates/2.5.0.0/hdp.repo -O /etc/yum.repos.d/hdp.repo

生成一下缓存:

yum makecache 
[root@code /]# yum makecache
已加载插件:fastestmirror
HDP-2.5.0.0                                                                                                                                                          | 2.9 kB  00:00:00     
HDP-UTILS-1.1.0.21                                                                                                                                                   | 2.9 kB  00:00:00     
Updates-ambari-2.4.2.0                                                                                                                                               | 2.9 kB  00:00:00     
base                                                                                                                                                                 | 3.6 kB  00:00:00     
epel/x86_64/metalink                                                                                                                                                 | 9.2 kB  00:00:00     
extras                                                                                                                                                               | 3.4 kB  00:00:00     
updates                                                                                                                                                              | 3.4 kB  00:00:00     
(1/20): HDP-2.5.0.0/primary_db                                                                                                                                       |  69 kB  00:00:03     
(2/20): HDP-2.5.0.0/other_db                                                                                                                                         |  13 kB  00:00:00     
(3/20): HDP-2.5.0.0/filelists_db                                                                                                                                     | 332 kB  00:00:04     
(4/20): HDP-UTILS-1.1.0.21/primary_db                                                                                                                                |  38 kB  00:00:02     
(5/20): HDP-UTILS-1.1.0.21/filelists_db                                                                                                                              |  95 kB  00:00:03     
(6/20): HDP-UTILS-1.1.0.21/other_db                                                                                                                                  |  20 kB  00:00:00     
(7/20): Updates-ambari-2.4.2.0/filelists_db                                                                                                                          | 139 kB  00:00:03     
(8/20): Updates-ambari-2.4.2.0/primary_db                                                                                                                            | 8.3 kB  00:00:03     
(9/20): Updates-ambari-2.4.2.0/other_db                                                                                                                              | 1.3 kB  00:00:00     
(10/20): epel/x86_64/prestodelta                                                                                                                                     |  325 B  00:00:03     
(11/20): base/7/x86_64/other_db                                                                                                                                      | 2.5 MB  00:00:05     
(12/20): epel/x86_64/filelists                                                                                                                                       |  10 MB  00:00:07     
(13/20): epel/x86_64/other                                                                                                                                           | 2.2 MB  00:00:07     
(14/20): extras/7/x86_64/filelists_db                                                                                                                                | 603 kB  00:00:04     
(15/20): updates/7/x86_64/filelists_db                                                                                                                               | 3.4 MB  00:00:00     
(16/20): updates/7/x86_64/other_db                                                                                                                                   | 578 kB  00:00:00     
(17/20): extras/7/x86_64/prestodelta                                                                                                                                 | 100 kB  00:00:03     
(18/20): extras/7/x86_64/other_db                                                                                                                                    | 126 kB  00:00:03     
(19/20): updates/7/x86_64/prestodelta                                                                                                                                | 679 kB  00:00:09     
(20/20): base/7/x86_64/filelists_db                                                                                                                                  | 6.9 MB  00:00:31     
Loading mirror speeds from cached hostfile
 * base: mirrors.zju.edu.cn
 * epel: mirrors.ustc.edu.cn
 * extras: centos.ustc.edu.cn
 * updates: centos.ustc.edu.cn
epel                                                                                                                                                                            12708/12708
epel                                                                                                                                                                            12708/12708
元数据缓存已建立

然后查看仓库id等信息,方便后面制作私有仓库。

[root@code /]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.zju.edu.cn
 * epel: mirrors.aliyun.com
 * extras: centos.ustc.edu.cn
 * updates: centos.ustc.edu.cn
源标识                                                                                                                  源名称                                                                                                                                          状态
HDP-2.5.0.0                                                                                                             HDP Version - HDP-2.5.0.0                                                                                                                          200
HDP-UTILS-1.1.0.21                                                                                                      HDP-UTILS Version - HDP-UTILS-1.1.0.21                                                                                                              64
Updates-ambari-2.4.2.0                                                                                                  ambari-2.4.2.0 - Updates                                                                                                                            12
base/7/x86_64                                                                                                           CentOS-7 - Base                                                                                                                                  9,911
epel/x86_64                                                                                                             Extra Packages for Enterprise Linux 7 - x86_64                                                                                                  12,708
extras/7/x86_64                                                                                                         CentOS-7 - Extras                                                                                                                                  434
updates/7/x86_64                                                                                                        CentOS-7 - Updates                                                                                                                               1,614
repolist: 24,943

5创建私有仓库
进入我们上面nginx设置的web目录,通过reposync命令从远程同步仓库数据到本地来,执行以下命令:
比如想要同步hdp相关仓库就输入:

cd /var/www/html
reposync -r Updates-ambari-2.4.2.0
reposync -r HDP-2.5.0.0
reposync -r HDP-UTILS-1.1.0.21

reposync -r xxx(repo id)
其中的repo id就是上面通过yum repolist查看到的第一列。

之后进入每个仓库目录下面,执行# createrepo .命令就可以创建一个源仓库了,也可以直接在当前目录下面执行,这样就把三个仓库都放在一个里面了。

# createrepo .

6使用私有仓库
局域网集群中其他服务器要使用该仓库,也需要进行一些配置。
在私有仓库的服务器镜像目录中新建一个hdp.repo文件,内容如下:

[HDP]
name=hdp Version - 2.5
baseurl=http://192.168.10.199/hdp
gpgcheck=0
enabled=1
priority=1

192.168.10.199为[server-ip]
其中参数说明:

  • [HDP]表示该仓库的id为HDP,可通过yum repolist查看。出现了该id即配置正确
  • baseurl表示仓库的根路径,这里如果是本地的话,可以输入:file:///var/www/html/hdp
  • gpgcheck=0表示不进行签名检查
  • enabled=1表示启用该仓库,如果为0则表示不使用该仓库
  • priority=1表示优先级,如果一个软件包在多个仓库都有,会优先使用这个。

然后在其他机器上,通过运行以下命令,导入仓库配置:

# wget -nv http://192.168.10.199/hdp/hdp.repo -O /etc/yum.repo.d/hdp.repo

之后进行仓库检测和缓存:

# yum repolist   # 查看是否有HDP这个repo id
# yum makecache

—the–end----

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值