我的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 小时前
Kubernetes (K8s) 部署Doris
云原生·容器·kubernetes
老友@4 小时前
RabbitMQ 延时队列插件安装与使用详解(基于 Delayed Message Plugin)
运维·分布式·docker·rabbitmq·延时队列
-SGlow-6 小时前
MySQL相关概念和易错知识点(3)(表内容的CURD、内置函数)
linux·运维·服务器·数据库·mysql
编程社区管理员7 小时前
Vue项目使用ssh2-sftp-client实现打包自动上传到服务器(完整教程)
运维·服务器·vue
UQWRJ7 小时前
菜鸟教程Linux ViVimYumApt笔记
linux·运维·笔记
sz66cm8 小时前
Linux基础 -- 内核快速向用户态共享内核变量方案之ctl_table
linux·运维·服务器
努力一点9489 小时前
ubuntu22.04系统入门 linux入门(二) 简单命令 多实践以及相关文件管理命令
linux·运维·服务器·人工智能·gpu算力
wb1899 小时前
企业WEB应用服务器TOMCAT
运维·前端·笔记·tomcat·云计算
利刃大大10 小时前
【在线五子棋对战】十一、整合封装服务器模块实现
运维·服务器·c++·项目·五子棋