Nas is so sweet to a loser programmer like me who can’t afford aliyun server.

conditions

  • Cluster hui or black cluster hui
  • Ali cloud domain name application, need to record
  • There is public IP in the home (not fixed, will often change), telecom generally have, no words can apply to customer service. Other broadband please Baidu
  • The router sets up port forwarding or DMZ hosts

The advantages of this approach are obvious

  • No need to use peanut shell FRP to do Intranet penetration, completely free, only the aliyun domain name fee
  • Speed depends on home broadband. For example, my home gigabit broadband, upload is a hundred megabytes, measured company download files can reach 12 megabytes per second
  • Super stable, no problems generally

The disadvantages are also obvious

  • Have a public IP address
  • Unable to use ports 80 and 443 (blocked), you will definitely need a port number to deploy the site

Ali cloud console to obtainAccessKey IDandAccess Key SecretTo access ali Cloud API

Create the aliyun.sh file in CDH and copy the following script into it

#! /bin/sh
set -e

if [ The $1 ]; then
	ApiId=The $1
fi

if [ $2 ]; then
	ApiKey=$2
fi

if [ $3 ]; then
	Domain=$3
fi

if [ -z "$ApiId" -o -z "$ApiKey" -o -z "$Domain" ]; then
	echo "Parameter missing"
	exit 1
fi

if [ $4 ]; then
	SubDomain=$4
fi

if [ -z "$SubDomain" ]; then
	SubDomain="@"
fi

Nonce=$(date -u "+%N")	# have a bug?
Timestamp=$(date -u "+%Y-%m-%dT%H%%3A%M%%3A%SZ")	# SB Ali Cloud, what the hell time format
Nonce=$Timestamp

urlencode() {
	local raw="The $1";
	local len="${#raw}"
	local encoded=""

	for i in `seq 1 $len`; do
		local j=$((i+1))
		local c=$(echo $raw | cut -c$i-$i)

		case $c in [a-zA-Z0-9.~_-]) ;;
			*)
			c=$(printf '%%%02X' "'$c");;esac

		encoded="$encoded$c"
	done

	echo $encoded
}

# $1 = query string
getSignature() {
	local encodedQuery=$(urlencode The $1)
	local message="GET&%2F&$encodedQuery"
	local sig=$(echo -n "$message" | openssl dgst -sha1 -hmac "$ApiKey&" -binary | openssl base64)
	echo $(urlencode $sig)}sendRequest() {
	local sig=$(getSignature The $1)
	local result=$(wget -qO- --no-check-certificate --content-on-error "https://alidns.aliyuncs.com?The $1&Signature=$sig")
	echo $result
}

getRecordId() {
	echo "Get$SubDomain.$DomainIP..."2 > &local queryString="AccessKeyId=$ApiId&Action=DescribeSubDomainRecords&Format=JSON&SignatureMethod=HMAC-SHA1&SignatureNonce=$Nonce& SignatureVersion = 1.0 & SubDomain =$SubDomain.$Domain&Timestamp=$Timestamp&Type=A&Version=2015-01-09"
	local result=$(sendRequest "$queryString")
	local code=$(echo $result | sed 's/.*,"Code":"\([A-z]*\)",.*/\1/')
	local recordId=$(echo $result | sed 's/.*,"RecordId":"\([0-9]*\)",.*/\1/')

	if [ "$code" = "$result"] && [!"$recordId" = "$result" ]; then
		local ip=$(echo $result | sed 's/.*,"Value":"\([0-9\.]*\)",.*/\1/')

		if [ "$ip"= ="$NewIP" ]; then
			echo "IP unchanged, exit script..."2 > &echo "quit"
		else
			echo $recordId
		fi
	else
		echo "null"
	fi
}

# $1 = record ID, $2 = new IP
updateRecord() {
	local queryString="AccessKeyId=$ApiId&Action=UpdateDomainRecord&DomainName=$Domain&Format=JSON&RR=$SubDomain&RecordId=The $1&SignatureMethod=HMAC-SHA1&SignatureNonce=$Nonce& SignatureVersion = 1.0 & Timestamp =$Timestamp&Type=A&Value=$2&Version=2015-01-09"
	local result=$(sendRequest $queryString)
	local code=$(echo $result | sed 's/.*,"Code":"\([A-z]*\)",.*/\1/')

	if [ "$code" = "$result" ]; then
		echo "$SubDomain.$DomainHas been to$NewIP."2 > &else
		echo "Update failed."2 > &echo $result2 > &fi
}

# $1 = new IP
addRecord() {
	local queryString="AccessKeyId=$ApiId&Action=AddDomainRecord&DomainName=$Domain&Format=JSON&RR=$SubDomain&SignatureMethod=HMAC-SHA1&SignatureNonce=$Nonce& SignatureVersion = 1.0 & Timestamp =$Timestamp&Type=A&Value=The $1&Version=2015-01-09"
	local result=$(sendRequest $queryString)
	local code=$(echo $result | sed 's/.*,"Code":"\([A-z]*\)",.*/\1/')

	if [ "$code" = "$result" ]; then
		echo "$SubDomain.$DomainHas been to$NewIP."2 > &else
		echo "Add failed."2 > &echo $result2 > &fi
}

# Get new IP address
echo "Get current IP..."
NewIP=$(wget -qO- --no-check-certificate "http://members.3322.org/dyndns/getip")
echo "The current IP is$NewIP."

# Get record ID of sub domain
recordId=$(getRecordId)

if[!"$recordId" = "quit" ]; then
	if [ "$recordId" = "null" ]; then
		echo "Domain name record does not exist, add$SubDomain.$Domain$NewIP..."
		addRecord $NewIP
	else
		echo "Domain name record already exists, updated$SubDomain.$Domain$NewIP..."
		updateRecord $recordId $NewIP
	fi
fi
Copy the code

I have placed this script in the following location, which can be changed according to your needs

Open The CDH Control Panel -> Plan the task

A new task is added. In the screenshot, the task is scheduled to be executed every 10 minutes from 7:00-20:50 every day

The script format is as follows

Sh [sh script address] [AccessKey ID] [AccessKey] Secret [top-level domain] [secondary domain]Copy the code

For example,

Sh/volume1 / public/DDNS/aliyun. Sh 9 qjrykshqeeeeek4 fNJGWee2IFyaUT5XvYeeyGXmeeiPre nas at sout.comCopy the code