1、环境准备
①CentOS Linux release 7.8 1台
②各系统根目录要至少100G存储空间
③确保可以连接外网
2、修改本地YUM源
①备份本地YUM源:
tar -zcvf /etc/yum.repos.d//CentOS-bk.tar.gz /etc/yum.repos.d/CentOS-*
②下载阿里YUM源:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
③检查阿里YUM源是否正常
yum repolist
④安装相关软件
yum install -y wget make cmake gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel createrepo yum-utils
yum-utils:reposync同步工具
createrepo:编辑yum库工具
plugin-priorities:控制yum源更新优先级工具,这个工具可以用来控制进行yum源检索的先后顺序,建议可以用在client端。
3、根据源标识同步源到本地目录
①创建本地同步目录
mkdir /repo
②将阿里YUM的Package同步到本地目录
reposync -p /repo
③创建索引
createrepo -po /repo/base/ /repo/base/
createrepo -po /repo/extras/ /repo/extras/
createrepo -po /repo/updates/ /repo/updates/
createrepo -po /repo/epel/ /repo/epel/
④更新数据源
createrepo --update /repo/base
createrepo --update /repo/extras
createrepo --update /repo/updates
createrepo --update /repo/epel
4、创建定时任务
#vi /repo/script/centos_yum_update.sh
#!/bin/bash
echo 'Updating Aliyum Source'
DATETIME=`date +%F_%T`
exec > /repo/scripts/aliyumrepo_$DATETIME.log
reposync -np /repo
if [ $? -eq 0 ];then
createrepo --update /repo/base
createrepo --update /repo/extras
createrepo --update /repo/updates
createrepo --update /repo/epel
echo "SUCESS: $DATETIME aliyum_yum update successful"
else
echo "ERROR: $DATETIME aliyum_yum update failed"
fi
②将脚本加入到定时任务中
# crontab -e
# Updating Aliyum Source
00 13 * * 6 [ $(date +%d) -eq $(cal | awk 'NR==3{print $NF}') ] && /bin/bash /repo/script/centos_yum_update.sh
每月第一个周六的13点更新阿里云yum源
5、配置Nginx访问服务
①创建运行账户
groupadd nginx
useradd -r -g nginx -s /bin/false -M nginx
yum install nginx -y
②找到nginx配置文件,并修改nginx配置文件:
# vi nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
root /repo ; #这里是yum源存放目录
location / {
autoindex on; #打开目录浏览功能
autoindex_exact_size off; # off:以可读的方式显示文件大小
autoindex_localtime on; # on、off:是否以服务器的文件时间作为显示的时间
charset utf-8,gbk; #展示中文文件名
index index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
③在客户端修改yum源,并指向本地搭建的yum源主机
# vi CentOS7.x-Base.repo
[base]
name=CentOS-$releasever - Base - mirror.template.com
baseurl=http://192.168.230.44/base/
path=/
enabled=1
gpgcheck=0
[updates]
name=CentOS-$releasever - Updates - mirror.template.com
baseurl=http://192.168.230.44/updates/
path=/
enabled=1
gpgcheck=0
[extras]
name=CentOS-$releasever - Extras - mirrors.template.com
baseurl=http://192.168.230.44/extras/
path=/
enabled=1
gpgcheck=0
[epel]
name=CentOS-$releasever - epel - mirrors.template.com
baseurl=http://192.168.230.44/epel/
failovermethod=priority
enabled=1
gpgcheck=0