CentOS本地源配置

1 安装httpd

在一台联网的机器上下载httpd离线包:

[root@localhost ~]# yum install --downloadonly --downloaddir=/httpd_rpm/ -y httpd

会下载以下依赖文件:

apr-1.4.8-3.el7_4.1.x86_64.rpm

apr-util-1.5.2-6.el7.x86_64.rpm

httpd-2.4.6-88.el7.centos.x86_64.rpm

httpd-tools-2.4.6-88.el7.centos.x86_64.rpm

mailcap-2.1.41-2.el7.noarch.rpm

使用命令安装本地rpm,安装以上下载的文件:

yum localinstall 包名

2 创建yum软件保存目录

[root@localhost ~]# mkdir -p /www/share/yum

3 修改yum配置文件

先备份yum配置文件,修改yum配置文件中yum软件包保存目录并开启rmp包缓存功能

[root@localhost ~]# cp /etc/yum.conf /etc/yum.conf.bak

[root@localhost ~]# vim /etc/yum.conf

[main]

#cachedir=/var/cache/yum/$basearch/$releasever

cachedir=/www/share/yum/$basearch/$releasever

keepcache=1

4 创建http共享目录,服务目录

[root@yumrepo www]# vim /etc/httpd/conf.d/share.conf

#http share

Alias /share /www/share



    Options Indexes FollowSymLinks

    IndexOptions NameWidth=* DescriptionWidth=* FoldersFirst

    IndexOptions SuppressIcon HTMLTable Charset=UTF-8 SuppressHTMLPreamble

    Order allow,deny

    Allow from all

    Require all granted

5 修改http配置文件

备份httpd配置并修改配置文件

[root@localhost ~]# cp /etc/httpd/conf/httpd.conf{,.bak}

[root@localhost ~]# echo "

ServerName localhost

#关闭版本号显示

ServerSignature Off

ServerTokens Prod

">>/etc/httpd/conf/httpd.conf

6 启动http服务

[root@localhost ~]# systemctl enable httpd.service && systemctl restart httpd.service

[root@localhost ~]# netstat -antp|grep 'httpd'

7 创建YUM软件仓库

[root@localhost ~]# mkdir -p /www/share/centos7_rpm

[root@localhost ~]# createrepo -p /www/share/centos7_rpm/

Saving Primary metadata

Saving file lists metadata

Saving other metadata

Generating sqlite DBs

Sqlite DBs complete

8 创建源文件

[root@localhost ~]# echo "

[My_share]

name=My_Souce

baseurl=http://服务IP地址/share/centos7_rpm/

gpgcheck=0

enabled=1

cost=88

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

">/www/share/Lan7.repo

9 下载软件包

9.1 将yum缓存的rpm包拷贝到/www/share/centos7_rpm/

[root@localhost ~]# find /www/share/yum -name *.rpm |sed -r 's#.*#mv & /www/share/centos7_rpm/\n#'|bash

9.2 下载没有安装过的包

[root@localhost ~]# yum install --downloadonly --downloaddir=/www/share/centos7_rpm/ -y 包名称

9.3 从新下载已经安装过的包

[root@localhost ~]# yum reinstall --downloadonly --downloaddir=/www/share/centos7_rpm/ -y 包名称

9.4 更新源

[root@localhost ~]# createrepo --update -p /www/share/centos7_rpm/

每次下载新的rpm后都需要执行该命令来更新yum

10 客户端使用源

10.1 下载服务端源文件到本地

wget -O /etc/yum.repos.d/Lan7.repo http://服务IP地址/share/Lan7.repo

10.2 客户端测试,查看源名称为myshare说明正常

yum install httpd

10.3 服务点更新yum后需要在客户端运行一下命令

yum makecache

 

你可能感兴趣的:(离线包,离线rpm,本地源,CentOS,rpm)