Metabase 是一个开源的商业智能和分析平台,允许用户轻松创建和共享交互式仪表板和报告,它可以连接到各种数据源,拖放界面使非技术用户可以轻松创建图表、图形和报告,它还提供了广泛的自定义选项, 它具有内置的数据仓库功能,可以在Amazon Redshift和Google BigQuery等外部数据仓库解决方案的帮助下处理大数据。
在 Ubuntu 22.04 LTS Jammy Jellyfish 上安装 Metabase
第 1 步。首先,通过在终端中运行以下命令,确保所有系统软件包都是最新的。apt
<span class="pln">sudo apt update sudo apt upgrade</span>
第 2 步。安装 Docker。
默认情况下,Docker 在 Ubuntu 22.04 基础存储库上不可用。现在运行以下命令将 Docker 存储库添加到系统中:
<span class="pln">echo </span><span class="str">"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"</span> <span class="pun">|</span><span class="pln"> sudo tee </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">apt</span><span class="pun">/</span><span class="pln">sources</span><span class="pun">.</span><span class="pln">list</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">docker</span><span class="pun">.</span><span class="pln">list</span>
接下来,将 GPG 密钥导入您的系统:
<span class="pln">curl </span><span class="pun">-</span><span class="pln">fsSL https</span><span class="pun">:</span><span class="com">//download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg</span>
启用存储库后,现在使用以下命令安装最新版本的 Docker 包:
<span class="pln">sudo apt update sudo apt install docker</span><span class="pun">-</span><span class="pln">ce docker</span><span class="pun">-</span><span class="pln">ce</span><span class="pun">-</span><span class="pln">cli containerd</span><span class="pun">.</span><span class="pln">io docker</span><span class="pun">-</span><span class="pln">compose</span><span class="pun">-</span><span class="pln">plugin</span>
您可以验证 Docker 是否已安装以及当前版本:
<span class="pln">docker </span><span class="pun">-</span><span class="pln">v</span>
成功安装后,启用 Docker(在系统启动时自动启动)、启动并使用以下命令验证状态:
<span class="pln">sudo systemctl enable docker sudo systemctl start docker sudo systemctl status docker</span>
默认情况下,Docker 需要根权限。如果要避免在每次运行命令时使用,请将用户名添加到组中:sudo
docker
docker
<span class="pln">sudo usermod </span><span class="pun">-</span><span class="pln">aG docker $</span><span class="pun">(</span><span class="pln">whoami</span><span class="pun">)</span><span class="pln"> su </span><span class="pun">-</span><span class="pln"> $</span><span class="pun">{</span><span class="pln">USER</span><span class="pun">}</span>
确认您的用户已添加到 Docker 组:
<span class="pln">groups</span>
有关安装和管理 Docker 的其他资源,请阅读下面的帖子:
- 如何在 Ubuntu Linux √ 上安装 Docker。
第 3 步。为元数据库创建 Docker 撰写文件。
首先,为元数据库配置创建一个目录:
<span class="pln">mkdir metabase cd metabase</span>
接下来,使用您喜欢的文本编辑器创建并打开 Docker 撰写文件:
<span class="pln">nano docker</span><span class="pun">-</span><span class="pln">compose</span><span class="pun">.</span><span class="pln">yml</span>
添加以下文件:
<span class="pln">version</span><span class="pun">:</span> <span class="str">'3.9'</span><span class="pln"> services</span><span class="pun">:</span><span class="pln"> metabase</span><span class="pun">:</span><span class="pln"> image</span><span class="pun">:</span><span class="pln"> metabase</span><span class="pun">/</span><span class="pln">metabase</span><span class="pun">:</span><span class="pln">latest container_name</span><span class="pun">:</span><span class="pln"> metabase hostname</span><span class="pun">:</span><span class="pln"> metabase volumes</span><span class="pun">:</span> <span class="pun">-</span> <span class="str">/dev/</span><span class="pln">urandom</span><span class="pun">:</span><span class="str">/dev/</span><span class="pln">random</span><span class="pun">:</span><span class="pln">ro ports</span><span class="pun">:</span> <span class="pun">-</span> <span class="lit">3000</span><span class="pun">:</span><span class="lit">3000</span><span class="pln"> environment</span><span class="pun">:</span><span class="pln"> MB_DB_TYPE</span><span class="pun">:</span><span class="pln"> postgres MB_DB_DBNAME</span><span class="pun">:</span><span class="pln"> metabase MB_DB_PORT</span><span class="pun">:</span> <span class="lit">5432</span><span class="pln"> MB_DB_USER_FILE</span><span class="pun">:</span> <span class="str">/run/</span><span class="pln">secrets</span><span class="pun">/</span><span class="pln">db_user MB_DB_PASS_FILE</span><span class="pun">:</span> <span class="str">/run/</span><span class="pln">secrets</span><span class="pun">/</span><span class="pln">db_password MB_DB_HOST</span><span class="pun">:</span><span class="pln"> postgres env_file</span><span class="pun">:</span> <span class="pun">-</span><span class="pln"> metabase</span><span class="pun">.</span><span class="pln">env healthcheck</span><span class="pun">:</span><span class="pln"> test</span><span class="pun">:</span><span class="pln"> curl </span><span class="pun">--</span><span class="pln">fail </span><span class="pun">-</span><span class="pln">I http</span><span class="pun">:</span><span class="com">//localhost:3000/api/health || exit 1</span><span class="pln"> interval</span><span class="pun">:</span> <span class="lit">15s</span><span class="pln"> retries</span><span class="pun">:</span> <span class="lit">5</span><span class="pln"> start_period</span><span class="pun">:</span> <span class="lit">10s</span><span class="pln"> timeout</span><span class="pun">:</span> <span class="lit">5s</span><span class="pln"> networks</span><span class="pun">:</span> <span class="pun">-</span><span class="pln"> metanet1 depends_on</span><span class="pun">:</span> <span class="pun">-</span><span class="pln"> postgres secrets</span><span class="pun">:</span> <span class="pun">-</span><span class="pln"> db_password </span><span class="pun">-</span><span class="pln"> db_user postgres</span><span class="pun">:</span><span class="pln"> image</span><span class="pun">:</span><span class="pln"> postgres</span><span class="pun">:</span><span class="pln">latest container_name</span><span class="pun">:</span><span class="pln"> postgres hostname</span><span class="pun">:</span><span class="pln"> postgres environment</span><span class="pun">:</span><span class="pln"> POSTGRES_USER_FILE</span><span class="pun">:</span> <span class="str">/run/</span><span class="pln">secrets</span><span class="pun">/</span><span class="pln">db_user POSTGRES_DB</span><span class="pun">:</span><span class="pln"> metabase POSTGRES_PASSWORD_FILE</span><span class="pun">:</span> <span class="str">/run/</span><span class="pln">secrets</span><span class="pun">/</span><span class="pln">db_password healthcheck</span><span class="pun">:</span><span class="pln"> test</span><span class="pun">:</span> <span class="pun">[</span><span class="str">'CMD'</span><span class="pun">,</span> <span class="str">'pg_isready'</span><span class="pun">,</span> <span class="str">'-U'</span><span class="pun">,</span> <span class="str">'postgres'</span><span class="pun">]</span><span class="pln"> volumes</span><span class="pun">:</span> <span class="pun">-</span> <span class="pun">./</span><span class="pln">postgresql</span><span class="pun">:</span><span class="str">/var/</span><span class="pln">lib</span><span class="pun">/</span><span class="pln">postgresql</span><span class="pun">/</span><span class="pln">data networks</span><span class="pun">:</span> <span class="pun">-</span><span class="pln"> metanet1 secrets</span><span class="pun">:</span> <span class="pun">-</span><span class="pln"> db_password </span><span class="pun">-</span><span class="pln"> db_user networks</span><span class="pun">:</span><span class="pln"> metanet1</span><span class="pun">:</span><span class="pln"> driver</span><span class="pun">:</span><span class="pln"> bridge secrets</span><span class="pun">:</span><span class="pln"> db_password</span><span class="pun">:</span><span class="pln"> file</span><span class="pun">:</span><span class="pln"> db_password</span><span class="pun">.</span><span class="pln">txt db_user</span><span class="pun">:</span><span class="pln"> file</span><span class="pun">:</span><span class="pln"> db_user</span><span class="pun">.</span><span class="pln">txt</span>
保存并关闭文件。PostgreSQL 数据库用户名和密码分别存储在文件和文件中。db_user.txt
db_password.txt
然后我们创建并打开文件进行编辑:db_user.txt
<span class="pln">nano db_user</span><span class="pun">.</span><span class="pln">txt</span>
接下来,创建并打开文件进行编辑:db_password.txt
<span class="pln">nano db_password</span><span class="pun">.</span><span class="pln">txt</span>
第 4 步。配置环境文件元数据库。
首先,我们使用以下命令生成一个加密密钥:
<span class="pln">openssl rand </span><span class="pun">-</span><span class="pln">base64 </span><span class="lit">32</span>
接下来,创建并打开文件进行编辑:metabase.env
<span class="pln">nano metabase</span><span class="pun">.</span><span class="pln">env</span>
向其添加以下代码。粘贴针对变量生成的密钥。填写元数据库域,包括 HTTPS 协议。使用您使用的任何提供商填写您的 SMTP 详细信息。我们正在使用 Amazon SES。变量设置为强,这意味着您的元数据库密码:MB_ENCRYPTION_SECRET_KEY
MB_PASSWORD_COMPLEXITY
<span class="pln">MB_SITE_URL</span><span class="pun">=</span><span class="pln">https</span><span class="pun">:</span><span class="com">//your-domain.com</span><span class="pln"> MB_SITE_NAME</span><span class="pun">=</span><span class="str">"Howtoforge"</span><span class="pln"> MB_ADMIN_EMAIL</span><span class="pun">=</span><span class="pln">meilana@your</span><span class="pun">-</span><span class="pln">domain</span><span class="pun">.</span><span class="pln">com MB_EMAIL_FROM_ADDRESS</span><span class="pun">=</span><span class="pln">admin@your</span><span class="pun">-</span><span class="pln">domain</span><span class="pun">.</span><span class="pln">com MB_EMAIL_FROM_NAME</span><span class="pun">=</span><span class="pln">idroot MB_EMAIL_SMTP_HOST</span><span class="pun">=</span><span class="pln">email</span><span class="pun">-</span><span class="pln">smtp</span><span class="pun">.</span><span class="pln">us</span><span class="pun">-</span><span class="pln">west</span><span class="pun">-</span><span class="lit">2.amazonaws</span><span class="pun">.</span><span class="pln">com MB_EMAIL_SMTP_USERNAME</span><span class="pun">=</span><span class="pln">AWS_USERID MB_EMAIL_SMTP_PASSWORD</span><span class="pun">=</span><span class="pln">AWS_KEY MB_EMAIL_SMTP_PORT</span><span class="pun">=</span><span class="lit">587</span><span class="pln"> MB_EMAIL_SMTP_SECURITY</span><span class="pun">=</span><span class="pln">starttls MB_ENCRYPTION_SECRET_KEY</span><span class="pun">=</span><span class="typ">QWPbmwNvWYVqR5Ne46dk0OvTH1xWGDt</span><span class="pun">=</span><span class="pln"> MB_ANON_TRACKING_ENABLED</span><span class="pun">=</span><span class="kwd">false</span><span class="pln"> MB_APPLICATION_NAME</span><span class="pun">=</span><span class="typ">Howtoforge</span> <span class="typ">Metabase</span><span class="pln"> MB_PASSWORD_COMPLEXITY</span><span class="pun">=</span><span class="pln">strong</span>
完成所有配置文件后,就可以启动和启动容器了:
<span class="pln">docker compose up </span><span class="pun">-</span><span class="pln">d</span>
您可以使用以下命令观察容器的状态:
<span class="pln">watch docker ps</span>
第5步。安装 Nginx
默认情况下,Nginx 在 Ubuntu 22.04 基本存储库上可用。现在运行以下命令,将最新版本的 Nginx 安装到您的 Ubuntu 系统中:
<span class="pln">sudo apt install nginx</span>
成功安装后,启用 Nginx(在系统启动时自动启动)、启动并使用以下命令验证状态:
<span class="pln">sudo systemctl enable nginx sudo systemctl start nginx sudo systemctl status nginx</span>
确认安装并检查已安装的 Nginx 构建版本:
<span class="pln">nginx </span><span class="pun">-</span><span class="pln">v</span>
现在创建虚拟主机并打开文件:/etc/nginx/conf.d/metabase.conf
<span class="pln">nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">metabase</span><span class="pun">.</span><span class="pln">conf</span>
添加以下文件:
<span class="pln">server </span><span class="pun">{</span> <span class="com"># Redirect any http requests to https</span><span class="pln"> listen </span><span class="lit">80</span><span class="pun">;</span><span class="pln"> listen </span><span class="pun">[::]:</span><span class="lit">80</span><span class="pun">;</span><span class="pln"> server_name your</span><span class="pun">-</span><span class="pln">domain</span><span class="pun">.</span><span class="pln">com</span><span class="pun">;</span> <span class="kwd">return</span> <span class="lit">301</span><span class="pln"> https</span><span class="pun">:</span><span class="com">//$host$request_uri;</span> <span class="pun">}</span><span class="pln"> server </span><span class="pun">{</span><span class="pln"> listen </span><span class="lit">443</span><span class="pln"> ssl http2</span><span class="pun">;</span><span class="pln"> listen </span><span class="pun">[::]:</span><span class="lit">443</span><span class="pln"> ssl http2</span><span class="pun">;</span><span class="pln"> server_name your</span><span class="pun">-</span><span class="pln">domain</span><span class="pun">.</span><span class="pln">com</span><span class="pun">.</span><span class="pln">com</span><span class="pun">;</span><span class="pln"> access_log </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">log</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">metabase</span><span class="pun">.</span><span class="pln">access</span><span class="pun">.</span><span class="pln">log</span><span class="pun">;</span><span class="pln"> error_log </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">log</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">metabase</span><span class="pun">.</span><span class="pln">error</span><span class="pun">.</span><span class="pln">log</span><span class="pun">;</span><span class="pln"> location </span><span class="pun">/</span> <span class="pun">{</span><span class="pln"> proxy_set_header X</span><span class="pun">-</span><span class="typ">Real</span><span class="pun">-</span><span class="pln">IP $remote_addr</span><span class="pun">;</span><span class="pln"> proxy_set_header X</span><span class="pun">-</span><span class="typ">Forwarded</span><span class="pun">-</span><span class="typ">Proto</span><span class="pln"> $scheme</span><span class="pun">;</span><span class="pln"> proxy_set_header X</span><span class="pun">-</span><span class="typ">Forwarded</span><span class="pun">-</span><span class="typ">Host</span><span class="pln"> $http_host</span><span class="pun">;</span><span class="pln"> proxy_set_header X</span><span class="pun">-</span><span class="typ">Forwarded</span><span class="pun">-</span><span class="typ">For</span><span class="pln"> $proxy_add_x_forwarded_for</span><span class="pun">;</span><span class="pln"> proxy_pass http</span><span class="pun">:</span><span class="com">//127.0.0.1:3000;</span> <span class="pun">}</span> <span class="pun">}</span>
保存并关闭文件,然后使用以下命令重新启动 Nginx 服务:
<span class="pln">nginx </span><span class="pun">-</span><span class="pln">t sudo systemctl restart nginx</span>
有关安装 Nginx 的其他资源,请阅读下面的帖子:
- 如何在 Ubuntu Linux √ 上安装 Nginx
第 6 步。使用“让我们加密 SSL”保护元数据库。
首先,使用以下命令安装 Certbot 客户端:
<span class="pln">sudo apt install certbot python3</span><span class="pun">-</span><span class="pln">certbot</span><span class="pun">-</span><span class="pln">nginx</span>
接下来,按照以下步骤使用Let’s Encrypt获取SSL证书:
<span class="pln">certbot </span><span class="pun">--</span><span class="pln">apache </span><span class="pun">-</span><span class="pln">d your</span><span class="pun">-</span><span class="pln">domain</span><span class="pun">.</span><span class="pln">com</span>
让我们加密证书的有效期为 90 天,强烈建议在证书过期之前续订证书。您可以通过运行以下命令来测试证书的自动续订:
<span class="pln">sudo certbot renew </span><span class="pun">--</span><span class="pln">dry</span><span class="pun">-</span><span class="pln">run</span>
步骤 7.配置防火墙。
Ubuntu 22.04 默认运行防火墙。启用通过端口 HTTP 和 HTTPS 的连接:ufw
80
443
<span class="pln">sudo ufw allow </span><span class="str">'Nginx FULL'</span><span class="pln"> sudo ufw enable sudo ufw status</span>
第8步。访问元数据库 Web 界面。
成功安装后,打开您的 Web 浏览器并使用 URL 访问元数据库 Web UI。您将被重定向到以下页面:https://your-domain.com
感谢您使用本教程在 Ubuntu 系统上使用 Docker Compose 安装元数据库。有关其他帮助或有用信息,我们建议您查看元数据库官方网站。