搭建 centos7 YUM 源

搭建 centos7 YUM 源

1. 创建yum软件保存目录

[root@localhost ~]# mkdir -p /www/share/yum

2. 修改yum配置文件

  1. 先备份yum配置文件

    [root@localhost ~]# cp /etc/yum.conf /etc/yum.conf.bak
    
  2. 修改yum配置文件中yum软件包保存目录并开启rmp包缓存功能

    [root@localhost ~]# vim /etc/yum.conf
    
    [main]
    #cachedir=/var/cache/yum/$basearch/$releasever
    cachedir=/www/share/yum/$basearch/$releasever
    keepcache=1
    

3. 安装createrepo和http

  1. createrepo 命令用于创建yum源(软件仓库),即为存放于本地特定位置的众多rpm包建立索引,描述各包所需依赖信息,并形成元数据。

    [root@localhost ~]# yum install createrepo httpd -y
    

4. 创建http共享目录

[root@localhost ~]# vim /etc/httpd/conf.d/share.conf
#http share
Alias /share /www/share
<Directory "/www/share">
    Options Indexes FollowSymLinks
    IndexOptions NameWidth=* DescriptionWidth=* FoldersFirst
    IndexOptions SuppressIcon HTMLTable Charset=UTF-8 SuppressHTMLPreamble
    Order allow,deny
    Allow from all
    Require all granted
</Directory>

5. 修改http配置文件

  1. 备份httpd配置并修改配置文件

    [root@localhost ~]# cp /etc/httpd/conf/httpd.conf{,.bak}
    
    [root@localhost ~]# echo "
    ServerName localhost
    #关闭版本号显示
    ServerSignature Off
    ServerTokens Prod
    ">>/etc/httpd/conf/httpd.conf
    

6. 启动http服务

[root@localhost ~]# systemctl enable httpd.service && systemctl restart httpd.service
[root@localhost ~]# netstat -antp|grep 'httpd'

7. 访问 http 服务

  1. 浏览器访问192.168.92.60/share ,能访问即正常

  2. 如果不能访问可尝试关闭防火墙

    [root@localhost ~]# systemctl stop firewalld.service
    
  3. 若果出现403错误,可以尝试调整selinux,或者关闭。

     [root@localhost ~]# setenforce 0
    

8. 创建YUM软件仓库

[root@localhost ~]# mkdir -p /www/share/centos7_rpm
[root@localhost ~]# createrepo -p /www/share/centos7_rpm/
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@localhost ~]# ll /www/share/centos7_rpm/
total 4
drwxr-xr-x 2 root root 4096 Jun 19 09:40 repodata

9. 创建源文件

  1. 创建源文件,baseurl换成自己ip地址
[root@localhost ~]# echo "
[My_share]
name=My_Souce
baseurl=http://192.168.92.60/share/centos7_rpm/
gpgcheck=0
enabled=1
cost=88
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
">/www/share/Lan7.repo

10. 下载软件包

  1. 将yum缓存的rpm包拷贝到/www/share/centos7_rpm/

    [root@localhost ~]# find /www/share/yum -name *.rpm |sed -r 's#.*#mv & /www/share/centos7_rpm/\n#'|bash
    
  2. 下载没有安装过的包

    [root@localhost ~]# yum install --downloadonly --downloaddir=/www/share/centos7_rpm/ -y 包名称
    
  3. 重新下载已经安装过的包

    [root@localhost ~]# yum reinstall --downloadonly --downloaddir=/www/share/centos7_rpm/ -y 包名称
    
  4. 更新源

    [root@localhost ~]# createrepo --update -p /www/share/centos7_rpm/
    
  5. 创建rpm下载、yum更新shell

    [root@localhost ~]# echo '#!/bin/sh
    [ $# = 0 ] && {
    echo "更新源"
    /usr/bin/createrepo --update -p /www/share/centos7_rpm/
    } || {
    echo "yum下载"
    yum install --downloadonly --downloaddir=/www/share/centos7_rpm/ -y $*
    echo "更新源"
    /usr/bin/createrepo --update -p /www/share/centos7_rpm/
    }
    '>yumd.sh
    
    [root@localhost ~]# ln -s $(pwd)/yumd.sh /usr/bin/yumd
    
    [root@localhost ~]# chmod +x yumd.sh
    

执行 yumd 更新源,执行 yumd 软件1 软件2 ,就会下载相关软件并更新源

11. 下载OpenStack安装包

  1. 仅作为参考,根据需求添加其它组件

    [root@localhost ~]# yum install centos-release-openstack-queens -y #安装OpenStack官方源
    [root@localhost ~]# yum install --downloadonly --downloaddir=/www/share/centos7_rpm/ -y \
    python-openstackclient openstack-selinux python-openstackclient python2-PyMySQL \
    openstack-utils \
    mariadb mariadb-server mariadb-galera-server python2-PyMySQL \
    erlang socat rabbitmq-server \
    openstack-keystone httpd mod_wsgi memcached python-memcached \
    apr apr-util \
    openstack-glance python-glance \
    openstack-nova-api openstack-nova-conductor \
    openstack-nova-console openstack-nova-novncproxy \
    openstack-nova-scheduler openstack-nova-placement-api \
    openstack-nova-compute python-openstackclient openstack-selinux \
    openstack-neutron openstack-neutron-ml2 \
    openstack-neutron-linuxbridge python-neutronclient ebtables ipset \
    openstack-neutron-linuxbridge ebtables ipset \
    openstack-dashboard \
    openstack-cinder targetcli python-keystone lvm2 \
    corosync pacemaker pcs fence-agents resource-agents \
    openstack-neutron-linuxbridge
    
  2. 更新源

    [root@localhost ~]# createrepo --update -p /www/share/centos7_rpm/
    

12. 客户端使用源

  1. 下载服务端源文件到本地

    [root@localhost ~]# wget -O /etc/yum.repos.d/Lan7.repo http://192.168.92.60/share/Lan7.repo
    
  2. 客户端测试,查看源名称为myshare说明正常

    [root@localhost ~]# yum install httpd
    
  3. 参考来源:

    1. https://blog.csdn.net/networken/article/details/80729234
    2. https://blog.csdn.net/gcangle/article/details/50197753
    3. https://blog.csdn.net/sxy2475/article/details/76744899
    4. https://blog.csdn.net/linuxprobe18/article/details/80639220
    5. docker离线安装:https://blog.csdn.net/qq_15807167/article/details/80588856
发布了24 篇原创文章 · 获赞 15 · 访问量 9837

猜你喜欢

转载自blog.csdn.net/yangwenpei116/article/details/91355362