我的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
相关推荐
你想考研啊6 分钟前
三、jenkins使用tomcat部署项目
运维·tomcat·jenkins
代码老y42 分钟前
Docker:容器化技术的基石与实践指南
运维·docker·容器
典学长编程1 小时前
Linux操作系统从入门到精通!第二天(命令行)
linux·运维·chrome
DuelCode2 小时前
Windows VMWare Centos Docker部署Springboot 应用实现文件上传返回文件http链接
java·spring boot·mysql·nginx·docker·centos·mybatis
你想考研啊3 小时前
四、jenkins自动构建和设置邮箱
运维·jenkins
Code blocks4 小时前
使用Jenkins完成springboot项目快速更新
java·运维·spring boot·后端·jenkins
饥饿的半导体5 小时前
Linux快速入门
linux·运维
杨浦老苏6 小时前
开源服务运行监控工具Lunalytics
docker·群晖·网站监控
还是奇怪7 小时前
Linux - 安全排查 2
linux·运维·安全
牛奶咖啡137 小时前
Linux系统的常用操作命令——文件远程传输、文件编辑、软件安装的四种方式
运维·服务器·软件安装·linux云计算·scp文件远程传输·vi文件编辑·设置yum的阿里云源