window Cassandra环境搭建

一、下载

https://www.apache.org/dyn/closer.lua/cassandra/3.11.12/apache-cassandra-3.11.12-bin.tar.gz

二、解压,并配置环境变量

window Cassandra环境搭建_第1张图片

三、运行cassandra.bat

直接点击cassandra.bat运行,若出现屏幕一闪而过,则表示有错误。

开一个dos窗口,再运行:cassandra.bat

若出现以下问题,则表示要JDK1.8以上。


D:\JavaWeb\apache-cassandra-3.11.12\bin>cassandra.bat
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
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/ca
ssandra/service/CassandraDaemon : Unsupported major.minor version 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
2)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)


D:\JavaWeb\apache-cassandra-3.11.12\bin>

可用: set JAVA_HOME=D:\JavaWeb\Java\jdk1.8.0_301

临时设置JAVA_HOME变量。然后再重新运行:cassandra.bat

运行后:

window Cassandra环境搭建_第2张图片

四、用nodetool工具确认Cassandra已经启动

运行nodetool.bat求(也要用jdk8)

 看到,表示成功。

 五、测试

运行cqlsh.bat, 报错,检测不到Python.

D:\JavaWeb\apache-cassandra-3.11.12\bin>cqlsh.bat
Can't detect Python version!

要先安装Python2.

下载地址:

https://www.python.org/download/releases/2.7/

安装步骤参考:

https://blog.csdn.net/liangkaiping0525/article/details/80686266


D:\JavaWeb\apache-cassandra-3.11.12\pylib>python2 setup.py install
Traceback (most recent call last):
  File "setup.py", line 33, in 
    ext_modules=get_extensions(),
  File "setup.py", line 26, in get_extensions
    from Cython.Build import cythonize
ImportError: No module named Cython.Build

D:\JavaWeb\apache-cassandra-3.11.12\pylib>python2 -m cqlsh
D:\JavaWeb\Python27\python2.exe: No module named cqlsh

D:\JavaWeb\apache-cassandra-3.11.12\pylib>cd ..

D:\JavaWeb\apache-cassandra-3.11.12>cd ./bin

D:\JavaWeb\apache-cassandra-3.11.12\bin>python2 -m cqlsh

WARNING: console codepage must be set to cp65001 to support utf-8 encoding on Wi
ndows platforms.
If you experience encoding problems, change your console codepage with 'chcp 650
01' before starting cqlsh.

Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.12 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
WARNING: pyreadline dependency missing.  Install to enable tab completion.
cqlsh> CREATE KEYSPACE IF NOT EXISTS store WITH REPLICATION = { 'class' : 'Simpl
eStrategy', 'replication_factor' : '1' };
cqlsh> CREATE TABLE IF NOT EXISTS store.shopping_cart (
   ... userid text PRIMARY KEY,
   ... item_count int,
   ... last_update_timestamp timestamp
   ... );
cqlsh> INSERT INTO store.shopping_cart
   ... (userid, item_count, last_update_timestamp)
   ... VALUES ('9876', 2, toTimeStamp(now()));
cqlsh> INSERT INTO store.shopping_cart
   ... (userid, item_count, last_update_timestamp)
   ... VALUES ('1234', 5, toTimeStamp(now()));
cqlsh> SELECT * FROM store.shopping_cart;

 userid | item_count | last_update_timestamp
--------+------------+---------------------------------
   1234 |          5 | 2022-03-12 04:57:08.790000+0000
   9876 |          2 | 2022-03-12 04:57:07.482000+0000

(2 rows)
cqlsh>  INSERT INTO store.shopping_cart (userid, item_count) VALUES ('4567', 20)
;
cqlsh>  INSERT INTO store.shopping_cart (userid, item_count) VALUES ('4567', 20)
;
cqlsh> SELECT * FROM store.shopping_cart;

 userid | item_count | last_update_timestamp
--------+------------+---------------------------------
   4567 |         20 |                            null
   1234 |          5 | 2022-03-12 04:57:08.790000+0000
   9876 |          2 | 2022-03-12 04:57:07.482000+0000

(3 rows)
cqlsh>

以后:再次登录:

window Cassandra环境搭建_第3张图片

环境搭建完成后,就可以用ORM 工具Bee查询数据了.

		NameTranslateHandle.setSchemaName("store");
		Suid suid=BF.getSuid();
		List list2=suid.select(new ShoppingCart());
		Printer.printList(list2);

就4行Java代码,就是如此简单!

详细步骤参考:https://blog.csdn.net/abckingaa/article/details/123553811

Bee,互联网新时代的Java ORM工具,更快、更简单、更自动,开发速度快,运行快,更智能!

Bee让程序员/软件工程师,从手工编码中解放出来,Bee更适合智能软件制造时代!

十分钟即可入门!

立志做最懂用户的软件!

你可能感兴趣的:(DB,Bee,ORM,Cassandra,NoSQL)