yum本地源制作

公司使用CentOS跑openstack,由于yum相关的国外源太慢了,所以需要在公司内部做一个openstackc rdo的本地源。

以下就以rdo为例(http://openstack.redhat.com/Quickstart),介绍本地源制作方案:

选择一台CentOS服务器,安装以下软件:

yum install yum-utils createrepo yum-plugin-priorities
yum install httpd

设置httpd

chkconfig httpd on
service httpd start

获取repo文件并使用reposync同步源

yum install -y http://rdo.fedorapeople.org/rdo-release.rpm
yum repolist  #可以看到源的id列表

同步openstack-icehouse这个repo

cd /var/www/html/
reposync --repoid=openstack-icehouse

第一次同步时间较长,同步结束后

createrepo –update 	/var/www/html/openstack-icehouse

创建完成后,就可以使用web测试:http://[ip]/openstack-icehouse/

此处若使用其他目录下的文件夹的符号链接到/var/www/html处,需要关闭SELinux的安全选项

setenforce 0

测试如有问题可能是80端口未开放

vi /etc/sysconfig/iptables

添加以下内容到其中已有的22端口这条规则的下面

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

配置crontab定时任务进行定期reposync和createrepo

yum install crontabs

添加执行reposync和createrepo的crontab命令

这次在公司直接做了很多常用源的镜像,写了个crontab定期半夜2点执行的脚本,完整如下:

#!/bin/bash
BASE_PATH=/home/repo
cd $BASE_PATH
REPO_LIST=(base extras updates foreman foreman-plugins openstack-icehouse puppetlabs-deps puppetlabs-products epel)
for REPO_NAME in ${REPO_LIST[@]}; do
        echo -------$REPO_NAME--------
        LOGFILE_PATH=$BASE_PATH/reposync_log/$REPO_NAME
        mkdir -p $LOGFILE_PATH
        reposync --repoid=$REPO_NAME 2>&1 | tee $LOGFILE_PATH/reposync_$(date +"%Y%m%d%H").log
        if [ $REPO_NAME = base ] || [ $REPO_NAME = extras ] || [ $REPO_NAME = updates ]; then
                createrepo --update $REPO_NAME/Packages 2>&1 | tee $LOGFILE_PATH/createrepo_$(date +"%Y%m%d%H").log
        else
                createrepo --update $REPO_NAME 2>&1 | tee $LOGFILE_PATH/createrepo_$(date +"%Y%m%d%H").log
        fi
done

脚本完成了对REPO_LIST下源的镜像同步工作,并记录log(其中base等repo的rpm包在Packages文件夹下,所以createrepo的时候,路径多一层)

搞定了本地源,如果要使用的话就修改机器的/etc/yum.repos.d下的文件,将bashurl写成本地ip和路径,并把gpgcheck设置为0。

—————–

一般没有国内源的话,自己做个本地yum源会比较好,由国内源的话可以直接使用速度也很快,配置方案如下:

CentOS的yum管理工具虽然有fastestmiror这样的管理工具,但在实际使用yum安装时依然有可能选用国外的源,这就造成了安装速度过慢的问题。我们可以换用国内的源,国内比较知名的有中科大、网易、搜狐的源。下面以中科大源配置为例:

查看centOS版本

cat /etc/redhat-release

关闭fastestmirror插件

vim /etc/yum/pluginconf.d/fastestmirror.conf

修改enable = 0

换中科大源(https://lug.ustc.edu.cn/wiki/mirrors/help/centos),其中需要选用centOS相应版本的配置:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
vim CentOS-Base.repo

添加以下内容(基于centos6)

# 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-$releasever - Base - mirrors.ustc.edu.cn
baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.ustc.edu.cn
baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.ustc.edu.cn
baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.ustc.edu.cn
baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.ustc.edu.cn
baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6

运行yum makecache

—————

中科大centOS源:https://lug.ustc.edu.cn/wiki/mirrors/help/centos
网易centOS源:http://mirrors.163.com/.help/centos.html
中科大epel源:https://lug.ustc.edu.cn/wiki/mirrors/help/epel

Tags : , ,

One thought on “yum本地源制作”

发表评论

电子邮件地址不会被公开。 必填项已用*标注

Click the right image To submit your comment: