自己搭建yum仓库

1.关闭防火墙和SELinux
# systemctl stop firewalld
# systemctl disable firewalld
# vim /etc/selinux/config
SELINUX=disabled
 
2.安装yum-utils createrepo
# yum install yum-utils createrepo
 
3.同步包,这里选择阿里源
/etc/yum.repos.d/CentOS-Base.repo默认的就是腾讯的yum源
# wget http://mirrors.aliyun.com/repo/Centos-7.repo
# cp Centos-7.repo /etc/yum.repo.d/CentOS-Base.repo
# reposync –p /data/yum/
同步完成可以看到目标目录下出现几个目录
# ll /data/yum/
total 24
drwxr-xr-x 3 root root 4096 Aug 28 08:53 base
drwxr-xr-x 3 root root 4096 Aug 27 23:46 epel
drwxr-xr-x 3 root root 4096 Aug 27 23:58 extras
drwxr-xr-x 3 root root 4096 Aug 28 00:02 nginx
drwxr-xr-x 3 root root 4096 Aug 28 00:38 updates
创建yum列表,完成后会发现多了一个这个目录:
# createrepo -p /data/yum
# ll /data/yum/
drwxr-xr-x 2 root root 4096 Aug 28 09:03 repodata
 
4.安装Nginx
# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
# yum install -y nginx
需要添加几行配置:
# vim /etc/nginx/nginx.conf
user  root;
 
http {
...
    autoindex on;
    autoindex_exact_size off;
    autoindex_localtime on;
...
}
 
4)在Nginx里面创建一个软连接目录指向/data/yum
# cd /usr/share/nginx/html
# ln -s /data/yum CentOS-yum/version_7/64bit
名字可以自己定义,还可以分不同的版本,这里就用centos7的好了
 
5)启动nginx服务
systemctl start nginx
 
6)编辑repo文件
需要安装一个软件,可以控制yum源先后使用查找
# yum install -y yum-plugin-priorities
# vim /etc/yum.repos.d/CentOS-Base.repo
[mylocal]
name=source_from_localserver
baseurl=http://132.232.82.148/yum
gpgcheck=0
enable=1
priority=1
 
7)刷新yum缓存并重建
# yum clean all
# yum makecache
Loaded plugins: fastestmirror, langpacks, priorities
epel                                                                                                     | 3.2 kB  00:00:00     
mylocal                                                                                                  | 2.9 kB  00:00:00     
nginx                                                                                                    | 2.9 kB  00:00:00     
(1/2): mylocal/other_db                                                                                  | 6.1 MB  00:01:49     
(2/2): mylocal/filelists_db                                                                              |  21 MB  00:03:55     
Loading mirror speeds from cached hostfile
Metadata Cache Created
可以看到本地的yum缓存已经出来了
# yum repolist
 
8)测试一下:
# yum install -y tree
Dependencies Resolved
 
================================================================================================================================
Package                    Arch                         Version                            Repository                     Size
================================================================================================================================
Installing:
tree                       x86_64                       1.6.0-10.el7                       mylocal                        46 k
 
Transaction Summary
================================================================================================================================
Install  1 Package
Repository已经显示的是mylocal
 
9)自动更新
# crontab -l
0 2 * * 6 # reposync -np /data/yum >>/dev/null 2>&1
设置一个自动命令,在每周6凌晨2点的时候进行更新,-np表示只更新新的rpm包
 
 参考:https://blog.csdn.net/u012402276/article/details/53158682

猜你喜欢

转载自www.cnblogs.com/teezzy/p/9546335.html