树莓派的入门指南
从镜像烧录开始,到配置VNC,介绍树莓派拿到手之后的基本设置。
环境介绍:
- 工作电脑:Mac M1, v11.6
- 树莓派硬件版本: 3B
- 树莓派系统版本:raspios_arm64-2021-05-28
下载系统镜像
需要注意的是 armhf 是 32 位的,arm64 才是64 位 (opens in a new window)的。下载的 zip 文件尽量用 Keka 等第三方工具解压,用 Mac 自带的归档实用工具解压会遇到烧录之后校验失败的问题
烧录工具
新版本已经默认关闭了 SSH,在 SD 卡的根目录新建一个名为”ssh”的空文件,系统启动时会检测这个文件,然后开启 SSH 功能
树莓派接上电源线,按一下线中间的按钮,树莓派通电之后会亮红灯,先用网线连上路由器,在路由器设置页面查看当前树莓派连上的 IP 地址
打开电脑终端,输入命令: ssh [email protected]
pi是默认的用户名,后面的 IP 地址换成第 2 步获取的 IP,默认密码是raspberry
新版本默认取消了 VNC 功能,需要自己安装
sudo apt-get install tightvncserver启动,然后输入一个密码
vncserver :1在 Mac 安装一个 VNC Viewer (opens in a new window) 软件,打开之后在地址栏输入地址192.168.x.x:1,再输入密码,即可看到树莓派的桌面。
在第 4 步完成之后,能看到桌面自然也可以图形化设置了,下面提供一种命令行设置方式
- 打开
/etc/wpa_supplicant/wpa_supplicant.conf文件 - 添加下面的内容
network={ ssid="WIFI名字" psk="WIFI密码"}- 验证连接:
sudo wpa_cli reconfigure
防止每次 DHCP 分配不同的 IP,设置静态 IP 是必需的。图形化设置即可,当然也有命令行设置, 打开/etc/dhcpcd.conf文件,添加如下内容:
interface eth0inform 192.168.1.7static routers=192.168.1.3static domain_name_servers=114.114.114.114eth0 是有限连接,wlan0 是 WIFI 连接
推荐清华大学的,具体看帮助文档 (opens in a new window)。 第一步,把/etc/apt/sources.list 所有内容替换为:
deb http://mirrors.tuna.tsinghua.edu.cn/debian buster main contrib non-freedeb http://mirrors.tuna.tsinghua.edu.cn/debian-security/ buster/updates main contrib non-freedeb http://mirrors.tuna.tsinghua.edu.cn/debian buster-updates main contrib non-free## 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释#deb-src http://mirrors.tuna.tsinghua.edu.cn/debian buster main contrib non-free#deb-src http://mirrors.tuna.tsinghua.edu.cn/debian-security/ buster/updates main contrib non-free#deb-src http://mirrors.tuna.tsinghua.edu.cn/debian buster-updates main contrib non-free第二步,把/etc/apt/sources.list.d/raspi.list 所有内容替换为
deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui## 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释#deb-src http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui第三步,更新:sudo apt-get update
可能会有个错误:
pi@raspberrypi:~ $ sudo apt-get updateGet:1 http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian buster InRelease [15.0 kB]Get:2 http://mirrors.tuna.tsinghua.edu.cn/raspberrypi buster InRelease [32.6 kB]Err:1 http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian buster InReleaseThe following signatures couldn't be verified because the public key is not available: NO_PUBKEY 9165938D90FDDD2E然后执行命令
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 9165938D90FDDD2E-
编辑文件
/etc/init.d/vncserver, 加入下面的内容#!/bin/sh#### BEGIN INIT INFO## Provides: vncserver## Required-Start: $local_fs## Required-Stop: $local_fs## Default-Start: 2 3 4 5## Default-Stop: 0 1 6## Short-Description: Start/stop vncserver#### END INIT INFO## More details see:## http://www.penguintutor.com/linux/vnc#### Customize this entry## Set the USER variable to the name of the user to start vncserver underexport USER='pi'#### End customization requiredeval cd ~$USERcase "$1" instart)## 启动命令行。此处自定义分辨率、控制台号码或其它参数。su $USER -c '/usr/bin/vncserver -depth 16 -geometry 800x480 :1'su $USER -c '/usr/bin/vncserver -depth 16 -geometry 1024x768 :2'su $USER -c '/usr/bin/vncserver -depth 16 -geometry 1280x800 :3'su $USER -c '/usr/bin/vncserver -depth 16 -geometry 1440x900 :4'su $USER -c '/usr/bin/vncserver -depth 16 -geometry 1920x1080 :5'su $USER -c '/usr/bin/vncserver -depth 16 -geometry 1440x1440 :6'echo "Starting VNC server for $USER ";;stop)## 终止命令行。此处控制台号码与启动一致。su $USER -c '/usr/bin/vncserver -kill :1'echo "vncserver stopped";;*)echo "Usage: /etc/init.d/vncserver {start|stop}"exit 1;;esacexit 0 -
保存文件,增加可执行属性,
Terminal window sudo chmod 755 /etc/init.d/vncserversudo update-rc.d vncserver defaults -
设置 0 端口分辨率:
sudo vi /boot/config.txt, 取消下面两行的注释,没有就加上
framebuffer_width=1280framebuffer_height=720- 以后就可以通过在 IP 地址后面通过修改端口来打开不同分辨率的桌面了,比如输入”192.168.x.x”,可以打开 1920x1080 分辨率。
如果能使用 SSH,那么肯定可以使用 sftp 了,下载 Filezilla (opens in a new window),打开之后在主机项里面填 sftp://192.168.x.x,端口可以忽略。
-
安装 pip 管理 python 包和 shadowsocks
Terminal window sudo apt-get install python-pip python-m2cryptosudo pip install shadowsocks如果加密方式是 chacha20 的,则还需要以下命令来安装 libsodium
Terminal window wget https://download.libsodium.org/libsodium/releases/LATEST.tar.gztar zxf LATEST.tar.gzcd libsodium*./configuremake && sudo make install修复关联
Terminal window echo /usr/local/lib > /etc/ld.so.conf.d/usr_local_lib.confldconfig -
创建客户端配置文件
/etc/shadowsocks.json{"server": "58.***.**.*","server_port": 8390,"password": "********","method": "aes-256-cfb","local_port": 1080,"timeout": 600} -
设置开机启动,在
/etc/rc.local的 exit 之前添加如下:/usr/local/bin/sslocal -c /etc/shadowsocks.json &
大部分文章都是用 polipo (opens in a new window),但是作者已经明说不在维护这个工具了。推荐使用 proxychains ng (opens in a new window),这个库现在还很活跃。
安装命令:
git clone https://github.com/rofl0r/proxychains-ngcd proxychains-ng./configuremake && sudo make installsudo make install-config修改配置文件/usr/local/etc/proxychains.conf最后一行,改成下面的样子:
socks5 127.0.0.1 1080测试命令: proxychains4 curl ip.cn
