# 🇨🇳 Detailed installation guide + control panel | 超级详细教学安装discourse+控制面板

**URL:** <https://meta.discourse.org/t/detailed-installation-guide-control-panel-discourse/278426>\
**Category:** Sysadmins\
**Tags:** chinese-translation\
**Created:** [2023年九月9日 16:59 UTC](https://meta.discourse.org/t/detailed-installation-guide-control-panel-discourse/278426 "2023-09-09T16:59:47Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![zengyunsi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zengyunsi/32/265722_2.png) [@zengyunsi](https://meta.discourse.org/u/zengyunsi)\
**Post date:** [2023年九月9日 16:59 UTC](https://meta.discourse.org/t/detailed-installation-guide-control-panel-discourse/278426/1 "2023-09-09T16:59:48Z")

</div>

我是一个做网站菜鸟，因为兴趣爱好，想搭建一个技术交流社区，准备搭建一个discourse，分享这篇教程，希望对有需要安装discourse的朋友，有帮助，避免踩坑，discourse的中文教程比较少，有的教程已经过时了，全靠翻译软件，研究了好几天。

需要做一个属于自己的discourse需要准备的：

阿里云轻量云服务器香港一个，国内的服务器下载github的插件像蜗牛一样，所以还是推荐用阿里云香港的轻量云，或者其它家轻量服务器，轻量服务器比较便宜，适合新手，配置需要内存大于2GB，不然会无法安装，如果需要装到国内服务器，可以采用香港服务器按量付费，然后用平台里的制作镜像然后克隆到国内服务器的方式，这样会节省踩坑的时间。

一个好记的短域名并解析到服务器ip，推荐com和net，其它域名缺少辨识度，域名可以搜[域名批量查询](https://ww.west.cn/web/mi)，用规则查询比较短的。

系统：Ubuntu 20.04，比较常用。

开通新的服务器以后，先把防火墙端口都打开(后期调试完毕以后，根据需求关掉端口，只保留用到的端口，省的被黑客攻击)，在控制面板设置好root的密码，然后直接在网页上ssh远程连接到服务器上，或者下载 [XTerminal](https://www.terminal.icu/)之类的ssh软件。

 ![image](https://global.discourse-cdn.com/meta/original/4X/3/7/4/3742afe9f4ff34dae1c57777511230e1f21bdb86.png)

然后粘贴下面三个命令，按回车执行，有选项的时候按yes，升级系统源还有安装git软件。

```plaintext

apt update
apt upgrade -y
apt install git

```

然后粘贴下面三个命令，按回车执行，用管理员身份，这一步 **sudo -s** 如果操作不仔细，会在安装的时候出现一些创建莫名失败的提示，导致安装失败，是因为没有权限导致的。

```plaintext
sudo -s
git clone https://github.com/discourse/discourse_docker.git /var/discourse
cd /var/discourse
chmod 700 containers

```

下载完以后，执行安装向导

```plaintext
./discourse-setup

```

然后根据提示输入要绑定的域名，第一次安装时间比较久，建议先除了主域名以外其它，随便乱填，然后后面能够成功再重新构建，看不懂的可以用截图加微信图片翻译，邮件可以用[阿里云的邮件服务](https://dns.console.aliyun.com/)。

 ![image](https://global.discourse-cdn.com/meta/original/4X/c/e/b/ceb12a0920d6fabdc26f20d3e489f7a825a31597.png)

然后会有一个提示是继续安装还是按ctrl+c取消，建议继续安装。

安装完成以后访问绑定的域名出现注册页面代表discourse安装成功了。

然后安装一个[liunx面板](https://1panel.cn/)，这一步主要是为了安装其它网站程序，以及方便菜鸟傻瓜式管理用，对比了下这个面板比宝塔要简单很多，而且比较清爽，不会很多广告，而且安装的速度只要几秒钟，不会像宝塔一样，要长时间编译环境。

执行下面的脚本：

```plaintext
curl -sSL https://resource.fit2cloud.com/1panel/package/quick_start.sh -o quick_start.sh && sudo bash quick_start.sh

```

安装的时候会提示检测到已经安装过docker，然后出现登陆后台。

按照提示，找到后台登陆进去，在容器管理里面可以看到app，就是discourse，可以在这里启动或者停止。

 ![image](https://global.discourse-cdn.com/meta/original/4X/5/0/6/50674411ae96cc8271f73a8858c771c5f26d2dd9.png)

然后进入文件，编辑app.yml，主要修改的地方，用中文注释了。

 ![image](https://global.discourse-cdn.com/meta/original/4X/d/3/e/d3e4a712cdeb6d65fd6cbf2725cbf6e9d88b5939.png)

```plaintext
## this is the all-in-one, standalone Discourse Docker container template
##
## After making changes to this file, you MUST rebuild
## /var/discourse/launcher rebuild app
##
## BE *VERY* CAREFUL WHEN EDITING!
## YAML FILES ARE SUPER SUPER SENSITIVE TO MISTAKES IN WHITESPACE OR ALIGNMENT!
## visit http://www.yamllint.com/ to validate this file as needed

templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  ## Uncomment the next line to enable the IPv6 listener
  #- "templates/web.ipv6.template.yml"
  - "templates/web.ratelimited.template.yml"
  ## Uncomment these two lines if you wish to add Lets Encrypt (https)
  - "templates/web.ssl.template.yml"
  - "templates/web.letsencrypt.ssl.template.yml"

## which TCP/IP ports should this container expose?
## If you want Discourse to share a port with another webserver like Apache or nginx,
## see https://meta.discourse.org/t/17247 for details
expose:
  - "80:80" # http
  - "443:443" # https

params:
  db_default_text_search_config: "pg_catalog.english"

  ## Set db_shared_buffers to a max of 25% of the total memory.
  ## will be set automatically by bootstrap based on detected RAM, or you can override
  db_shared_buffers: "128MB"
  ## 修改附件上传的最大值
  upload_size: 300m
  ## can improve sorting performance, but adds memory usage per-connection
  #db_work_mem: "40MB"

  ## Which Git revision should this container use? (default: tests-passed)
  #version: tests-passed

env:
  LC_ALL: en_US.UTF-8
  LANG: en_US.UTF-8
  LANGUAGE: en_US.UTF-8
  DISCOURSE_DEFAULT_LOCALE: zh_CN

  ## How many concurrent web requests are supported? Depends on memory and CPU cores.
  ## will be set automatically by bootstrap based on detected CPUs, or you can override
  UNICORN_WORKERS: 2

  ## TODO: The domain name this Discourse instance will respond to
  ## Required. Discourse will not work with a bare IP number.
  ## 修改主域名
  DISCOURSE_HOSTNAME: bbs.izdh.net

  ## Uncomment if you want the container to be started with the same
  ## hostname (-h option) as specified above (default "$hostname-$config")
  #DOCKER_USE_HOSTNAME: true

  ## TODO: List of comma delimited emails that will be made admin and developer
  ## on initial signup example 'user1@example.com,user2@example.com'
  ## 修改管理员邮箱
  DISCOURSE_DEVELOPER_EMAILS: 'xxxx@gmail.com'

  ## TODO: The SMTP mail server used to validate new accounts and send notifications
  # SMTP ADDRESS, username, and password are required
  # WARNING the char '#' in SMTP password can cause problems!
  ## 修改发信邮箱服务器
  DISCOURSE_SMTP_ADDRESS: smtpdm.aliyun.com
  ## 修改发信邮箱端口
  DISCOURSE_SMTP_PORT: 80
  ## 修改为自动发信邮箱账号
  DISCOURSE_SMTP_USER_NAME: xxxx@xxx.net
  ## 修改发信邮箱密码
  DISCOURSE_SMTP_PASSWORD: "dj6bCRxoHt25NcD6"
  #DISCOURSE_SMTP_ENABLE_START_TLS: true # (optional, default true)
  DISCOURSE_SMTP_DOMAIN: smtpdm.aliyun.com
  ## 修改为自动发信邮箱账号
  DISCOURSE_NOTIFICATION_EMAIL: xxxx@xxx.net
  DISCOURSE_SMTP_ENABLE_START_TLS: false
  ## If you added the Lets Encrypt template, uncomment below to get a free SSL certificate
  LETSENCRYPT_ACCOUNT_EMAIL: me@example.com

  ## The http or https CDN address for this Discourse instance (configured to pull)
  ## see https://meta.discourse.org/t/14857 for details
  #DISCOURSE_CDN_URL: https://discourse-cdn.example.com
  
  ## The maxmind geolocation IP address key for IP address lookup
  ## see https://meta.discourse.org/t/-/137387/23 for details
  #DISCOURSE_MAXMIND_LICENSE_KEY: 1234567890123456

## The Docker container is stateless; all data is stored in /shared
volumes:
  - volume:
      host: /var/discourse/shared/standalone
      guest: /shared
  - volume:
      host: /var/discourse/shared/standalone/log/var-log
      guest: /var/log

## Plugins go here
## see https://meta.discourse.org/t/19157 for details
## 安装2个插件
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/discourse/discourse-solved	 
          - git clone https://github.com/discourse/discourse-reactions

## Any custom commands to run after building
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='info@unconfigured.discourse.org'"
  - exec: echo "End of custom commands"

```

修改保存以后，回到终端，使用指令或者在后台停止容器，然后再重构，不过好像没安装这个面板可以不用停止容器，安装这个面板了以后不停止容器直接重构会报错。

```plaintext
./launcher stop app
./launcher bootstrap app`

```

等待重构完成，执行容器启动命令。

```plaintext
./launcher start app

```

进入discourse，会提示发邮件激活，如果收不到，可以用下面指令，创建一个管理员账号直接跳过，然后在左边设置里语言设置为中文即可，然后有个地方可以发邮件测试，会提示报错原因，多试几次就可以成功了。

```plaintext
./launcher enter app
rake admin:create

```

 ![image](https://global.discourse-cdn.com/meta/original/4X/a/6/8/a685267d88390836e874ecfe12e36807ed9d437d.png)

如果需要创建其它网站，直接参考[官方的教程](https://www.bilibili.com/video/BV1rY411z78k/)，比较简单就不详细介绍了，也可以在网站里，新建一个环境，然后网站权限修改成777，就可以安装各种程序了。

 ![image](https://global.discourse-cdn.com/meta/original/4X/2/2/7/227f1331eca5364db4c51ab62a488fe1865b2069.png)

主要解决的问题，可以一个服务器运行几个网站，这样节省了买服务器的费用，而且更加适合新手。

后面测试邮件发送的时候发现的一个问题：

容器的这些设置，编辑app.yml里面，重构好像并不起作用， **需要在容器环境变量这里修改** ，不过只需要5-6秒就可以生效，对插件安装有没有影响还不太清楚。

 ![image](https://global.discourse-cdn.com/meta/original/4X/8/4/a/84a31cfff2c023a5f335463652ce8906f5ee1d79.png)

和其它网站共存好像就是先新建一个反向代理，然后把默认的容器443端口改成一个10443，然后要配置证书，就能正常访问了。

反向代理

 ![image](https://global.discourse-cdn.com/meta/original/4X/4/5/e/45e2272e93d0843f138f2ce3292fd7fa55242109.png)

配置证书

 ![image](https://global.discourse-cdn.com/meta/original/4X/b/5/f/b5fb1d9fdd7c2e0e6dea16ccef74ad331f8147ca.png)

---

_[View the full topic](https://meta.discourse.org/t/detailed-installation-guide-control-panel-discourse/278426)._
