1. 程式人生 > >CentOS7基於http方式搭建本地yum源

CentOS7基於http方式搭建本地yum源

1.建立yum軟體儲存目錄

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

2. 修改yum配置檔案

先備份yum配置檔案,修改yum配置檔案中yum軟體包儲存目錄並開啟rmp包快取功能

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

3.安裝createrepo和http

createrepo 命令用於建立yum源(軟體倉庫),即為存放於本地特定位置的眾多rpm包建立索引,描述各包所需依賴資訊,並形成元資料。

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

4.建立http共享目錄

[[email protected] www]# 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配置檔案

備份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'

瀏覽器訪問192.168.92.60/share ,能訪問即正常
這裡寫圖片描述

7.建立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

8.建立原始檔

[[email protected] ~]# 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

9.下載軟體包

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.下載沒有安裝過的包

[[email protected] ~]# yum install --downloadonly --downloaddir=/www/share/centos7_rpm/ -y 包名稱

3.重新下載已經安裝過的包

[[email protected] ~]# yum reinstall --downloadonly --downloaddir=/www/share/centos7_rpm/ -y 包名稱

4.更新源

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

5.建立rpm下載、yum更新shell

[[email protected] ~]# 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
[[email protected] ~]# ln -s $(pwd)/yumd.sh /usr/bin/yumd
[[email protected] ~]# chmod +x yumd.sh

執行 yumd 更新源,執行 yumd 軟體1 軟體2 ,就會下載相關軟體並更新源

10.下載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.更新源

createrepo --update -p /www/share/centos7_rpm/

11.客戶端使用源

1.下載服務端原始檔到本地

wget -O /etc/yum.repos.d/Lan7.repo http://192.168.92.60/share/Lan7.repo

2.客戶端測試,檢視源名稱為myshare說明正常

yum install httpd

參考來源:http://www.cnblogs.com/elvi/p/7657770.html