參考文章: html
https://www.cnblogs.com/lldsn/p/10479493.htmlnode
系統版本centos 7.5 最小化安裝 nginx
修改主機名 c++
hostnamectl set-hostname yum.localvim
安裝wget軟件包 centos
yum install wget -y 瀏覽器
修改yum源 bash
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo服務器
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repoapp
驗證阿里雲是否正常
yum repolist
安裝依賴包
yum install -y wget make cmake gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel createrepo yum-utils
建立本地目錄
mkdir /mirror
同步rpm包到本地的
reposync -p /mirror
更新新的rpm包
reposync -np /mirror
建立索引
createrepo -po /mirror/base/ /mirror/base/
createrepo -po /mirror/extras/ /mirror/extras/
createrepo -po /mirror/updates/ /mirror/updates/
createrepo -po /mirror/epel/ /mirror/epel/
createrepo -po /mirror/epel/ /mirror/centosplus/
更新數據源
createrepo --update /mirror/base
createrepo --update /mirror/extras
createrepo --update /mirror/updates
createrepo --update /mirror/epel
createrepo --update /mirror/centosplus
安裝nginx
yum install nginx -y
修改nginx的配置文件
vi /etc/nginx/nginx.conf
nginx.conf配置文件內容以下
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /mirror; #修改未mirro目錄
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
autoindex on; #打開目錄瀏覽功能
autoindex_exact_size off; # off:以可讀的方式顯示文件大小
autoindex_localtime on; # on、off:是否以服務器的文件時間做爲顯示的時間
charset utf-8,gbk; #展現中文文件名
index index.html;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
重啓nginx服務
systemctl restart nginx.service
將nginx添加到開機啓動
systemctl enable nginx.service
使用瀏覽器訪問測試nginx是否能被成功訪問。
yum客戶端配置
cd /etc/yum.repos.d/
備份系統自帶的yum源
tar -zcvf yum.bak.tar.gz /etc/yum.repos.d/CentOS-*
刪除系統自帶的repo文件
rm -rf CentOS-*
建立yum配置文件
vi local.repo
local.repo配置文件的內容以下
[base]
name=CentOS-Base(GDS)
baseurl=http://192.168.197.20/base
path=/
enabled=1
gpgcheck=0
[updates]
name=CentOS-Updates(GDS)
baseurl=http://192.168.197.20/updates
path=/
enabled=1
gpgcheck=0
[extras]
name=CentOS-Extras(GDS)
baseurl=http://192.168.197.20/extras
path=/
enabled=1
gpgcheck=0
[epel]
name=CentOS-Epel(GDS)
baseurl=http://192.168.197.20/epel
path=/
enabled=1
gpgcheck=0
清除
測試安裝一個rpm包
yum install vim -y
服務器端週期性的更新rpm包,手工命令以下
更新rpm包
reposync -np /mirror
更新以後須要從新更新數據源
createrepo --update /mirror/base
createrepo --update /mirror/extras
createrepo --update /mirror/updates
createrepo --update /mirror/epel
也能夠建立定時更新的腳本
#vim /mirror/script/centos_yum_update.sh
#!/bin/bash
echo 'Updating Aliyum Source'
DATETIME=`date +%F_%T`
exec > /var/log/aliyumrepo_$DATETIME.log
reposync -np /mirror
if [ $? -eq 0 ];then
createrepo --update /mirror/base
createrepo --update /mirror/extras
createrepo --update /mirror/updates
createrepo --update /mirror/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 /mirror/script/centos_yum_update.sh
每個月第一個週六的13點更新阿里雲yum源