转载: Ubuntu 系统安装 discourse +1panel

系统: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,可以在这里启动或者停止。

image

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

image

## 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,就可以安装各种程序了。

image

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

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

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

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

反向代理

image
配置证书

image

原文请访问:超级详细教学安装discourse+控制面板 - installation - Discourse Meta