树莓派安装步骤
树莓派安装步骤
镜像烧录
Tips
如果没有显示器连接线推荐使用树莓派官方烧录器进行系统烧录(官方烧录器可以设置wifi密码,打开SSH)安装VNC进行远程连接
可以自己下载镜像进行烧录
下载地址https://downloads.raspberrypi.com/raspios_full_arm64/images/raspios_full_arm64-2024-11-19/2024-11-19-raspios-bookworm-arm64-full.img.xz
也可以选择系统镜像进行烧录
配置如下
烧录完成镜像就可以直接开机使用SSH进行连接
SSH连接
ssh zhang@192.168.3.146 //用户名@ip地址
如果存在密钥会输出一下信息
Offending ECDSA key in /Users/zhangyingyu/.ssh/known_hosts:13
Host key for 192.168.3.146 has changed and you have requested strict checking.
Host key verification failed.
重置Key
ssh-keygen -R 192.168.3.146
Tips切换root用户
sudo -i
RealVNC
- 安装 RealVNC:
sudo apt-get install realvnc-vnc-server realvnc-vnc-viewer
- 启用VNC:
sudo raspi-config
• 选择 Interface Options。
• 启用 VNC。
- 电脑安装RealVNC(下载地址https://www.realvnc.com/en/connect/download/)
注:输入IP后,连接需要输入入配置的用户名和密码
换源
需要修改sources.list和raspi.list
注:好像不用系统版本链接后面内容不一样(俺也不确定…)修改的时候对照一下系统中原始文件后面的内容即可
sudo nano /etc/apt/sources.list
更换内容
deb https://mirrors.tuna.tsinghua.edu.cn/debian bookworm main contrib non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian bookworm-updates main contrib non-free-firmware
sudo nano /etc/apt/sources.list.d/raspi.list
更换内容
deb https://mirrors.tuna.tsinghua.edu.cn/raspberrypi bookworm main
安装Docker
设置 Docker 的 apt 存贮库
# 卸载旧版本(如果有):
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done
# 添加 Docker 官方 GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/debian/gpg -o /etc/apt/keyrings/docker_aliyun.asc
sudo chmod a+r /etc/apt/keyrings/docker_aliyun.asc
# 添加仓库到 Apt 源:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker_aliyun.asc] http://mirrors.aliyun.com/docker-ce/linux/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker_aliyun.list > /dev/null
sudo apt-get update
安装Docker软件包
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
验证安装
sudo docker run hello-world
普通用户可操作Docker
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
国内加速镜像 pull 失败问题
创建或修改 /etc/docker/daemon.json
文件,并重启 docker
服务。
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://docker.pidoc.tech"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
参考:https://pidoc.cn/docs/pidoc/install_docker
图形化
下载 Docker 图形化界面 portainer
sudo docker pull portainer/portainer
创建 portainer 容器并命名为portainer_data:
sudo docker volume create portainer_data
sudo docker run -d -p 9000:9000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
进入portainer的web页面
浏览器输入 树莓派的IP:9000 (如:http://192.168.1.9:9000/)即可进入管理界面。
参考:https://blog.csdn.net/Chino68/article/details/119736457
升级Python
运行以下命令,检查当前的 Python 版本:
python3 --version
在升级之前,确保系统的软件包是最新的:
sudo apt update
sudo apt upgrade -y
安装依赖工具
sudo apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev
查看最新的 Python 版本
通过访问 Python 官方网站 或运行以下命令查看最新版本:
apt list python3*
下载Python源码
wget https://www.python.org/ftp/python/3.x.x/Python-3.x.x.tgz
解压并编译安装
tar -xvzf Python-3.x.x.tgz
cd Python-3.x.x
./configure --enable-optimizations
make -j$(nproc) # 使用所有可用的 CPU 核心进行编译
sudo make altinstall
安装完成后,检查新版本是否成功安装:
python3.x --version
切换默认 Python 版本
sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.x 1
sudo update-alternatives --config python3
[!WARNING]
编译的python缺少apt_pkg包???
安装Homeassistant
推荐使用Docker中安装 在本文下方
安装方法
安装HACS
下载 HACS 压缩包:
https://github.com/hacs/integration/releases
将文件的所属用户更改为 homeassistant**:**
sudo chown homeassistant:homeassistant hacs.zip
移动文件到 Home Assistant 配置目录:
sudo mv hacs.zip /home/homeassistant/.homeassistant/custom_components/
切换到目标目录并解压:
cd /home/homeassistant/.homeassistant/custom_components/
sudo -u homeassistant unzip hacs.zip -d hacs
安装ha_xiaomi
https://github.com/XiaoMi/ha_xiaomi_home
配置需用Chrome(Safari会出现跳转不了问题),扫码登陆xiaomi后跳转如果访问不了homeassistant.local改为ip地址加端口号8123
安装Homekit Bridge
设备与集成—>添加
我只添加了灯(根据自己实际需要进行添加),添加后,在Homeassistant的通知中会有一条新通知,用HomeKit扫描二维码进行添加
在Docker中安装
docker run -d \
--name homeassistant \
--privileged \
--restart=unless-stopped \
-e TZ=MY_TIME_ZONE \
-v /PATH_TO_YOUR_CONFIG:/config \
-v /run/dbus:/run/dbus:ro \
--network=host \
ghcr.io/home-assistant/home-assistant:stable
Once the Home Assistant Container is running Home Assistant should be accessible using http://<host>:8123
(replace with the hostname or IP of the system). You can continue with onboarding.
重启容器
docker restart homeassistant
在homeassistant容器中安装HACS
docker ps
查看homeassistant容器的ID
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6af23f693ad2 portainer/portainer "/portainer" 2 hours ago Up 42 minutes 8000/tcp, 9443/tcp, 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp portainer
ba1f830d80c3 ghcr.io/home-assistant/raspberrypi4-homeassistant:stable "/init" 2 hours ago Up 42 minutes homeassistant
执行
docker exec -it ba1f830d80c3 /bin/bash
# 如果在config目录下直接
ls
# 如果不在
cd config
进入config后执行
wget -O - https://hacs.vip/get | bash -
重启HA
INFO: Unpacking...
INFO: Copying new files...
INFO: Removing temp files...
INFO: Installation complete.
INFO: 安装成功!
INFO: Remember to restart Home Assistant before you configure it.
INFO: 请重启 Home Assistant
zhang:/config# exit
exit
zhang@zhang:~ $ docker restart ba1f830d80c3
ba1f830d80c3
zhang@zhang:~ $
在Home assistant容器中安转xiaomi_home
zhang@zhang:~ $ docker exec -it ba1f830d80c3 /bin/bash
zhang:/config# git clone https://github.com/XiaoMi/ha_xiaomi_home.git
Cloning into 'ha_xiaomi_home'...
remote: Enumerating objects: 929, done.
remote: Counting objects: 100% (468/468), done.
remote: Compressing objects: 100% (213/213), done.
remote: Total 929 (delta 357), reused 256 (delta 252), pack-reused 461 (from 3)
Receiving objects: 100% (929/929), 827.82 KiB | 1.31 MiB/s, done.
Resolving deltas: 100% (505/505), done.
zhang:/config# ls
automations.yaml custom_components home-assistant.log home-assistant_v2.db scenes.yaml tts
blueprints deps home-assistant.log.1 home-assistant_v2.db-shm scripts.yaml
configuration.yaml ha_xiaomi_home home-assistant.log.fault home-assistant_v2.db-wal secrets.yaml
zhang:/config# cd ha_xiaomi_home/
zhang:/config/ha_xiaomi_home# ./install.sh /config
Xiaomi Home installation is completed. Please restart Home Assistant.
zhang:/config/ha_xiaomi_home# exit
exit
zhang@zhang:~ $ docker restart ba1f830d80c3
ba1f830d80c3
在Docker中安装OpenWrt
https://blog.csdn.net/weixin_42275461/article/details/135719962
在Docker中安装MySql
添加容器,并设置root用户密码为pi
sudo docker run --restart unless-stopped --name mysql --net=host -e MYSQL_ROOT_PASSWORD=pi -d mysql/mysql-server
进入mysql容器,设置密码并登陆mysql
sudo docker exec -it mysql bash
mysql -u root -p
设置root用户可以远端访问
# 这将切换到 mysql 系统数据库,存储 MySQL 用户和权限相关的信息。
USE mysql;
SELECT host, user FROM user;
# 将 root 用户的 host 字段从 localhost 修改为 %,以允许任意主机连接:
UPDATE user SET host = '%' WHERE host = 'localhost' AND user = 'root';
# 修改完 user 表后,需要刷新权限以使更改生效:
FLUSH PRIVILEGES;
# MySQL 8.0 默认使用 caching_sha2_password 身份验证插件,但某些客户端可能不支持。你可以将其更改为 mysql_native_password:
# 这一步会同时设置 root 用户的新密码为 pi。
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'pi';
# 确保所有更改立即生效:
FLUSH PRIVILEGES;
个人记录,仅供参考