树莓派搭建局域网网盘


安装、设置系统

下载镜像,烧录

  1. 下载官网最新64位系统
  2. 使用BalenaEtcher烧录进TF卡里

    注意!!!不再推荐了,应该使用树莓派官方镜像烧录工具,否则难以设置新用户,因为不再预置pi默认用户,详情见官网说明

设置无头启动

  1. 开启SSH

    烧录完成的TF卡连接电脑,进入到boot根目录,新建一个名为ssh的空白文件(不需要后缀名)

  2. 设置WIFI连接

    1. TF卡插入电脑,在 boot 分区下新建 wpa_supplicant.conf 文件
    2. 按照下面的参考格式填入内容并保存 wpa_supplicant.conf 文件

      # 国家码设置
      country=CN
      # 接口设置
      ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
      update_config=1
      
      # 网络信息配置
      network={
      ssid="NTest"       # wifi账号
      psk="12345678"     # wifi密码,一般要>8个字符
      key_mgmt=WPA-PSK   # 密钥管理算法,通常家用路由都是WPA-PSK,企业路由是WPA-EAP
                         # 如果要连接的wifi是没有密码的,需要配置为:key_mgmt=NONE
      #scan_ssid=1       # 对于隐藏的SSID,需要配置此参数
      priority=1         # 优先级,数字越大,优先级越高(不可以是负数)
      }
      
      #可以配置多个WIFI
      network={
      ssid="WiFi-B"
      psk="12345678"
      key_mgmt=WPA-PSK
      priority=2
      scan_ssid=1
      }
      
  3. 登陆SSH

    1. 通过路由器查看对应设备的IP地址
    2. ssh登陆(使用putty或者windows PowerShell都可以)
    3. 输入ip地址,连接ssh,默认用户名是:pi 默认密码是:raspberry

      更正!!!!根据官网,新的树莓派映像不再预置用户pi,将使用引导创建新用户,

      如果是新用户,需要连接显示器键盘创建新用户,

      如果是无头用户,可以使用树莓派官方烧录工具,在设置选项卡中填入用户名和密码

      但我不想再接一根线到显示器,也不想非得用官方工具重新烧录,所以还有最后一种手动方法

      参考官网给出的方法,原文如下:

      This file should contain a single line of text, consisting of username:encrypted- password – so your desired username, followed immediately by a colon, followed immediately by an encrypted representation of the password you want to use.
      
      To generate the encrypted password, the easiest way is to use OpenSSL on a Raspberry Pi that is already running – open a terminal window and enter
      
      echo 'mypassword' | openssl passwd -6 -stdin
      This will produce what looks like a string of random characters, which is actually an encrypted version of the supplied password.

      首先在一台linux系统上生成密码的加密表示文本,使用命令

      echo 'mypassword' | openssl passwd -6 -stdin

      这是使用服务器生成的jiang123@的加密表示

      $6$IeHbk8I313satTzC$4jm.6GDK9WbvMfa2rdt6YcE/EXJ8A1u9lvZm9d5Q2EgQpjTSmitTKZ7FCTIIL6ISaFsUQXHYkDphvB6x8eZpH/

      在boot根目录创建userconf 文件,填入如下。冒号前填你要设置的用户名,冒号后填入用加密表示的密码,不要回车,只有一行,直接保存

      username:encrypted-password
    4. 设置windows powershell 自动登陆免密码(可选)

       1. 生成公私钥对
      ssh-keygen
      1. 将本机的公钥复制到远程机器

        1. Linux(用户端)

             ssh-copy-id -i .ssh/id_rsa.pub(公钥路径)  用户名字@192.168.x.xxx
        2. windows(window下无ssh-copy-id 命令)
         cat ~/.ssh/id_rsa.pub | ssh root@服务器ip地址 “cat >> ~/.ssh/authorized_keys”

树莓派基础设置

树莓派换源

  1. 首先通过 uname -m 确定你使用的系统的架构。
  2. 备份原始文件(可选步骤)

    sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak
    sudo mv /etc/apt/sources.list.d/raspi.list /etc/apt/sources.list.d/raspi.list.bak
  3. 编辑 /etc/apt/sources.list 文件(软件源),参考如下命令:

    sudo nano /etc/apt/sources.list
  4. 填入对应内容

    # armv7l 用户:编辑 `/etc/apt/sources.list` 文件,删除原文件所有内容,用以下内容取代
    deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ bullseye main non-free contrib rpi
    # deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ bullseye main non-free contrib rpi
    
    # armv7l 用户如果需要开启 multi-arch 使用 arm64 软件源,需要在 `/etc/apt/sources.list` 中加上
    deb [arch=arm64] http://mirrors.tuna.tsinghua.edu.cn/raspbian/multiarch/ bullseye main
    
    # aarch64 用户:编辑 `/etc/apt/sources.list` 文件,用以下内容取代:
    # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
    deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
  5. 编辑系统源配置,参考如下命令:

    sudo nano /etc/apt/sources.list.d/raspi.list

    同样修改网址,修改后文件如下(参考):

    # 对于两个架构,编辑 `/etc/apt/sources.list.d/raspi.list` 文件,删除原文件所有内容,用以下内容取代:
    deb https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ bullseye main
  6. 配置更新,逐个输入以下命令更新,速度视网速决定,耐心等待

    #更新软件源列表
    sudo apt-get update
    #更新软件版本
    sudo apt-get upgrade
    sudo apt-get dist-upgrade
    #更新系统内核,可以不更新
    sudo rpi-update

树莓派设置

  1. 连接后先运行passwd更改默认密码,在linux里面键入密码是不会有星号提示的,自行键入然后回车就可以(因为新系统的用户名和密码都是自己创建的,这一步用不着了)
  2. 再键入sudo passwd设置管理员账号的密码,建议和上一个设的一样(其实不安全,但确实方便)
  3. 运行sudo raspi-config 命令打开设置界面
  4. 逐一调试。先选择Hostname 把主机名改成你能够识别的就可以了,要是局域网内就一台树莓派也没必要改了
  5. 选择Localisation Options —–>Change Timezone,把时区更改为你所在城市即可(反正中国都一样,随便选)
  6. 选择Interfaceing OptionsSSH VNC SPI I2C Serial 1-Wire Remote GPIO 都改成开启状态好了,反正现在不用以后说不定会用到。

    由于开启VNC 需要下载,建议在更改完软件源后再进行这一步!!!!

  7. 选择Overlock 选项进行超频,可以直接上到Turbo模式也没问题的(树莓派只有1和2好像有这个选项,4B没有)
  8. 选择Advanced Options,选择Expand Filesystem可以把SD卡重构利用,在Memory Split里面选择给GPU分配的内存,直接写到256就可以了。
  9. 修改默认地区,语言。
  10. 做完那些选择退出以后机器会重启,需要重连一遍

安装常用软件

  1. 默认树莓派没有安装vim,执行下列命令安装。

    sudo apt-get install -y vim

    安装好之后就可以使用vi或者vim进行编辑操作,但是没有代码高亮显示。

    在~目录下面新建.vimrc文件可以实现

    pi@raspberrypi ~ $ cd ~
    pi@raspberrypi ~ $ sudo nano .vimrc
    //键入以下内容并保存
    set number
    syntax on
    set tabstop=4  
  2. 为了方便以后给树莓派挂载移动硬盘或U盘,还要安装文件系统格式支持

    exFAT格式支持:

    sudo apt-get install exfat-fuse

    NTFS格式支持:

    sudo apt-get install ntfs-3g

声明:Beyondlogic|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - 树莓派搭建局域网网盘


我们最终会在没有黑暗的地方相遇