啊里云oss省流量的方案

版权声明:http://www.thinkunion.net https://blog.csdn.net/weixin_43932088/article/details/85986500

方案一,oss+cdn,因为cdn单价便宜,所以使用这个方案非常不错,还可以加速。

但是我发现海外的cdn节点一点都不便宜,而且目前暂无海外流量包,仅支持按量计费

按量付费:
国内0.24/G
北美0.46/G,亚太0.79-0.85 中东非洲等1.31,南美1.31

所以,如果我们的是海外的站点,那么使用cdn这个方案并不能省到流量。

方案二,shell监控ecs流量动态切换资源链接。

通过观察发现服务器的流量并不是24小时都处理满载的状态运行。而是波浪形的,

在非满载运行的情况下,完全是可以把资源用回服务器的。

我们设定一个阀值比如8M峰值就使用oss的资源,其他时间则使用服务器的。

这样可以充分利用服务器的原本宽带资源。

我们写一个shell来监控,把资源标识放到一个文件中(或者存入redis),便于其他程序去获取

trf.sh

#!/bin/bash

function trfrecord(){
	if [ ! -f "trf.record" ]; then
	        pre=""
	else
	        pre=$(cat trf.record)
	fi
	timestamp=`date +%s`
	trf=$(cat /proc/net/dev | grep eth0 | tr : " " | awk '{print $10}')
	echo ${trf}":"${timestamp} > trf.record

	ll=0
	if [ $pre ];then
	        trfpre=$(echo $pre|awk -F ":" '{print $1}')
	        timepre=$(echo $pre|awk -F ":" '{print $2}')
	        ll=$[$[$trf-$trfpre]/$[$timestamp-$timepre]]
	fi
	llb=$[${ll}*8]
	####8M的阀值####
	poin=$[1048576*8]
	if [ $llb -gt $poin ];then
		echo 'oos'>'/www/trf'
                #redis-cli set trf oss
	else
		echo 'ecs'>'/www/trf'
                #redis-cli set trf ecs
	fi
}

####5秒的间隔####
step=5
while [[ true ]]; do
	trfrecord
	sleep $step
done

运行使用命令:

nohup ./trf.sh >/dev/null 2>&1 &

部署了这个方案后,服务器流量得到了充分的利用,oss直接节省了至少一半的流量。

well done!!!!!!!!!!!!

猜你喜欢

转载自blog.csdn.net/weixin_43932088/article/details/85986500