本文介绍开源问答社区平台Answer的容器化部署。
笔者一直想搭建一个类似stack overflower这样的平台,自使用了Typora,就正式全面用Markdown+Typora+git来积累自己的个人知识库,但没有做到web化,现在也还在探索更好的方法。
无意间看到了 Answer 项目,觉得可能满足需求。其实这个项目早在 2022 年就已经由 SegmentFault 团队开源了,去年就进入了Apache 软件基金会孵化器。只是我知道的晚而已。
本文直接使用官方提供的docker镜像来部署。该项目使用 Golang 编写,有时间可以研究一下,当然这是后话。
Answer主要功能有(摘自官方文档):
官方有详细的安装文档,这里结合自己的实际情况给出步骤。
通过以下命令下载官方镜像:
docker pull apache/answer
注:也可以在docker-comose阶段自动下载。虽然自动方便,不过笔者喜欢按部就班做。
docker-compose.yaml
文件:
# cat docker-compose.yaml
version: "3"
services:
answer:
image: apache/answer
container_name: answer
ports:
- '9080:80'
restart: on-failure
volumes:
- ./answer-data:/data
# - /etc/localtime:/etc/localtime
#environment:
# - TZ=Asia/Shanghai
#volumes:
# answer-data:./data
docker-compose.yaml
文件根据实际情况作了修改,说明如下:
/data
存在数据,将其映射至宿主机目录。启动:
docker-compose up -d
启动日志如下:
Attaching to answer
answer | [upload-dir] try to install...
answer | [upload-dir] install success, upload directory is /data/uploads
answer | [i18n] try to install i18n bundle...
answer | [i18n] find i18n bundle 42
answer | [i18n] install af_ZA.yaml bundle...
answer | [i18n] install af_ZA.yaml bundle success
answer | [i18n] install ar_SA.yaml bundle...
...
answer | [i18n] install zh_CN.yaml bundle...
answer | [i18n] install zh_CN.yaml bundle success
answer | [i18n] install zh_TW.yaml bundle...
answer | [i18n] install zh_TW.yaml bundle success
answer | install all initial environment done
answer | [SUCCESS] answer installation service will run at: http://localhost:80/install/
输入http://
,根据提示进行安装。
步骤1:选择语言。
值得说明的是,Answer 支持MarialDB/MySQL、PostgreSQL 和 SQLite 数据库。前2者需要配置数据库信息,如数据库地址、用户、密码等,见下图。而SQLite不需要额外的配置。
步骤3:创建配置文件
根据网页提示添加即可。需要说明的是,问题必须有对应的标签,可自定义添加,也可用管理员登录统一添加。页面示例:
路径:后台管理->用户管理。
可以批量添加用户。格式为用户名,邮箱,密码
,注意事项:
可以修改用户状态,如停用、删除、提升至管理员,等。
路径:后台管理->站点设置。
一般的设置较简单,根据网站提示即可。这里说一下笔者设置的地方。
就目前情况看,即使搭建了这个平台,即使在内部推行了这个平台,使用者还是自己而已。但无论如何,还是走出了一步,还需看后续效果。
官方网站:https://answer.apache.org/
源码:https://github.com/apache/incubator-answer
启动日志(有删改):
$ docker-compose logs
Attaching to answer
answer | [upload-dir] try to install...
answer | [upload-dir] install success, upload directory is /data/uploads
answer | [i18n] try to install i18n bundle...
answer | [i18n] find i18n bundle 42
answer | install all initial environment done
answer | [SUCCESS] answer installation service will run at: http://localhost:80/install/
[fengxuan@master incubator-answer]$ docker-compose logs -f
Attaching to answer
answer | [upload-dir] try to install...
answer | [upload-dir] install success, upload directory is /data/uploads
answer | [i18n] try to install i18n bundle...
answer | [i18n] find i18n bundle 42
answer | install all initial environment done
answer | [SUCCESS] answer installation service will run at: http://localhost:80/install/
answer | [config-file] try to create at /data/conf/config.yaml
answer | [config-file] create directory success, config file is /data/conf/config.yaml
answer | [config-file] install success
answer | check table not exist
answer | [i18n] try to install i18n bundle...
answer | [i18n] find i18n bundle 42
answer | [i18n] install zh_CN.yaml file exist, try to replace it
answer | [i18n] install zh_CN.yaml bundle...
answer | [i18n] install zh_CN.yaml bundle success
answer | [i18n] install zh_TW.yaml file exist, try to replace it
answer | [i18n] install zh_TW.yaml bundle...
answer | [i18n] install zh_TW.yaml bundle success
answer | try to create cache directory /data/cache
answer | try to load cache file from /data/cache/cache.db
answer | open /data/cache/cache.db: no such file or directory
answer | try to create database directory /data
answer | try to save cache file to /data/cache/cache.db
answer | upgrade done
answer | config file path: /data/conf/config.yaml
answer | Answer is starting..........................
answer | 2024-01-14 16:03:00.773 INFO data/data.go:118 try to load cache file from /data/cache/cache.db
answer | start cron
answer | answer Version: 1.2.1 Revision: d8c5577