当前负责的项目有几十台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、 挂载镜像文件
- [root@server10~]# mkdir /mnt/iso
- [root@server10~]# mount /home/CentOS-7-x86_64-DVD-1503-01.iso/mnt/iso
- [root@server10~]# ls /mnt/iso
- 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等。
- #新建本地源配置文件
- [root@server10~]# vi /etc/yum.repo.d/CentOS7-local.repo
- #内容如下:
- [CentOS7-iso]
- Name=CentOS-$releasever– Media
- Baseurl=file:///mnt/iso
- gpgcheck=1
- Enabled=1
- gpgkey=file:///etc/pki/rpm-gpg/PRM-GPG-KEY-CentOS-7
4、 利用本地yum源安装依赖软件
- #安装apache服务和repo下的xml生成工具
- [root@server10~]# yum install httpd createrepo
5、 新建yum源目录并拷贝相关镜像文件:
- [root@server10~]# mkdir -p /data/yum.repo/centos/7/os/x86_64/Packages
- [root@server10~]# mkdir -p /data/yum.repo/centos/7/updates/x86_64/Packages
- [root@server10~]# mkdir -p /data/yum.repo/tools/
- [root@server10~]# cp -R /mnt/iso/Packages/*/data/yum.repo/centos/7/os/x86_64/Packages/
- [root@server10~]# cp -R /mnt/iso/repodata/data/yum.repo/centos/7/os/x86_64
- [root@server10~]# cp -R /mnt/iso/repodata/data/yum.repo/centos/7/updates/x86_64
- [root@server10~]# cp -R /mnt/iso/repodata /data/yum.repo/tools
- [root@server10~]# cp -R /mnt/iso/RPM-GPG-KEY-CentOS-7/data/yum.repo/
- #注:其他包可拷贝到/data/yum.repo/tools下,如jdk
6、启动http服务:
- #删除原有的/var/www/html目录
- [root@server10~]# rm -rf /var/www/html
- #建立安装文件与tomcat部署目录的软连接
- [root@server10~]# ln -s /data/yum.repo /var/www/html
- #启动服务
- [root@server10~]# service httpd start
- #验证httpd是否成功启动
- [root@server10~]# service httpd status
- #验证yum源相关资源是否能正常访问
- [root@server10~]#wget http:// 192.168.0.10/RPM-GPG-KEY-CentOS-7
- #如果httpd服务正常运行,但资源无法正常访问,请进行以下检查:
- # 1、防火墙是否已关闭
- [root@server10~]# service iptables status
- #2、检查selinux的模式,确定将其修改为permissive模式
- [root@server10~]# getenforce
- [root@server10~]# setenforce 0
- #3、检查/etc/httpd/conf/httpd.conf相关配置是否满足访问要求
7、客户端yum源配置repo文件
- [root@server11~]# cd /etc/yum.repo/
- [root@server11 ~]# vi CentOS-Base.repo
- 内容如下:
- [base]
- name=CentOS-$releasever - Base
- baseurl=http:// 192.168.0.10/centos/$releasever/os/$basearch/
- gpgcheck=1
- enabled=1
- gpgkey=http:// 192.168.0.10/RPM-GPG-KEY-CentOS-7
-
- [updates]
- name=CentOS-$releasever - Updates
- baseurl=http:// 192.168.0.10/centos/$releasever/updates/$basearch/
- gpgcheck=1
- enabled=1
- gpgkey=http:// 192.168.0.10/RPM-GPG-KEY-CentOS-5
-
- #其他软件的yum源配置
- [root@server11 ~]# vi CentOS-Tools.repo
- 内容如下:
- [tools]
- name=CentOS-$releasever - Base
- baseurl=http://192.168.0.10/tools/
- gpgcheck=0
- enabled=1
8、附加内容createrepo常用命令
在上述步骤结束后,更新需要使用yum机器/etc/yum.repo目录中的文件为第四步中更改的内容,即可使用yum,yum 命令在这里就不说了,补充几个yum服务器常用的命令:
- #更新或创建主目录文件索引
- createrepo /app/yum.repo/centos/7/os/x86_64
- #更新或创建升级目录文件索引
- createrepo /app/yum.repo/centos/7/updates/x86_64/
- #更新或创建tools目录文件索引
- createrepo/app/yum.repo/tools
- #更新或创建yum组索引,yum组,比如admintools 它包含多个rpm,可以用yum grouplist查看
- createrepo-g /mnt/cdrom/repodata/comps.xml /var/www/html/yum.repo/centos/7/updates/x86_64/
- createrepo -g /mnt/cdrom/repodata/comps.xml/var/www/html/yum.repo/centos/7/os/x86_64/