Discourse安装和部署

4,119 阅读3分钟

由于社区需要一款问答和讨论的软件,了解到Discource是一款国外开源和社区活到软件,Discourse自带有数据库Postgres、Redis,会自动保存和备份数据,开发语言是Ruby、Js, 安装是基于Docker的,屏蔽了环境的差异。国外软件构建过程会自动下载一些依赖了,安装过程也是碰到了一些小麻烦,顺便记录下,让后面的小伙伴少踩些坑……

环境准备

  • 云服务器,可以是腾讯阿里或其它云服务器,操作系统最好是Ubuntu16+,Centos在新版本也支持的
  • 一个域名,用于浏览器访问,比如:ask.cloudquery.hub

安装部署

discource github 地址:

github.com/discourse/d…

安装 docker, 以 ubuntu 18 举例

sudo apt-get update
sudo apt-get install -y docker.io

安装 discourse

  • 安装discourse docker镜像:
sudo -s
git clone https://github.com/discourse/discourse_docker.git /var/discourse
cd /var/discourse

- 克隆示例配置文件:
cp samples/standalone.yml containers/app.yml
  • 编辑应用配置文件
vim containers/app.yml
  • 如果你身在大陆,则需要进行镜像加速。找到配置文件中的templates块,添加国内镜像templates/web.china.template.yml
templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/web.china.template.yml"
  - "templates/web.ratelimited.template.yml"

  • 这里列出需要修改的几项(非完整配置文件):
env:
LANG: en_US.UTF-8

# 设置网站域名
DISCOURSE_HOSTNAME: 'ask.cloudquery.hub'

# 设置系统管理员邮箱,安装完成这些邮件会收到激活邮件,数字邮件收不到
DISCOURSE_DEVELOPER_EMAILS: 'me@example.com,you@example.com'

# 设置系统邮箱配置,用于向用户发邮件
DISCOURSE_SMTP_ADDRESS: smtp.qq.com
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: user@qq.com
# 如果这个是QQ个人或企业邮件,这个必须是邮箱授权码,否则安装后管理员收不到邮件
# qq邮箱授权码 在qq邮箱=》设置=》账户=》开启pop3/smtp服务, disourse通过授权码登录邮件
DISCOURSE_SMTP_PASSWORD: 4jNxUvnVxBp1K3Y
run:
  - exec: echo "Beginning of custom commands"
  ## If you want to set the 'From' email address for your first registration, uncomment and change:
  ## After getting the first signup email, re-comment the line. It only needs to run once.
  - exec: rails r "SiteSetting.notification_email='user@qq.com'"
  - exec: echo "End of custom commands"

  • 开始构建docker app应用,这个步骤会比较久
./launcher bootstrap app
  • 启动app启动
./launcher start app
  • 启动成功就可以在浏览器中输入域名,激活管理员账号即可

安装注意

QQ邮箱是端口是587, 填465不行

如果修改了配置要生效,要重新生成app应用

./launcher rebuild app

launcher 用法

launcher 
Usage: launcher COMMAND CONFIG [--skip-prereqs]
Commands:
    start:      启动/初始化容器
    stop:       关闭运行中的容器
    restart:    重启容器
    destroy:    关闭并删除容器
    enter:      使用 nsenter 进入容器
    ssh:        在运行中的容器中启动 bash shell
    logs:       容器的 Docker 日志
    mailtest:   测试容器中的邮件配置
    bootstrap:  基于配置文件预设模板初始化容器
    rebuild:    重建一个容器(删除老容器,初始化,启动新容器)

网站启动 https

1.阿里云域名可申请免费 Https 证书,申请后下载Nginx服务器对应的证书7119671_example.com_nginx.zip

2.上传证书到服务器,解压到目录:/var/discourse/shared/standalone/ssl 后会得到 7119671_example.com.pem 和 7119671_example.com.key

3.重命名为 ssl.crt,ssl.key,这两个文件名是固定的,在web.ssl.template.yml, Discourse 根据固定的目录和文件名查找网站证书

 ssl_certificate /shared/ssl/ssl.crt;
 ssl_certificate_key /shared/ssl/ssl.key;

4.在 container/app.yml 下增加 - "templates/web.ssl.template.yml"

templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/web.ssl.template.yml"
  - "templates/web.china.template.yml"
  - "templates/web.ratelimited.template.yml"

5.运行 launcher rebuild app