1、首先从http://cassandra.apache.org/download/网站上找到cassandra,如下图所示:
windows系统下cassandra的安装方法

 

 
2、点击3.11.3跳转到下载地址,如下图所示:
windows系统下cassandra的安装方法


3、点击下载,如果浏览器无法下载可以使用迅雷直接复制地址下载,下载好的文件如下图所示:
windows系统下cassandra的安装方法
4、然后在指定目录创建一个cassandra-3.11.3文件夹,如下图所示:

windows系统下cassandra的安装方法
5、将apache-cassandra-3.11.3-bin.tar.gz压缩包中的内容解压到此目录中,如下图所示:
windows系统下cassandra的安装方法

6、配置环境变量,新建一个CASSANDRA_HOME变量,值为:D:\InstallFile\cassandra-3.11.3,如下图所示:
windows系统下cassandra的安装方法

7、在Path环境变量中在末尾添加:;%CASSANDRA_HOME%\bin;,注意分号,如下图所示:
windows系统下cassandra的安装方法

8、然后打开dos窗口可以查看是否设置成功,输入:echo %java_home%和echo %cassandra_home%,如下图所示可以打印出环境变量值说明设置成功。
windows系统下cassandra的安装方法

9、在D:\InstallFile\cassandra-3.11.3目录中新建一个data目录,如下图所示:
windows系统下cassandra的安装方法

10、找到cassandra.yaml配置文件,如下图所示:
windows系统下cassandra的安装方法

11、对该文件编辑,然后找到data_file_directories如下图所示:
windows系统下cassandra的安装方法

12、添加一数据目录,如下图所示:
windows系统下cassandra的安装方法

13、在D:\InstallFile\cassandra-3.11.3目录中新建一个commitlog目录,如下图所示:
windows系统下cassandra的安装方法

14、在cassandra.yaml配置文件中找到commitlog_directory,如下图所示:
windows系统下cassandra的安装方法

15、将commitlog_directory修改为如下图所示(注意:在saved_caches_directory:和D:\InstallFile\cassandra-3.11.3\saved_caches之间有一个空格,否则会无法解析配置文件的,此处赞不写空格,等会看启动错误):
windows系统下cassandra的安装方法

16、在D:\InstallFile\cassandra-3.11.3目录中新建一个saved_caches目录,如下图所示:
windows系统下cassandra的安装方法

17、在cassandra.yaml配置文件中找到saved_caches_directory,如下图所示:
windows系统下cassandra的安装方法

18、将saved_caches_directory修改为如下图所示(注意:在saved_caches_directory:和D:\InstallFile\cassandra-3.11.3\saved_caches之间有一个空格,否则会无法解析配置文件的):
windows系统下cassandra的安装方法

19、配置好之后保存,然后找到D:\InstallFile\cassandra-3.11.3\bin目录中的cassandra.bat文件,如下图所示(注意:启动的时候不要双击启动,否则出现错误窗口就会消失,需要打开dos窗口执行):
windows系统下cassandra的安装方法

20、打开DOS窗口,并进入到D:\InstallFile\cassandra-3.11.3\bin目录中,如下图所示:
windows系统下cassandra的安装方法

21、回车启动,会提示以下错误:

WARNING! Powershell script execution unavailable.
   Please use 'powershell Set-ExecutionPolicy Unrestricted'
   on this user-account to run cassandra with fully featured
   functionality on this platform.
Starting with legacy startup options
Starting Cassandra Server
INFO  [main] 2018-11-07 09:34:44,057 YamlConfigurationLoader.java:89 - Configuration location: file:/D:/InstallFile/cassandra-3.11.3/conf/cassandra.yaml
Exception (org.apache.cassandra.exceptions.ConfigurationException) encountered during startup: Invalid yaml: file:/D:/InstallFile/cassandra-3.11.3/conf/cassandra.yaml
 Error: while scanning a simple key; could not found expected ':';  in 'reader', line 201, column 1:
    # Enable / disable CDC functiona ...
    ^
ERROR [main] 2018-11-07 09:34:44,163 CassandraDaemon.java:708 - Exception encountered during startup: Invalid yaml: file:/D:/InstallFile/cassandra-3.11.3/conf/cassandra.yaml
 Error: while scanning a simple key; could not found expected ':';  in 'reader', line 201, column 1:
    # Enable / disable CDC functiona ...
    windows系统下cassandra的安装方法

22、出现此错误的原因就是在配置文件时存在冒号“:”后没有空格所引起的,如下图所示:
windows系统下cassandra的安装方法

23、在冒号后加个空格,如下图所示:
windows系统下cassandra的安装方法

24、在次启动即可成功,如下图所示:
windows系统下cassandra的安装方法

25、如果需要cqlsh.bat来进行连接,则需要安装python,如下图所示:
windows系统下cassandra的安装方法

26、装好python后即可打开,如下图所示(注意:要重新打开dos窗口):
windows系统下cassandra的安装方法

27、通过用户登录,cassandra的默认用户名和密码为:cassandra,如下图所示:
windows系统下cassandra的安装方法

28、查询keyspaces,输入命令:describe keyspaces;如下图所示:
windows系统下cassandra的安装方法

29、列出来的相当于关系型数据的的系统数据库名,使用:CREATE KEYSPACE IF NOT EXISTS MyCasDB WITH REPLICATION = {'class': 'SimpleStrategy','replication_factor':1};命令创建一个数据库mycasdb,如下图所示:
windows系统下cassandra的安装方法

30、在mycasdb数据库中创建一个表,首先使用use mycasdb;表示要使用此数据库,然后在使用:
windows系统下cassandra的安装方法

31、使用describe tables;查看数据库中的表,如下图所示:
windows系统下cassandra的安装方法

32、向user表中插入输入,使用:

INSERT INTO user (id,user_name) VALUES (1,'sxj');
INSERT INTO user (id,user_name) VALUES (2,'sxj12');
INSERT INTO user (id,user_name) VALUES (3,'sxj123');
INSERT INTO user (id,user_name) VALUES (4,'sxj1234');

如下图所示:
windows系统下cassandra的安装方法

33、使用查询select * from user;查询数据,如下图所示:
windows系统下cassandra的安装方法

34、删除语句:delete from user where id=2;
windows系统下cassandra的安装方法

35、在删除语句时必须加条件,否则会出现:SyntaxException:line 1:16 mismatched input ';' expecting K_WHERE,如下图所示:
windows系统下cassandra的安装方法

 

 
————————————————
版权声明:本文为CSDN博主「sxjlinux」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/sunxiaoju/article/details/83817586

相关文章:

  • 2021-12-06
  • 2021-06-26
  • 2021-10-26
  • 2022-01-16
  • 2021-11-30
  • 2021-06-09
  • 2021-07-03
  • 2021-04-20
猜你喜欢
  • 2021-05-28
  • 2022-02-09
  • 2021-12-12
  • 2021-10-28
  • 2021-06-19
  • 2022-12-23
相关资源
相似解决方案