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

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

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

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

一个好记的短域名并解析到服务器ip,推荐com和net,其它域名缺少辨识度,域名可以搜域名批量查询,用规则查询比较短的。

系统:Ubuntu 20.04,比较常用。

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

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


apt update
apt upgrade -y
apt install git

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

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

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

./discourse-setup

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

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

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

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

执行下面的脚本:

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

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

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

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

## 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"

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

./launcher stop app
./launcher bootstrap app`

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

./launcher start app

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

./launcher enter app
rake admin:create

如果需要创建其它网站,直接参考官方的教程,比较简单就不详细介绍了,也可以在网站里,新建一个环境,然后网站权限修改成777,就可以安装各种程序了。

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

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

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

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

反向代理

配置证书

2 Likes

其实discourse_docker clone到哪个文件夹都可以,都会自动安装到/var/discourse去……

In truth, the location to which one clones the discourse_docker repository is immaterial, as it will invariably be installed automatically to the /var/discourse directory…

理论上不太可能啊,正规操作是编辑app.yml然后rebuild

In theory, it seems rather improbable. The proper procedure would be to modify the app.yml file and subsequently rebuild the application.

1 Like

:sweat_smile:但是编辑配置文件 发现rebuild没起作用 还是改容器里的环境变量几秒钟就生效了 省的rebuild了 ···插件有没有影响暂时不清楚

之前没打
sudo -s
结果不停地报错啊 都不知道问题在哪里了····

大神,你知道中文用户名怎么样使用api吗,标头里不能包含中文

:sweat_smile: I say, tinkering with the configuration file proved fruitless, as the rebuild didn’t take effect. However, altering the container’s environment variables worked like a charm in mere seconds, sparing me the bother of rebuilding. The impact on plugins remains uncertain for the time being.

Previously, I’d neglected to enter ‘sudo -s’, resulting in a barrage of error messages. I was utterly flummoxed as to the source of the problem.

I say, old chap, might you know how a Chinese username could utilise the API? The header, you see, mustn’t contain Chinese characters.

蛤,有这个问题吗,你贴日志

Oh, I say, is that truly the issue? Perhaps you could share the log entries with me.

老外说可以,但是我怎么弄都不行··· :sweat_smile:

The advice said it was possible, but no matter how I tried, I simply couldn’t manage it… :sweat_smile:

如果可以试试用这个吧,鬼知道你发的请求用的什么编码

If feasible, perhaps we could give this a go. Heaven knows what encoding your request utilised.

1 Like

居然能在论坛里看到中文帖子😭

楼主可以一起交流建设论坛的经验吗?

It’s astonishing to stumble upon a Chinese post in this forum! :sob:

Might I enquire, dear thread starter, if you’d be willing to share your experiences in forum development? Your insights would be most appreciated.

1 Like

:sweat_smile:我也是新手,感觉内容为主吧,技术为辅,现在就是不知道怎么弄七牛云的内容储存,还有怎么引流

:sweat_smile: I’m a novice as well, and I reckon content should be the primary focus, with technology playing a supporting role. At present, I’m rather perplexed about how to utilise Qiniu Cloud for content storage, and I’m equally uncertain about the most effective methods for attracting traffic to my platform.

后面发现一个bug,upload_size: 300m,上传附件尺寸没办法生效不知道哪里的问题,只好还是不装面板了··

Subsequently, a flaw was uncovered. The ‘upload_size: 300m’ setting proved ineffective in regulating attachment dimensions. The root cause remained elusive, compelling me to forgo the installation of the control panel altogether.

我是用的亚马逊S3

不过阿里oss也兼容S3了,你可以试试

确实,搭好就看怎么弄内容了

I am utilising Amazon S3 for my storage needs.

However, it’s worth noting that Alibaba OSS has now become compatible with S3. You might consider giving it a try.

Indeed, once the infrastructure is in place, the focus shifts to populating it with content.

应该是按他说的方法改

记得当时我改的时候也是改参数加重构,我用的腾讯云,每次重构都挂代理,折腾的要死

It appears one ought to modify it according to his suggested method.

I recall when I made alterations at the time, I too adjusted parameters and refactored. I utilised Tencent Cloud, and each refactoring required a proxy connection. It was an absolute nightmare to sort out.

@Lhc_fl @zengyunsi 有没有办法实现论坛用户名字段保护呀,自定义里只有敏感词屏蔽和允许的用户字段

@Lhc_fl @zengyunsi Is there any way to implement forum username field protection? The custom settings only include sensitive word filtering and permitted user fields.

支持中文 Unicode 用户名:Discourse 支持中文用户名 - Discourse - iSharkFly

Support for Chinese Unicode usernames: Discourse accommodates Chinese usernames - Discourse - iSharkFly

虽然但是,什么叫做用户名字段保护,修改username必须经过审核吗

如果是上面那种,discourse并无原生功能,建议考虑写插件

或者你直接定期看一遍全站的用户名,看有没有问题

@go_ahead 另外我建议用英文或者中英混合单独开帖子问,这样ot在meta是要被拆分帖子的

用中文问也会让几位不会中文的管理员感到困扰,因为他们并不很容易知道我们在说什么

Whilst I understand your query, allow me to elucidate on the concept of username field protection and the necessity for username modifications to undergo a vetting process.

If that is indeed the case, Discourse lacks such a native functionality. I would suggest contemplating the development of a bespoke plugin to address this requirement.

Alternatively, you might consider conducting periodic reviews of all usernames across the platform to identify any potential issues.

@go_ahead Furthermore, I would recommend posing your question in English or a combination of English and Chinese in a separate thread. This approach is preferable, as off-topic discussions in the meta section are typically subject to thread separation.

Utilising Chinese exclusively may prove challenging for our non-Chinese speaking moderators, as they may struggle to comprehend the subject matter of our discourse.

我好像找到了这个功能,是这个

It appears I have stumbled upon this feature; I believe this is it.

1 Like

奈何我的英语水平很垃圾呀,也缺少和他们沟通的经验,后边会注意个问题,非常感谢呀 !

Alas, my command of the English language is woefully inadequate, and I find myself lacking in experience when it comes to communicating with them. I shall endeavour to be more mindful of this matter henceforth. I am most grateful for your guidance!

根据我的理解,管理员通常会把有中文的主题发布到 chinese-translation 这个 tag 下面。

一般来说问题不是非常大,也可以在你发布帖子的下面给个英文提示。

其实还好,管理员可以用翻译软件翻译个大概。问题不大。

According to my understanding, moderators typically categorise topics containing Chinese content under the ‘chinese-translation’ tag.

Generally speaking, the issue is not particularly significant, and one could also provide an English summary beneath one’s post.

In truth, it’s not overly problematic, as moderators can utilise translation software to garner a general understanding. The matter is of little consequence.

1 Like

🇨🇳 Discourse Official Install Guide | Discourse 云平台安装 这个内容应该还是可以用的。

但,我们用的是纯服务器,是从 Docker 容器开始的,可能没有用到控制台方面的配置。

The official Discourse installation guide referenced in the Chinese text is likely still applicable. However, it’s worth noting that our implementation utilises bare metal servers, commencing with Docker containers. As such, we may not have employed the console-related configurations mentioned in the guide.

This approach, starting from Docker containers on pure servers, potentially diverges from the standard installation process, particularly in terms of console setup and management. It’s crucial to bear this distinction in mind when following the official guide, as certain steps may need to be adapted or omitted to suit our specific deployment method.

:sweat_smile:说的是api ,没办法用中文调用

:sweat_smile: I’m afraid the API doesn’t support Chinese language input.

感觉可能是这个面板的问题····还是用原来的方法纯净安装得了·· 我想用七牛云

It appears the issue may lie with this particular panel… Perhaps it’s best to revert to the original method and perform a clean installation. I’m inclined to utilise Qiniu Cloud for this purpose.