Apache Cassandra是一个强大的开源NoSQL数据库管理系统,旨在处理分布式服务器上的大量数据。它提供高可用性、容错和可伸缩性的能力使其成为处理大规模数据存储和检索的组织的首选。
在 Debian 12 书虫上安装 Apache Cassandra
第 1 步。在我们安装任何软件之前,通过在终端中运行以下命令来确保您的系统是最新的非常重要:apt
<span class="pln">sudo apt update</span>
此命令将刷新存储库,允许您安装最新版本的软件包。
第 2 步。安装所需的软件。
Cassandra 需要 Java 才能运行。安装 OpenJDK 11,它是 Cassandra 的兼容版本:
<span class="pln">sudo apt install openjdk</span><span class="pun">-</span><span class="lit">11</span><span class="pun">-</span><span class="pln">jdk</span>
大多数Linux发行版都预装了Python。使用以下方法检查您的 Python 版本:
<span class="pln">python3 </span><span class="pun">--</span><span class="pln">version</span>
如果未安装 Python,则可以使用以下方法安装它:
<span class="pln">sudo apt install python3</span>
第 3 步。在 Debian 12 上安装 Apache Cassandra。
现在用于下载 Cassandra 二进制发行版。替换为您选择的版本:wget
<version>
<span class="pln">wget https</span><span class="pun">:</span><span class="com">//www.apache.org/dyn/closer.lua/cassandra/4.1.3/apache-cassandra-4.1.3-bin.tar.gz</span>
解压缩下载的文件:
<span class="pln">tar </span><span class="pun">-</span><span class="pln">xzvf apache</span><span class="pun">-</span><span class="pln">cassandra</span><span class="pun">-</span><span class="lit">4.1</span><span class="pun">.</span><span class="lit">3</span><span class="pun">-</span><span class="pln">bin</span><span class="pun">.</span><span class="pln">tar</span><span class="pun">.</span><span class="pln">gz</span>
使用以下命令将解压缩的目录移动到该目录:/opt
<span class="pln">sudo mv apache</span><span class="pun">-</span><span class="pln">cassandra</span><span class="pun">-</span><span class="lit">4.1</span><span class="pun">.</span><span class="lit">3</span> <span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span>
使用以下命令创建指向 Cassandra 目录的符号链接:
<span class="pln">sudo ln </span><span class="pun">-</span><span class="pln">s </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">apache</span><span class="pun">-</span><span class="pln">cassandra</span><span class="pun">-</span><span class="lit">4.1</span><span class="pun">.</span><span class="lit">3</span> <span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">cassandra</span>
将以下行添加到 /etc/environment 文件的末尾:
<span class="pln">CASSANDRA_HOME</span><span class="pun">=</span><span class="str">"/opt/cassandra"</span><span class="pln"> PATH</span><span class="pun">=</span><span class="str">"$PATH:$CASSANDRA_HOME/bin"</span>
使用以下命令重新加载环境变量:
<span class="pln">source </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">environment</span>
使用以下命令启动 Cassandra 服务:
<span class="pln">sudo </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">cassandra</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">cassandra</span>
使用以下命令验证 Cassandra 服务是否正在运行:
<span class="pln">nodetool status</span>
如果服务正在运行,则应看到类似于以下内容的输出:
<span class="typ">Datacenter</span><span class="pun">:</span><span class="pln"> datacenter1 </span><span class="pun">=======================</span> <span class="typ">Status</span><span class="pun">=</span><span class="typ">Up</span><span class="pun">/</span><span class="typ">Down</span> <span class="pun">|</span><span class="str">/ State=Normal/</span><span class="typ">Leaving</span><span class="pun">/</span><span class="typ">Joining</span><span class="pun">/</span><span class="typ">Moving</span> <span class="pun">--</span> <span class="typ">Address</span> <span class="typ">Load</span> <span class="typ">Tokens</span> <span class="typ">Owns</span> <span class="typ">Host</span><span class="pln"> ID </span><span class="typ">Rack</span><span class="pln"> UN </span><span class="lit">127.0</span><span class="pun">.</span><span class="lit">0.1</span> <span class="lit">1.22</span> <span class="typ">MiB</span> <span class="lit">256</span> <span class="pun">?</span> <span class="lit">12345678</span><span class="pun">-</span><span class="lit">1234</span><span class="pun">-</span><span class="lit">1234</span><span class="pun">-</span><span class="lit">1234</span><span class="pun">-</span><span class="lit">123456789012</span><span class="pln"> rack1</span>
第 4 步。创建系统服务单元。
要将 Cassandra 作为服务进行管理,请创建一个单元文件:systemd
<span class="pln">sudo nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">systemd</span><span class="pun">/</span><span class="pln">system</span><span class="pun">/</span><span class="pln">cassandra</span><span class="pun">.</span><span class="pln">service</span>
将以下行添加到文件中:
<span class="pun">[</span><span class="typ">Unit</span><span class="pun">]</span> <span class="typ">Description</span><span class="pun">=</span><span class="typ">Apache</span> <span class="typ">Cassandra</span><span class="pln"> database server </span><span class="typ">After</span><span class="pun">=</span><span class="pln">network</span><span class="pun">.</span><span class="pln">target </span><span class="pun">[</span><span class="typ">Service</span><span class="pun">]</span> <span class="typ">Type</span><span class="pun">=</span><span class="pln">forking </span><span class="typ">User</span><span class="pun">=</span><span class="pln">cassandra </span><span class="typ">Group</span><span class="pun">=</span><span class="pln">cassandra </span><span class="typ">ExecStart</span><span class="pun">=</span><span class="str">/opt/</span><span class="pln">cassandra</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">cassandra </span><span class="pun">-</span><span class="pln">p </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">run</span><span class="pun">/</span><span class="pln">cassandra</span><span class="pun">/</span><span class="pln">cassandra</span><span class="pun">.</span><span class="pln">pid </span><span class="typ">ExecStop</span><span class="pun">=</span><span class="str">/opt/</span><span class="pln">cassandra</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">nodetool stop </span><span class="typ">Restart</span><span class="pun">=</span><span class="pln">on</span><span class="pun">-</span><span class="pln">failure </span><span class="pun">[</span><span class="typ">Install</span><span class="pun">]</span> <span class="typ">WantedBy</span><span class="pun">=</span><span class="pln">multi</span><span class="pun">-</span><span class="pln">user</span><span class="pun">.</span><span class="pln">target</span>
使用以下命令重新加载守护程序:systemd
<span class="pln">sudo systemctl daemon</span><span class="pun">-</span><span class="pln">reload</span>
使用以下命令重新加载守护程序:systemd
<span class="pln">sudo systemctl start cassandra</span>
使用以下命令验证 Cassandra 服务是否正在运行:
<span class="pln">sudo systemctl status cassandra</span>
第5步。使用 nodetool 监控 Cassandra。
Nodetool是一个用于监视和管理Cassandra的命令行实用程序。常见的节点工具命令包括:
-
nodetool status
:集群状态。nodetool tpstats
:线程池统计信息。nodetool cfstats
:列族统计信息。
第 6 步。在 Ubuntu 22.04 上访问 Apache Cassandra。
这是用Python编写的命令行工具,用于执行Cassandra查询语言(CQL)命令。它是Cassandra客户端命令行实用程序。您可以通过键入以下内容连接到数据库:cqlsh
cqlsh
<span class="pln">cqlsh</span>
感謝您使用這本教鬥在 Debian 12 Bookworm 上安裝最新版本的 Apache Cassandra NoSQL 資料庫。如需其他帮助或有用信息,我们建议您查看 Cassandra 官方网站。