CockroachDB因其弹性而受到青睐,因为它提供了强大的一致性,并且可以在硬件或网络故障中幸存下来。它特别适合需要高可用性和低延迟数据访问的应用程序。
在 Ubuntu 22.04 LTS Jammy Jellyfish 上安装 CockroachDB
第 1 步。首先,通过在终端中运行以下命令,确保所有系统软件包都是最新的。apt
<span class="pln">sudo apt update sudo apt upgrade</span>
第 2 步。安装所需的依赖项。
CockroachDB 有某些需要安装的依赖项。使用以下命令安装它们:
<span class="pln">sudo apt install </span><span class="pun">-</span><span class="pln">y curl lsof wget</span>
第 3 步。在 Ubuntu 22.04 上安装 CockroachDB。
现在,让我们继续下载最新版本的 CockroachDB:
<span class="pln">wget https</span><span class="pun">:</span><span class="com">//binaries.cockroachdb.com/cockroach-latest.linux-amd64.tgz</span>
下载后,是时候从下载的存档中提取文件了。使用以下命令:
<span class="pln">tar </span><span class="pun">-</span><span class="pln">xvzf cockroach</span><span class="pun">-</span><span class="pln">latest</span><span class="pun">.</span><span class="pln">linux</span><span class="pun">-</span><span class="pln">amd64</span><span class="pun">.</span><span class="pln">tgz</span>
CockroachDB是一个单一的二进制可执行文件。要使其在系统范围内可访问,请将其移动到系统路径中列出的目录:
<span class="pln">sudo mv cockroach </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span>
现在,创建一个数据目录至关重要,CockroachDB将在其中存储其数据:
<span class="pln">mkdir </span><span class="pun">-</span><span class="pln">p </span><span class="pun">~/</span><span class="pln">cockroach</span><span class="pun">-</span><span class="pln">data</span>
使用以下命令初始化新的 CockroachDB 节点:
<span class="pln">cockroach init </span><span class="pun">--</span><span class="pln">insecure </span><span class="pun">--</span><span class="pln">host</span><span class="pun">=</span><span class="pln">localhost</span>
“”标志允许在不加密的情况下进行快速设置。在生产环境中,应使用安全配置。--insecure
第 4 步。配置蟑螂数据库。
CockroachDB 需要配置才能有效使用。您必须指定 IP 地址和 CockroachDB 应侦听的端口。编辑“蟑螂”二进制文件中的集群设置:
<span class="pln">cockroach start </span><span class="pun">--</span><span class="pln">background </span><span class="pun">--</span><span class="pln">store</span><span class="pun">=</span><span class="pln">path</span><span class="pun">-</span><span class="pln">to</span><span class="pun">-</span><span class="pln">your</span><span class="pun">-</span><span class="pln">data</span><span class="pun">-</span><span class="pln">directory \ </span><span class="pun">--</span><span class="pln">listen</span><span class="pun">-</span><span class="pln">addr</span><span class="pun">=<</span><span class="pln">your</span><span class="pun">-</span><span class="pln">ip</span><span class="pun">-</span><span class="pln">address</span><span class="pun">></span> <span class="pun">--</span><span class="pln">http</span><span class="pun">-</span><span class="pln">addr</span><span class="pun">=<</span><span class="pln">your</span><span class="pun">-</span><span class="pln">ip</span><span class="pun">-</span><span class="pln">address</span><span class="pun">>:</span><span class="lit">8080</span>
替换为系统的 IP 地址。<your-ip-address>
为您的 CockroachDB 实例分配唯一的集群名称。例如:
<span class="pun">--</span><span class="kwd">join</span><span class="pun">=<</span><span class="pln">your</span><span class="pun">-</span><span class="pln">ip</span><span class="pun">-</span><span class="pln">address</span><span class="pun">>:</span><span class="lit">26257</span> <span class="pun">--</span><span class="pln">locality</span><span class="pun">=</span><span class="pln">region</span><span class="pun">=</span><span class="pln">us</span><span class="pun">,</span><span class="pln">zone</span><span class="pun">=</span><span class="pln">us</span><span class="pun">-</span><span class="pln">west</span>
要启动 CockroachDB,请使用以下命令:
<span class="pln">cockroach start </span><span class="pun">--</span><span class="pln">background </span><span class="pun">--</span><span class="pln">store</span><span class="pun">=</span><span class="pln">path</span><span class="pun">-</span><span class="pln">to</span><span class="pun">-</span><span class="pln">your</span><span class="pun">-</span><span class="pln">data</span><span class="pun">-</span><span class="pln">directory \ </span><span class="pun">--</span><span class="pln">listen</span><span class="pun">-</span><span class="pln">addr</span><span class="pun">=<</span><span class="pln">your</span><span class="pun">-</span><span class="pln">ip</span><span class="pun">-</span><span class="pln">address</span><span class="pun">></span> <span class="pun">--</span><span class="pln">http</span><span class="pun">-</span><span class="pln">addr</span><span class="pun">=<</span><span class="pln">your</span><span class="pun">-</span><span class="pln">ip</span><span class="pun">-</span><span class="pln">address</span><span class="pun">>:</span><span class="lit">8080</span>
第5步。访问 CockroachDB Admin UI。
要访问 CockroachDB 管理员 UI,请打开您的 Web 浏览器并导航到:
<span class="pln">http</span><span class="pun">:</span><span class="com">//<your-ip-address>:8080</span>
感谢您使用本教程在 Ubuntu 系统上安装 CockroachDB。有关其他帮助或有用信息,我们建议您查看CockroachDB官方网站。