03.04 搭建內網yum源,解決依賴包難題

我們通常使用 `yum install` 命令來在線安裝 linux系統的軟件, 這種方式可以自動處理依賴性關係,並且一次安裝所有依賴的軟體包,但是經常會遇到從國外鏡像下載速度慢,無法下載的情況。或者內網無法訪問公網的情況,那麼此時我們就需要一個穩定的yum 源作為我們日常使用的地址。

由於森哥原來做過一次圖片存儲位置變更至阿里雲的OSS上,未能及時將原來的圖片同時遷移至OSS上,造成圖片的缺失,以後有機會再補上。

搭建內網yum源,解決依賴包難題

搭建內網yum源,解決依賴包難題

一、解釋

什麼是yum源?

yum源就是使用yum命令下載軟件的鏡像地址。

我們通常使用 yum install 命令來在線安裝 linux系統的軟件, 這種方式可以自動處理依賴性關係,並且一次安裝所有依賴的軟體包,但是經常會遇到從國外鏡像下載速度慢,無法下載的情況。或者內網無法訪問公網的情況,那麼此時我們就需要一個穩定的yum 源作為我們日常使用的地址。

搭建內網yum源,解決依賴包難題

選擇一個穩定的公網yum源,這裡我們選擇阿里的yum源,地址:https://developer.aliyun.com/mirror

二、安裝配置Nginx環境

2.1、安裝Nginx

2.1.1、關閉防火牆及SeLinux

<code>sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
setenforce 0/<code>
<code>systemctl stop firewalld    //停止系統默認的防火牆
systemctl mask firewalld   //屏蔽服務(讓它不能啟動)
yum remove -y firewalld   //卸載默認的防火牆/<code>

2.1.2、設置ulimit值

<code>vi /etc/security/limits.conf/<code>
<code>root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535/<code>
<code>ulimit -SHn 65536   //執行,立即永久生效。/<code>

2.1.3、更新CentOS repo源

<code>curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum install -y epel-release
yum localinstall -y https://mirrors.ustc.edu.cn/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm  //安裝Nginx yum源
yum clean all
yum makecache/<code>


當您的/etc/yum.repos.d/下有多個yum源時,下面同步時,也會全部同步下來。

2.1.4、安裝依賴包及編譯環境


<code>yum groupinstall -y "Development Tools"
yum install -y binutils make cmake gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers  gd gd-devel perl expat expat-devel nss_ldap unixODBC unixODBC-devel libxslt-devel libevent-devel libtool-ltdl bison libtool zip unzip gmp-devel pcre pcre-devel perl-core python-devel perl-devel perl-ExtUtils-Embed compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel libaio libaio-devel sysstat
yum install -y yum-utils    //等下要執行reposync同步時使用
yum install -y createrepo   //創建repodata文件時用到
yum update -y/<code>

2.1.5、安裝Nginx

<code>yum install -y automake autoconf libtool make
yum install -y nginx
systemctl enable nginx    //開機自啟動
systemctl start nginx     //啟動Nginx
systemctl stop nginx      //停止Nginx
systemctl restart nginx   //重啟Nginx
systemctl reload nginx    //加載Nginx配置文件/<code>

2.2、配置Nginx服務

2.2.1、修改/etc/nginx/nginx.conf

增加:

autoindex on; 表示自動在index.html的索引打開

autoindex_exact_size on; 表示如果有文件則顯示文件大小

autoindex_localtime on; 表示顯示更改時間,以當前系統時間為準

2.2.2、配置完成後運行Nginx服務

<code>systemctl start nginx     //啟動Nginx
systemctl stop nginx      //停止Nginx
systemctl restart nginx   //重啟Nginx

systemctl reload nginx    //加載Nginx配置文件/<code>

2.2.3、創建index.html文件

在index.html中加入下面內容,CentOS7-Ali目錄是後面放置rpm包的目錄。

<code>

ALL of the packages in the below:









These packagers from of CentO`S ISO.





These packagers from of "Internet service provider".


Please replace the file and fill in the following content:



Way: /etc/yum.repos.d/CentOS-Base.repo

/<code>

172.16.2.21 該IP為您的Nginx服務器的IP,您也可以自行分配一個域名。

2.2.4、在/usr/local/nginx/html中創建CentOS7-Ali目錄

增加目錄的執行權限

<code>Chmod –R +x /usr/local/nginx/html//<code>

2.3、同步公網YUM源

2.3.1、同步並下載阿里源中CentOS7的包,第一次同步下載時間會比較長

<code>reposync -p /usr/local/nginx/html/CentOS7-Ali/<code>

同步完成後在web界面會看到新建的四個目錄

2.3.2、創建yum源倉庫

使用createrepo -p .命令創建repodata文件。

進入CentOS7-Ali/base/Packages/中執行

<code>createrepo -p ./<code>

2.4、配置客戶端的yum源

<code>yum-config-manager --add-repo="http://172.16.2.21/CentOS7-Ali/base/Packages"/<code>

配置完成後使用 yum makecache命令更新緩存成功。

2.5、通過定時任務方式讓yum源自動到阿里源更新。

2.5.1、創建更新腳本:/etc/nginx/yumupdate.sh

“-np”的意思為僅僅更新新更新的軟件到指定目錄

<code>vi /etc/nginx/yumupdate.sh/<code>
<code>#!/bin/bash
usr/bin/reposync -np /usr/local/nginx/html/CentOS7-Ali//<code>

2.5.2、配置定時任務

crontab -e配置定時任務

<code>0       0       *       *       0       /etc/nginx/yumupdate.sh/<code>


分享到:


相關文章: