树莓派向OrangePi Zero的迁移

树莓派3b+拿来跑几个网络服务太奢侈了,50不到买了块Orangepi Zero,然后将目前的内容迁移过去

  • 从Armbian的下载页面下载OrangePi Zero的固件(Armbian Bionic 对应 ubuntu18.04;Armbian Buster 对应 debian 10 Buster)并将img包解压出来。
  • Linux系统通过dd命令将固件烧写到TF卡。windows使用Win32DiskImager写入。
  • 烧写完毕将TF卡装入Zero,上电,同时路由器直接固定好有线网络。
  • Linux直接在终端使用命令ssh root@192.168.0.x,默认密码1234,Windows可使用PuTTY之类的,首次进入会进行修改密码和创建普通用户的引导。
  • 接下来开始迁移,先更改下软件源(vim /etc/apt/sources.list),附上更改后的软件源。
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main universe restricted
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main universe restricted
  • 顺带替换一下armbian的源
    /etc/apt/sources.list.d/armbian.list替换成下面的内容
deb http://mirrors.tuna.tsinghua.edu.cn/armbian bionic main bionic-utilsbionic-desktop
  • 然后进行软件更新
    sudo apt-get update && sudo apt-get upgrade -y
  • 安装Python相关库,实现风扇启停
sudo apt install python3-pip
sudo cp /usr/bin/python3 /usr/bin/python
pip3 install OPi.GPIO
  • 时区设置,设置夜间启停以及crontab
    sudo armbian-config,在Personal-->Timezone设置时区
  • 编写风扇启停,使用OPi.GPIO库
vim /home/pi/fan_speed.py

#!/usr/bin/python3
#coding:utf8
#自动风扇控制程序,使用wiringPi的gpio命令来操作GPIO
import time
import OPi.GPIO as GPIO
import datetime
 
# 范围时间
d_time = datetime.datetime.strptime(str(datetime.datetime.now().date())+'6:30', '%Y-%m-%d%H:%M')
d_time1 =  datetime.datetime.strptime(str(datetime.datetime.now().date())+'22:30', '%Y-%m-%d%H:%M')
#控制风扇的GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
FAN_GPIO=14
GPIO.setup(14,GPIO.OUT)
while True:
    n_time = datetime.datetime.now()
    # 获取CPU温度
    tmpFile = open( '/sys/class/thermal/thermal_zone0/temp' )
    cpu_temp_raw = tmpFile.read()
    tmpFile.close()
    cpu_temp = round(float(cpu_temp_raw)/1000, 1)
    print(cpu_temp)
    #如果温度大于50`C,就启动风扇
    if n_time > d_time and n_time<d_time1:
        #print('sun')
        if cpu_temp>=35 :
            GPIO.output(14, GPIO.LOW) 
            
        #如果温度小于45`C,就关闭风扇
        if cpu_temp<30 :
            GPIO.output(14, GPIO.HIGH) 
    else:
        #print('night')
        if cpu_temp>=40 :
            GPIO.output(14, GPIO.LOW) 
            
        #如果温度小于45`C,就关闭风扇
        if cpu_temp<35 :
            GPIO.output(14, GPIO.HIGH) 
    time.sleep(10)

python /home/pi/fan_speed.py检查一下是否可运行

  • 为开启armbian的开机启动配置
    vim /lib/systemd/system/rc.local.service

在最后添加下面三行内容

[Install]  
WantedBy=multi-user.target  
Alias=rc-local.service

然后就可以在/etc/rc.local中添加需要的开机启动脚本,脚本要写在exit 0的前面。

  • 添加开机启动脚本与crontanb定时任务
sudo vim /etc/rc.local
/usr/bin/python3 /home/pi/fan_speed.py > /home/pi/fan_speed.log
sudo vim /etc/crontab
59 22 * * * root /sbin/shutdown -h now
59 22 * * * root /sbin/shutdown -h now
30 8   * * * root wakeonlan 
sudo apt-get install nginx
  • 安装nginx,先查看配置
ps  -ef | grep nginx
find /|grep nginx.conf
vim /etc/nginx/nginx.conf
##
# Virtual Host Configs
##
server {
    keepalive_requests 120; #单连接请求上限次数。
    listen   11820;   #监听端口
    server_name  127.0.0.1;   #监听地址       
           rewrite ^/(.*) https://nas.hdugeek.club:11821/$1 permanent;
}
server {
#    keepalive_requests 500;
    listen   11821;   #监听端口
    server_name  nas.hdugeek.club;   #监听地址   
    ssl on;
    ssl_certificate        /home/pi/ssl/server.crt;
    ssl_certificate_key      /home/pi/ssl/server.key;
           ssl_session_timeout  5m;
          ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
           ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
           ssl_prefer_server_ciphers on;
        location   ^~{       #请求的url过滤,正则匹配,~为区分大小写,~*为不区分大小写。
        proxy_pass http://10.21.16.117/;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
} 
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
  • 同时下载SSL文件到对应文件夹,server.crt合成文件顺序要对
mkdir ssl
wget -P /home/pi/ssl https://geeknas.cos.ap-shanghai.myqcloud.com/server.crt
wget -P /home/pi/ssl https://geeknas.cos.ap-shanghai.myqcloud.com/server.key

nginx -s reload重启nginx

  • 参照一键脚本内容安装ShadowsocksR,可能要先翻墙

添加新评论