centos7自建yum源 安装rpm
如果生产环境需要大规模的安装部署rpm包,每次安装,更新,都需要上传,安装,比较麻烦,可以在生产环境中自建一个yum源。
1、http安装
yum -y install httpd http-devel
service httpd start
chkconfig httpd on
2、createrepo安装
yum -y install createrepo
3、创建repodata目录
cd /var/www/html/
mkdir sinobbdyum/x86_64 -p
createrepo -p -d -o sinobbdyum/x86_64/ sinobbdyum/x86_64/
4、把需要发布的安装包存放到repodata目录
cp ./*.rpm /var/www/html/sinobbdyum/x86_64/
5、更新发布yum源,由于有新增rpm包需要
createrepo --update sinobbdyum/x86_64/ #更新本地源
6、客户端设备上增加repo源文件
cd /etc/yum.repos.d
vim sinobbd.repo
[sinobbd]
name=sinobbd-yum
baseurl=http://192.168.0.25/sinobbdyum/x86_64
gpgcheck=0
7、测试是否生效
先清除客户端本地yum数据源缓存,在进行安装
rpm clean all
yum install test.rpm
异常:如果出现
[root@localhost ~]# createrepo -p -d -o yum/centos/6/x86_64 yum/centos/6/x86_64
Traceback (most recent call last):
File "/usr/share/createrepo/genpkgmetadata.py", line 28, in <module>
import createrepo
ImportError: No module named createrepo
————————————————
##nginx安装并配置自动同步
三、创建索引
mkdir /opt/yum/centos/7/os/x86_64/
createrepo /opt/yum/centos/7/os/x86_64/
四、配置nginx
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /opt/yum/centos/7/os/x86_64/; ##这里
# 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 {
}
}
五、同步相关包
1、设置阿里云镜像为本地yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
2、选择指定仓库标识作为本地yum源:
yum repolist查看yum仓库标识
3、将阿里云中的epel源同步到本地/opt/yum/centos/7/os/中;第一次同步是时间可能较长,我这里有9911个rpm包。
reposync -r base -p /opt/yum/centos/7/os/
脚本自动更新
vi /root/yum-update.sh
#!/bin/bash
datetime=`date +"%Y-%m-%d"`
exec > /var/log/centosrepo.log
reposync -d -r base -p /opt/yum/centos/7/os/
#同步镜像源
if [ $? -eq 0 ];then
createrepo --update /opt/yum/centos/7/os/x86_64
#每次添加新的rpm时,必须更新索引信息
echo "SUCESS: $datetime epel update successful"
else
echo "ERROR: $datetime epel update failed"
fi
定时任务:每周二凌晨三点同步yum源
crontab -e
0 2 * * 3 /bin/bash /root/yum-update.sh
4、更新索引
createrepo --update /opt/yum/centos/7/os/x86_64/
5、清理缓存数据
yum clean all && yum makecache
6、编写repo文件
vim /etc/yum.repos.d/feiyu-7.repo内容如下
[feiyu]
name=centos-feiyu
baseurl=http://192.168.0.27/centos/releasever/os/basearch/
enabled=1
gpgcheck=0
原文链接:https://blog.csdn.net/bbwangj/article/details/79130243
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?