首页 > 系统相关 >在Windows上运行单节点的Cassandra

在Windows上运行单节点的Cassandra

时间:2022-11-28 14:00:12浏览次数:69  
标签:Cassandra Windows thrift using new cassandra 节点 Thrift

Cassandra可以安裝在很多系统上, 我是安装在windows server 2008 R2上,安装相当简单,只要把下载下来的压缩包解压缩放到一个目录下就可以了,这里主要是记录下使用体验: Ca...

Cassandra可以安裝在很多系统上, 我是安装在windows server 2008 R2上,安装相当简单,只要把下载下来的压缩包解压缩放到一个目录下就可以了,这里主要是记录下使用体验:

Cassandra官网: ​​http://cassandra.apache.org/​​​,下载页面 ​​http://cassandra.apache.org/download/​

Cassandra用java开发的,要求安装JVM 1.6以上,推荐 Version 6 Update 23  到Java官网下载 ​​http://www.java.com/zh_CN/download/manual.jsp#win​​,要注意的是,Cassandra在windows上安装要设置两个系统参数:

  • JAVA_HOME : 一般是 C:\Program Files\Java\jre6
  • CASSANDRA_HOME : 看你解压缩到那个位置就写那个,我的是D:\apache-cassandra-0.7.0-rc4\

到Cassandra的bin下面运行cassandra.bat就会启动了,大概是这个样子:

在Windows上运行单节点的Cassandra_解压缩

在Windows上运行单节点的Cassandra_解压缩_02

在windows上Cassandra 不知道怎么设置成按Windows 服务方式运行,所以就另外开一个命令行来操作。

要确认Cassandra有没有再跑,可以用nodetool.bat这个工具进行确认。

在Windows上运行单节点的Cassandra_apache_03

因为只有一个节点,所以啥东西都不用配,直接用默认的 keyspace就可以玩了,Cassandra 提供了一个叫做 Cassandra CLI 的工具可以直接输入命令,运行cassadnra-cli.bat 就可以了了。我们就拿这个来试一下,Cassandra CLI 常用的命令有 set get show count,先拿set和get来做示例,还有quit/exit是离开 Cassandra CLI,也可以用 help 去查可用的命令,记得运行 cassandra-cli.bat 时要加个参数 --host 指定 cassandra node 的位置,不然就玩不转了。

在Windows上运行单节点的Cassandra_解压缩_04

在Windows上运行单节点的Cassandra_java_05

然后,我们可以参考README.txt文件中提供的范例进行测试。Cassandra 0.7.0 rc3 已经没有了默认的Keyspace (EX:Keyspace1) ,使用之前需要创建。set的语法大概长的像下面这样:

1.set Keyspace1.Standard1['geffzhang']['blog'] = 'http://www.dotnetting.cn'  
02. \ \ \ \ \
03. \ \ \_ key \ \_ value
04. \ \ \_ column
05. \_ keyspace \_ column family
就按照上面的语法来加几个数据进去,然后用get把数据拉出来看看

在Windows上运行单节点的Cassandra_apache_06




Cassandra在设计的时候,就是支持Thrift的,这意味着我们可以使用多种语言开发。对于Cassandra的开发本身而言,这是使用Thrift的好处:支持多语言。坏处也是显而易见的:Thrift API功能过于简单,不具备在生产环境使用的条件。

Cassandra 建议用户在它们的程序内用高阶API与Cassandrar进行通信,以C#来说,像是​​FluentCassandra​​​ 或 ​​Aquiles​​​。但是你也可以用官方出的最低阶API - ​​Thrift​​ 来与Cassandra沟通。

Thrift这个是Cassandra自带的最简单的一类API,这个文件在apache-cassandra-0.5.1.中包含了。可以直接使用。我们也可以自己安装一个Thrift,然后通过cassandra.thrift文件自动生成。如果你要使用Cassandra,那么我们必须要了解Thrift API,毕竟所有的其他更加高级的API都是基于这个来包装的。

Step 1 : Download Thrift

To ​​Thrift Download Page​​ get the latest stable release , for me , that is thrift-0.5.0.tar.gz (use for making thrift.dll) and Thrift compiler for Windows (thrift-0.5.0.exe) (for making Apache.Cassandra.dll).

Step 2 : Gnerate Thrift DLL

Unzip thrift-0.5.0.tar.gz (or new version) , find Thrift.csproj(or Thrift.sln) in \thrift\lib\csharp\src\

In Visual Studio , right click on [Thrift] -> [Build] , then you will get Thrift.dll in \bin\Debug\ (if no error)

Step 3 : Generate Apache.Cassandra DLL

Copy Thrift compiler for Windows (thrift-0.5.0.exe) to Cassandra Folder\interface\ , execute following command
  thrift-0.5.0.exe --gen csharp cassandra.thrift 

In principle, it should be generate a new folder called "gen-csharp", but dunno why , I had an error when I running it with version 0.6.8 , so I change cassandra version to 0.7.0 rc3 , then it passed.

After get C# source code , using Visual Studio create a new Class Libary project , then add all files in gen-csharp\Apache\Cassandra\  folder. Now build the project , maybe you will got 19~26 error, but don't worry, just some word-casing problem , do some upper case job can fixed it.
(EX: .count -> .Count )

Step 4 : Connecting Cassandra with C#

Add Thrift.dll and Apache.Cassandra.dll to your refence , you can use windows forms/console application/web application/or other , it doesn't matter .

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Apache.Cassandra;
using Thrift.Transport;
using Thrift.Protocol;

namespace Cassandra_Console
{
class Program
{
static void Main(string[] args)
{
TTransport frameTransport = new TFramedTransport(new TSocket("localhost", 9160));
TProtocol protocol = new TBinaryProtocol(transport);
TProtocol frameProtocol = new TBinaryProtocol(frameTransport);

Cassandra.Client client = new Cassandra.Client(frameProtocol, frameProtocol);

frameTransport.Open();
Console.WriteLine("Opening connection");

//for 0.7.0 , need select keyspace at first
client.set_keyspace("Keyspace1");
Console.WriteLine("keyspace set to Keyspace1");

System.Text.Encoding utf8Encoding = System.Text.Encoding.UTF8;

long timeStamp = DateTime.Now.Millisecond;

ColumnPath nameColumnPath = new ColumnPath()
{
Column_family = "Standard2",
Column = utf8Encoding.GetBytes("name")
};

ColumnParent nameColumnParent = new ColumnParent()
{
Column_family = "Standard2"
};

Column nameColume = new Column()
{
Name = utf8Encoding.GetBytes("name"),
Value = utf8Encoding.GetBytes("Geff zhang"),
Timestamp=timeStamp
};

Console.WriteLine("Inserting name columns");

//insert data
client.insert(utf8Encoding.GetBytes("Geff"),
nameColumnParent,
nameColume,
ConsistencyLevel.ONE);

//using the key to get column 'name'
ColumnOrSuperColumn returnedColumn = client.get(utf8Encoding.GetBytes("Geff"), nameColumnPath, ConsistencyLevel.ONE);
Console.WriteLine("Column Data in Keyspace1/Standard1: name: {0}, value: {1}",
utf8Encoding.GetString(returnedColumn.Column.Name),
utf8Encoding.GetString(returnedColumn.Column.Value));

Console.WriteLine("Closing connection");
frameTransport.Close();

Console.ReadLine();

}
}
}


标签:Cassandra,Windows,thrift,using,new,cassandra,节点,Thrift
From: https://blog.51cto.com/shanyou/5891106

相关文章

  • windows关闭端口方法
    https://blog.csdn.net/weixin_56306210/article/details/125642902在介绍各种端口的作用前,这里先介绍一下在Windows中如何关闭/打开端口,因为默认的情况下,有很多不安全的......
  • windows error LNK2019
    温馨提示,请使用ctrl+F进行快速查找ws2_32.liberrorLNK2001:无法解析的外部符号__imp_htonserrorLNK2001:无法解析的外部符号__imp_ntohlerrorLNK2001:无法解析......
  • 处理问题:windows server 2016由于没有远程桌面授权服务器可以提供许可证,远程会话被中
      windowsserver可以多用户同时登陆,默认最大远程登录数量为2,如果有更多人需要同时远程登录,则需要安装远程桌面授权服务,第一次安装后,免费期为120天,超过则无法正常远程......
  • PGL图学习之项目实践(UniMP算法实现论文节点分类、新冠疫苗项目实战,助力疫情)[系列九]
    原项目链接:https://aistudio.baidu.com/aistudio/projectdetail/5100049?contributionType=11.图学习技术与应用图是一个复杂世界的通用语言,社交网络中人与人之间的连接......
  • Windows office 密钥卸载
    介绍:设备上多次安装office和使用激活软件会造成同一软件有不同版本的秘钥,造成软件不能灵活的更新和使用最新的功能体验。经过多次的卸载安装,发现可以通过卸载不同版本的秘钥......
  • windows环境下,安装 telegraf ,监控服务器cup /disk 等
    十年河东,十年河西,莫欺少年穷学无止境,精益求精时序数据库对windows的支持真的不友好,搞了半天,最终功夫不负有心人,索性记录下来,省的其他人再走弯路1、下载influxdb​​https://......
  • Windows游戏找不到了怎么办?
      大家有的时候,可能是不慎操作,或是某些新装的Windows,会发现那些经典的游戏不见了,那它们去哪了呢?是长腿跑了?还是Windows偷工减料?都不是,让巩固来教你们把他们找出来......
  • Windows系统下PhpStorm+Xdebug安装与调试
    环境说明:系统:Windows10PhpStorm:2019.3.2PHP版本:7.3.21Xdebug版本 :2.7.2一、Xdebug介绍官网地址:https://xdebug.org/1.1什么是XdebugXdebug是一个开放源代码的......
  • windows防火墙
    Windows防火墙工具1.FirewallAppBlocker下载地址:https://www.sordum.org/8125/firewall-app-blocker-fab-v1-9/Peerblock下载地址:http://baoku.360.cn/soft/show/a......
  • Windows内核对象
    Windows内核对象Windows内核中外物皆对象,并通过对象管理器(内核组件)管理这些对象。例如进程内核对象,线程内核对象,文件内核对象,设备内核对象,互斥量内核对象等,每一个对象都有......