Cassandra安装与配置
Apache Cassandra和Datastax企业级被不同组织用于存储大量数据。在安装Apache Cassandra之前,您必须具备以下事项:
- 必须拥有datastax社区版本,可以点击这里下载Cassandra3.10。
- 必须提前安装好JDK8以上版本。
- 必须提前安装好JDK。
最新版本的Java 8,要验证是否安装了正确版本的Java,请在终端上输入:
java -version
对于使用cqlsh
, 需要安装Python 2.7
(一定要使用这个版本哦)。要验证是否安装了正确版本的Python
,请在终端上输入:
python --version
如下所示 -
C:\Users\Administrator>python --version
Python 2.7.10
C:\Users\Administrator>
从二进制tar文件安装
从Apache Cassandra下载网站下载最新的稳定版本。
将文件解压到某处,如在本示例为:D:\software\apache-cassandra-3.10
,例如:
注:为了使用方便,可以将
D:\software\apache-cassandra-3.10\bin
添加到环境变量中。
进入目录D:\software\apache-cassandra-3.10\bin
,通过从命令行调用 cassandra -f
,在前台启动Cassandra
。 按“Control + C”键停止Cassandra。 在后台通过从命令行调用cassandra
启动Cassandra。 调用kill pid
或pkill -f CassandraDaemon
来停止Cassandra,其中pid
是Cassandra进程标识,可以通过调用pgrep -f CassandraDaemon
来找到它。
通过从命令行调用nodetool
状态来验证Cassandra是否正在运行。
配置文件位于conf
子目录中。
由于Cassandra,日志和数据目录分别位于日志和数据子目录中。 旧版本默认为/var/log/cassandra
和/var/lib/cassandra
。 因此,有必要以root权限启动Cassandra,或者将conf/cassandra.yaml
更改为使用当前用户拥有的目录,如下文有关更改目录位置的部分所述。
现在我们来一步步地演示上面的命令,首先启动 cassandra , 在前台启动Cassandra
使用以下命令 -
D:\software\apache-cassandra-3.10\bin> cassandra -f
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
.... ....
INFO [main] 2017-04-17 22:35:51,658 Server.java:155 - Using Netty Version: [netty-buffer=netty-buffer-4.0.39.Final.38bdf86, netty-codec=netty-codec-4.0.39.Final.38bdf86, netty-codec-haproxy=netty-codec-haproxy-4.0.39.Final.38bdf86, netty-codec-http=netty-codec-http-4.0.39.Final.38bdf86, netty-codec-socks=netty-codec-socks-4.0.39.Final.38bdf86, netty-common=netty-common-4.0.39.Final.38bdf86, netty-handler=netty-handler-4.0.39.Final.38bdf86, netty-tcnative=netty-tcnative-1.1.33.Fork19.fe4816e, netty-transport=netty-transport-4.0.39.Final.38bdf86, netty-transport-native-epoll=netty-transport-native-epoll-4.0.39.Final.38bdf86, netty-transport-rxtx=netty-transport-rxtx-4.0.39.Final.38bdf86, netty-transport-sctp=netty-transport-sctp-4.0.39.Final.38bdf86, netty-transport-udt=netty-transport-udt-4.0.39.Final.38bdf86]
INFO [main] 2017-04-17 22:35:51,677 Server.java:156 - Starting listening for CQL clients on localhost/127.0.0.1:9042 (unencrypted)...
INFO [main] 2017-04-17 22:35:51,919 CassandraDaemon.java:528 - Not starting RPC server as requested. Use JMX (StorageService->startRPCServer()) or nodetool (enablethrift) to start it
这就启动了。。。
按“Control + C”键停止Cassandra。接下来演示在后台通过从命令行调用cassandra
启动Cassandra。
D:\software\apache-cassandra-3.10\bin> cassandra
... ...
INFO [main] 2017-04-17 22:37:38,985 ColumnFamilyStore.java:406 - Initializing system.schema_usertypes
INFO [main] 2017-04-17 22:37:39,002 ColumnFamilyStore.java:406 - Initializing system.schema_functions
INFO [main] 2017-04-17 22:37:39,042 ColumnFamilyStore.java:406 - Initializing system.schema_aggregates
INFO [main] 2017-04-17 22:37:39,046 ViewManager.java:137 - Not submitting build tasks for views in keyspace system as storage service is not initialized
INFO [main] 2017-04-17 22:37:39,614 ApproximateTime.java:44 - Scheduling approximate time-check task with a precision of 10 milliseconds
... ...
INFO [main] 2017-04-17 22:37:56,101 Server.java:155 - Using Netty Version: [netty-buffer=netty-buffer-4.0.39.Final.38bdf86, netty-codec=netty-codec-4.0.39.Final.38bdf86, netty-codec-haproxy=netty-codec-haproxy-4.0.39.Final.38bdf86, netty-codec-http=netty-codec-http-4.0.39.Final.38bdf86, netty-codec-socks=netty-codec-socks-4.0.39.Final.38bdf86, netty-common=netty-common-4.0.39.Final.38bdf86, netty-handler=netty-handler-4.0.39.Final.38bdf86, netty-tcnative=netty-tcnative-1.1.33.Fork19.fe4816e, netty-transport=netty-transport-4.0.39.Final.38bdf86, netty-transport-native-epoll=netty-transport-native-epoll-4.0.39.Final.38bdf86, netty-transport-rxtx=netty-transport-rxtx-4.0.39.Final.38bdf86, netty-transport-sctp=netty-transport-sctp-4.0.39.Final.38bdf86, netty-transport-udt=netty-transport-udt-4.0.39.Final.38bdf86]
INFO [main] 2017-04-17 22:37:56,128 Server.java:156 - Starting listening for CQL clients on localhost/127.0.0.1:9042 (unencrypted)...
INFO [main] 2017-04-17 22:37:56,427 CassandraDaemon.java:528 - Not starting RPC server as requested. Use JMX (StorageService->startRPCServer()) or nodetool (enablethrift) to start it
如下图所示 -
要运行Cassandra shell,重新启动一个命令行窗口并输入cqlsh
命令,您将看到命令行执行的结果以下:
D:\software\apache-cassandra-3.10\bin> cqlsh
WARNING: console codepage must be set to cp65001 to support utf-8 encoding on Windows platforms.
If you experience encoding problems, change your console codepage with 'chcp 65001' before starting cqlsh.
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.10 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
WARNING: pyreadline dependency missing. Install to enable tab completion.
cqlsh>