Centos6.5通过创建局域网http实现yum源的更新

简介:

(一)简述

        公司通过新进了一批服务器,通过VMware的Vsphere企业级的虚拟化解决方案创建了一批虚拟机,只供内网访问,所有的虚拟机无法上外网,所以造成了原先的yum源通过外网的方式安装软件包而无法安装,所以为了日常的软件包的安装,只能在内网创建新的yum源来进行安装。

环境介绍:

名称 IP地址 功能
yum源服务端 172.22.11.108 yum源的服务端
yum客户端(使用者) 172.22.11.103 yum源的使用者


(二)yum源服务端的配置

  1. 首先查看一下服务端的yum的相关信息

1
2
3
4
5
6
[root@GVPA02-011108 cdrom] # rpm -qa|grep yum 
yum-plugin-security-1.1.30-14.el6.noarch
yum-plugin-fastestmirror-1.1.30-14.el6.noarch
yum-metadata-parser-1.1.2-16.el6.x86_64
yum-3.2.29-40.el6.centos.noarch
yum-utils-1.1.30-14.el6.noarch

2,安装createrepo,repo下的xml生成工具

1
[root@GVPA02-011108 cdrom] # yum install -y createrepo

3,制作yum源

    3.1,随意创建一个文件夹作为yum的仓库名称,用来存放RPM包

1
[root@GVPA02-011108 cdrom] # mkdir /yumrepo

    3.2,挂载光盘并把光盘里边RPM包都拷到/yumrepo文件夹里

1
2
3
4
5
6
7
8
[root@GVPA02-011108 cdrom] # mount /dev/cdrom /mnt
mount : block device  /dev/sr0  is write-protected, mounting  read -only
[root@GVPA02-011108 cdrom] # cp -r /mnt/
CentOS_BuildTag                GPL                            RELEASE-NOTES-en-US.html       RPM-GPG-KEY-CentOS-Security-6
.discinfo                      images/                        repodata/                      RPM-GPG-KEY-CentOS-Testing-6
EFI/                           isolinux/                      RPM-GPG-KEY-CentOS-6           TRANS.TBL
EULA                           Packages/                      RPM-GPG-KEY-CentOS-Debug-6     .treeinfo
[root@GVPA02-011108 cdrom] # cp -r /mnt/Packages/* /yumrepo/

    3.3把密钥也拷贝到/yumrepo文件夹里

1
[root@GVPA02-011108 cdrom] # cp /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 /yumrepo/


4,执行命令生成repodata ,创建主目录文件索引。-v参数后边跟你的RPM包的文件夹。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@GVPA02-011108 cdrom] #createrepo -v  /yumrepo
Worker 0: reading kernel-devel-2.6.32-431.el6.x86_64.rpm
Worker 0: reading samyak-gujarati-fonts-1.2.1-9.el6.noarch.rpm
Worker 0: reading srptools-0.0.4-15.el6.x86_64.rpm
Worker 0: reading kdenetwork-4.3.4-11.el6_0.1.x86_64.rpm
Workers Finished
Gathering worker results
Saving Primary metadata
Saving  file  lists metadata
Saving other metadata
Generating sqlite DBs
Starting other db creation: Wed Nov  1 18:53:22 2017
Ending other db creation: Wed Nov  1 18:53:23 2017
Starting filelists db creation: Wed Nov  1 18:53:23 2017
Ending filelists db creation: Wed Nov  1 18:53:28 2017
Starting primary db creation: Wed Nov  1 18:53:28 2017
Ending primary db creation: Wed Nov  1 18:53:31 2017
Sqlite DBs complete

5,制作本地yum源文件,要以.repo为结尾的。配置好目前还不能用,要用httpd来代理出来

1
2
3
4
5
6
[root@GVPA02-011108 yumrepo] # vim /etc/yum.repos.d/localyum.repo
[base]
name=localyum
baseurl=http: //172 .22.11.108
gpgcheck=0
gpgkey= file : ///yumrepo/RPM-GPG-KEY-CentOS-6

6,基于http的yum源相关配置

    6.1,安装apache软件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[root@GVPA02-011108 yumrepo] # yum install httpd -y
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.2.15-29.el6.centos will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==========================================================================================================================
  Package                  Arch                      Version                                 Repository               Size
==========================================================================================================================
Installing:
  httpd                    x86_64                    2.2.15-29.el6.centos                    base                    821 k
Transaction Summary
==========================================================================================================================
Install       1 Package(s)
Total download size: 821 k
Installed size: 2.9 M
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
   Installing : httpd-2.2.15-29.el6.centos.x86_64                                                                      1 /1 
   Verifying  : httpd-2.2.15-29.el6.centos.x86_64                                                                      1 /1 
Installed:
   httpd.x86_64 0:2.2.15-29.el6.centos                                                                                     
Complete!

    6.2,修改httpd.conf配置文件的DocumentRoot 和<Directory "/yumrepo">两个配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
[root@GVPA02-011108 yumrepo] # vim /etc/httpd/conf/httpd.conf
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot  "/yumrepo"
 
 
<Directory  "/yumrepo" >
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
     Options Indexes FollowSymLinks
 
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
     AllowOverride None
 
#
# Controls who can get stuff from this server.
#
     Order allow,deny
     Allow from all
 
< /Directory >

    6.3,删除欢迎页面welcome.conf,并给/yumrepo赴权限

1
2
[root@GVPA02-011108 yumrepo] # rm /etc/httpd/conf.d/welcome.conf 
rm : remove regular  file  ` /etc/httpd/conf .d /welcome .conf'? y

    6.4,关闭selinux并重启下httpd服务

1
2
3
4
5
[root@GVPA02-011108 conf] # /etc/init.d/httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.22.11.108  for  ServerName
                                                            [  OK  ]
[root@GVPA02-011108 conf] # echo 0 > /selinux/enforce   #########不添加这个条件可能出现403禁止访问                                              [  OK  ]

访问界面如下即可:

e594537e5b398f6d5a63335a46e4fbd2.png-wh_


7,如果yum包需要更新的话,可以直接在阿里云或163上进行更新,并执行如下命令

1
2
3
4
[root@GVPA02-011108 conf] # wget -np -t 1 -nH –cut-dirs=1 -r -c -L –exclude-directories=repodata –accept=rpm,zip,gz,xml http://mirrors.163.com/centos/6.5/os/x86_64/Packages/ -P /yumrepo   ###下载最新的rpm包
[root@GVPA02-011108 conf] # createrepo --update /yumrepo             ####更新yum源
 
###客户端只需要yum clean all 和yum makecache 即可就能直接使用了




(三)yum客户端配置

1,在yum客户端172.22.11.104上将默认 的yum源关闭,并设置epel.repo将enables 为0

1
2
3
4
5
6
7
8
9
[root@SIPA01-011104 yum.repos.d] # vim epel.repo 
[epel]
name=Extra Packages  for  Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https: //mirrors .fedoraproject.org /metalink ?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=0
gpgcheck=1
gpgkey= file : ///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

2,创建自己的localyum.repo文件

1
2
3
4
5
6
[root@SIPA01-011104 yum.repos.d] # vim localyum.repo 
[base]
name=localyum
baseurl=http: //172 .22.11.108
gpgcheck=0
gpgkey= file : ///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

3,清除和加载rpm包

1
2
3
4
5
6
7
8
9
10
11
12
[root@SIPA01-011104 yum.repos.d] # yum clean all
Loaded plugins: fastestmirror, security
Cleaning repos: base
Cleaning up Everything
Cleaning up list of fastest mirrors
[root@SIPA01-011104 yum.repos.d] # yum makecache
Loaded plugins: fastestmirror, security
Determining fastest mirrors
base                                                                                               | 2.9 kB     00:00     
base /filelists_db                                                                                   | 4.1 MB     00:00     
base /primary_db                                                                                     | 3.3 MB     00:00     
base /other_db                                                                                       | 1.8 MB     00:00

4,客户端执行完成,就可以直接使用yum install命令了。


本文转自 lqbyz 51CTO博客,原文链接:http://blog.51cto.com/liqingbiao/1978066


相关文章
|
安全 关系型数据库 MySQL
CentOS 7 yum 安装 MySQL教程
在CentOS 7上安装MySQL 8,其实流程很清晰。首先通过官方Yum仓库来安装服务,然后启动并设为开机自启。最重要的环节是首次安全设置:需要先从日志里找到临时密码来登录,再修改成你自己的密码,并为远程连接创建用户和授权。最后,也别忘了在服务器防火墙上放行3306端口,这样远程才能连上。
3111 16
|
Linux
Centos6配置阿里云yum源报错
在CentOS 6配置阿里云Yum源时,可能出现EPEL仓库访问报错(404 Not Found)。解决方法:编辑`/etc/yum.repos.d/epel.repo`文件,将`enabled`和`gpgcheck`参数设为0 ``` 此设置可解决仓库无法访问的问题。
2718 29
|
缓存 Ubuntu Linux
Linux中yum、rpm、apt-get、wget的区别,yum、rpm、apt-get常用命令,CentOS、Ubuntu中安装wget
通过本文,我们详细了解了 `yum`、`rpm`、`apt-get`和 `wget`的区别、常用命令以及在CentOS和Ubuntu中安装 `wget`的方法。`yum`和 `apt-get`是高层次的包管理器,分别用于RPM系和Debian系发行版,能够自动解决依赖问题;而 `rpm`是低层次的包管理工具,适合处理单个包;`wget`则是一个功能强大的下载工具,适用于各种下载任务。在实际使用中,根据系统类型和任务需求选择合适的工具,可以大大提高工作效率和系统管理的便利性。
2036 25
|
缓存 Linux
CentOS-6的iso下载地址镜像yum源
通过上述步骤,您可以成功下载CentOS 6的ISO镜像文件,并配置适用于CentOS 6的YUM源。尽管CentOS 6已经停止更新,但使用这些镜像和YUM源配置,可以继续在需要的环境中使用和维护CentOS 6系统。
9496 20
|
Linux 虚拟化 开发者
一键将CentOs的yum源更换为国内阿里yum源
一键将CentOs的yum源更换为国内阿里yum源
24568 31
CentOs9 yum源出现404问题
CentOs9-stream yum源出现404问题
|
缓存 Linux
解决CentOS 7停止更新后yum源失效问题【图文教程】
以上步骤完成后,你的 CentOS 7 系统就会使用阿里云的 yum 源,更换yum以后就可以正常使用啦。
16902 2
centos使用阿里的yum源
centos使用阿里的yum源
2200 0
|
存储 关系型数据库 MySQL
MySQL介绍和MySQL包安装 -- RHEL系列(Yum资源库安装MySQL)
MySQL是一款开源关系型数据库,高性能、易用、跨平台,支持多种存储引擎,广泛应用于Web开发、企业级应用等领域。本教程介绍其特点、架构及在主流Linux系统中的安装配置方法。
1764 0
MySQL介绍和MySQL包安装 -- RHEL系列(Yum资源库安装MySQL)
|
缓存 Ubuntu 前端开发
yum的安装和使用(包含安装过程中遇到的问题及解决方法)
yum的安装和使用(包含安装过程中遇到的问题及解决方法)
2202 1
yum的安装和使用(包含安装过程中遇到的问题及解决方法)