您的位置:首页 > 运维架构 > Linux

centos7下自建yum源同步阿里源仓库-搭建篇1

2020-09-29 15:37 1011 查看

yum源服务端配置工作

一、安装必要的软件

yum install -y wget make cmake gcc gcc-c++  &&\
yum install -y pcre-devel lib zlib-devel  \
openssl openssl-devel createrepo yum-util

安装nginx ,一会需要对外提供http服务。

yum -y install nginx

二、创建索引
下一步将nginx的根目录配置为索引根目录/opt/yum/centos/7/os/。

mkdir /opt/yum/centos/7/os/x86_64/
createrepo /opt/yum/centos/7/os/x86_64/

三、 nginx配置如下:

cat /etc/nginx/conf.d/yum.conf
server {
listen       9000 default_server;
server_name  _;
root         /opt/yum/centos/7/os/;  ##这里

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

location / {
##这里
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
index index.html;
}

error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

四、设置阿里云镜像为本地yum源

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

#yum repolist查看yum仓库标识

五、同步base源到自建的yum仓库地址

reposync -r base -p /opt/yum/centos/7/os/

同理,可以同步epel源到自建仓库目录

reposync -r epel -p /opt/yum/centos/7/os/

六、上述同步完成以后,更新仓库索引

createrepo  --update /opt/yum/centos/7/os/base/
createrepo  --update /opt/yum/centos/7/os/epel/

此时yum源仓库配置完成。

客户端机器测试自建yum源

1.客户端服务器配置/etc/yum.repos.d目录的repo仓库

cp -rp /etc/yum.repos.d /etc/yum.repos.d.bak
rm -rf /etc/yum.repos.d/*
#新建编辑base和epel的仓库文件
#cat smcaiot-base.repo
[smcaiot-base]
name=centos-base
baseurl=http://192.168.101.21:9000/base/
enabled=1
gpgcheck=0

#cat smcaiot-epel.repo
[smcaiot-epel]
name=smcaiot-epel
baseurl=http://192.168.101.21:9000/epel/
enabled=1
gpgcheck=0

2.清理缓存

yum clean all && yum makecache

3.测试yum安装,比如 yum -y install htop 发现安装速度还是比较快的。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: