如果生產環境需要大規模的安裝部署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