windows系统下cassandra的安装方法

1、首先从http://cassandra.apache.org/download/网站上找到cassandra,如下图所示:

windows系统下cassandra的安装方法_第1张图片

2、点击3.11.3跳转到下载地址,如下图所示:

windows系统下cassandra的安装方法_第2张图片

3、点击下载,如果浏览器无法下载可以使用迅雷直接复制地址下载,下载好的文件如下图所示:

4、然后在指定目录创建一个cassandra-3.11.3文件夹,如下图所示:

windows系统下cassandra的安装方法_第3张图片

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

windows系统下cassandra的安装方法_第4张图片

6、配置环境变量,新建一个CASSANDRA_HOME变量,值为:D:\InstallFile\cassandra-3.11.3,如下图所示:

windows系统下cassandra的安装方法_第5张图片

7、在Path环境变量中在末尾添加:;%CASSANDRA_HOME%\bin;,注意分号,如下图所示:

windows系统下cassandra的安装方法_第6张图片

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

windows系统下cassandra的安装方法_第7张图片

9、在D:\InstallFile\cassandra-3.11.3目录中新建一个data目录,如下图所示:

windows系统下cassandra的安装方法_第8张图片

10、找到cassandra.yaml配置文件,如下图所示:

windows系统下cassandra的安装方法_第9张图片

 

11、对该文件编辑,然后找到data_file_directories如下图所示:

windows系统下cassandra的安装方法_第10张图片

12、添加一数据目录,如下图所示:

windows系统下cassandra的安装方法_第11张图片

13、在D:\InstallFile\cassandra-3.11.3目录中新建一个commitlog目录,如下图所示:

windows系统下cassandra的安装方法_第12张图片

14、在cassandra.yaml配置文件中找到commitlog_directory,如下图所示:

windows系统下cassandra的安装方法_第13张图片

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

windows系统下cassandra的安装方法_第14张图片

16、在D:\InstallFile\cassandra-3.11.3目录中新建一个saved_caches目录,如下图所示:

windows系统下cassandra的安装方法_第15张图片

17、在cassandra.yaml配置文件中找到saved_caches_directory,如下图所示:

windows系统下cassandra的安装方法_第16张图片

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

windows系统下cassandra的安装方法_第17张图片

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

windows系统下cassandra的安装方法_第18张图片

20、打开DOS窗口,并进入到D:\InstallFile\cassandra-3.11.3\bin目录中,如下图所示:

windows系统下cassandra的安装方法_第19张图片

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的安装方法_第20张图片

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

windows系统下cassandra的安装方法_第21张图片

23、在冒号后加个空格,如下图所示:

windows系统下cassandra的安装方法_第22张图片

24、在次启动即可成功,如下图所示:

windows系统下cassandra的安装方法_第23张图片

25、如果需要cqlsh.bat来进行连接,则需要安装python,如下图所示:

windows系统下cassandra的安装方法_第24张图片

26、装好python后即可打开,如下图所示(注意:要重新打开dos窗口):

windows系统下cassandra的安装方法_第25张图片

27、通过用户登录,cassandra的默认用户名和密码为:cassandra,如下图所示:

windows系统下cassandra的安装方法_第26张图片

28、查询keyspaces,输入命令:describe keyspaces;如下图所示:

windows系统下cassandra的安装方法_第27张图片

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

30、在mycasdb数据库中创建一个表,首先使用use mycasdb;表示要使用此数据库,然后在使用:

31、使用describe tables;查看数据库中的表,如下图所示:

windows系统下cassandra的安装方法_第28张图片

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');

如下图所示:

33、使用查询select * from user;查询数据,如下图所示:

windows系统下cassandra的安装方法_第29张图片

34、删除语句:delete from user where id=2;

windows系统下cassandra的安装方法_第30张图片

35、在删除语句时必须加条件,否则会出现:SyntaxException:line 1:16 mismatched input ';' expecting K_WHERE,如下图所示:

你可能感兴趣的:(windows系统下cassandra的安装方法)