discourse 安装_如何使用Discourse在半天之内建立内部团队论坛

discourse 安装

by Ben Cheng

通过本诚

如何使用Discourse在半天之内建立内部团队论坛 (How to set up an internal team forum in half a day using Discourse)

TL;DR: I’ve deployed Discourse on Kubernetes (K8s) for my company’s internal discussion platform. Because I couldn’t find a simple tutorial, I documented my steps to help other developers do it too.

TL; DR:我已经在公司内部讨论平台的Kubernetes(K8s)上部署了Discourse 。 因为找不到简单的教程,所以我记录了我的步骤以帮助其他开发人员也这样做。

我为什么要在Kubernetes上部署Discourse? (Why would I want to deploy Discourse on Kubernetes?)

  1. Our company already has a Kubernetes cluster for random tools and staging deployment, so it is cheaper to deploy on the existing cluster for an internal Discourse usage.

    我们公司已经有一个用于随机工具和暂存部署的Kubernetes集群,因此将其部署在现有集群上以进行内部Discourse使用会更便宜。
  2. As a founder, I don’t get many chances to code anymore. I wanted to learn how to use Kubernetes because my team has been using it a lot lately.

    作为创始人,我没有太多机会编写代码了。 我想学习如何使用Kubernetes,因为我的团队最近一直在使用它。

本教程快速概述 (A quick overview of this tutorial)

The tutorial and the sample config below shows how to deploy a single Discourse web-server. This server needs to connect to a PostgreSQL and Redis server. We are using Google Cloud Registry and gcePersistentDisk for storage. So let's begin:

下面的教程和示例配置显示了如何部署单个Discourse Web服务器 。 该服务器需要连接到PostgreSQLRedis服务器 。 我们正在使用Google Cloud RegistrygcePersistentDisk进行存储。 因此,让我们开始:

创建Discourse应用程序Docker映像 (Create Discourse app Docker image)

We will “misuse” the launcher provided by discourse_docker to create the docker image for the Discourse web server. And by “misuse” I mean that we have over-used the launcher script to create docker images for production use.

我们将“滥用” discourse_docker提供的启动器,以为Discourse Web服务器创建docker映像。 “滥用”是指我们过度使用了启动程序脚本来创建用于生产的docker映像。

1. Clone from https://github.com/discourse/discourse_docker to your local environment.

1.从https://github.com/discourse/discourse_docker克隆到您的本地环境。

2. Setup a temporary Redis server and PostgresSQL database in the local environment.

2.在本地环境中设置一个临时的Redis服务器PostgresSQL数据库

3. Create a containers/web_only.yml (as shown below)

3.创建一个containers/web_only.yml (如下所示)

  • The env var is not relevant to K8s. It’s just for building the local image, so let’s fill in something that works for your local environment.

    env var与K8无关。 它仅用于构建本地图像,因此让我们填写适用于您本地环境的内容。
  • Determine the plugins you want to install with your Discourse setting here.

    在此处使用“话语”设置确定要安装的插件。

4. Tip: The local Redis instances might be in protected-mode, and won’t allow a Docker guest to host the connection. For this case, you should start your Redis server with the protected-mode turned off: redis-server --protected-mode no

4。 提示 本地Redis实例可能处于保护模式,并且不允许Docker guest虚拟机托管连接。 在这种情况下,应在关闭保护模式的情况下启动Redis服务器: redis-server --protected-mode no

5. Create the Docker images and upload the images to your K8s Docker registry. In this case, we are using Google Cloud Registry:

5.创建Docker映像并将映像上传到您的K8s Docker注册表。 在这种情况下,我们使用的是Google Cloud Registry:

  • Create Docker image with Discourse’s launcher: ./launcher bootstrap web_only

    使用Discourse的启动器创建Docker映像: ./launcher bootstrap web_only

  • Verify that the image is created: docker images. You should see the Discourse image in the list if successful.

    确认已创建映像: docker images 。 如果成功,您应该在列表中看到“话语”图像。

  • Upload the image to the registry with this command:

    使用以下命令将图像上传到注册表:

Sample config in web_only.yml :

web_only.yml示例配置:

现在我们准备部署到K8 (Now we’re ready to deploy to K8s)

1. Prepare a persistent volume

1.准备一个持久卷

We will need a persistent volume as the database to store the user info and the discussion items. We are using GCEPersistentDisk for the persistent disk on the K8s cluster. Now, let’s create two 10GB disks for the app and database respectively. You may consider your Discourse usage to adjust the disk size configuration.

我们将需要一个永久卷作为数据库来存储用户信息和讨论项。 我们正在将GCEPersististentDisk用于K8s集群上的永久磁盘。 现在,让我们分别为应用程序和数据库创建两个10GB磁盘。 您可以考虑使用Discourse来调整磁盘大小配置。

2. Deploy to Kubernetes

2.部署到Kubernetes

Next, we will configure the deployment settings of the K8s cloud. Customize the sample K8s file. Here are some variables you probably want to tweak:

接下来,我们将配置K8s云的部署设置。 自定义示例K8s文件。 以下是您可能需要调整的一些变量:

volumes.yaml

volumes.yaml

  • For both persistent volumes:

    对于两个持久卷:

    - metadata.name

    -元数据名称

    - spec.capacity.storage

    -规格容量存储

    - spec.gcePersistentDisk.pdName (for the persistent disk name above)

    -spec.gcePersistentDisk.pdName(用于上面的永久磁盘名称)

    - spec.claimRef.namespace (for the namespace you’re using in K8s)

    -spec.claimRef.namespace(用于您在K8s中使用的名称空间)

  • The sample file here assumes you are using gcePersistentDisk. volumes.yaml needs to change heavily depending on what type of persistent disk you plan to use.

    这里的样本文件假定您正在使用gcePersistentDisk 。 volume.yaml需要根据计划使用的永久磁盘类型进行大量更改。

redis.yaml

redis.yaml

  • Redis Deployment:

    Redis部署:

    - spec.template.spec.containers.resources.* (CPU and Memory resources for cache server)

    -spec.template.spec.containers.resources。*(高速缓存服务器的CPU和内存资源)

pgsql.yaml

pgsql.yaml

  • PersistentVolumeClaim (pgsql-pv-claim):

    PersistentVolumeClaim( pgsql-pv-claim ):

    -

    --

    spec.resources.requests.storage (storage of DB server)

    spec.resources.requests.storage (数据库服务器的存储)

discourse.yaml

discourse.yaml

  • PersistentVolumeClaim (discourse-pv-claim)

    PersistentVolumeClaim( discourse-pv-claim )

    - spec.resources.requests.storage (storage of web-server disk for logs and backups)

    -spec.resources.requests.storage(用于记录和备份的Web服务器磁盘的存储)

  • Deployment (web-server)

    部署( web-server )

    -

    --

    spec.template.spec.containers.image (Set the URL to point to your Docker image)

    spec.template.spec.containers.image (设置URL指向您的Docker映像)

    -

    --

    spec.template.spec.containers.env

    spec.template.spec.containers.env

DISCOURSE_DEVELOPER_EMAILS

DISCOURSE_DEVELOPER_EMAILS

DISCOURSE_DEVELOPER_EMAILSDISCOURSE_HOSTNAME

DISCOURSE_DEVELOPER_EMAILS DISCOURSE_HOSTNAME

DISCOURSE_DEVELOPER_EMAILSDISCOURSE_HOSTNAMEDISCOURSE_SMTP_ADDRESS

DISCOURSE_DEVELOPER_EMAILS DISCOURSE_HOSTNAME DISCOURSE_SMTP_ADDRESS

DISCOURSE_DEVELOPER_EMAILSDISCOURSE_HOSTNAMEDISCOURSE_SMTP_ADDRESSDISCOURSE_SMTP_PORT

DISCOURSE_DEVELOPER_EMAILS DISCOURSE_HOSTNAME DISCOURSE_SMTP_ADDRESS DISCOURSE_SMTP_PORT

- spec.template.spec.containers.resources.* (CPU and Memory resources for your web-server)

-spec.template.spec.containers.resources。*(Web服务器的CPU和内存资源)

ingress.yaml

ingress.yaml

  • spec.rules.host

    spec.rules.host

  • spec.tls.hosts

    spec.tls.hosts

Recommended: From there, you might want to create your own namespace for the deployment. Also assume you have set the right context to run the kubectl command in the namespace. (For details, read Kubernetes documentation). Otherwise, you should rename most of the names in the config files above to unique names and add some labels. Apply secrets. dbUsername and dbPassword can be anything you want. Please set the right smtpUsername and smtpPassword for the mail delivery services you use. Another note on HTTPS for Ingress: you should read this document and the Ingress controllers specific to your cluster and update ingress.yaml accordingly.

推荐:从那里,您可能要为部署创建自己的名称空间。 还要假设您设置了正确的上下文以在名称空间中运行kubectl命令。 (有关详细信息,请阅读Kubernetes文档 )。 否则,您应该将上述配置文件中的大多数名称重命名为唯一名称,并添加一些标签。 应用秘密。 dbUsernamedbPassword可以是您想要的任何内容。 请为您使用的邮件传递服务设置正确的smtpUsernamesmtpPassword 。 关于HTTPS for Ingress的另一个说明:您应该阅读本文档以及特定于集群的Ingress控制器,并相应地更新ingress.yaml

Apply all config files:

应用所有配置文件:

Before starting the app, run the following on PostgreSQL instance to initialize the database properly. You can find your pod name by running kubectl get pods.

在启动应用程序之前,请在PostgreSQL实例上运行以下命令以正确初始化数据库。 您可以通过运行kubectl get pods来找到您的pod名称。

Create Discourse deployment and Ingress with these commands:

使用以下命令创建Discourse部署和Ingress:

From here, your Discourse instance should be up and running. Below are some useful commands in case things don't work and require debugging:

从这里开始,您的Discourse实例应已启动并正在运行。 以下是一些有用的命令,以防万一无法正常工作并需要调试:

设置S3备份和文件上传 (Setup S3 backup and file upload)

Discourse can use AWS S3 for backup and file upload. Here are the steps to enable it:

Discourse可以使用AWS S3进行备份和文件上传。 以下是启用它的步骤:

1. Create two S3 buckets: one for backup and one for file upload. Set them as private.

1.创建两个S3存储桶:一个用于备份,一个用于文件上传。 将它们设置为私人。

2. Create an IAM user with API access only and attach the AWS inline policy below:

2.创建仅具有API访问权限的IAM用户,并在下面附加AWS嵌入式策略:

3. Fill in the Access Key and Key ID in Discourse Setting.

3.在“ 话语设置”中填写访问密钥和密钥ID。

Then Discourse can upload files to the S3 bucket you’ve specified, so you can attach image and file attachments in each post.

然后Discourse可以将文件上传到您指定的S3存储桶中,因此您可以在每个帖子中附加图像和文件附件。

而已! (That’s it!)

I hope this piece is helpful for you to set up your own Discourse platform. It’s also a practical exercise for me to try deploying an app on K8s.

希望本文对您建立自己的Discourse平台有所帮助。 对我来说,尝试在K8s上部署应用程序也是一种实践练习。

潜在的改进和扩大规模: (Potential improvement and scaling up:)

  • It’s possible to run multiple replicas for Discourse web-server for scaling up. It should work, but I haven’t tried yet.

    可以为Discourse Web服务器运行多个副本以进行扩展。 它应该可以工作,但是我还没有尝试过。
  • We could also deploy Primary-Replica PostgreSQL for scaling up. We’re using Bitnami’s PostgreSQL docker image and you can read the relevant instructions here.

    我们还可以部署Primary-Replica PostgreSQL以进行扩展。 我们正在使用Bitnami的PostgreSQL docker镜像,您可以在此处阅读相关说明。

Building an app? Our free developer tools and open source backend will make your job easier.

建立应用程式? 我们免费的开发人员工具开源后端将使您的工作更加轻松。

翻译自: https://www.freecodecamp.org/news/how-to-set-up-an-internal-team-forum-in-half-a-day-using-discourse-b13588d907fe/

discourse 安装

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值