快捷搜索:  汽车  科技

网络yum源的配置方法(解决依赖包难题)

网络yum源的配置方法(解决依赖包难题)autoindex_exact_size on; 表示如果有文件则显示文件大小autoindex on; 表示自动在index.html的索引打开选择一个稳定的公网yum源,这里我们选择阿里的yum源,地址:https://developer.aliyun.com/mirrorsed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config setenforce 0systemctl stop firewalld //停止系统默认的防火墙 systemctl mask firewalld //屏蔽服务(让它不能启动) yum remove -y firewalld //卸载默认的防火墙2.1.2、设置ulimit值vi/etc/security/limits.confroot soft nofile

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

由于森哥原来做过一次图片存储位置变更至阿里云的OSS上,未能及时将原来的图片同时迁移至OSS上,造成图片的缺失,以后有机会再补上。

网络yum源的配置方法(解决依赖包难题)(1)

搭建内网yum源,解决依赖包难题

一、解释

什么是yum源?

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

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

网络yum源的配置方法(解决依赖包难题)(2)

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

二、安装配置Nginx环境

2.1、安装Nginx

2.1.1、关闭防火墙及SeLinux

sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config setenforce 0

systemctl stop firewalld //停止系统默认的防火墙 systemctl mask firewalld //屏蔽服务(让它不能启动) yum remove -y firewalld //卸载默认的防火墙

2.1.2、设置ulimit值

vi/etc/security/limits.conf

root soft nofile 65535 root hard nofile 65535 * soft nofile 65535 * hard nofile 65535

ulimit-SHn65536//执行,立即永久生效。

2.1.3、更新CentOS repo源

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


当您的/etc/yum.repos.d/下有多个yum源时,下面同步时,也会全部同步下来。

2.1.4、安装依赖包及编译环境


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

2.1.5、安装Nginx

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配置文件

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服务

systemctl start nginx //启动Nginx systemctl stop nginx //停止Nginx systemctl restart nginx //重启Nginx systemctl reload nginx //加载Nginx配置文件

2.2.3、创建index.html文件

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

<p style="font-weight:bolder;color:green;font-size:30px;">ALL of the packages in the below:</p> <br/> <a href="http://172.16.2.21/CentOS-YUM/Aliyun">Aliyun</a><br/> These packagers from of CentO`S ISO.<br/> <a href="http://172.16.2.21/CentOS7-Ali">CentOS</a><br/> These packagers from of "Internet service provider".<br/> <p style="font-weight:bolder;color:red;font-size:18px;">Please replace the file and fill in the following content:</p> <p style="font-weight:bolder;color:blue;font-size:15px;">Way: /etc/yum.repos.d/CentOS-Base.repo</p>

172.16.2.21 该IP为您的Nginx服务器的IP,您也可以自行分配一个域名。

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

增加目录的执行权限

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

2.3、同步公网YUM源

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

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

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

2.3.2、创建yum源仓库

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

进入CentOS7-Ali/base/Packages/中执行

createrepo-p.

2.4、配置客户端的yum源

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

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

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

2.5.1、创建更新脚本:/etc/nginx/yumupdate.sh

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

vi/etc/nginx/yumupdate.sh

#!/bin/bash usr/bin/reposync -np /usr/local/nginx/html/CentOS7-Ali/

2.5.2、配置定时任务

crontab -e配置定时任务

00**0/etc/nginx/yumupdate.sh

猜您喜欢: