本地CentOS依赖包下载(有网络环境)
yum只下载不安装依赖包
$ yum install --downloadonly --downloaddir=/root/download
创建依赖包所在的yum repo目录
$ mkdir -p /root/download
默认情况下,下载的rpm包位于以下位置:/var/cache/yum/x86_64/7
$ ll /var/cache/yum/x86_64/7 drwxr-xr-x 4 root root 4096 Dec 19 03:28 base drwxr-xr-x 4 root root 4096 Dec 19 03:28 extras -rw-r--r-- 1 root root 117 Dec 19 03:31 timedhosts -rw-r--r-- 1 root root 381 Dec 19 03:31 timedhosts.txt drwxr-xr-x 4 root root 4096 Dec 19 03:28 updates
获取createrepo安装包
$ yum install --downloadonly --downloaddir=/root/download createrepo
获取更新yum源
$ yum update --downloadonly --downloaddir=/root/download
获取nginx安装包
$ vi /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/ gpgcheck=0 enabled=1
$ yum install --downloadonly --downloaddir=/root/download nginx
创建docker安装源
$ tee /etc/yum.repos.d/docker.repo <<-'EOF' [dockerrepo] name=Docker Repository baseurl=https://yum.dockerproject.org/repo/main/centos/7/ enabled=1 gpgcheck=1 gpgkey=https://yum.dockerproject.org/gpg EOF $ yum --downloadonly --downloaddir=/root/download install docker-engine
设置平时yum安装软件时不删除安装包
$ vi /etc/yum.conf keepcache=1
安装createrepo
$ yum install createrepo
初始化yum源的repodata
$ createrepo -pdo /root/download /root/download $ createrepo --update /root/download
把依赖复制到完全离线环境
把yum获取的rpm文件保存到yum-repo
把yum-repo复制到离线环境的CentOS的/yum-repo目录
CentOS完全离线环境docker-engine安装(无网络环境)
移除默认的yum repo配置
$ cd /etc/yum.repos.d $ ll -rw-r--r-- 1 root root 1664 Nov 29 18:12 CentOS-Base.repo -rw-r--r-- 1 root root 1309 Nov 29 18:12 CentOS-CR.repo -rw-r--r-- 1 root root 649 Nov 29 18:12 CentOS-Debuginfo.repo -rw-r--r-- 1 root root 630 Nov 29 18:12 CentOS-Media.repo -rw-r--r-- 1 root root 1331 Nov 29 18:12 CentOS-Sources.repo -rw-r--r-- 1 root root 2893 Nov 29 18:12 CentOS-Vault.repo -rw-r--r-- 1 root root 314 Nov 29 18:12 CentOS-fasttrack.repo $ mkdir bak $ mv CentOS-* bak
进行yum客户端配置
$ vi /etc/yum.repos.d/localyum.repo [localyum] name=localyum baseurl=file:///yum-repo enable=1 gpgcheck=0
进行yum源更新
$ yum clean all $ yum makecache
进行yum更新
$ yum update
yum update后会自动生成CentOS-*文件,务必删除
$ cd /etc/yum.repos.d $ mv CentOS-* bak
安装createrepo
$ yum install createrepo
安装nginx
$ yum install nginx
设置nginx的访问路径指向自定义yum源目录
$ vi /etc/nginx/conf.d/default.conf location / { root /yum-repo; autoindex on; index index.html index.htm; }
重启nginx
$ nginx -s reload
验证nginx设置
$ curl -L localhost
yum客户端配置,设置baseurl为http://localhost
$ vi /etc/yum.repos.d/localyum.repo baseurl=http://localhost
进行yum源更新
$ yum clean all $ yum makecache
验证yum源
$ yum search docker-engine $ yum install docker-engine
如果/root/download下有新增的rpm安装包,请使用以下命令更新repo
$ createrepo --update /root/download