ubuntu安装discourse论坛程序

1、概述

Discourse 是 Stack Overflow 的联合创始人 Jeff Atwood 推出的一个的开源论坛项目。
基于 Ruby on Rails 和 Ember.js 开发,数据库使用 PostgreSQL 和 Redis。

好了废话不多说开整,discourse需要使用docker安装,因此第一步先装个docker。

2、安装docker

#卸载旧版本docker
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done

sudo apt update
sudo apt install ca-certificates curl gnupg -y
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y

sudo docker run hello-world

如果是国内服务器,可以使用国内daocloud的一键脚本安装。

curl -sSL https://get.daocloud.io/docker | sh 

3、安装discourse

3.1、拉取源码

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

3.2、使用discourse-setup安装

执行 ./discourse-setup 命令后,按照引导提示填写配置即可。

涉及到的命令如下。

./discourse-setup

###网站域名,不带http(s)
Hostname for your Discourse? [discourse.example.com]: 666.doget.net

Checking your domain name . . .
Connection to 666.doget.net succeeded.

#管理员邮箱
Email address for admin account(s)? [me@example.com,you@example.com]: adm@doget.net
#smtp地址
SMTP server address? [smtp.example.com]: smtp.doget.net
#smtp端口,回车默认587,其他端口自行输入
SMTP port? [587]: 
#smtp账号,填邮箱账号即可
SMTP user name? [user@example.com]: 233@doget.net
#smtp密码,如果是qq邮箱等需要填授权码
SMTP password? [pa$$word]: mqtxupkksnahbabc
#发件地址和邮箱账号保持一致
notification email address? [noreply@666.doget.net]: 233@doget.net
#输入回车跳过
Optional email address for Let's Encrypt warnings? (ENTER to skip) [me@example.com]: 
Optional Maxmind License key (ENTER to continue without MAXMIND GeoLite2 geolocation database) [1234567890123456]: 

#核对信息,没问题回车,有问题输入n重填
Does this look right?

这里不过多赘述,本文主要介绍第二种安装方式。

3.2、手动安装

所谓手动安装则是不使用官方提供的discourse-setup命令引导安装,而是自己修改配置文件后手动启动。

###拷贝一份配置文件,放到containers目录下并重命名为app.yml
cp ./samples/standalone.yml ./containers/app.yml

由于discourse已内置了nginx,且服务器上已有其他web服务,直接安装则会造成443端口冲突。

本文选择使用服务器上的nginx来反代discourse。因此需要对app.yml配置文件稍作修改。

  1. templates节点下增加以下配置 -"templates/web.socketed.template.yml"
  2. 注释掉expose节点下的端口
  3. 修改论坛网址及邮箱配置
#论坛地址
DISCOURSE_HOSTNAME: 'tst.doget.net'
#管理员邮箱
DISCOURSE_DEVELOPER_EMAILS: '1233@doget.net'
#发件配置
DISCOURSE_SMTP_ADDRESS: smtp.doget.net
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: 233@doget.net
DISCOURSE_SMTP_PASSWORD: mqtxupkksnahbabc
DISCOURSE_SMTP_ENABLE_START_TLS: true           # (optional, default true)
DISCOURSE_SMTP_DOMAIN: doget.net    # (required by some providers)
DISCOURSE_NOTIFICATION_EMAIL: 233@doget.net    # (address to send notifications from)
  1. 启动discourse,执行如下两个命令
./launcher bootstrap app
./launcher start app
  1. 修改nginx配置
server
{
   listen 80;
   listen 443 ssl http2;
   server_name tst.doget.net;

   #SSL-START SSL related configuration, do NOT delete or modify the next line of commented-out 404 rules
   #error_page 404/404.html;
   ssl_certificate    /www/server/panel/vhost/cert/tst.doget.net/fullchain.pem;
   ssl_certificate_key    /www/server/panel/vhost/cert/tst.doget.net/privkey.pem;
   ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
   ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
   ssl_prefer_server_ciphers on;
   ssl_session_cache shared:SSL:10m;
   ssl_session_timeout 10m;
   add_header Strict-Transport-Security "max-age=31536000";
   error_page 497  https://$host$request_uri;
	   #SSL-END

   ##主要是这里的配置
   location / {
	 add_header Content-Security-Policy "upgrade-insecure-requests;connect-src *";
	 proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock:;
	 proxy_set_header Host $http_host;
	 proxy_http_version 1.1;
	 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	 proxy_set_header X-Forwarded-Proto https;
	 proxy_set_header X-Real-IP $remote_addr;
	 }

   access_log  /www/wwwlogs/tst.doget.net.log;
   error_log  /www/wwwlogs/tst.doget.net.error.log;
}

不出意外网站已经能正常访问。

完整的discourse配置文件如下

## 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"
  - "templates/web.socketed.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: "256MB"

  ## 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: en

  ## 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: 3

  ## TODO: The domain name this Discourse instance will respond to
  ## Required. Discourse will not work with a bare IP number.
  DISCOURSE_HOSTNAME: 'tst.doget.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: 'helloworld@88.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: smtp.doget.net
  DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: 233@doget.net
  DISCOURSE_SMTP_PASSWORD: mqtxupkksnahbabc
  DISCOURSE_SMTP_ENABLE_START_TLS: true           # (optional, default true)
  DISCOURSE_SMTP_DOMAIN: doget.net    # (required by some providers)
  DISCOURSE_NOTIFICATION_EMAIL: 233@doget.net    # (address to send notifications from)

  ## 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
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git

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

4、常用命令

程序更新

cd /var/discourse
sudo git pull
sudo ./launcher rebuild app

停止程序

./launcher destroy app

5、注意点

邮箱配置务必正确,qq之类的个人邮箱是无法发送大量邮件的,需要商业的邮件服务。

以下是阿里云邮件推送服务的配置。

DISCOURSE_SMTP_ADDRESS: smtpdm.aliyun.com
DISCOURSE_SMTP_PORT: 465
DISCOURSE_SMTP_USER_NAME: system@admin.net
DISCOURSE_SMTP_FORCE_TLS: true
DISCOURSE_SMTP_PASSWORD: fnvbZ7XDS8oJKZsBWS
DISCOURSE_SMTP_ENABLE_START_TLS: false           # (optional, default true)
DISCOURSE_SMTP_DOMAIN: aliyun.com    # (required by some providers)
DISCOURSE_NOTIFICATION_EMAIL: system@admin.net    # (address to send notifications from)

此外,vps配置不能太差,该程序极其耗费性能。

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享
评论 抢沙发

    暂无评论内容