Ubuntu 22.04 安装 Tryton 8.2 指南
在 Ubuntu 22.04 上从零完成 Tryton 8.2 服务端安装:PostgreSQL 安装建库建角色 → pip 在线与 tar.gz 离线两种方案 → trytond-admin 初始化 → systemd 托管 → JSON-RPC 验证。
Ubuntu 22.04 安装 Tryton 8.2 指南
目标:在 Ubuntu 22.04 LTS 服务器上从零完成 Tryton 8.2 服务端(trytond)的完整安装:PostgreSQL 14 安装 → 建库建角色 → pip / 源码包两种方案安装 trytond 8.2.1 → 配置 → trytond-admin 初始化数据库与模块激活 → systemd 托管 → JSON-RPC 验证。已在 Ubuntu 22.04.5 LTS(内核环境 x86_64)实测通过。
一、环境信息
- 操作系统:Ubuntu 22.04.5 LTS x86_64
- Python:3.10.12(Ubuntu 22.04 系统自带,满足 trytond 8.2 要求的 >=3.10)
- 数据库:PostgreSQL 14.24(Ubuntu 22.04 官方仓库默认版本)
- Tryton 服务端:trytond 8.2.1(PyPI,2026-10-15 发布)
- 业务模块:trytond-party / trytond-product / trytond-account / trytond-sale 8.2.0(含依赖链共 13 个模块激活)
- 安装方式:方案 A = pip 在线安装(推荐);方案 B = 官方 tar.gz 源码包离线安装
- 监听端口:8000(HTTP JSON-RPC / REST)
- 配置文件:
/etc/tryton/trytond.conf;数据目录:/var/lib/tryton - 演示账号:
admin/q1w2e3r4
二、前置条件
开始安装前,确认服务器满足以下条件:
- 已具备 root 或 sudo 权限;
- 磁盘剩余空间 ≥ 2 GB(PostgreSQL 数据 + Python 依赖);
- 方案 A 需要能访问 PyPI(pypi.org);完全离线环境请直接用方案 B;
- 8000 端口未被占用:
ss -ltn | grep :8000 || echo "port 8000 is free"
预期输出:
port 8000 is free
三、版本选型说明
Tryton 按「系列」发布:每 6 个月一个新系列(形如 7.x / 8.x),普通系列维护 1 年,整数大版本(如 8.0)为 LTS、支持 5 年。截至 2026-10-25 的版本状态:
| 系列 | 性质 | 最新小版本 | 说明 |
|---|---|---|---|
| 8.2 | 当前稳定系列 | 8.2.1(2026-10-15) | 本文安装对象,功能最新 |
| 8.0 | LTS | 8.0.x | 5 年支持期,适合求稳的生产环境 |
| 7.8 / 7.6 | 旧系列 | — | 维护窗口已接近尾声 |
选择建议:新部署选当前系列 8.2;运行关键财务业务、要求 5 年不动大版本的选 LTS 8.0。本文以 8.2.1 为例。
四、PostgreSQL 安装与数据库准备(两方案共用)
Tryton 8.x 仅支持 PostgreSQL 作为后端数据库,因此必须先完成「安装 PostgreSQL → 建角色 → 建库」这条依赖链,否则后续 trytond-admin 初始化无从谈起。
4.1 安装 PostgreSQL 14
apt update
apt install -y postgresql
输出节选(实测首尾):
Reading package lists... Done
Building dependency tree... Done
...
Processing triggers for libc-bin (2.35-0ubuntu3.15) ...
启动数据库集群并确认状态:
service postgresql start
pg_lsclusters
实测输出:
* Starting PostgreSQL 14 database server
...done.
Ver Cluster Port Status Owner Data directory Log file
14 main 5432 online postgres /var/lib/postgresql/14/main /var/log/postgresql/postgresql-14-main.log
pg_lsclusters 显示 online 即 PostgreSQL 14 已在 5432 端口正常监听。
4.2 创建 tryton 数据库角色
Tryton 服务端以专用角色连接数据库,最小权限只需 LOGIN + CREATEDB(trytond-admin 会按需创建新库,生产可收回):
su - postgres -c "createuser -P -d -R -S tryton"
-P 会交互式提示输入密码,两次输入 q1w2e3r4;参数含义:-d 允许建库、-R 禁止建角色、-S 非超级用户。实测交互:
Enter password for new role:
Enter it again:
验证角色已创建:
su - postgres -c "psql -c '\du'"
实测输出:
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
tryton | Create DB | {}
4.3 创建 trytondb 业务数据库
以 tryton 角色为属主创建业务库 trytondb:
su - postgres -c "createdb -O tryton trytondb"
su - postgres -c "psql -l"
实测输出:
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+---------+-----------------------
postgres | postgres | UTF8 | C.UTF-8 | C.UTF-8 |
template0 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
trytondb | tryton | UTF8 | UTF-8 | C.UTF-8 |
(4 rows)
trytondb 出现在列表中且 Owner 为 tryton,数据库依赖链就绪。
⚠️ 注意:PostgreSQL 默认
pg_hba.conf对本地 TCP 连接采用 scram-sha-256 认证,trytond 通过localhost:5432连接时使用密码认证即可,无需修改 pg_hba。若 PostgreSQL 在另一台服务器上,需确保 pg_hba 放行 trytond 所在主机的 md5/scram 连接。
五、方案 A:pip 在线安装 trytond(推荐)
pip 安装是官方推荐的服务端安装方式(来源:tryton.org 下载页),依赖自动解析、升级方便,适合可联网服务器。
5.1 安装 Python 包管理工具
apt install -y python3-pip
python3 --version
pip3 --version
实测输出:
Python 3.10.12
pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)
5.2 安装 trytond 8.2.1 及 PostgreSQL 驱动
pip3 install --no-cache-dir trytond==8.2.1
pip3 install --no-cache-dir 'psycopg[binary]' psycopg-pool
第一条命令输出节选(实测首尾):
Collecting trytond==8.2.1
...
Installing collected packages: puremagic, polib, genshi, tzdata, typing-extensions, six, simpleeval, python-sql, pycparser, markupsafe, lxml, defusedxml, werkzeug, relatorio, python-dateutil, pwdlib, cffi, argon2-cffi-bindings, argon2-cffi, trytond
Successfully installed argon2-cffi-25.1.0 ... trytond-8.2.1 ... werkzeug-3.1.9
第二条命令实测输出:
Successfully installed psycopg-3.3.6 psycopg-binary-3.3.6
Successfully installed psycopg-pool-3.3.3
⚠️ 排障实录:
psycopg与psycopg-pool是 trytond 连接 PostgreSQL 的必需驱动,但不是 trytond 的声明依赖(trytond 把数据库驱动留给部署者自选)。漏装时trytond-admin会直接报ModuleNotFoundError: No module named 'psycopg'或No module named 'psycopg_pool',按本步补装即可解决。Tryton 8.x 使用 psycopg 3(不是老版本的 psycopg2),请勿装错包名。
5.3 安装业务功能模块
trytond 内核只提供框架,财务/销售/库存等功能由独立模块包提供。安装常用模块(依赖链会自动带上 company、currency、country、stock 等基础模块):
pip3 install --no-cache-dir trytond-party==8.2.0 trytond-product==8.2.0 trytond-account==8.2.0 trytond-sale==8.2.0
实测输出:
Installing collected packages: python-stdnum, trytond-currency, trytond-country, trytond-party, trytond-company, trytond-product, trytond-account, trytond-stock, trytond-account-product, trytond-account-invoice, trytond-account-invoice-stock, trytond-sale
Successfully installed python-stdnum-2.2 trytond-account-8.2.0 trytond-account-invoice-8.2.0 trytond-account-invoice-stock-8.2.0 trytond-account-product-8.2.0 trytond-company-8.2.0 trytond-country-8.2.0 trytond-currency-8.2.0 trytond-party-8.2.0 trytond-product-8.2.0 trytond-sale-8.2.0 trytond-stock-8.2.1
💡 说明:业务模块的版本号跟随系列(8.2.x),安装时锁定与 trytond 相同的系列号,避免跨系列混装导致 schema 不兼容。
5.4 验证安装
trytond --version
pip3 show trytond | head -8
实测输出:
trytond 8.2.1
Name: trytond
Version: 8.2.1
Summary: Tryton server
Home-page:
Author: Tiny SPRL, B2CK SRL, Openlabs Technologies & Consulting (P) Ltd, SALUC SA
Author-email: Cédric Krier <cedric.krier@b2ck.com>, Bertrand Chenal <bertrand.chenal@b2ck.com>, Nicolas Évrard <nicolas.evrard@b2ck.com>, Maxime Richez <maxime.richez@saluc.com>
Location: /usr/local/lib/python3.10/dist-packages
六、方案 B:官方 tar.gz 源码包离线安装
完全离线或审计要求严格的环境,可从官方下载页获取签名源码包安装。
6.1 下载源码包
mkdir -p /opt/tryton/src && cd /opt/tryton/src
curl -LO https://downloads.tryton.org/8.2/trytond-8.2.1.tar.gz
官方下载站对旧路径会返回 307 跳转到 CDN,实测响应头:
HTTP/2 307
server: nginx/1.31.6
content-type: text/html
curl -L 会自动跟随跳转完成下载。官方同时提供 signify 签名(公钥按系列发布在 downloads.tryton.org/signify/),有审计要求的场景可下载 .signify 签名文件校验。
6.2 离线安装
cd /opt/tryton/src
pip3 install --no-index --find-links=. trytond-8.2.1.tar.gz
--no-index 强制不访问 PyPI。注意 trytond 的运行依赖(werkzeug、lxml、python-sql、relatorio 等约 20 个包)同样需要离线 whl/tar.gz,需提前在联网机器用 pip3 download trytond==8.2.1 -d /opt/tryton/src 收集齐全后一并拷入。业务模块包(trytond-party 等)同理。
6.3 两种方案对比与选择建议
| 维度 | 方案 A:pip 在线 | 方案 B:tar.gz 离线 |
|---|---|---|
| 版本 | 8.2.1(指定) | 8.2.1(指定) |
| 是否需联网 | 需要访问 PyPI | 不需要 |
| 依赖处理 | pip 自动解析 | 需预先收集全部依赖包 |
| 安装结果 | 完全相同(site-packages) | 完全相同 |
| 适用场景 | 可联网服务器,首选 | 离线/审计环境 |
选择建议:能联网一律用方案 A;只有内网隔离或合规审计要求才走方案 B。两条路线装出的 trytond 完全一致,后续配置、初始化、systemd 托管步骤通用。
七、配置 trytond
创建配置与数据目录,写入主配置文件:
mkdir -p /etc/tryton /var/lib/tryton
cat > /etc/tryton/trytond.conf << 'EOF'
[database]
uri = postgresql://tryton:q1w2e3r4@localhost:5432/trytondb
path = /var/lib/tryton
[web]
listen = 0.0.0.0:8000
root = /var/lib/tryton/www
[cache]
model = 500
record = 500
field = 500
[session]
timeout = 600
EOF
关键项说明:
| 配置项 | 含义 | 说明 |
|---|---|---|
[database] uri | 数据库连接串 | 格式 postgresql://用户:密码@主机:端口/库名,与 4.2/4.3 建好的角色库对应 |
[database] path | 附件文件存储路径 | 报表、附件等二进制内容默认落盘而非入库 |
[web] listen | HTTP 监听地址 | 0.0.0.0:8000 对外提供服务;仅本机客户端可改 localhost:8000 |
[web] root | Web 客户端静态文件目录 | 部署 tryton-sao 后指向其构建产物 |
[cache] model/record/field | 元数据缓存条数 | 默认值偏小(200/2000/100),此处按中等规模调大 |
[session] timeout | 会话空闲超时(秒) | 默认 300,此处调整为 600 |
💡 说明:配置项还支持环境变量注入,格式为
TRYTOND_<节>__<键>(如TRYTOND_DATABASE__URI),适合机密信息不落盘。完整参数逐项详解见本专栏《Tryton 8.2 配置参数详解》。
八、初始化数据库(trytond-admin)
配置文件就绪后,用 trytond-admin 初始化 trytondb:创建全部框架表、激活已安装模块、设置 admin 账号。
printf 'q1w2e3r4\nq1w2e3r4\n' | trytond-admin -c /etc/tryton/trytond.conf -d trytondb --all --email admin@example.com -p
-c指定配置文件;-d指定目标数据库;--all更新所有已激活模块(首次初始化即创建全部框架表);--email预设 admin 邮箱,避免交互询问(排障见 FAQ);-p触发设置 admin 密码,从 stdin 读两行(密码 + 确认)。
实测输出:
6094 ... WARNING py.warnings ... UserWarning: The path specified in the URI will be overridden
email for "admin" of "trytondb" (empty for none):
Warning: Password input may be echoed.
password for "admin" of "trytondb":
Warning: Password input may be echoed.
password confirmation for "admin":
(邮箱已用 --email 预设时该行提示不阻塞;WARNING 为配置项提示,不影响初始化。)
激活业务模块(将已安装的 party/sale/account 等模块真正装进数据库):
trytond-admin -c /etc/tryton/trytond.conf -d trytondb -u party company currency country product account account_product account_invoice account_invoice_stock stock sale --activate-dependencies -v
-u 列出要激活的模块,--activate-dependencies 自动补齐缺失依赖。执行完成后验证模块状态:
su - postgres -c "psql -d trytondb -c 'SELECT name, state FROM ir_module ORDER BY name;'"
实测输出:
name | state
-----------------------+-----------
account | activated
account_invoice | activated
account_invoice_stock | activated
account_product | activated
company | activated
country | activated
currency | activated
ir | activated
party | activated
product | activated
res | activated
sale | activated
stock | activated
(13 rows)
13 个模块全部 activated,数据库初始化与模块激活完成。
九、systemd 托管
生产环境用 systemd 托管 trytond 进程。创建单元文件:
cat > /etc/systemd/system/trytond.service << 'EOF'
[Unit]
Description=Tryton server (trytond)
After=network.target postgresql.service
Requires=postgresql.service
[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/trytond -c /etc/tryton/trytond.conf -d trytondb
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=5
PIDFile=/run/trytond.pid
[Install]
WantedBy=multi-user.target
EOF
逐项说明:After/Requires=postgresql.service 保证数据库先于 trytond 就绪;Restart=on-failure 崩溃自动拉起;正式环境建议创建专用系统用户(如 useradd -r tryton)替换 User=root 并 chown 数据目录。
⚠️ 关键:
-d trytondb不可省略。trytond 对数据库连接池(Pool)采用惰性初始化,启动时若不用-d预声明数据库,首个涉及业务模型的请求(如登录)会因池中没有加载res.user模型而直接报 500 错误(实测现象与排障见 FAQ Q6)。-d与[database] uri中的库名保持一致。
启用并启动服务(每行一个单元):
systemctl daemon-reload
systemctl enable trytond
systemctl start trytond
systemctl is-active trytond
预期输出:
active
查看运行日志:
journalctl -u trytond --no-pager | tail -20
⚠️ 注意:systemd 托管需要以 systemd 为 init 的真实 Linux 服务器(Ubuntu 22.04 默认即 systemd)。若使用 Werkzeug 自带开发服务器观察前台日志,可手动执行
trytond -c /etc/tryton/trytond.conf -d trytondb,Ctrl+C 退出。
十、验证服务可用
trytond 启动后监听 8000 端口。注意其根路径仅接受 OPTIONS 预检,业务调用走 JSON-RPC(路径 /<数据库名>/rpc/)或 REST API。
验证服务版本(无数据库上下文的公共方法):
curl -s -X POST -H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","method":"common.server.version","params":[],"id":1}' \
http://localhost:8000/rpc/
实测输出:
"8.2"
验证数据库已注册:
curl -s -X POST -H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","method":"common.db.list","params":[],"id":1}' \
http://localhost:8000/rpc/
实测输出:
["trytondb"]
最后验证登录(common.db.login,库级方法,路径 /<数据库名>/rpc/):
curl -s -X POST -H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","method":"common.db.login","params":["admin",{"password":"q1w2e3r4"}],"id":1}' \
http://localhost:8000/trytondb/rpc/
实测输出:
[2,"78eed838bb93067c431d66e711f387b75f2283102d5c46f7d849935fad8964f3",null]
返回 [用户ID, 会话token, ...] 结构即登录成功,admin 账号可用。三个接口均正常返回,说明 trytond 服务端、PostgreSQL 连接、数据库初始化、模块加载全部就绪。接下来可用桌面客户端(tryton GTK 客户端)连接 服务器IP:8000、数据库 trytondb、账号 admin / q1w2e3r4 登录,或部署 tryton-sao Web 客户端提供浏览器访问。
十一、常见问题
Q1:执行 trytond-admin 报 ModuleNotFoundError: No module named 'psycopg'?
trytond 不自动携带数据库驱动。补装 psycopg 3 与连接池:pip3 install 'psycopg[binary]' psycopg-pool。注意不要装成 psycopg2,Tryton 8.x 已全面迁移到 psycopg 3。
Q2:trytond-admin 在脚本中执行报 EOFError: EOF when reading a line?
初始化新库时会交互询问 admin 邮箱与密码。脚本化部署用 --email admin@example.com 预设邮箱、-p 配合 stdin 两行输入密码(见本文第八节),或设置环境变量 TRYTONPASSFILE 指向密码文件。
Q3:curl 访问 http://localhost:8000/ 返回 405 Method Not Allowed?
正常现象。trytond 根路径只接受 CORS 预检(OPTIONS),业务接口路径为 /<数据库名>/rpc/(JSON-RPC POST)与 /<数据库名>/rest/...。用本文第十节的两个 curl 命令验证即可。
Q4:初始化/启动日志出现 UserWarning: The path specified in the URI will be overridden?
配置中 [database] uri 的库名与 -d 参数指定的库名并存时的提示,以 -d 为准,不影响功能。想去掉提示可保持两处一致。
Q5:如何升级到 8.2 系列的新小版本?
pip3 install --upgrade trytond==8.2.*
trytond-admin -c /etc/tryton/trytond.conf -d trytondb --all
systemctl restart trytond
先升级包、再执行 --all 让数据库 schema 跟随代码迁移、最后重启服务。跨系列(如 8.0 → 8.2)升级前务必备份数据库。
Q6:登录接口 common.db.login 返回 500,页面显示 'res.user'?
实测错误响应:
HTTP/1.1 500 INTERNAL SERVER ERROR
Server: Werkzeug/3.1.9 Python/3.10.12
Content-Type: text/html; charset=utf-8
<!doctype html>
<html lang=en>
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>'res.user'</p>
同时 trytond 日志中出现:
User = pool.get('res.user')
KeyError: 'res.user'
定位过程:trytond-console 里手动 pool.get('res.user') 正常、数据库中 res_user 表存在、ir_module 显示 res 模块已 activated——说明数据没问题,问题在服务端进程。根因是 trytond 的模型连接池(Pool)惰性初始化:服务启动时若未用 -d <库名> 声明数据库,WSGI 进程里的 Pool 实例是空壳,首个需要业务模型的请求(登录要查 res.user 校验密码)就会抛 KeyError。
解决方案:启动命令必须带 -d trytondb(见本文第九节 systemd 单元),即:
trytond -c /etc/tryton/trytond.conf -d trytondb
带上 -d 后登录实测返回会话 token:
[2,"78eed838bb93067c431d66e711f387b75f2283102d5c46f7d849935fad8964f3",null]
💡 延伸:用 gunicorn 等独立 WSGI 服务器托管 trytond 时无法传
-d,等价做法是设置环境变量TRYTOND_DATABASE_NAMES=trytondb(trytond 的 WSGI 入口application.py会读取该变量预初始化连接池),效果相同。
十二、卸载清理
按逆序移除:
systemctl stop trytond
systemctl disable trytond
rm -f /etc/systemd/system/trytond.service
systemctl daemon-reload
pip3 uninstall -y trytond trytond-sale trytond-account trytond-account-invoice trytond-account-invoice-stock trytond-account-product trytond-stock trytond-product trytond-company trytond-party trytond-country trytond-currency python-stdnum psycopg-pool psycopg-binary psycopg
rm -rf /etc/tryton /var/lib/tryton /opt/tryton
su - postgres -c "dropdb trytondb"
su - postgres -c "dropuser tryton"
如需保留业务数据,跳过最后两条 dropdb/dropuser 即可。
十三、参考链接
- Tryton 官方下载页:https://www.tryton.org/download (查询日期 2026-10-25)
- trytond on PyPI:https://pypi.org/project/trytond/ (查询日期 2026-10-25)
- 官方文档 - 服务端配置:https://docs.tryton.org/projects/server/en/latest/ (查询日期 2026-10-25)
- 官方模块目录(PyPI Tryton 分类):https://pypi.org/search/?c=Framework+%3A%3A+Tryton (查询日期 2026-10-25)