本地yum倉庫搭建

yum:

yum的全稱是yellow dog updater,modified,是一個shell前端軟件包管理器;基于RPM包管理,能夠從指定的服務器下載RPM包并自動安裝,可以自動處理依賴性關系,并且一次性安裝所有依賴的軟件包,無需一次次頻繁的下載、安裝。

yum的作用就是可以避免安裝,從而簡化安裝過程。

例子:

執(zhí)行yum install -y https:表示從yum上下載https包并安裝;-y表示執(zhí)行過程中yes/no選擇yes,減少人機交互;這里獲取安裝包是從網(wǎng)絡上獲取并下載,而實際情況更多的是局域網(wǎng),無法從外網(wǎng)下載https安裝包,此時配置本地yum很有用!

為什么需要配置本地yum源:

1. 在沒有網(wǎng)絡時,無法下載到y(tǒng)um對應的軟件,就無法安裝,所以需要配置本地的yum源。

2. 在下載軟件時,可以不走網(wǎng)絡,直接走本地的yum倉庫,安裝軟件更加方便,速度更快,但是,所有的客戶端都必須走內(nèi)網(wǎng)。

yum.png

具體部署

yum源倉庫部署(這里的源指的是服務端)

服務端部署
下載相應軟件
1)yum install -y createrepo 這個命令用來創(chuàng)建yum倉庫
2)yum install -y nginx 這里需要訪問網(wǎng)站,所以需要nginx
3)yum install -y yum-plugin-priorities.noarch 這個命令用來在識別優(yōu)先級

第一歷程:將你的yum壓縮包拖入家目錄中,并解壓

unzip yum.zip

第二歷程:創(chuàng)建/yum/目錄,作為yum倉庫,將解壓后的yum目錄中的數(shù)據(jù)移動到倉庫目錄中

mkdir /yum
mv ~/yum/* /yum

第三歷程:安裝創(chuàng)建倉庫的命令,并創(chuàng)建倉庫

yum install createrepo -y
createrepo /yum

創(chuàng)建成功后,/yum目錄中會多出這個repodata目錄,如果沒有這個目錄,說明yum倉庫沒有創(chuàng)建成功。


image.png

第四個歷程:使用nginx發(fā)布yum倉庫

yum install nginx -y

編寫nginx配置文件,然就檢查語法,重啟,做好本地hosts解析,在瀏覽器打開:
配置文件如下

[root@yum /yum]# vim /etc/nginx/nginx.conf 
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

   # include /etc/nginx/conf.d/*.conf;
    server {
    listen       80;
    server_name  www.yum.com;
    autoindex on;
    location / {
        root   /yum;
        index  index.html index.htm;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
}

瀏覽器測試如下


image.png

客戶端部署

第一歷程:下載優(yōu)先級軟件

yum install -y yum-plugin-priorities.noarch

第二個歷程:編寫local.repo文件,讓用戶下載軟件時優(yōu)先走本地源
priority=1,添加一條優(yōu)先級。

cd /etc/yum.repos.d/
[root@lb01 /etc/yum.repos.d]# vim local.repo
[local]
name=local
baseurl=http://10.0.0.77/
enabled=1
gpgcheck=0
priority=1

我在做yum倉庫的時候,遇到了一個小錯誤,就是所有的步驟都做完了,最后還是走的阿里源。
解決方法,將下面的源移走,或者注釋掉,我是把所有的源移走以后另外配的yum源,讓他走我的源倉庫,也會是上面配的local:

[root@lb01 /etc/yum.repos.d]# ll
total 40
-rw-r--r--  1 root root 2575 Jun 23 14:27 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Apr 29  2018 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Apr 29  2018 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Apr 29  2018 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Apr 29  2018 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Apr 29  2018 CentOS-Sources.repo
-rw-r--r--. 1 root root 4768 Apr 29  2018 CentOS-Vault.repo
-rw-r--r--. 1 root root  664 May 30 09:16 epel.repo
-rw-r--r--  1 root root  100 Jun 19 09:39 nginx.repo

測試環(huán)節(jié):


image.png
最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容