搭建内网Linux CentOS yum源,摆脱依赖包困扰

什么是yum源?

yum源就是使用yum命令下载软件的镜像地址。

我们通常使用 yum install 命令来在线安装 linux系统的软件, 这种方式可以自动处理依赖性关系,并且一次安装所有依赖的软体包,但是经常会遇到从国外镜像下载速度慢,无法下载的情况。或者内网无法访问公网的情况,那么此时我们就需要一个稳定的yum 源作为我们日常使用的地址。


搭建内网Linux CentOS yum源,摆脱依赖包困扰


首先,选择一个稳定的公网yum源,这里我们选择阿里的yum源,地址:https://developer.aliyun.com/mirror

第一步:安装Nginx

1、关闭防火墙和SElinux

2、nginx安装:

依赖包:

yum -y install gcc* zlib-devel pcre pcre-devel openssl-devel perl perl-devel perl-ExtUtils-Embed

参数:

./configure --prefix=/opt/1s1k/nginx-1.12.1 --with-http_stub_status_module --without-poll_module --without-select_module --with-http_ssl_module --with-http_realip_module --with-http_perl_module --with-pcre-jit --error-log-path=/opt/1s1k/nginx-1.12.1/logs/error.log --http-log-path=/opt/1s1k/nginx-1.12.1/logs/access.log

第二步、配置nginx服务

1、修改nginx配置文件/usr/local/nginx/conf/nginx.conf

增加:

autoindex on; 表示自动在index.html的索引打开

autoindex_exact_size on; 表示如果有文件则显示文件大小

autoindex_localtime on; 表示显示更改时间,以当前系统时间为准


搭建内网Linux CentOS yum源,摆脱依赖包困扰

2、配置完成后运行nginx服务

启动:/usr/local/nginx/sbin/nginx

重启:/usr/local/nginx/sbin/nginx -s reload

关闭:/usr/local/nginx/sbin/nginx -s stop

3、创建index.html文件

/usr/local/nginx/html/index.html

在index.html中加入下面内容,CentOS7-Ali目录是后面放置rpm包的目录。

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


搭建内网Linux CentOS yum源,摆脱依赖包困扰

4、在/usr/local/nginx/html中创建CentOS7-Ali目录

增加目录的执行权限

Chmod –R +x /usr/local/nginx/html/


搭建内网Linux CentOS yum源,摆脱依赖包困扰

第三步、同步公网YUM源

1、同步并下载阿里源中CentOS7的包,第一次同步下载时间会比较长

reposync -p /usr/local/nginx/html/CentOS7-Ali

同步完成后在web界面会看到新建的三个目录


搭建内网Linux CentOS yum源,摆脱依赖包困扰

2、创建yum源仓库

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

搭建内网Linux CentOS yum源,摆脱依赖包困扰

第四步、配置客户端的yum源

yum-config-manager --add-repo="http://10.100.50.120/CentOS7-Ali/base/Packages"

配置完成后使用 yum makecache命令更新缓存成功。


第五步、通过定时任务方式让yum源自动到阿里源更新。

1、创建更新脚本:/usr/local/nginx/sbin/yumupdate.sh

“-np”的意思为仅仅更新新更新的软件到指定目录


搭建内网Linux CentOS yum源,摆脱依赖包困扰

2、配置定时任务。

run-parts的意思是执行后面目录中的脚本


搭建内网Linux CentOS yum源,摆脱依赖包困扰


分享到:


相關文章: