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 pidpkill -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安裝與配置

要運行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>