如何在 Ubuntu 18.04 上安装 Mailtrain 时事通讯软件如何在 Ubuntu 18.04 上安装 Mailtrain 时事通讯软件如何在 Ubuntu 18.04 上安装 Mailtrain 时事通讯软件如何在 Ubuntu 18.04 上安装 Mailtrain 时事通讯软件
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

如何在 Ubuntu 18.04 上安装 Mailtrain 时事通讯软件

在此页

  1. 要求
  2. 开始
  3. 安装 Docker 和 Docker Compose
  4. 使用 Docker 安装 Mailtrain
  5. 访问 Mailtrain Web 界面
  6. 将 Nginx 配置为 Mailtrain 的反向代理
  7. 使用 Lets Encrypt 保护 Mailtrain
  8. 结论

Mailtrain 是一个免费、开源和自托管的时事通讯应用程序,它由支持 MySQL/MariaDB 数据库后端的 Node.js 构建。 Mailtrain 允许您通过 API 手动添加订阅者,或从 CSV 文件导入。 Mailtrain 具有一组丰富的功能,包括模板编辑器、自动化、自定义字段、RSS 活动、HTML 代码编辑器等等。如果您有一长串订阅者并希望轻松管理它们,那么 Mailtrain 是您的最佳选择。

在本教程中,我们将向您展示如何在 Ubuntu 18.04 服务器上使用 Docker 安装 Mailtrain 时事通讯应用程序。

要求

  • 一台运行 Ubuntu 18.04 的服务器。
  • 用您的服务器 IP 指向的有效域名。
  • 在您的服务器上配置了根密码。

入门

在开始之前,您需要使用最新版本更新您的系统。您可以通过运行以下命令来执行此操作:

apt-get update -y
apt-get upgrade -y

接下来,重新启动系统以应用更改。

安装 Docker 和 Docker Compose

默认情况下,最新版本的 Docker 在 Ubuntu 18.04 默认存储库中不可用。因此,您需要将 Docker 存储库添加到您的系统中。

首先,使用以下命令安装所需的包:

apt-get install curl git apt-transport-https ca-certificates -y

接下来,使用以下命令下载并添加 Docker 的 PGP 密钥:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -

接下来,通过编辑 /etc/apt/sources.list 文件添加 Docker CE 存储库:

nano /etc/apt/sources.list

在文件末尾添加以下行:

deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable

完成后保存并关闭文件。然后,更新存储库并使用以下命令安装 Docker CE:

apt-get update -y
apt-get install docker-ce -y

安装成功后,您可以使用以下命令检查 Docker 服务的状态:

systemctl status docker

您应该看到以下输出:

Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-10-24 16:15:25 UTC; 21min ago
     Docs: https://docs.docker.com
 Main PID: 1402 (dockerd)
    Tasks: 45
   CGroup: /system.slice/docker.service
           ?? 1402 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
           ??10312 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 3000 -container-ip 172.18.0.4 -container-port 3000

Oct 24 16:23:04 ubuntu1804 dockerd[1402]: time="2019-10-24T16:23:04.817021656Z" level=info msg="Layer sha256:b875b006eb8ffb0434ce3a26cb04c9017c
Oct 24 16:24:09 ubuntu1804 dockerd[1402]: time="2019-10-24T16:24:09.879265134Z" level=info msg="ignoring event" module=libcontainerd namespace=
Oct 24 16:24:10 ubuntu1804 dockerd[1402]: time="2019-10-24T16:24:10.065610315Z" level=warning msg="20676b10252b4a484e32a7d7534b3b386cc2a1e5efd1
Oct 24 16:25:52 ubuntu1804 dockerd[1402]: time="2019-10-24T16:25:52.649551513Z" level=info msg="Layer sha256:903ab9000f0a93e49537d5d00c5c8a8cab
Oct 24 16:26:47 ubuntu1804 dockerd[1402]: time="2019-10-24T16:26:47.428865652Z" level=info msg="Layer sha256:903ab9000f0a93e49537d5d00c5c8a8cab
Oct 24 16:27:41 ubuntu1804 dockerd[1402]: time="2019-10-24T16:27:41.603287585Z" level=info msg="Layer sha256:903ab9000f0a93e49537d5d00c5c8a8cab

接下来,使用 pip 命令安装最新版本的 docker compose,如下所示:

apt-get install python-pip
apt-get install docker-compose

安装完成后,您可以继续下一步。

使用 Docker 安装 Mailtrain

首先,使用以下命令从 Git 存储库下载最新版本的 Mailtrain:

git clone git://github.com/Mailtrain-org/mailtrain.git

接下来,将目录更改为 mailtrain 并重命名默认的 docker-compose 文件:

cd mailtrain
mv docker-compose.override.yml.tmpl docker-compose.override.yml

接下来,使用以下命令启动 Mailtrain docker 容器:

docker-compose up -d

此命令将下载并启动 mailtrain、mysql 和 redis 容器,如下所示:

Creating network "mailtrain_default" with the default driver
Creating volume "mailtrain_mailtrain-node-config" with default driver
Creating volume "mailtrain_mailtrain-node-data" with default driver
Creating volume "mailtrain_mailtrain-redis-data" with default driver
Creating volume "mailtrain_mailtrain-node-reports" with default driver
Creating volume "mailtrain_mailtrain-mysq-data" with default driver
Pulling redis (redis:3.0)...
3.0: Pulling from library/redis
f5cc0ee7a6f6: Pull complete
5fc25ed18e87: Pull complete
e025bc8872f6: Pull complete
77c68b51b836: Pull complete
7c403ece3755: Pull complete
0a653bd338f4: Pull complete
31531fd948c6: Pull complete
Digest: sha256:730b765df9fe96af414da64a2b67f3a5f70b8fd13a31e5096fee4807ed802e20
Status: Downloaded newer image for redis:3.0
Pulling mysql (mysql:5.7)...
5.7: Pulling from library/mysql
80369df48736: Pull complete
e8f52315cb10: Pull complete
cf2189b391fc: Pull complete
cc98f645c682: Pull complete
27a27ac83f74: Pull complete
fa1f04453414: Pull complete
d45bf7d22d33: Pull complete
c7d49ffebc56: Pull complete
511a8052b204: Pull complete
5d5df4c12444: Pull complete
d482603a2922: Pull complete
Digest: sha256:44b33224e3c406bf50b5a2ee4286ed0d7f2c5aec1f7fdb70291f7f7c570284dd
Status: Downloaded newer image for mysql:5.7
Building mailtrain
:
:
Removing intermediate container 20676b10252b
 ---> 0abdb4121f54
Step 6/9 : COPY . /app
 ---> c8af7560e844
Step 7/9 : EXPOSE 3000
 ---> Running in 3ff55179a229
Removing intermediate container 3ff55179a229
 ---> d83b49d4b24b
Step 8/9 : ENTRYPOINT ["bash", "/app/docker-entrypoint.sh"]
 ---> Running in e5baf6a1ea2e
Removing intermediate container e5baf6a1ea2e
 ---> c4f899a0f8f9
Step 9/9 : CMD ["node", "index.js"]
 ---> Running in fe94519d2bd3
Removing intermediate container fe94519d2bd3
 ---> 2808c2972f20
Successfully built 2808c2972f20
Successfully tagged mailtrain:latest
WARNING: Image for service mailtrain was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating mailtrain_redis_1 ... done
Creating mailtrain_mysql_1 ... done
Creating mailtrain_mailtrain_1 ... done

您现在可以使用以下命令检查所有正在运行的容器:

docker ps

您应该看到以下输出:

CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                    NAMES
0e837c586c39        mailtrain:latest    "bash /app/docker-en…"   About a minute ago   Up 55 seconds       0.0.0.0:3000->3000/tcp   mailtrain_mailtrain_1
49a4e69a09c6        mysql:5.7           "docker-entrypoint.s…"   About a minute ago   Up About a minute   3306/tcp, 33060/tcp      mailtrain_mysql_1
a1449b64a196        redis:3.0           "docker-entrypoint.s…"   About a minute ago   Up About a minute   6379/tcp                 mailtrain_redis_1

访问 Mailtrain Web 界面

Mailtrain 容器现已启动并侦听端口 3000。接下来,打开 Web 浏览器并输入 URL http://your-server-ip:3000。您应该在以下页面中看到 Mailtrain 默认仪表板:

现在,点击登录按钮。您应该会看到以下页面:

以 admin/admin 身份提供默认用户名和密码,然后单击“登录”按钮。您应该在以下页面中看到 Mailtrain 默认仪表板:

将 Nginx 配置为 Mailtrain 的反向代理

接下来,您需要在端口 3000 上创建一个 Nginx 作为 Mailtrain 的反向代理。为此,首先通过运行以下命令安装 Nginx Web 服务器:

apt-get install nginx -y

接下来,使用以下命令创建 Nginx 虚拟主机配置文件:

nano /etc/nginx/sites-available/mailtrain.conf

添加以下行:

upstream mailtrain {
  server 127.0.0.1:3000 weight=100 max_fails=5 fail_timeout=5;
}

server {
  listen          80;
  server_name     example.com;

  location / {
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://mailtrain/;
  }
}

完成后保存并关闭文件。然后,使用以下命令检查 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 虚拟主机文件:

ln -s /etc/nginx/sites-available/mailtrain.conf /etc/nginx/sites-enabled/

最后,重启 Nginx 网络服务器以应用配置:

systemctl restart nginx

使用 Lets Encrypt 保护 Mailtrain

接下来,您需要安装 Certbot 客户端以使用 Lets Encrypt 免费 SSL 保护 Mailtrain。默认情况下,最新版本的 Certbot 在 Ubuntu 18.04 默认存储库中不可用。因此,通过运行以下命令添加 Certbot 存储库:

add-apt-repository ppa:certbot/certbot

接下来,更新存储库并使用以下命令安装 Certbot:

apt-get update -y
apt-get install certbot python-certbot-nginx -y

安装后,运行以下命令为您的域 example.com 下载 Lets Encrypt 免费 SSL,并配置 Nginx 以使用此证书。

certbot --nginx -d example.com

提供您的电子邮件地址并同意服务条款。成功安装证书后,您应该会看到以下输出:

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

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/example.com/privkey.pem
   Your cert will expire on 2020-01-22. 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

您现在可以使用 URL https://example.com 安全地访问您的 Mailtrain 应用程序。

结论

在上面的教程中,我们学习了如何在 Ubuntu 18.04 服务器上使用 docker 安装 Mailtrain。我们还学习了如何将 Nginx 配置为 Mailtrain 的反向代理,并使用 Lets Encrypt 免费 SSL 保护 Mailtrain。如果您有任何问题,请随时问我。

©2015-2025 艾丽卡 support@alaica.com