配置局域网YUM源

当前负责的项目有几十台Linux服务器,在安装各类软件的时候需要大量依赖包,而项目部署的环境属于内网环境,与Internet网完全隔离,无法采用配置网络yum源的方式安装rpm包,直接在每台linux服务器上配置本地yum源也比较麻烦,而采用直接下载rpm包用rpm命令安装更是费时费力。所以在内网环境下采用配置局域网yum源,实现下载、安装、升级软件包有利于提高软件部署效率、保障软件版本一致性。

接下来将介绍基于http服务配置yum服务器的详细过程:

 

1、  环境及软件准备

Yum服务器主机:192.168.0.10  server10

需要配置yum源的主机:192.168.0.11  server11

操作系统:CentOS Linux7.1.1503

镜像包:CentOS-7-x86_64-DVD-1503-01.iso

 

2、  挂载镜像文件

[plain]  view plain  copy
  1. [root@server10~]# mkdir /mnt/iso  
  2. [root@server10~]# mount /home/CentOS-7-x86_64-DVD-1503-01.iso/mnt/iso  
  3. [root@server10~]# ls /mnt/iso  
  4. CentOS_BuildTag     EFI EULA   GPL   images   isoLinux  LiveOS  Packages   repodata  PRM-GPG-KEY-CentOS-7  PRM-GPG-KEY-CentOS-Testing-7 TRANS.TBL  

3、  配置本地yum源

配置本地yum的目的主要为了方便搭建yum服务器时安装相关其他软件,如httpd、createrepo等。

[plain]  view plain  copy
  1. #新建本地源配置文件  
  2. [root@server10~]# vi /etc/yum.repo.d/CentOS7-local.repo  
  3. #内容如下:  
  4. [CentOS7-iso]  
  5. Name=CentOS-$releasever– Media  
  6. Baseurl=file:///mnt/iso  
  7. gpgcheck=1  
  8. Enabled=1  
  9. gpgkey=file:///etc/pki/rpm-gpg/PRM-GPG-KEY-CentOS-7  

4、  利用本地yum源安装依赖软件

[plain]  view plain  copy
  1. #安装apache服务和repo下的xml生成工具  
  2. [root@server10~]# yum install httpd createrepo      

5、  新建yum源目录并拷贝相关镜像文件:

[plain]  view plain  copy
  1. [root@server10~]# mkdir -p /data/yum.repo/centos/7/os/x86_64/Packages  
  2. [root@server10~]# mkdir -p /data/yum.repo/centos/7/updates/x86_64/Packages  
  3. [root@server10~]# mkdir -p /data/yum.repo/tools/  
  4. [root@server10~]# cp -R /mnt/iso/Packages/*/data/yum.repo/centos/7/os/x86_64/Packages/  
  5. [root@server10~]# cp -R /mnt/iso/repodata/data/yum.repo/centos/7/os/x86_64  
  6. [root@server10~]# cp -R /mnt/iso/repodata/data/yum.repo/centos/7/updates/x86_64  
  7. [root@server10~]# cp -R /mnt/iso/repodata /data/yum.repo/tools  
  8. [root@server10~]# cp -R /mnt/iso/RPM-GPG-KEY-CentOS-7/data/yum.repo/  
  9. #注:其他包可拷贝到/data/yum.repo/tools下,如jdk  

6、启动http服务:

[plain]  view plain  copy
  1. #删除原有的/var/www/html目录  
  2. [root@server10~]# rm -rf /var/www/html  
  3. #建立安装文件与tomcat部署目录的软连接  
  4. [root@server10~]# ln -s /data/yum.repo /var/www/html  
  5. #启动服务  
  6. [root@server10~]# service httpd start  
  7. #验证httpd是否成功启动  
  8. [root@server10~]# service httpd status  
  9. #验证yum源相关资源是否能正常访问  
  10. [root@server10~]#wget http:// 192.168.0.10/RPM-GPG-KEY-CentOS-7  
  11. #如果httpd服务正常运行,但资源无法正常访问,请进行以下检查:  
  12. # 1、防火墙是否已关闭  
  13. [root@server10~]# service iptables status  
  14. #2、检查selinux的模式,确定将其修改为permissive模式  
  15. [root@server10~]# getenforce  
  16. [root@server10~]# setenforce 0  
  17. #3、检查/etc/httpd/conf/httpd.conf相关配置是否满足访问要求  

7、客户端yum源配置repo文件

[plain]  view plain  copy
  1. [root@server11~]# cd /etc/yum.repo/  
  2. [root@server11 ~]# vi CentOS-Base.repo  
  3. 内容如下:  
  4. [base]  
  5. name=CentOS-$releasever - Base  
  6. baseurl=http:// 192.168.0.10/centos/$releasever/os/$basearch/  
  7. gpgcheck=1  
  8. enabled=1  
  9. gpgkey=http:// 192.168.0.10/RPM-GPG-KEY-CentOS-7  
  10.     
  11. [updates]  
  12. name=CentOS-$releasever - Updates  
  13. baseurl=http:// 192.168.0.10/centos/$releasever/updates/$basearch/  
  14. gpgcheck=1   
  15. enabled=1  
  16. gpgkey=http:// 192.168.0.10/RPM-GPG-KEY-CentOS-5  
  17.     
  18. #其他软件的yum源配置  
  19. [root@server11 ~]# vi CentOS-Tools.repo  
  20. 内容如下:  
  21. [tools]  
  22. name=CentOS-$releasever - Base  
  23. baseurl=http://192.168.0.10/tools/  
  24. gpgcheck=0  
  25. enabled=1  

8、附加内容createrepo常用命令

在上述步骤结束后,更新需要使用yum机器/etc/yum.repo目录中的文件为第四步中更改的内容,即可使用yum,yum 命令在这里就不说了,补充几个yum服务器常用的命令:

[plain]  view plain  copy
  1. #更新或创建主目录文件索引  
  2. createrepo /app/yum.repo/centos/7/os/x86_64  
  3. #更新或创建升级目录文件索引  
  4. createrepo /app/yum.repo/centos/7/updates/x86_64/  
  5. #更新或创建tools目录文件索引  
  6. createrepo/app/yum.repo/tools  
  7. #更新或创建yum组索引,yum组,比如admintools 它包含多个rpm,可以用yum grouplist查看  
  8. createrepo-g /mnt/cdrom/repodata/comps.xml /var/www/html/yum.repo/centos/7/updates/x86_64/  
  9. createrepo -g /mnt/cdrom/repodata/comps.xml/var/www/html/yum.repo/centos/7/os/x86_64/  

猜你喜欢

转载自blog.csdn.net/zyq11223/article/details/78694401