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 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>