本教程适用于以下操作系统版本

  • Ubuntu 22.04 (Jammy Jellyfish)
  • Ubuntu 20.04 (Focal Fossa)

本页内容

  • 前提条件
  • 安装并配置 PostgreSQL
  • 安装并配置 Focalboard
  • 为 Focalboard 创建 Systemd 服务文件
  • 配置 Nginx 作为反向代理
  • 访问 Focalboard Web 界面
  • 为 Focalboard 启用 SSL
  • 结论

Focalboard 是一款开源、可自托管的项目管理工具。它支持多语言,是 Asana、Trello 和 Notion 的替代方案,开发者可用它在团队间跟踪和管理工作。它基于看板(kanban)模式,可用于桌面和服务器。它也可作为独立的个人服务器用于测试和开发。Focalboard 帮助开发者保持一致,以完成任务、达成里程碑并实现目标。

在本文中,我们将向你展示如何在 Ubuntu 22.04 上以 Nginx 作为反向代理安装 Focalboard。

前提条件

  • 一台运行 Ubuntu 22.04 的服务器。
  • 一个指向你服务器 IP 的有效域名。
  • 服务器上已配置 root 密码。

安装并配置 PostgreSQL

Focalboard 使用 PostgreSQL 来存储其数据。因此,你的系统上必须安装 PostgreSQL 数据库服务器。

如果尚未安装,你可以使用以下命令连同其他软件包一起安装:

apt-get install curl wget gnupg2 -y
apt-get install postgresql postgresql-contrib -y

安装 PostgreSQL 后,使用以下命令连接到 PostgreSQL:

su - postgres
psql

接下来,使用以下命令为 PostgreSQL 创建数据库和用户:

CREATE DATABASE focaldb;
CREATE USER focaluser WITH PASSWORD 'password';

接下来,使用以下命令退出 PostgreSQL shell:

\q
exit

完成后,你可以继续下一步。

安装并配置 Focalboard

首先,访问 Focalboard 的 Git Hub 下载页面,并使用以下命令下载最新版本的 Focalboard:

VER=$(curl -s https://api.github.com/repos/mattermost/focalboard/releases/latest|grep tag_name | cut -d '"' -f 4)
wget https://github.com/mattermost/focalboard/releases/download/${VER}/focalboard-server-linux-amd64.tar.gz

下载完成后,使用以下命令解压下载的文件:

tar -xvzf focalboard-server-linux-amd64.tar.gz

接下来,使用以下命令将 focalboard 移动到 /opt 目录:

mv focalboard /opt

接下来,编辑 Focalboard 配置文件:

nano /opt/focalboard/config.json

修改以下与你的数据库匹配的行,如下所示:

"dbtype": "postgres",
"dbconfig": "postgres://focaluser:password@localhost/focaldb?sslmode=disable&connect_timeout=10",

完成后保存并关闭文件。

为 Focalboard 创建 Systemd 服务文件

使用 systemd 来启动和管理 Focalboard 是个不错的做法。为此,你需要为 Focalboard 创建一个 systemd 服务文件:

nano /lib/systemd/system/focalboard.service

添加以下行:

[Unit]
Description=Focalboard server

[Service]
Type=simple
Restart=always
RestartSec=5s
ExecStart=/opt/focalboard/bin/focalboard-server
WorkingDirectory=/opt/focalboard

[Install]
WantedBy=multi-user.target

保存并关闭文件,然后重新加载 systemd 守护进程以应用更改:

systemctl daemon-reload

接下来,使用以下命令启动并启用 Focalboard 服务:

systemctl start focalboard
systemctl enable focalboard

现在你可以使用以下命令检查 Focalboard 的状态:

systemctl status focalboard

你将看到以下输出:

? focalboard.service - Focalboard server
     Loaded: loaded (/lib/systemd/system/focalboard.service; disabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-08-21 11:22:22 UTC; 8s ago
   Main PID: 4347 (focalboard-serv)
      Tasks: 4 (limit: 2242)
     Memory: 18.1M
        CPU: 1.977s
     CGroup: /system.slice/focalboard.service
             ??4347 /opt/focalboard/bin/focalboard-server

Aug 21 11:22:23 ubuntu2204 focalboard-server[4347]: debug [2022-08-21 11:22:23.507 Z] listener(s) for blockID                  caller="ws/ser>
Aug 21 11:22:23 ubuntu2204 focalboard-server[4347]: debug [2022-08-21 11:22:23.507 Z] listener(s) for blockID                  caller="ws/ser>
Aug 21 11:22:23 ubuntu2204 focalboard-server[4347]: debug [2022-08-21 11:22:23.510 Z] listener(s) for workspaceID              caller="ws/ser>
Aug 21 11:22:23 ubuntu2204 focalboard-server[4347]: debug [2022-08-21 11:22:23.510 Z] listener(s) for blockID                  caller="ws/ser>
Aug 21 11:22:23 ubuntu2204 focalboard-server[4347]: debug [2022-08-21 11:22:23.510 Z] listener(s) for blockID                  caller="ws/ser>
Aug 21 11:22:24 ubuntu2204 focalboard-server[4347]: debug [2022-08-21 11:22:24.928 Z] import archive - done                    caller="app/im>
Aug 21 11:22:24 ubuntu2204 focalboard-server[4347]: info  [2022-08-21 11:22:24.937 Z] initialized workspace                    caller="app/wo>
Aug 21 11:22:24 ubuntu2204 focalboard-server[4347]: info  [2022-08-21 11:22:24.941 Z] Server.Start                             caller="server>
Aug 21 11:22:24 ubuntu2204 focalboard-server[4347]: info  [2022-08-21 11:22:24.941 Z] http server started                      caller="web/we>
Aug 21 11:22:24 ubuntu2204 focalboard-server[4347]: info  [2022-08-21 11:22:24.947 Z] Starting unix socket server              caller="server>

此时,Focalboard 已启动并监听 8000 端口。你可以使用以下命令检查其监听端口:

ss -antpl | grep focalboard

你将看到以下输出:

LISTEN 0      4096               *:8000            *:*    users:(("focalboard-serv",pid=4347,fd=9))
LISTEN 0      4096               *:9092            *:*    users:(("focalboard-serv",pid=4347,fd=8))

完成后,你可以继续下一步。

配置 Nginx 作为反向代理

接下来,安装并配置 Nginx 作为反向代理以通过 80 端口访问 Focalboard 是个不错的做法。首先,使用以下命令安装 Nginx 服务器:

apt-get install nginx -y

安装 Nginx 服务器后,创建一个 Nginx 虚拟主机配置文件:

nano /etc/nginx/conf.d/focalboard.conf

添加以下行:

upstream focalboard {
   server localhost:8000;
   keepalive 32;
}

server {
   listen 80;

   server_name focalboard.example.com;

   location ~ /ws/* {
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "upgrade";
       client_max_body_size 50M;
       proxy_set_header Host $http_host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;
       proxy_set_header X-Frame-Options SAMEORIGIN;
       proxy_buffers 256 16k;
       proxy_buffer_size 16k;
       client_body_timeout 60;
       send_timeout 300;
       lingering_timeout 5;
       proxy_connect_timeout 1d;
       proxy_send_timeout 1d;
       proxy_read_timeout 1d;
       proxy_pass http://focalboard;
   }

   location / {
       client_max_body_size 50M;
       proxy_set_header Connection "";
       proxy_set_header Host $http_host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;
       proxy_set_header X-Frame-Options SAMEORIGIN;
       proxy_buffers 256 16k;
       proxy_buffer_size 16k;
       proxy_read_timeout 600s;
       proxy_cache_revalidate on;
       proxy_cache_min_uses 2;
       proxy_cache_use_stale timeout;
       proxy_cache_lock on;
       proxy_http_version 1.1;
       proxy_pass http://focalboard;
   }
}

完成后保存并关闭文件,然后使用以下命令检查 Nginx 是否存在语法配置错误:

nginx -t

你将看到以下输出:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

接下来,重启 Nginx 服务以应用配置更改:

systemctl restart nginx

你也可以使用以下命令检查 Nginx 状态:

systemctl status nginx

你应该会看到以下输出:

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-08-21 11:24:08 UTC; 7s ago
       Docs: man:nginx(8)
    Process: 5017 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 5018 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 5019 (nginx)
      Tasks: 2 (limit: 2242)
     Memory: 2.6M
        CPU: 35ms
     CGroup: /system.slice/nginx.service
             ??5019 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             ??5020 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Aug 21 11:24:08 ubuntu2204 systemd[1]: Starting A high performance web server and a reverse proxy server...
Aug 21 11:24:08 ubuntu2204 systemd[1]: Started A high performance web server and a reverse proxy server.

访问 Focalboard Web 界面

现在,打开你的 Web 浏览器并输入 URL http://focalboard.example.com/login 来访问 Focalboard。你将被重定向到 Focalboard 登录页面:

在 Ubuntu 22.04 系统上完整安装 Focalboard 项目管理看板教程

点击创建账户按钮。你应该会看到 Focalboard 账户创建页面:

在 Ubuntu 22.04 系统上完整安装 Focalboard 项目管理看板教程

填写你的电子邮件地址、管理员用户名、密码,然后点击 Register 按钮。你应该会在接下来的页面看到 Focalboard 仪表板:

在 Ubuntu 22.04 系统上完整安装 Focalboard 项目管理看板教程

为 Focalboard 启用 SSL

出于安全考虑,使用 Let's Encrypt SSL 保护 Focalboard 是个不错的做法。接下来,你需要安装 Certbot 客户端软件包来安装和管理 Let's Encrypt SSL。

首先,使用以下命令安装 Certbot:

apt-get install python3-certbot-nginx -y

安装完成后,运行以下命令为你的网站安装 Let's Encrypt SSL:

certbot --nginx -d focalboard.example.com

系统将要求你提供一个有效的电子邮件地址并接受服务条款,如下所示:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): 
[email protected]


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for focalboard.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/focalboard.conf

接下来,选择是否将 HTTP 流量重定向到 HTTPS,如下所示:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

输入 2 并按 Enter 完成安装。你应该会看到以下输出:

Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/focalboard.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://focalboard.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=focalboard.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/focalboard.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/focalboard.example.com/privkey.pem
   Your cert will expire on 2022-11-21. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

结论

恭喜!你已在 Ubuntu 22.04 上成功安装 Focalboard 并以 Nginx 作为反向代理。现在你可以在组织中部署 Focalboard,并开始通过 Web 浏览器轻松管理和跟踪你的项目。如有任何问题,欢迎随时问我。