由于我的N1在Armbian上安装了宝塔面板,并架设了NextCloud(性能低下)所以还是装了Cloudreve,利用IPv6实现外网的便捷访问。Docker使用仅仅是为了DDNS还是很浪费资源的。所以就使用宝塔的计划任务来实现吧!

01-1024x618.jpg
其中的更新时间建议每天执行,当然也可以更频繁些,例如N小时一次。

aliddnsipv6_ak="**********"
aliddnsipv6_sk="************************"
aliddnsipv6_name1='www'
aliddnsipv6_domain='xxx.com'
aliddnsipv6_ttl="600"

if [ "$aliddnsipv6_name1" = "@" ]
then
  aliddnsipv6_name=$aliddnsipv6_domain
else
  aliddnsipv6_name=$aliddnsipv6_name1.$aliddnsipv6_domain
fi

now=`date`

die () {
    echo $1
}

ipv6s=`ip addr show eth0 | grep "inet6.*global" | awk '{print $2}' | awk -F"/" '{print $1}'` || die "$ipv6"

for ipv6 in $ipv6s
do
  #ipv6 = $ipv6
  break
done

echo $ipv6

current_ipv6=`nslookup -query=AAAA $aliddnsipv6_name 2>&1`
#echo $current_ipv6

current_ipv6=`echo "$current_ipv6" | grep 'Address: ' | tail -n1 | awk '{print $NF}'`
echo $current_ipv6

if [ "$?" -eq "0" ]
then
    current_ipv6=`echo "$current_ipv6" | grep 'Address: ' | tail -n1 | awk '{print $NF}'`
    echo $current_ipv6

    if [ "$ipv6" = "$current_ipv6" ]
    then
        echo "skipping"
    fi
# fix when A record removed by manual dns is always update error
else
    unset aliddnsipv6_record_id
fi


timestamp=`date -u "+%Y-%m-%dT%H%%3A%M%%3A%SZ"`


urlencode() {
    # urlencode 
    out=""
    while read -n1 c
    do
        case $c in
            [a-zA-Z0-9._-]) out="$out$c" ;;
            *) out="$out`printf '%%%02X' "'$c"`" ;;
        esac
    done
    echo -n $out
}

enc() {
    echo -n "$1" | urlencode
}

send_request() {
    local args="AccessKeyId=$aliddnsipv6_ak&Action=$1&Format=json&$2&Version=2015-01-09"
    local hash=$(echo -n "GET&%2F&$(enc "$args")" | openssl dgst -sha1 -hmac "$aliddnsipv6_sk&" -binary | openssl base64)
    curl -s "http://alidns.aliyuncs.com/?$args&Signature=$(enc "$hash")"
}

get_recordid() {
    grep -Eo '"RecordId":"[0-9]+"' | cut -d':' -f2 | tr -d '"'
}

query_recordid() {
    send_request "DescribeSubDomainRecords" "SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&SubDomain=$aliddnsipv6_name&Timestamp=$timestamp&Type=AAAA"
}

update_record() {
    send_request "UpdateDomainRecord" "RR=$aliddnsipv6_name1&RecordId=$1&SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&TTL=$aliddnsipv6_ttl&Timestamp=$timestamp&Type=AAAA&Value=$(enc $ipv6)"
}

add_record() {
    send_request "AddDomainRecord&DomainName=$aliddnsipv6_domain" "RR=$aliddnsipv6_name1&SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&TTL=$aliddnsipv6_ttl&Timestamp=$timestamp&Type=AAAA&Value=$(enc $ipv6)"
}

#add support */%2A and @/%40 record


if [ "$aliddnsipv6_record_id" = "" ]
then
    aliddnsipv6_record_id=`query_recordid | get_recordid`
    #echo '-----------------' $aliddnsipv6_record_id
fi
if [ "$aliddnsipv6_record_id" = "" ]
then
    aliddnsipv6_record_id=`add_record | get_recordid`
    echo "added record $aliddnsipv6_record_id"
else
    update_record $aliddnsipv6_record_id
    echo "updated record $aliddnsipv6_record_id"
fi

参数说明:

AccessKey ID:
aliddnsipv6_ak="**********"

Access Key Secret
aliddnsipv6_sk="************************"

子域名:

aliddnsipv6_name1='www'

域名:

aliddnsipv6_domain='xxx.com'

TTL:

aliddnsipv6_ttl="600"

show:etho 是指定网卡获取IPv6,可通过ifconfig命令来获取网卡名
ipv6s=ip addr show eth0 | grep "inet6.*global" | awk '{print $2}' | awk -F"/" '{print $1}' || die "$ipv6"
配置好了之后保存,可以尝试执行一次看是否已经生效,如果正常就OK啦!是不是很简单?

网络环境所限,在使用Armbian的时候经常下载软件出问题,下载不到或者下载中断,所以找来了国内的源,更换一下,下载会变快很多。

假定armbian已经安装完成

1、打开putty,输入N1的IP地址连接并登陆

2、输入命令

nano /etc/apt/sources.list

复制代码
3、在原先的源前面加#号注释掉,并将国内源复制过去

deb http://mirrors.ustc.edu.cn/debian stretch main contrib non-free
deb http://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free
deb http://mirrors.ustc.edu.cn/debian stretch-backports main contrib non-free
deb http://mirrors.ustc.edu.cn/debian-security/ stretch/updates main contrib non-free

复制代码
改 armbian 源

nano /etc/apt/sources.list.d/armbian.list

将里面的那行注释掉(在前面添加 # )然后添加这行

deb https://mirrors.tuna.tsinghua.edu.cn/armbian bionic main bionic-utils bionic-desktop

4、ctrl+x退出编辑,按y回车保存
5、执行

apt update && apt upgrade -y

复制代码

常用命令:

更换软件源:

sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list
sed -i 's|security.debian.org|mirrors.tuna.tsinghua.edu.cn/debian-security|g' /etc/apt/sources.list
sed -i 's|apt.armbian.com|mirrors.tuna.tsinghua.edu.cn/armbian|g' /etc/apt/sources.list.d/armbian.list

复制代码
至此,软件源更换完毕。

6、安装docker

curl -fsSL https://get.docker.com -o get-docker.sh

sh get-docker.sh --mirror Aliyun

复制代码
使用上述命令安装会调用阿里云的镜像,安装速度较快。

7、配置docker镜像加速
登陆

dev.aliyun.com

复制代码
进入容器镜像服务,得到镜像加速器地址

8、putty下执行

mkdir -p /etc/docker

tee /etc/docker/daemon.json 

./install.sh

...
...

# reboot 重启设备
# poweroff 关闭设备
# apt update && apt upgrade -y

关闭或重启设备时将U盘拔出,就可以进入安装到 EMMC 的系统了.

如果要配置和使用无线可以用 nmtui, 至少还有个界面看

如果没有公网 IP 可以使用 Frp 等工具来打洞: Frp

有公网就直接上 DDNS 吧,我使用的是 CloudFlare, 一个脚本加定时任务就能搞定:

#!/bin/bash

localIpv6=`ip -6 a | grep global | awk '{print $2}' | awk -F '/' '{print $1}'`

echo "ipv6 is: $localIpv6, updating to CloudFlare..."

curl -X PUT https://api.cloudflare.com/client/v4/zones/$zone/dns_records/$domain \
  -H 'Content-Type: application/json' \
  -H 'X-Auth-Email: [email protected]' \
  -H 'X-Auth-Key: yourapikey' \
  -H 'cache-control: no-cache' \
  -d '{"type": "AAAA","proxied": false,"name": "example.com","content": "'$localIpv6'"}'

crontab 加个任务

  */5 * * * * sh /root/ddns.sh > /dev/null

附件下载CloudFlareddns.zip