最近在折腾Discourse,此文记录一下安装过程。
官方推荐的是docker部署。
docker安装
[可选]内存不够的添加swap
这里是添加了2GB的swap,并在/etc/fstab文件中添加一行以确保在重启后仍能使用这个swap文件。
sudo dd if=/dev/zero of=/var/swapfile bs=1024 count=2097152
sudo chmod 600 /var/swapfile
sudo mkswap /var/swapfile
sudo swapon /var/swapfile
echo '/var/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
安装nginx
sudo apt install nginx
添加nginx配置
域名换成自己的。
cd /etc/nginx/sites-available
cp default meta.example.com
cd ../sites-enabled
ln -s ../sites-available/meta.example.com
修改nginx配置 vim /etc/nginx/sites-enabled/meta.example.com
,将证书换成自己的。
如何使用cloudflare或者阿里云申请证书请参考文章:[还没写呢]
server {
listen 80;
server_name meta.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name meta.example.com;
client_max_body_size 100M;
location / {
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;
}
ssl_certificate /etc/ssl/meta.example.com/cert.pem;
ssl_certificate_key /etc/ssl/meta.example.com/key.pem;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_protocols TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
ssl_prefer_server_ciphers on;
add_header Strict-Transport-Security max-age=15768000;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/ssl/meta.example.com/fullchain.pem;
}
nginx重启
service nginx restart
拉取项目
sudo -s
git clone https://github.com/discourse/discourse_docker.git /var/discourse
cd /var/discourse
chmod 700 containers
[自定义]修改 launcher
主要修改95行,如果使用自己打包的image,需要修改此处。
新建Discourse配置文件
新建containers/app.yml
templates:
- "templates/postgres.template.yml"
- "templates/redis.template.yml"
- "templates/web.template.yml"
- "templates/web.ratelimited.template.yml"
- "templates/web.socketed.template.yml"
params:
db_default_text_search_config: "pg_catalog.english"
env:
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LANGUAGE: en_US.UTF-8
DISCOURSE_HOSTNAME: meta.example.com # 此处修改成你的域名
DISCOURSE_DEVELOPER_EMAILS: [email protected] # discourse管理员邮箱
# SMTP配置
DISCOURSE_SMTP_ADDRESS: smtpdm.aliyun.com # SMTP地址
DISCOURSE_SMTP_AUTHENTICATION: login # 使用阿里云邮件推送服务需要添加
DISCOURSE_SMTP_OPENSSL_VERIFY_MODE: none
DISCOURSE_SMTP_PORT: 80 # SMTP服务器端口
DISCOURSE_SMTP_USER_NAME: [email protected] # SMTP用户名
DISCOURSE_SMTP_PASSWORD: ******** # SMTP密码
DISCOURSE_SMTP_ENABLE_START_TLS: true
DISCOURSE_NOTIFICATION_EMAIL: [email protected]
volumes:
- volume:
host: /var/discourse/shared/standalone
guest: /shared
- volume:
host: /var/discourse/shared/standalone/log/var-log
guest: /var/log
hooks:
after_code:
- exec:
cd: $home/plugins
cmd:
- git clone https://github.com/discourse/docker_manager.git
- git clone https://github.com/discourse/discourse-chat-integration.git # 插件,不用的可以不安装
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='[email protected]'" # 如果您想设置首次注册的“发件人”电子邮件地址,把这里邮箱改成你的
- exec: echo "End of custom commands"
Discourse!启动!
cd /var/discourse
./launcher rebuild app
QA
Q: 报错:Environment: development WARNING: ember-test-selectors: You are using an unsupported ember-cli-babel version. data-test properties are not automatically stripped from your JS code.
A: 增加swap。内存不够了。
参考文章:
https://meta.discourse.org/t/run-other-websites-on-the-same-machine-as-discourse/17247
https://lala.im/8668.html
评论区