Ubuntu 22.04 安装 WeeWX 5.5.2 指南
在 Ubuntu 22.04 上从零安装 WeeWX 5.5.2 的双方案实测指南:官方 apt 仓库在线安装(systemd 托管+首条归档验证)与 tar.gz 离线 venv 安装(weectl station create 数据区+单元适配),含配置要点、六类常见问题与卸载清理。
Ubuntu 22.04 安装 WeeWX 5.5.2 指南
目标:在 Ubuntu 22.04 服务器上从零安装 WeeWX 5.5.2 并完成 systemd 托管、首次归档与报告生成验证。覆盖两条实测路径:官方 apt 仓库在线安装(推荐,自带 systemd 单元)与官方 tar.gz 离线安装(venv + 手动托管,适合无外网软件源的内网机)。文中全部命令与回显均在 Ubuntu 22.04 实机执行验证。
一、环境信息
- 操作系统:Ubuntu 22.04(x86_64,内核 7.0.0-38-generic,systemd 可用)
- Python:3.10.12(Ubuntu 22.04 自带,满足官方「Python 3.6 or later」要求)
- WeeWX 版本:5.5.2(官方最新稳定版,发布件 weewx-5.5.2.tgz 打包日期 2026-09-23,apt 包版本 weewx_5.5.2-1)
- 网络:服务器可访问 weewx.com 官方域(apt 仓库与下载页同域)
- 默认站点假设:本文以官方默认的 Simulator(软件模拟器)驱动贯穿验证,无真实气象站也能完整跑通;接入真实硬件只改一个配置参数
二、前置条件
- 一台 Ubuntu 22.04 服务器(1 核 512 MB 内存即可,官方自述在 500 MHz/512 MB 的设备上即可稳定运行,本文实测运行期常驻内存约 15.5 MB);
- 可用的系统时间同步(systemd-timesyncd 默认满足):WeeWX 会按归档时间戳落库,时钟漂移会造成记录间隔异常;
- root 或 sudo 权限;
- (方案 A)可访问
https://weewx.com/apt/python3;(方案 B)可访问https://weewx.com/downloads/,或已从官方页下载weewx-5.5.2.tgz拷贝到服务器。
三、版本选型说明
| 交付形态 | 版本标识 | 来源 | 适用 |
|---|---|---|---|
| apt 在线安装 | weewx 5.5.2-1 | weewx.com 官方 apt 仓库 | 可联网,推荐:自动建 weewx 用户、装 systemd 单元并启动 |
| tar.gz 离线安装 | weewx-5.5.2.tgz(3.9 MiB) | weewx.com/downloads/released_versions/ | 内网/受限环境:pip + venv 安装,数据区与单元文件手动托管 |
- 本文实测时官方最新稳定版为 5.5.2(下载页 weewx-5.5.2.tgz,2026-09-23 15:18),apt 仓库同步为 5.5.2-1,两渠道版本一致;
- SHA-256 校验值(实测计算):
261cad9950c9f463689deda9da1f6c95d5b73cbce948a36b9a41f65402bd3486; - WeeWX 5.x 起官方同时支持两种形态:DEB/RPM 包形态(配置在
/etc/weewx/)与 pip/tar.gz 形态(数据集中在~/weewx-data/),两形态目录布局不同,本文第四、五章分别按官方布局记录。
四、方案 A:官方 apt 仓库在线安装(推荐)
4.1 方案说明
WeeWX 官方维护 apt 仓库(https://weewx.com/apt/python3),安装包会自动完成:创建 weewx:weewx 用户组、写入 /etc/weewx/weewx.conf、安装 systemd 单元 weewx.service 并直接启动服务。安装过程中的交互向导询问站点位置/经纬度/海拔/站型,全部回车可跳过(默认 Simulator 模拟器 + 北极默认站点),后续随时用 weectl station reconfigure 重配。
4.2 安装 GPG 密钥与软件源
sudo apt update
sudo apt install -y wget gnupg
# 导入官方仓库签名密钥
wget -qO - https://weewx.com/keys.html | sudo gpg --dearmor --output /etc/apt/trusted.gpg.d/weewx.gpg
# 写入官方源(buster 代号是官方统一入口,Ubuntu 22.04 同样使用)
echo "deb [arch=all] https://weewx.com/apt/python3 buster main" | sudo tee /etc/apt/sources.list.d/weewx.list
刷新索引,确认官方源命中:
sudo apt update
实测回显(节选):
Get:3 https://weewx.com/apt/python3 buster InRelease [4,078 B]
Get:4 https://weewx.com/apt/python3 buster/main all Packages [6,919 B]
4.3 安装 weewx 包
sudo apt install -y weewx
实测回显(节选,安装末尾的配置动作序列):
Setting up weewx (5.5.2-1) ...
Using weewx:weewx as user:group
Adding system group weewx
Adding system user weewx
Installing udev rules
Installing bash completion
Using configuration file /etc/weewx/weewx.conf
Creating skins directory /etc/weewx/skins
Creating user extension directory /etc/weewx/bin/user
Configuring database directory /var/lib/weewx
Configuring reporting directory /var/www/html/weewx
Setting permissions weewx:weewx on /etc/weewx
Installing systemd units
Enabling startup using systemd
Starting weewxd using systemd
⚠️ 注意:在交互终端安装会弹出 debconf 配置向导(站点位置、纬度、经度、海拔、站型五问)。本文为脚本化实测,使用非交互模式安装,向导全部取默认值。默认站点为官方彩蛋——
location = "Santa's Workshop, North Pole"(北极圣诞老人工坊),纬度 90.0,站型 Simulator。
4.4 安装产物与目录布局
DEB 形态的关键路径(WEEWX_ROOT 为 /etc/weewx/):
| 路径 | 内容 |
|---|---|
| /etc/weewx/weewx.conf | 主配置文件(WEEWX_ROOT) |
| /etc/weewx/skins/ | 皮肤(Seasons/Smartphone/Mobile/Standard/Ftp/Rsync 等) |
| /etc/weewx/bin/user/ | 用户扩展目录 |
| /etc/weewx/examples/ | 官方扩展示例 |
| /var/lib/weewx/weewx.sdb | SQLite 归档数据库 |
| /var/www/html/weewx/ | 报告输出目录(HTML_ROOT) |
| /usr/share/weewx/ | 程序本体(BIN_ROOT:weewxd.py、weectl.py、weectllib 等) |
| /lib/systemd/system/weewx.service | systemd 单元 |
| /etc/default/weewx | 服务环境变量(如 DAEMON 系统默认值) |
确认 systemd 单元内容(节选):
$ systemctl cat weewx
[Unit]
Description=WeeWX weather system
Requires=time-sync.target
After=time-sync.target
Wants=network-online.target
After=network-online.target
[Service]
ExecStart=/usr/share/weewx/weewxd /etc/weewx/weewx.conf
StandardOutput=null
StandardError=journal+console
RuntimeDirectory=weewx
RuntimeDirectoryMode=775
User=weewx
Group=weewx
[Install]
WantedBy=multi-user.target
服务以非特权用户 weewx 运行,Requires=time-sync.target 保证时钟先就绪。
4.5 服务状态与启动日志验证
systemctl status weewx
实测回显(节选):
● weewx.service - WeeWX weather system
Loaded: loaded (/lib/systemd/system/weewx.service; enabled; preset: enabled)
Active: active (running) since Thu 2026-10-30 14:50:57 UTC; 1min 12s ago
Main PID: 2761 (python3)
Memory: 15.5M
CPU: 1.844s
CGroup: /system.slice/weewx.service
└─2761 python3 /usr/share/weewx/weewxd.py /etc/weewx/weewx.conf
观察启动日志(WeeWX 启动即输出完整的运行环境自述,这是核对安装是否正确的第一手证据):
journalctl -u weewx --no-pager
实测回显(节选):
INFO __main__: Initializing weewxd version 5.5.2
INFO __main__: Command line: /usr/share/weewx/weewxd.py /etc/weewx/weewx.conf
INFO __main__: Using Python: 3.10.12 (main, Nov 4 2024, 22:26:14) [GCC 11.4.0]
INFO __main__: Located at: /usr/bin/python3
INFO __main__: Platform: Linux-7.0.0-38-generic-x86_64-with-glibc2.35
INFO __main__: Locale: 'C.UTF-8'
INFO __main__: Entry path: /usr/share/weewx/weewxd.py
INFO __main__: WEEWX_ROOT: /etc/weewx
INFO __main__: Config file: /etc/weewx/weewx.conf
INFO __main__: User weewx Group weewx
INFO weewx.engine: Loading station type Simulator (weewx.drivers.simulator)
INFO weewx.engine: StdConvert target unit is 0x1
INFO weewx.engine: StdWXCalculate will use data binding wx_binding
INFO weewx.manager: Created and initialized table 'archive' in database 'weewx.sdb'
INFO weewx.manager: Created daily summary tables
INFO weewx.archive: Archive will use data binding wx_binding
INFO weewx.archive: Record generation will be attempted in 'hardware'
INFO weewx.archive: Using archive interval of 300 seconds (specified in weewx configuration)
INFO weewx.restx: StationRegistry: Posting not enabled.
INFO weewx.restx: Wunderground: Posting not enabled.
INFO weewx.restx: PWSweather: Posting not enabled.
INFO weewx.restx: CWOP: Posting not enabled.
INFO weewx.restx: WOW: Posting not enabled.
INFO weewx.restx: WOW-BE: Posting not enabled.
INFO weewx.restx: AWEKAS: Posting not enabled.
INFO weewx.engine: 'pyephem' detected, extended almanac data is available
INFO __main__: Starting up weewx version 5.5.2
INFO weewx.engine: Clock error is -0.02 seconds (positive is fast)
INFO weewx.engine: Using binding 'wx_binding' to database 'weewx.sdb'
INFO weewx.manager: Starting backfill of daily summaries
INFO weewx.manager: Empty database
INFO weewx.engine: Starting main packet loop.
要点核对:Loading station type Simulator(默认模拟器驱动已加载)、Using archive interval of 300 seconds(5 分钟归档间隔)、七个 restful 上传服务全部 Posting not enabled(未配置上传)、Starting main packet loop.(主循环启动)。
4.6 首条归档与报告生成验证
WeeWX 在归档边界(每 5 分钟整点)落一条归档记录,随后立即触发报告生成。启动约 5 分钟后验证:
查询归档数据库(先装 sqlite3 客户端):
sudo apt install -y sqlite3
sqlite3 /var/lib/weewx/weewx.sdb 'SELECT COUNT(*) FROM archive;'
sqlite3 /var/lib/weewx/weewx.sdb "SELECT dateTime, datetime(dateTime, 'unixepoch'), outTemp, barometer, windSpeed, rain FROM archive LIMIT 3;"
实测回显:
1
1|2026-10-30 14:55:00|32.6|31.1|0.0|0.0
启动于 14:50:57,首条归档落在下一个 300 秒边界 14:55:00,模拟器产生的室外温度 32.6°F、气压 31.1 inHg——数据链路(驱动→服务链→数据库)全部打通。
检查报告输出:
ls /var/www/html/weewx/ | head
ls /var/www/html/weewx/ | wc -l
实测回显:
NOAA
celestial.html
dayET.png
dayUV.png
daybarometer.png
dayhum.png
67
首次生成 67 个文件:index.html 主页、17 张当日曲线图(day*.png)、月度图(month*.png)、天文页 celestial.html、NOAA/ 目录下的月报年报文本(NOAA-2026-10.txt、NOAA-2026.txt)等。用浏览器访问 http://<服务器IP>/weewx/(需已有 Nginx/Apache 托管 /var/www/html)即可看到 Seasons 皮肤站点。
五、方案 B:官方 tar.gz 离线安装(venv 形态)
5.1 方案说明
内网机器无法访问官方 apt 源时,可用官方 tar.gz 发布件手工安装。WeeWX 5.x 的 tar.gz 是标准 Python 包:用 venv 隔离依赖安装后,由 weectl station create 在家目录生成自包含「站点数据区」(配置、皮肤、数据库、输出全在一个目录),systemd 单元由官方模板适配而来。该形态与方案 A 互斥使用,二选一。
5.2 下载与校验
在有外网的机器(或服务器直连官方下载页)下载:
wget https://weewx.com/downloads/released_versions/weewx-5.5.2.tgz
ls -l weewx-5.5.2.tgz
sha256sum weewx-5.5.2.tgz
实测回显:
-rw-r--r-- 1 root root 4105654 Sep 23 15:18 weewx-5.5.2.tgz
261cad9950c9f463689deda9da1f6c95d5b73cbce948a36b9a41f65402bd3486 weewx-5.5.2.tgz
文件大小 4105654 字节与官方下载页标注的 3.9 MiB 一致,SHA-256 与 4.2 节校验值比对无误后再进入安装。内网机可经 U 盘/跳板机传入 /root/。
5.3 创建 venv 并安装
apt install -y python3.10-venv
python3 -m venv /opt/weewx-venv
/opt/weewx-venv/bin/pip install /root/weewx-5.5.2.tgz
/opt/weewx-venv/bin/weectl --version
实测回显(节选):
Setting up python3.10-venv (3.10.12-1~22.04.18) ...
weectl 5.5.2
⚠️ 排障实录:Ubuntu 22.04 最小安装直接执行
python3 -m venv会失败,报错The virtual environment was not created successfully because ensurepip is not available——venv 模块在系统里但 ensurepip 组件缺失,必须先apt install python3.10-venv再建 venv。pip 安装过程需从 PyPI 拉取 WeeWX 依赖(configobj、Cheetah3、Pillow、pyephem 等),若内网无 PyPI 访问,可在外网机用pip download /root/weewx-5.5.2.tgz -d wheels/把依赖下载成 wheel 包后内网安装。
5.4 创建站点数据区
/opt/weewx-venv/bin/weectl station create --no-prompt
实测回显(节选):
Creating configuration file /root/weewx-data/weewx.conf
Processing configuration file /root/weewx-data/weewx.conf
Creating directory /root/weewx-data/skins
Copying new skin Seasons into /root/weewx-data/skins/Seasons
Copying new skin Horizon into /root/weewx-data/skins/Horizon
Copying new skin Ftp into /root/weewx-data/skins/Ftp
Copying new skin Mobile into /root/weewx-data/skins/Mobile
Copying new skin Standard into /root/weewx-data/skins/Standard
Copying new skin Rsync into /root/weewx-data/skins/Rsync
Copying new skin Smartphone into /root/weewx-data/skins/Smartphone
Copying examples into /root/weewx-data/examples
Creating a new 'user' directory at /root/weewx-data/bin/user
Copying utility files into /root/weewx-data/util
Copying script files into /root/weewx-data/scripts
Saving configuration file /root/weewx-data/weewx.conf
数据区 /root/weewx-data/ 自包含全部运行要素:weewx.conf(默认 Simulator 站型与北极默认站点)、7 套皮肤、examples/ 扩展示例、bin/user/ 用户扩展、util/(官方 systemd/openrc/launchd 单元模板)、scripts/ 辅助脚本。不指定路径时默认落在执行用户家目录(root 即 /root/weewx-data);可用 weectl station create /data/weewx-data 指定其他位置。
5.5 安装 systemd 单元并启动
官方模板在数据区内,且 station create 已自动把 ExecStart 适配为当前 venv 解释器路径:
$ cat /root/weewx-data/util/systemd/weewx.service
[Unit]
Description=WeeWX weather system
Documentation=https://weewx.com/docs
Requires=time-sync.target
After=time-sync.target
Wants=network-online.target
After=network-online.target
[Service]
ExecStart=/opt/weewx-venv/bin/python3 /opt/weewx-venv/lib/python3.10/site-packages/weewxd.py /root/weewx-data/weewx.conf
StandardOutput=null
StandardError=journal+console
User=root
Group=root
[Install]
WantedBy=multi-user.target
拷贝为系统单元(服务名自定义,示例用 weewx-pip)并启动:
cp /root/weewx-data/util/systemd/weewx.service /etc/systemd/system/weewx-pip.service
systemctl daemon-reload
systemctl start weewx-pip
systemctl is-active weewx-pip
实测回显:
active
启动日志验证(journalctl -u weewx-pip --no-pager,节选):
INFO __main__: Command line: /opt/weewx-venv/lib/python3.10/site-packages/weewxd.py /root/weewx-data/weewx.conf
INFO __main__: Using Python: 3.10.12 (main, Aug 31 2026, 10:18:17) [GCC 11.4.0]
INFO __main__: Located at: /opt/weewx-venv/bin/python3
INFO __main__: Platform: Linux-7.0.0-38-generic-x86_64-with-glibc2.35
INFO __main__: WEEWX_ROOT: /root/weewx-data
INFO __main__: Config file: /root/weewx-data/weewx.conf
INFO __main__: User module: /root/weewx-data/bin/user
INFO weewx.restx: PWSweather: Posting not enabled.
INFO weewx.restx: CWOP: Posting not enabled.
INFO weewx.engine: 'pyephem' detected, extended almanac data is available
INFO __main__: Starting up weewx version 5.5.2
INFO weewx.engine: Using binding 'wx_binding' to database 'weewx.sdb'
INFO weewx.manager: Starting backfill of daily summaries
INFO weewx.manager: Empty database
INFO weewx.engine: Starting main packet loop.
核对 WEEWX_ROOT: /root/weewx-data 与 Located at: /opt/weewx-venv/bin/python3——数据区与 venv 解释器绑定关系正确。
5.6 归档与报告验证
与方案 A 相同的验证逻辑,路径换成 pip 形态布局(数据库与报告默认都在数据区内,SQLITE_ROOT = archive、HTML_ROOT = public_html 均为相对 WEEWX_ROOT 的路径):
sqlite3 /root/weewx-data/archive/weewx.sdb 'SELECT COUNT(*) FROM archive;'
sqlite3 /root/weewx-data/archive/weewx.sdb "SELECT dateTime, datetime(dateTime, 'unixepoch'), outTemp, barometer FROM archive LIMIT 2;"
ls /root/weewx-data/public_html/ | wc -l
实测回显(启动于 16:09:54 UTC,首个归档边界 16:10:00 即落记录):
2
1793376600|2026-10-30 16:10:00|32.677674230835|31.0999999948355
1793376900|2026-10-30 16:15:00|32.5682211426044|31.0999791604895
67
归档计数正常增长、public_html/ 生成 67 个文件(index.html、day*.png 曲线、NOAA/ 月报年报)——venv 形态的完整数据链路(驱动→服务链→数据库→报告)验证通过。
5.7 开机自启
systemctl enable weewx-pip
实测回显:
Created symlink /etc/systemd/system/multi-user.target.wants/weewx-pip.service → /etc/systemd/system/weewx-pip.service.
六、方案对比与选择建议
| 维度 | 方案 A:官方 apt 仓库 | 方案 B:tar.gz + venv |
|---|---|---|
| 版本 | 5.5.2-1(与官方同步) | 5.5.2(发布件手动下载) |
| 是否需联网安装 | 是(weewx.com apt 源) | 否(离线包即可,但 pip 依赖需 PyPI 或预下载 wheel) |
| 运行身份 | 专用低权用户 weewx:weewx | 单元模板默认 root(生产建议仿方案 A 建低权用户并 chown 数据区) |
| 配置/数据布局 | /etc/weewx + /var/lib/weewx + /var/www/html/weewx 分离 | 全部集中在 ~/weewx-data 单目录 |
| systemd 单元 | 自动安装并启动 weewx.service | 官方模板拷贝适配(服务名自定) |
| 升级方式 | apt update && apt install weewx | 下载新版 tgz 后 pip install 覆盖 |
| 适用 | 联网服务器日常部署(推荐) | 内网/受限环境、需要多版本并存 |
选择建议:可联网一律选方案 A(省去用户创建、单元安装、目录权限三件套);内网或需要把整套 WeeWX 收纳进单目录备份/迁移的场景选方案 B。
七、配置说明
两种形态安装后的第一件配置事都是把默认的「北极模拟器站点」改成你的真实信息:
# DEB 形态
sudo systemctl stop weewx
sudo weectl station reconfigure --location="Beijing Haidian" --latitude=39.9042 --longitude=116.4074 --altitude=44,meter --no-prompt
sudo rm /var/lib/weewx/weewx.sdb # 默认站数据与真实站点无关,删除后重建干净库
sudo systemctl start weewx
# pip 形态(路径替换为你的数据区)
/opt/weewx-venv/bin/weectl station reconfigure --config=/root/weewx-data/weewx.conf --location="Beijing Haidian" --latitude=39.9042 --longitude=116.4074 --altitude=44,meter --no-prompt
weectl station reconfigure 会先把旧配置备份为 weewx.conf.时间戳 再改。站点位置实测改完后,报告主页标题随即更新(index.html 中出现新站名)。改配置后删除旧库可避免「默认模拟器数据混入真实数据」——WeeWX 的单位制与站点元数据在库创建时固化,站点级改动建议重建库。完整的 weewx.conf 参数逐段讲解见《WeeWX 5.5.2 配置参数详解》,weectl 全部子命令见《WeeWX 常用 CLI 命令与排障详解》。
八、常见问题
Q1:安装完成但 /var/www/html/weewx/ 是空的?
报告在首个归档边界(最长 5 分钟)后才生成,启动后立刻查看会扑空。用 journalctl -u weewx --no-pager | tail -5 看到 Starting main packet loop. 后再等满一个归档间隔。另外确认系统时区理解正确:归档边界按服务器本地时间整点对齐,日志里可见 Using archive interval of 300 seconds。
Q2:apt 安装时没有弹出站点配置向导?
脚本化/非交互环境(如云初始化)下 debconf 不弹窗,全部取默认值(北极 + Simulator)。用 sudo weectl station reconfigure --no-prompt 补配置即可,见第七章。
Q3:服务启动失败,日志报 configobj.ParseError?
weewx.conf 手工编辑时缩进/语法错误会导致解析失败,例如 configobj.ParseError: Invalid line (' broken option without value') (matched as neither section nor keyword) at line 52.。WeeWX 对配置缩进敏感:段名 [Section] 顶格、子段逐级缩进两空格、键值对必须有值。修复后 systemctl restart weewx。
Q4:journalctl 里出现 ERROR weewx.reportengine: Generator terminated?
多为报告输出目录权限问题:weewxd 以 weewx 用户运行,若把 HTML_ROOT 改到 /var/www/html 下自建目录而目录属主不是 weewx,会报 PermissionError: [Errno 13] Permission denied。处理:sudo mkdir -p <新目录> && sudo chown weewx:weewx <新目录> 后重启。
Q5:想接入真实气象站,怎么换驱动?
station_type 改成对应驱动名(如 Davis Vantage 系列用 Vantage),并保证对应驱动配置段存在。可用 sudo weectl station reconfigure --driver=weewx.drivers.vantage --no-prompt 自动写入。注意:没有真实硬件时切换硬件驱动会让服务反复崩溃退出(打不开串口 /dev/ttyUSB0),保留 Simulator 驱动即可随时评估。
Q6:两台机器想共用同一个 weewx 包,能否 apt 一份 pip 一份并存? 可以但没必要——两形态的命令入口(/usr/bin/weectl 与 venv 内 weectl)与数据区完全独立,互不干扰;但排障成本翻倍,建议一台机器只用一种形态。
九、卸载与清理
9.1 方案 A 卸载
# 仅卸载软件,保留配置与数据
sudo apt remove weewx
# 连配置一起卸载(数据 /var/lib/weewx 仍保留)
sudo apt purge weewx
彻底清理(官方卸载文档步骤,按需执行):
sudo rm -r /var/www/html/weewx /var/lib/weewx /etc/weewx
sudo rm /etc/default/weewx
sudo gpasswd -d $USER weewx # 若曾把当前用户加入 weewx 组
sudo userdel weewx
sudo groupdel weewx
sudo rm /etc/apt/sources.list.d/weewx.list /etc/apt/trusted.gpg.d/weewx.gpg
sudo apt update
9.2 方案 B 卸载
systemctl stop weewx-pip
systemctl disable weewx-pip
rm /etc/systemd/system/weewx-pip.service
systemctl daemon-reload
rm -r /opt/weewx-venv /root/weewx-data # 数据区含历史归档库,确认无需保留后再删
十、参考链接
- 官方 Debian/Ubuntu 快速上手:https://weewx.com/docs/5.5/quickstarts/debian/
- 官方下载页(weewx-5.5.2.tgz):https://weewx.com/downloads/
- 官方卸载说明:https://weewx.com/docs/5.5/quickstarts/debian/(Uninstalling 一节)
- 官方 pip 安装说明:https://weewx.com/docs/5.5/quickstarts/pip/
- 站内相关:《WeeWX 介绍与选型指南》 | 《WeeWX 5.5.2 配置参数详解》 | 《WeeWX 常用 CLI 命令与排障详解》