我的docker随笔43:问答平台answer部署

本文介绍开源问答社区平台Answer的容器化部署。

起因

笔者一直想搭建一个类似stack overflower这样的平台,自使用了Typora,就正式全面用Markdown+Typora+git来积累自己的个人知识库,但没有做到web化,现在也还在探索更好的方法。

无意间看到了 Answer 项目,觉得可能满足需求。其实这个项目早在 2022 年就已经由 SegmentFault 团队开源了,去年就进入了Apache 软件基金会孵化器。只是我知道的晚而已。

本文直接使用官方提供的docker镜像来部署。该项目使用 Golang 编写,有时间可以研究一下,当然这是后话。

概述

Answer主要功能有(摘自官方文档):

  • 提问和回答 - 提出问题并从你的用户和团队那里获得答案。
  • 组织内容 - 将你的内容组织为分类和标签。
  • 集成 - 与你现有的工具和服务集成。
  • 游戏化 - 奖励用户的贡献。
  • 现代用户界面 - 现代且响应式的用户界面。
  • 可扩展 - 使用插件扩展 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文件根据实际情况作了修改,说明如下:

  • Anserver使用目录/data存在数据,将其映射至宿主机目录。
  • 映射外部端口8090。
  • 本想自动设置时区,但经测试无效,因此保留注释。

启动:

复制代码
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://<ip>:9080/,根据提示进行安装。

页面配置

步骤1:选择语言。

步骤2:选择数据库。为简单起见,使用了sqlite3。

值得说明的是,Answer 支持MarialDB/MySQL、PostgreSQL 和 SQLite 数据库。前2者需要配置数据库信息,如数据库地址、用户、密码等,见下图。而SQLite不需要额外的配置。

步骤3:创建配置文件

步骤4:配置网站信息,注意,这里填写的用户是管理员。

登录后页面如下:

添加问题/回答

根据网页提示添加即可。需要说明的是,问题必须有对应的标签,可自定义添加,也可用管理员登录统一添加。页面示例:

添加用户

路径:后台管理->用户管理。

可以批量添加用户。格式为用户名,邮箱,密码,注意事项:

  • 用户名长度需大于4字符。
  • 邮箱不能与已存在用户的相同。
  • 密码长度需大于8字符。

示例如下:

可以修改用户状态,如停用、删除、提升至管理员,等。

网站设置

路径:后台管理->站点设置。

一般的设置较简单,根据网站提示即可。这里说一下笔者设置的地方。

登录设置,不允许用户注册。

特权设置,使用级别1。

小结

就目前情况看,即使搭建了这个平台,即使在内部推行了这个平台,使用者还是自己而已。但无论如何,还是走出了一步,还需看后续效果。

官方网站: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
相关推荐
科士威传动1 小时前
滚珠导轨在汽车自动化装配线中的核心传动
运维·自动化·汽车
David爱编程1 小时前
Docker 安全全揭秘:防逃逸、防漏洞、防越权,一篇学会容器防御!
后端·docker·容器
倔强的石头1062 小时前
【Linux指南】文件系统基础操作与路径管理
linux·运维·服务器
TDengine (老段)3 小时前
TDengine 快速体验(Docker 镜像方式)
大数据·数据库·物联网·docker·时序数据库·tdengine·涛思数据
中科三方3 小时前
如何通过DNS解析实现负载均衡?有哪些优势?
运维·负载均衡
安科瑞刘鸿鹏3 小时前
双碳时代,能源调度的难题正从“发电侧”转向“企业侧”
大数据·运维·物联网·安全·能源
小呆瓜历险记3 小时前
ubuntu 22.04搭建SOC开发环境
linux·运维·ubuntu
码农101号3 小时前
Linux中shell流程控制语句
linux·运维·服务器
聪明小萝卜4 小时前
无法与IP建立连接,未能下载VSCode服务器
运维·服务器
JuiceFS4 小时前
深度解析 JuiceFS 权限管理:Linux 多种安全机制全兼容
运维·后端