搭建本地yum仓库
2019-05-04 本文已影响0人
Linux_wu_sir
方法一:
第一步:光盘挂载
[root@m01 ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only
第二步:编写文件
[root@m01 ~]# vim /etc/yum.repos.d/local_yum
[local_yum]
name=local yum
baseurl=file:///mnt
gpgcheck=0 #因为是光盘安装,不需要检查
enabled=1
priority=1 #优先级越低越优先
第三步:清理缓存和安装优先级
[root@m01 ~]# yum install yum-plugin-priorities.noarch #安装优先级
[root@m01 ~]# yum clean all #清理缓存:
[root@m01 ~]# yum repolist #查看仓库立有多少安装包
其它设备如果想要使用,可以结合NFS使用。
第四步:如果有新的rpm包,放入并更新。
[root@m01 ~]# createrepo --update /application/yum/centos7/x86_64/
方法二:
第一步:修改yum配置文件
[root@m01 ~]# sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.conf
第二步:关闭防火墙和SELINUX
[root@m01 ~]# getenforce
Disabled
[root@m01 ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
第三步:下载createrepo组件包
[root@m01 ~]# yum install -y createrepo
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
Package createrepo-0.9.9-28.el7.noarch already installed and latest version
Nothing to do
第四步:备份rpm包并更新元数据
[root@m01 ~]# find / -type f -name "*.rpm" | xargs -i cp {} /usr/share/nginx/html/yum/centos7/x86_64/
[root@m01 ~]# createrepo /usr/share/nginx/html/yum/centos7/x86_64/ #类似数据库建库建表一样,或者理解成创建inode
Spawning worker 0 with 508 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
第五步:搭建Apache或Nginx服务
本例中采用的yum安装的nginx,修改相关配置文件如下
server {
listen 80;
server_name 10.0.0.61;
location / {
root /usr/share/nginx/html/yum/centos7/x86_64;
autoindex on;
}
}
修改完成后重启服务
或在要共享的目录下执行
[root@oldboy yum]# python -m SimpleHTTPServer 80 &> /dev/null &
[1] 8738
[root@oldboy yum]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
python 8725 root 3u IPv4 57388 0t0 TCP *:http (LISTEN)
[root@oldboy yum]# curl 10.0.0.61
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html>
<title>Directory listing for /</title>
<body>
<h2>Directory listing for /</h2>
<hr>
<ul>
<li><a href="x86_64/">x86_64/</a>
</ul>
<hr>
</body>
</html>
第六步:修改其它设备的yum源
[root@m01 ~]# cat local_yum
[local]
name=local yum
baseurl=http://10.0.0.61
gpgcheck=0
enabled=1
第七步:如果有新的rpm包,放入共享目录中并更新元数据。
[root@m01 ~]# createrepo --update /application/yum/centos7/x86_64/