背景:现有服务器放在内网,且服务器版本为未注册的redhat,无法提供yum服务。
目标:在内网中搭建yum repo服务,使同一个域中的机器均可使用yum。
思路:完成该任务需要解决以下三个问题:
(1)服务器操作系统版本为redhat ,虽然本地已经有yum源的包,但未经注册无法使用。
(2)服务器在内网,无法直接连接外网开源的yum源,如网易源和阿里源。
(3)搭建Yum repo,这样该域内的服务器均只需通过配置即可获得yum服务,无需每台机器都安装。
解决过程:
问题(1):将redhat的yum修改为使用centos的yum服务
1、cat /etc/redhat-release , 查看服务器版本:
Red Hat Enterprise Linux Server release 6.5 (Santiago)
2、rpm -qa |grep yum 查看服务器上的yum包,如下:
yum-metadata-parser-1.1.2-16.el6.x86_64
yum-utils-1.1.30-14.el6.noarch
yum-3.2.29-30.el6.noarch
yum-rhn-plugin-0.9.1-40.el6.noarch
yum-plugin-security-1.1.30-14.el6.noarch
3、rpm -e (包名) --nodeps 忽略关联关系,删除服务器上的yum包
5、rpm -ivh (包名) --nodeps 安装第四步下载好的5个包。
到目前为止,redhat上的yum包已被替换。如果此机器可以连接外网,则可以直接按照以下第6步配置即可。
【6】、
vi /etc/yum.repos.d/CentOS-Base.repo (ps:如果比较信任所连接的源,则可配置
gpgcheck
=0
,这样可以跳过验证
)
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
[base]
name=CentOS-6 - Base - 163.com
gpgcheck=0
#released updates
[updates]
name=CentOS-6 - Updates - 163.com
gpgcheck=1
#additional packages that may be useful
[extras]
name=CentOS-6 - Extras - 163.com
gpgcheck=0
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6 - Plus - 163.com
gpgcheck=1
enabled=0
#contrib - packages by Centos Users
[contrib]
name=CentOS-6 - Contrib - 163.com
gpgcheck=1
enabled=0
实际上,我的服务器在内网,无法连接internet,需解决问题(2):将外网的包直接load到内网服务器上。
2、通过sftp上传到内网服务器/data_disk/iso 文件夹中
3、服务器设置yum 软件仓库
(1)mkdir /mnt 新建文件夹 /mnt/
(2)mount -o loop /data_disk/mnt/
CentOS-6.9-x86_64-bin-DVD1.iso /mnt/
将iso 文件挂载
(3)df -h 查看挂载情况,如下说明已经挂载完成。
4、vi /etc/yum.repos.d/CentOS6-Base-163.repo 将[base ] [
updates
][
extras
]中的baseurl 指向本地源所在文件夹 ,即
baseurl=file:///mnt/
暂时将gpgcheck关闭,即gpgcheck=0 ,整个文件配置如下。
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
[base]
name=CentOS-6 - Base - 163.com
baseurl=file:///mnt/
gpgcheck=0
#released updates
[updates]
name=CentOS-6 - Updates - 163.com
baseurl=file:///mnt/
gpgcheck=1
#additional packages that may be useful
[extras]
name=CentOS-6 - Extras - 163.com
baseurl=file:///mnt/
gpgcheck=0
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6 - Plus - 163.com
gpgcheck=1
enabled=0
#contrib - packages by Centos Users
[contrib]
name=CentOS-6 - Contrib - 163.com
gpgcheck=1
enabled=0
完成以上配置后,本地机器即可通过yum服务进行基础服务包的安装。
问题(3):搭建本地yum repo
1、
yum install httpd creatrepo 在作为仓库的服务器端的机器上,安装httpd服务和创建yum源的服务
2、vi /etc/httpd/conf/httpd.conf 进入配置文件修改httpd服务的 apache配置,修改文件中的 ServerName 内网ip:端口 (端口用80端口,试过改成其他端口无法使用,暂时还没找到原因)
3、客户端配置:vi /etc/yum.repos.d/CentOS6-Base-163.repo 新建一个yum的配置文件,复制如下内容,注意标红的内网ip:端口 即为第2步中服务端配置的内网ip和端口。
#CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
[base]
name=CentOS-6 - Base - 163.com
#baseurl=file:///mnt/
baseurl=http://
内网ip:端口
/yum/CentOS/
gpgcheck=0
gpgkey=file:///var/www/html/yum/CentOS
#released updates
[updates]
name=CentOS-6 - Updates - 163.com
#baseurl=file:///mnt/
baseurl=http://
内网ip:端口
/yum/CentOS/
gpgcheck=0
gpgkey=file:///var/www/html/yum/CentOS
#additional packages that may be useful
[extras]
name=CentOS-6 - Extras - 163.com
#baseurl=file:///mnt/
baseurl=http://
内网ip:端口
/yum/CentOS/
gpgcheck=0
gpgkey=file:///var/www/html/yum/CentOS
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6 - Plus - 163.com
baseurl=http://
内网ip:端口
/yum/CentOS/
gpgcheck=0
enabled=0
gpgkey=file:///var/www/html/yum/CentOS
#contrib - packages by Centos Users
[contrib]
name=CentOS-6 - Contrib - 163.com
baseurl=http://
内网ip:端口
/yum/CentOS/
gpgcheck=0
enabled=0
gpgkey=file:///var/www/html/yum/CentOS
完成以上配置后,内网yum仓库即配置完成。
本文档详细介绍了如何在内网环境中,将Redhat服务器的yum替换为Centos服务,以及如何搭建内网yum repo服务。首先,通过更换yum包并配置CentOS-Base.repo文件来使未注册的Redhat服务器使用Centos源。然后,针对内网环境,通过将CentOS ISO镜像加载到服务器并配置本地源,实现离线安装基础服务包。最后,通过安装httpd和creatrepo服务,搭建本地yum仓库,并在客户端配置指向该仓库的源。
1162

被折叠的 条评论
为什么被折叠?



