AlmaLinux 嵌入式设备安装指南
本指南详细介绍如何在各种嵌入式设备上安装和配置 AlmaLinux,包括树莓派、ARM 开发板、工控机等设备。
1. 支持的嵌入式设备
1.1 ARM 架构支持
设备类型 | 架构 | AlmaLinux 支持 | 性能等级 | 推荐用途 |
---|---|---|---|---|
树莓派 4B/400 | ARM64 | 官方支持 | ⭐⭐⭐⭐ | 学习开发、IoT |
树莓派 3B+ | ARM64 | 官方支持 | ⭐⭐⭐ | 轻量应用 |
Orange Pi 5 | ARM64 | 社区支持 | ⭐⭐⭐⭐ | 媒体中心 |
NVIDIA Jetson | ARM64 | 社区支持 | ⭐⭐⭐⭐⭐ | AI 计算 |
香橙派 Zero | ARM32 | 有限支持 | ⭐⭐ | 基础 IoT |
1.2 x86 嵌入式设备
设备类型 | 架构 | AlmaLinux 支持 | 性能等级 | 推荐用途 |
---|---|---|---|---|
Intel NUC | x86_64 | 完全支持 | ⭐⭐⭐⭐⭐ | 边缘计算 |
工控机 | x86_64 | 完全支持 | ⭐⭐⭐⭐ | 工业控制 |
迷你主机 | x86_64 | 完全支持 | ⭐⭐⭐⭐ | 家庭服务器 |
单板计算机 | x86 | 有限支持 | ⭐⭐⭐ | 特殊应用 |
2. 树莓派安装配置
2.1 硬件准备
bash
# 树莓派 4B 推荐配置
处理器: Broadcom BCM2711 (ARM Cortex-A72 四核)
内存: 4GB LPDDR4-3200 (最低推荐)
存储: 32GB+ MicroSD (Class 10, U3)
网络: 千兆以太网 + 2.4/5GHz WiFi
USB: USB 3.0 x2, USB 2.0 x2
视频: Micro HDMI x2 (支持4K@60fps)
电源: 5V/3A USB-C (官方电源适配器)
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
2.2 系统安装
bash
# 下载 AlmaLinux ARM64 镜像
wget https://mirrors.aliyun.com/almalinux/9/images/aarch64/AlmaLinux-9-RaspberryPi-latest-aarch64.raw.xz
# 验证下载完整性
sha256sum AlmaLinux-9-RaspberryPi-latest-aarch64.raw.xz
# 解压镜像
xz -d AlmaLinux-9-RaspberryPi-latest-aarch64.raw.xz
# 写入SD卡 (假设SD卡设备为 /dev/sdb)
sudo dd if=AlmaLinux-9-RaspberryPi-latest-aarch64.raw of=/dev/sdb bs=4M status=progress conv=fsync
# 同步数据
sync
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
使用 Raspberry Pi Imager 安装:
bash
# 安装 Raspberry Pi Imager
sudo dnf install rpi-imager -y
# 或下载 AppImage 版本
wget https://downloads.rpi.org/imager/imager_latest_amd64.deb
# 转换为rpm或直接安装
# 启动图形界面
rpi-imager
# 选择自定义镜像 → AlmaLinux ARM64 镜像
# 配置WiFi、SSH、用户账户
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
2.3 首次启动配置
bash
# 通过串口或SSH连接 (默认用户: almalinux)
ssh [email protected]
# 或使用IP地址
ssh [email protected]
# 首次登录后更改密码
passwd
# 更新系统
sudo dnf update -y
# 扩展文件系统 (如果需要)
sudo dnf install cloud-utils-growpart -y
sudo growpart /dev/mmcblk0 2
sudo resize2fs /dev/mmcblk0p2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2.4 硬件功能配置
bash
# 启用硬件功能
sudo raspi-config
# 或手动编辑配置文件
# 编辑引导配置
sudo nano /boot/config.txt
# GPU 内存分配
gpu_mem=64 # 默认值,无桌面环境
gpu_mem=128 # 桌面环境推荐
# 启用SPI/I2C/UART
dtparam=spi=on
dtparam=i2c_arm=on
enable_uart=1
# 启用摄像头
start_x=1
gpu_mem=128
# 4K HDMI输出
hdmi_group=2
hdmi_mode=87
hdmi_cvt=3840 2160 60 6 0 0 0
# 重启应用配置
sudo reboot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2.5 性能优化
bash
# CPU 性能调节
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
# 内存优化
echo 'vm.swappiness=1' | sudo tee -a /etc/sysctl.conf
echo 'vm.min_free_kbytes=65536' | sudo tee -a /etc/sysctl.conf
# 安装性能监控工具
sudo dnf install htop iotop -y
# GPU 温度监控
sudo dnf install lm_sensors -y
sensors-detect --auto
vcgencmd measure_temp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
3. Orange Pi 5 安装
3.1 硬件规格
bash
# Orange Pi 5 规格
处理器: Rockchip RK3588S (ARM Cortex-A76 x4 + A55 x4)
内存: 4GB/8GB/16GB LPDDR4x
存储: eMMC 接口 + MicroSD + M.2 SSD
网络: 千兆以太网 + WiFi6 + 蓝牙5.0
USB: USB 3.0 x1, USB 2.0 x3, Type-C x1
视频: HDMI 2.1 (8K@60fps), eDP, MIPI DSI
GPIO: 40Pin 兼容树莓派
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
3.2 系统准备
bash
# 编译 AlmaLinux 内核 (针对 RK3588)
git clone https://github.com/AlmaLinux/kernel.git
cd kernel
# 配置编译环境
sudo dnf groupinstall "Development Tools" -y
sudo dnf install bc bison flex elfutils-libelf-devel openssl-devel -y
# 交叉编译工具链
sudo dnf install gcc-aarch64-linux-gnu -y
# 获取 Orange Pi 5 设备树
wget https://raw.githubusercontent.com/orangepi-xunlong/orangepi-build/main/external/config/boards/orangepi5.conf
# 编译内核和设备树
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j$(nproc)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
3.3 制作启动镜像
bash
# 创建启动分区结构
sudo fdisk /dev/sdb << EOF
o
n
p
1
+512M
t
c
n
p
2
w
EOF
# 格式化分区
sudo mkfs.vfat -F32 /dev/sdb1
sudo mkfs.ext4 /dev/sdb2
# 挂载分区
sudo mkdir -p /mnt/{boot,root}
sudo mount /dev/sdb1 /mnt/boot
sudo mount /dev/sdb2 /mnt/root
# 复制 AlmaLinux 根文件系统
sudo tar -xzf almalinux-9-aarch64-rootfs.tar.gz -C /mnt/root
# 安装引导程序 (U-Boot)
sudo dd if=u-boot-orangepi5.bin of=/dev/sdb bs=1024 seek=8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
4. NVIDIA Jetson 配置
4.1 Jetson 设备支持
bash
# 支持的 Jetson 设备
Jetson AGX Orin: ARM64, 32GB RAM, 2048 CUDA核心
Jetson Xavier NX: ARM64, 8GB RAM, 384 CUDA核心
Jetson Nano: ARM64, 4GB RAM, 128 CUDA核心
Jetson TX2: ARM64, 8GB RAM, 256 CUDA核心
1
2
3
4
5
2
3
4
5
4.2 JetPack 适配
bash
# 安装 NVIDIA 容器运行时
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
# 转换为 DNF 仓库配置
cat > /etc/yum.repos.d/nvidia-docker.repo << 'EOF'
[nvidia-docker]
name=NVIDIA Docker Repository
baseurl=https://nvidia.github.io/nvidia-docker/centos8/x86_64
enabled=1
gpgcheck=1
gpgkey=https://nvidia.github.io/nvidia-docker/gpgkey
EOF
# 安装 NVIDIA 容器工具包
sudo dnf install nvidia-container-toolkit -y
# 配置 Docker
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
4.3 CUDA 环境配置
bash
# 安装 CUDA 开发环境
wget https://developer.download.nvidia.com/compute/cuda/repos/rhel8/aarch64/cuda-repo-rhel8-11-8-local-11.8.0_520.61.05-1.aarch64.rpm
sudo rpm -i cuda-repo-rhel8-11-8-local-11.8.0_520.61.05-1.aarch64.rpm
sudo dnf clean all
sudo dnf install cuda -y
# 配置环境变量
echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
# 验证 CUDA 安装
nvcc --version
nvidia-smi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
5. Intel NUC 工控配置
5.1 工控机优化配置
bash
# BIOS 设置优化
# - 禁用不必要的设备 (音频、蓝牙等)
# - 启用 Watchdog 定时器
# - 设置电源故障后自动启动
# - 配置风扇策略为静音模式
# 安装工控专用软件包
sudo dnf install watchdog lm_sensors fancontrol -y
# 配置硬件监控
sudo sensors-detect --auto
sensors
# 配置 Watchdog
echo 'watchdog-device = /dev/watchdog' >> /etc/watchdog.conf
echo 'watchdog-timeout = 60' >> /etc/watchdog.conf
sudo systemctl enable watchdog
sudo systemctl start watchdog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
5.2 实时性优化
bash
# 安装实时内核
sudo dnf install kernel-rt kernel-rt-devel -y
# 配置内核启动参数
sudo grubby --update-kernel=ALL --args="isolcpus=2,3 rcu_nocbs=2,3 nohz_full=2,3"
# 安装实时调度工具
sudo dnf install rt-tests rtkit -y
# 测试实时性能
sudo cyclictest -t 4 -p 80 -n -i 10000 -l 10000
# 配置进程优先级
echo '@realtime soft rtprio 99' >> /etc/security/limits.conf
echo '@realtime hard rtprio 99' >> /etc/security/limits.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
6. IoT 应用部署
6.1 MQTT 消息代理
bash
# 安装 Mosquitto MQTT 代理
sudo dnf install mosquitto mosquitto-clients -y
# 配置 Mosquitto
sudo nano /etc/mosquitto/mosquitto.conf
# 基本配置
port 1883
allow_anonymous false
password_file /etc/mosquitto/passwd
# 创建用户
sudo mosquitto_passwd -c /etc/mosquitto/passwd iot-user
# 启用服务
sudo systemctl enable mosquitto
sudo systemctl start mosquitto
# 测试连接
mosquitto_pub -h localhost -t test/topic -m "Hello IoT"
mosquitto_sub -h localhost -t test/topic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
6.2 Docker 容器化部署
bash
# 安装 Docker (ARM64 优化)
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo dnf install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y
# 配置 Docker daemon
sudo mkdir -p /etc/docker
cat > /etc/docker/daemon.json << 'EOF'
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "3"
},
"storage-driver": "overlay2",
"registry-mirrors": [
"https://registry.cn-hangzhou.aliyuncs.com"
]
}
EOF
sudo systemctl enable docker
sudo systemctl start docker
# 部署 IoT 应用栈
cat > docker-compose.yml << 'EOF'
version: '3.8'
services:
influxdb:
image: influxdb:1.8
ports:
- "8086:8086"
volumes:
- influxdb-data:/var/lib/influxdb
environment:
- INFLUXDB_DB=iot_data
- INFLUXDB_ADMIN_USER=admin
- INFLUXDB_ADMIN_PASSWORD=password
grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
volumes:
- grafana-data:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
node-red:
image: nodered/node-red:latest
ports:
- "1880:1880"
volumes:
- node-red-data:/data
volumes:
influxdb-data:
grafana-data:
node-red-data:
EOF
docker compose up -d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
6.3 传感器数据采集
bash
# 安装 Python 开发环境
sudo dnf install python3 python3-pip python3-dev -y
# 安装 GPIO 库 (树莓派)
pip3 install RPi.GPIO gpiozero
# 安装传感器库
pip3 install adafruit-circuitpython-dht w1thermsensor
# 温湿度传感器示例
cat > sensor_reader.py << 'EOF'
#!/usr/bin/env python3
import time
import json
import paho.mqtt.client as mqtt
from gpiozero import MCP3008
import adafruit_dht
# 配置传感器
dht = adafruit_dht.DHT22(board.D4)
adc = MCP3008(channel=0)
# MQTT 配置
client = mqtt.Client()
client.connect("localhost", 1883, 60)
while True:
try:
# 读取温湿度
temperature = dht.temperature
humidity = dht.humidity
# 读取模拟传感器
analog_value = adc.value * 100
# 构造数据
data = {
"timestamp": int(time.time()),
"temperature": temperature,
"humidity": humidity,
"analog": analog_value
}
# 发送到 MQTT
client.publish("sensors/data", json.dumps(data))
print(f"Published: {data}")
except RuntimeError as e:
print(f"Sensor error: {e}")
time.sleep(30)
EOF
chmod +x sensor_reader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
7. 嵌入式设备管理
7.1 远程管理配置
bash
# 配置 SSH 密钥认证
ssh-keygen -t ed25519 -C "embedded-device"
ssh-copy-id user@device-ip
# 配置VPN连接 (WireGuard)
sudo dnf install wireguard-tools -y
# 生成密钥对
wg genkey | tee privatekey | wg pubkey > publickey
# 配置 WireGuard
sudo nano /etc/wireguard/wg0.conf
[Interface]
PrivateKey = YOUR_PRIVATE_KEY
Address = 10.0.0.2/24
DNS = 8.8.8.8
[Peer]
PublicKey = SERVER_PUBLIC_KEY
Endpoint = your-server.com:51820
AllowedIPs = 0.0.0.0/0
# 启用 WireGuard
sudo systemctl enable wg-quick@wg0
sudo systemctl start wg-quick@wg0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
7.2 自动化部署
bash
# 使用 Ansible 管理多设备
sudo dnf install ansible -y
# 创建设备清单
cat > inventory.ini << 'EOF'
[raspberry-pi]
pi-01 ansible_host=192.168.1.101
pi-02 ansible_host=192.168.1.102
[orange-pi]
opi-01 ansible_host=192.168.1.111
[all:vars]
ansible_user=almalinux
ansible_ssh_private_key_file=~/.ssh/id_ed25519
EOF
# 创建部署脚本
cat > deploy.yml << 'EOF'
---
- name: Deploy IoT Application
hosts: all
become: yes
tasks:
- name: Update system
dnf:
name: "*"
state: latest
- name: Install Docker
dnf:
name: docker-ce
state: present
- name: Start Docker service
systemd:
name: docker
state: started
enabled: yes
- name: Deploy application
docker_container:
name: iot-app
image: iot-app:latest
state: started
restart_policy: always
EOF
# 执行部署
ansible-playbook -i inventory.ini deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
8. 故障排除和维护
8.1 常见问题解决
bash
# SD 卡读写错误
# 检查文件系统
sudo fsck /dev/mmcblk0p2
# 修复文件系统
sudo e2fsck -f /dev/mmcblk0p2
# 温度过高问题
# 监控温度
watch -n 1 'vcgencmd measure_temp'
# 配置散热 (树莓派)
echo 'temp_limit=80' >> /boot/config.txt
echo 'arm_freq_min=600' >> /boot/config.txt
# 内存不足
# 启用 ZRAM
sudo dnf install zram-generator -y
cat > /etc/systemd/zram-generator.conf << 'EOF'
[zram0]
zram-size = ram / 2
compression-algorithm = lz4
EOF
sudo systemctl start [email protected]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
8.2 备份和恢复
bash
# 创建 SD 卡镜像备份
sudo dd if=/dev/mmcblk0 of=backup-$(date +%Y%m%d).img bs=4M status=progress
# 压缩备份
gzip backup-$(date +%Y%m%d).img
# 恢复镜像
sudo dd if=backup-20231201.img of=/dev/mmcblk0 bs=4M status=progress
# 自动化备份脚本
cat > /root/backup.sh << 'EOF'
#!/bin/bash
BACKUP_DIR="/backup"
DATE=$(date +%Y%m%d_%H%M%S)
# 创建配置备份
tar -czf $BACKUP_DIR/config-$DATE.tar.gz /etc /home/*/
# 备份应用数据
docker run --rm -v iot-data:/source -v $BACKUP_DIR:/backup alpine tar czf /backup/data-$DATE.tar.gz -C /source .
# 清理旧备份 (保留30天)
find $BACKUP_DIR -name "*.tar.gz" -mtime +30 -delete
EOF
chmod +x /root/backup.sh
echo "0 2 * * * /root/backup.sh" | crontab -
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
通过本指南,您可以在各种嵌入式设备上成功部署 AlmaLinux,并根据设备特性进行相应的优化配置,实现稳定可靠的嵌入式 Linux 系统运行。