Cassandra系列-1-安裝-啟動

redhouser發表於2012-05-31

擦作系統版本:
[root@rhel5 lib]# uname -a
Linux rhel5 2.6.18-8.el5xen #1 SMP Thu Mar 15 21:02:53 EDT 2007 i686 i686 i386 GNU/Linux

1環境準備
1.1使用者準備
--logon as root
mkdir -p /nosql/cassandra

groupadd nosqlg
useradd nosql -g nosqlg

chown -R nosql:nosqlg /nosql/cassandra
chmod -R 755 /nosql/cassandra

passwd nosql

1.2 java準備
使用java version "1.6.0_06" 時報錯,參見附錄1。

在上下載jre1.7:
以nosql使用者ftp到/nosql/cassandra
tar -zxvf jre-7u4-linux-i586[1].tar.gz

1.3 修改使用者profile
vi .bash_profile
-----------add following lines
JAVA_HOME=/nosql/cassandra/jre1.7.0_04
export JAVA_HOME

PATH=$JAVA_HOME/bin:$PATH:$HOME/bin
export PATH
------------

. ./.bash_profile

[nosql@rhel5 bin]$ java -version
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b20)                                                                                
Java HotSpot(TM) Server VM (build 23.0-b21, mixed mode)

2軟體安裝、配置
2.1下載軟體
從下載apache-cassandra-1.0.10-bin.tar.gz

2.2ftp
以nosql使用者ftp到/nosql/cassandra

2.3解壓檔案
--logon as nosql:
[nosql@rhel5]$ cd /nosql/cassandra

[nosql@rhel5 cassandra]$tar -xzf apache-cassandra-1.0.10-bin.tar.gz
[nosql@rhel5 cassandra]$ ls -lrt
total 16
drwxr-xr-x 8 nosql nosqlg 4096 May 25 15:50 apache-cassandra-1.0.10

[nosql@rhel5 cassandra]$ cd a*
[nosql@rhel5 apache-cassandra-1.0.10]$ ls -lrt
total 192
-rw-r--r-- 1 nosql nosqlg   4104 May  5  2012 README.txt
drwxr-xr-x 3 nosql nosqlg   4096 May  5  2012 pylib
-rw-r--r-- 1 nosql nosqlg   1378 May  5  2012 NOTICE.txt
-rw-r--r-- 1 nosql nosqlg  30376 May  5  2012 NEWS.txt
-rw-r--r-- 1 nosql nosqlg  11609 May  5  2012 LICENSE.txt
-rw-r--r-- 1 nosql nosqlg 106935 May  5  2012 CHANGES.txt
drwxr-xr-x 2 nosql nosqlg   4096 May 25 15:50 interface
drwxr-xr-x 3 nosql nosqlg   4096 May 25 15:50 lib
drwxr-xr-x 4 nosql nosqlg   4096 May 25 15:50 javadoc
drwxr-xr-x 2 nosql nosqlg   4096 May 25 15:50 bin
drwxr-xr-x 2 nosql nosqlg   4096 May 25 16:09 conf

2.4配置cassandra
[nosql@rhel5 apache-cassandra-1.0.10]$ cd conf
[nosql@rhel5 conf]$ ls -lrt
total 48
-rw-r--r-- 1 nosql nosqlg   298 May  5  2012 README.txt
-rw-r--r-- 1 nosql nosqlg  1228 May  5  2012 log4j-tools.properties
-rw-r--r-- 1 nosql nosqlg  1850 May  5  2012 log4j-server.properties
-rw-r--r-- 1 nosql nosqlg 21223 May  5  2012 cassandra.yaml
-rw-r--r-- 1 nosql nosqlg  1358 May  5  2012 cassandra-topology.properties
-rw-r--r-- 1 nosql nosqlg  7653 May  5  2012 cassandra-env.sh

2.4.1配置cassandra.yaml
[nosql@rhel5 conf]$vi cassandra.yaml
----------------------------------------------------------
# directories where Cassandra should store data on disk.
data_file_directories:
    - /nosql/cassandra/data

# commit log
commitlog_directory: /nosql/cassandra/commitlog

# saved caches
saved_caches_directory: /nosql/cassandra/saved_caches

cluster_name: 'MyCluster'

# TCP port, for commands and data
storage_port: 7000

# port for Thrift to listen for clients on
rpc_port: 9160
----------------------------------------------------------

說明:設定initial_token:0報錯,保留空即可,參見附錄2。

2.4.2配置log4j-server.properties
[nosql@rhel5 conf]$ vi log4j-server.properties
----------------------------------------------------------
# Edit the next line to point to your logs directory
log4j.appender.R.File=/nosql/cassandra/system.log
----------------------------------------------------------

2.4.3配置cassandra-env.sh
[nosql@rhel5 conf]$ vi cassandra-env.sh
MAX_HEAP_SIZE根據系統實體記憶體設定;HEAP_NEWSIZE設定為MAX_HEAP_SIZE/4;這兩個引數會自動設定,可以去掉註釋指定具體值.
----------------------------------------------------------
MAX_HEAP_SIZE="400M"
HEAP_NEWSIZE="100M"
----------------------------------------------------------

3 啟動
[nosql@rhel5 conf]$ cd ../bin
[nosql@rhel5 bin]$ ls -lrt
total 144
-rwxr-xr-x 1 nosql nosqlg  1175 May  5  2012 stop-server
-rwxr-xr-x 1 nosql nosqlg  1672 May  5  2012 sstableloader
-rwxr-xr-x 1 nosql nosqlg  1780 May  5  2012 sstablekeys
-rwxr-xr-x 1 nosql nosqlg  1697 May  5  2012 sstable2json
-rwxr-xr-x 1 nosql nosqlg  1859 May  5  2012 nodetool.bat
-rwxr-xr-x 1 nosql nosqlg  2165 May  5  2012 nodetool
-rwxr-xr-x 1 nosql nosqlg  1696 May  5  2012 json2sstable
-rwxr-xr-x 1 nosql nosqlg   974 May  5  2012 cqlshrc.sample
-rwxr-xr-x 1 nosql nosqlg 71811 May  5  2012 cqlsh
-rw-r--r-- 1 nosql nosqlg  1575 May  5  2012 cassandra.in.sh
-rwxr-xr-x 1 nosql nosqlg  1667 May  5  2012 cassandra-cli
-rwxr-xr-x 1 nosql nosqlg  6440 May  5  2012 cassandra

3.1前端啟動
[nosql@rhel5 bin]$ ./cassandra -f
 INFO 20:22:32,933 Logging initialized
 INFO 20:22:32,943 JVM vendor/version: Java HotSpot(TM) Server VM/1.7.0_04
 INFO 20:22:32,943 Heap size: 245366784/245366784
 INFO 20:22:32,944 Classpath: ./../conf:./../build/classes/main:./../build/classes/thrift:./../lib/antlr-3.2.jar:./../lib/apache-car
 INFO 20:22:32,947 JNA not found. Native methods will be disabled.
 INFO 20:22:32,966 Loading settings from file:/nosql/cassandra/apache-cassandra-1.0.10/conf/cassandra.yaml
 INFO 20:22:33,209 DiskAccessMode 'auto' determined to be standard, indexAccessMode is standard
 INFO 20:22:33,227 Global memtable threshold is enabled at 78MB                                                                     P
 INFO 20:22:33,708 Creating new commitlog segment /nosql/cassandra/commitlog/CommitLog-1401020553708.log                            R
 INFO 20:22:33,742 Couldn't detect any schema definitions in local storage.                                                         W
 INFO 20:22:33,744 Found table data in data directories. Consider using the CLI to define your schema.                              t
 INFO 20:22:33,768 No commitlog files found; skipping replay                                                                        u
 INFO 20:22:33,778 Cassandra version: 1.0.10                                                                                        7
 INFO 20:22:33,778 Thrift API version: 19.20.0                                                                                      ?
 INFO 20:22:33,779 Loading persisted ring state                                                                                     7
 INFO 20:22:33,787 Starting up server gossip                                                                                        ?
 INFO 20:22:33,818 Enqueuing flush of serialized/live bytes, 3 ops)
 INFO 20:22:33,820 Writing serialized/live bytes, 3 ops)                                     7
 INFO 20:22:33,874 Completed flushing /nosql/cassandra/data/system/LocationInfo-hd-1-Data.db (231 bytes)                            7
 INFO 20:22:33,910 Starting Messaging Service on port 7000                                                                          7
 INFO 20:22:33,923 This node will not auto bootstrap because it is configured to be a seed node.                                    7
 WARN 20:22:33,939 Generated random token 159495876378727078405590336465058029385. Random tokens will result in an unbalanced ring;s7
 INFO 20:22:33,944 Enqueuing flush of serialized/live bytes, 2 ops)                            ?
 INFO 20:22:33,945 Writing serialized/live bytes, 2 ops)                                        
 INFO 20:22:33,955 Completed flushing /nosql/cassandra/data/system/LocationInfo-hd-2-Data.db (163 bytes)
 INFO 20:22:33,961 Node localhost/127.0.0.1 state jump to normal
 INFO 20:22:33,963 Bootstrap/Replace/Move completed! Now serving reads.
 INFO 20:22:33,965 Will not load MX4J, mx4j-tools.jar is not in the classpath
 INFO 20:22:34,041 Binding thrift service to localhost/127.0.0.1:9160
 INFO 20:22:34,049 Using TFastFramedTransport with a max frame. size of 15728640 bytes.
 INFO 20:22:34,057 Using synchronous/threadpool thrift server on localhost/127.0.0.1 : 9160
 INFO 20:22:34,058 Listening for thrift clients...
 INFO 20:23:22,498 Stop listening to thrift clients
 INFO 20:23:22,499 Waiting for messaging service to quiesce
 INFO 20:23:22,500 MessagingService shutting down server thread.


[nosql@rhel5 cassandra]$ pwd
/nosql/cassandra
[nosql@rhel5 cassandra]$ ls -rlt
total 32
drwxr-xr-x 6 nosql nosqlg 4096 Apr 12  2012 jre1.7.0_04
drwxr-xr-x 8 nosql nosqlg 4096 May 25 15:50 apache-cassandra-1.0.10
drwxr-xr-x 2 nosql nosqlg 4096 May 25 20:22 saved_caches
drwxr-xr-x 3 nosql nosqlg 4096 May 25 20:22 data
drwxr-xr-x 2 nosql nosqlg 4096 May 25 20:22 commitlog
-rw-r--r-- 1 nosql nosqlg 8676 May 25 20:23 system.log

--&gt自動建立了data,commitlog,saved_caches目錄,system.log日誌

4.2後臺啟動
[nosql@rhel5 bin]$ ./cassandra

[nosql@rhel5 bin]$ ps -ef|grep nosql
nosql    30613     1  1 20:32 pts/2    00:00:02
/nosql/cassandra/jre1.7.0_04/bin/java
-ea
-javaagent:/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/jamm-0.2.5.jar
-XX:+UseThreadPriorities
-XX:ThreadPriorityPolicy=42
-Xms240M
-Xmx240M
-Xmn60M
-XX:+HeapDumpOnOutOfMemoryError
-Xss128k
-XX:+UseParNewGC
-XX:+UseConcMarkSweepGC
-XX:+CMSParallelRemarkEnabled
-XX:SurvivorRatio=8
-XX:MaxTenuringThreshold=1
-XX:CMSInitiatingOccupancyFraction=75
-XX:+UseCMSInitiatingOccupancyOnly
-Djava.net.preferIPv4Stack=true
-Dcom.sun.management.jmxremote.port=7199
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dlog4j.configuration=log4j-server.properties
-Dlog4j.defaultInitOverride=true
-cp /nosql/cassandra/apache-cassandra-1.0.10/bin/../conf
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../build/classes/main
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../build/classes/thrift
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/antlr-3.2.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/apache-cassandra-1.0.10.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/apache-cassandra-clientutil-1.0.10.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/apache-cassandra-thrift-1.0.10.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/avro-1.4.0-fixes.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/avro-1.4.0-sources-fixes.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/commons-cli-1.1.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/commons-codec-1.2.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/commons-lang-2.4.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/compress-lzf-0.8.4.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/concurrentlinkedhashmap-lru-1.2.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/guava-r08.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/high-scale-lib-1.1.2.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/jackson-core-asl-1.4.0.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/jackson-mapper-asl-1.4.0.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/jamm-0.2.5.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/jline-0.9.94.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/json-simple-1.1.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/libthrift-0.6.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/log4j-1.2.16.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/servlet-api-2.5-20081211.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/slf4j-api-1.6.1.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/slf4j-log4j12-1.6.1.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/snakeyaml-1.6.jar
   :/nosql/cassandra/apache-cassandra-1.0.10/bin/../lib/snappy-java-1.0.4.1.jar
   org.apache.cassandra.thrift.CassandraDaemon


[nosql@rhel5 bin]$ ./nodetool -h rhel5 ring
Address         DC          Rack        Status State   Load            Owns    Token                                      
127.0.0.1       datacenter1 rack1       Up     Normal  11.18 KB        100.00% 159495876378727078405590336465058029385 

[nosql@rhel5 bin]$ ./nodetool -h rhel5 info
Token            : 159495876378727078405590336465058029385
Gossip active    : true
Load             : 11.18 KB
Generation No    : 1401021139
Uptime (seconds) : 1634
Heap Memory (MB) : 43.25 / 234.00
Data Center      : datacenter1
Rack             : rack1
Exceptions       : 0


[nosql@rhel5 bin]$ ./nodetool -h rhel5 cfstats
Keyspace: system
        Read Count: 13
        Read Latency: 4.639230769230769 ms.
        Write Count: 9
        Write Latency: 1.6746666666666667 ms.
        Pending Tasks: 0
                Column Family: NodeIdInfo
                SSTable count: 0
                Space used (live): 0
                Space used (total): 0
                Number of Keys (estimate): 0
                Memtable Columns Count: 0
                Memtable Data Size: 0
                Memtable Switch Count: 0
                Read Count: 0
                Read Latency: NaN ms.
                Write Count: 0
                Write Latency: NaN ms.
                Pending Tasks: 0
                Bloom Filter False Postives: 0
                Bloom Filter False Ratio: 0.00000
                Bloom Filter Space Used: 0
                Key cache capacity: 1
                Key cache size: 0
                Key cache hit rate: NaN
                Row cache: disabled
                Compacted row minimum size: 0
                Compacted row maximum size: 0
                Compacted row mean size: 0

                Column Family: Versions
                SSTable count: 1
                Space used (live): 4715
                Space used (total): 4715
                Number of Keys (estimate): 128
                Memtable Columns Count: 3
                Memtable Data Size: 105
                Memtable Switch Count: 1
                Read Count: 0
                Read Latency: NaN ms.
                Write Count: 6
                Write Latency: 1.585 ms.
                Pending Tasks: 0
                Bloom Filter False Postives: 0
                Bloom Filter False Ratio: 0.00000
                Bloom Filter Space Used: 24
                Key cache capacity: 1
                Key cache size: 0
                Key cache hit rate: NaN
                Row cache: disabled
                Compacted row minimum size: 73
                Compacted row maximum size: 86
                Compacted row mean size: 86

                Column Family: Schema
                SSTable count: 0
                Space used (live): 0
                Space used (total): 0
                Number of Keys (estimate): 0
                Memtable Columns Count: 0
                Memtable Data Size: 0
                Memtable Switch Count: 0
                Read Count: 2
                Read Latency: 0.098 ms.
                Write Count: 0
                Write Latency: NaN ms.
                Pending Tasks: 0
                Bloom Filter False Postives: 0
                Bloom Filter False Ratio: 0.00000
                Bloom Filter Space Used: 0
                Key cache capacity: 1
                Key cache size: 0
                Key cache hit rate: NaN
                Row cache: disabled
                Compacted row minimum size: 0
                Compacted row maximum size: 0
                Compacted row mean size: 0

                Column Family: Migrations
                SSTable count: 0
                Space used (live): 0
                Space used (total): 0
                Number of Keys (estimate): 0
                Memtable Columns Count: 0
                Memtable Data Size: 0
                Memtable Switch Count: 0
                Read Count: 0
                Read Latency: NaN ms.
                Write Count: 0
                Write Latency: NaN ms.
                Pending Tasks: 0
                Bloom Filter False Postives: 0
                Bloom Filter False Ratio: 0.00000
                Bloom Filter Space Used: 0
                Key cache capacity: 1
                Key cache size: 0
                Key cache hit rate: NaN
                Row cache: disabled
                Compacted row minimum size: 0
                Compacted row maximum size: 0
                Compacted row mean size: 0

                Column Family: IndexInfo
                SSTable count: 0
                Space used (live): 0
                Space used (total): 0
                Number of Keys (estimate): 0
                Memtable Columns Count: 0
                Memtable Data Size: 0
                Memtable Switch Count: 0
                Read Count: 0
                Read Latency: NaN ms.
                Write Count: 0
                Write Latency: NaN ms.
                Pending Tasks: 0
                Bloom Filter False Postives: 0
                Bloom Filter False Ratio: 0.00000
                Bloom Filter Space Used: 0
                Key cache capacity: 1
                Key cache size: 0
                Key cache hit rate: NaN
                Row cache: disabled
                Compacted row minimum size: 0
                Compacted row maximum size: 0
                Compacted row mean size: 0

                Column Family: LocationInfo
                SSTable count: 1
                Space used (live): 6729
                Space used (total): 6729
                Number of Keys (estimate): 128
                Memtable Columns Count: 0
                Memtable Data Size: 0
                Memtable Switch Count: 2
                Read Count: 11
                Read Latency: 5.465 ms.
                Write Count: 3
                Write Latency: 1.854 ms.
                Pending Tasks: 0
                Bloom Filter False Postives: 0
                Bloom Filter False Ratio: 0.00000
                Bloom Filter Space Used: 1936
                Key cache capacity: 1
                Key cache size: 1
                Key cache hit rate: 0.5714285714285714
                Row cache: disabled
                Compacted row minimum size: 73
                Compacted row maximum size: 179
                Compacted row mean size: 130

                Column Family: HintsColumnFamily
                SSTable count: 0
                Space used (live): 0
                Space used (total): 0
                Number of Keys (estimate): 0
                Memtable Columns Count: 0
                Memtable Data Size: 0
                Memtable Switch Count: 0
                Read Count: 0
                Read Latency: NaN ms.
                Write Count: 0
                Write Latency: NaN ms.
                Pending Tasks: 0
                Bloom Filter False Postives: 0
                Bloom Filter False Ratio: 0.00000
                Bloom Filter Space Used: 0
                Key cache capacity: 1
                Key cache size: 0
                Key cache hit rate: NaN
                Row cache: disabled
                Compacted row minimum size: 0
                Compacted row maximum size: 0
                Compacted row mean size: 0

----------------


[nosql@rhel5 bin]$ ./nodetool -h rhel5 netstats
Mode: NORMAL
Not sending any streams.
Not receiving any streams.
Pool Name                    Active   Pending      Completed
Commands                        n/a         0              0
Responses                       n/a         0              0

[nosql@rhel5 bin]$ ./nodetool -h rhel5 netstats
Mode: NORMAL
Not sending any streams.
Not receiving any streams.
Pool Name                    Active   Pending      Completed
Commands                        n/a         0              0
Responses                       n/a         0              0
[nosql@rhel5 bin]$ ./nodetool -h rhel5 version
ReleaseVersion: 1.0.10

[nosql@rhel5 bin]$ ./nodetool -h rhel5 tpstats
Pool Name                    Active   Pending      Completed   Blocked  All time blocked
ReadStage                         0         0              0         0                 0
RequestResponseStage              0         0              0         0                 0
MutationStage                     0         0              8         0                 0
ReadRepairStage                   0         0              0         0                 0
ReplicateOnWriteStage             0         0              0         0                 0
GossipStage                       0         0              0         0                 0
AntiEntropyStage                  0         0              0         0                 0
MigrationStage                    0         0              0         0                 0
MemtablePostFlusher               0         0              3         0                 0
StreamStage                       0         0              0         0                 0
FlushWriter                       0         0              3         0                 0
MiscStage                         0         0              0         0                 0
InternalResponseStage             0         0              0         0                 0
HintedHandoff                     0         0              0         0                 0

Message type           Dropped
RANGE_SLICE                  0
READ_REPAIR                  0
BINARY                       0
READ                         0
MUTATION                     0
REQUEST_RESPONSE             0


附錄:
1,要求Java 1.6,但使用如下版本時報錯:
[nosql@rhel5 bin]$ java -version                                                                                                    ;
java version "1.6.0_06"                                                                                                             ;
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)                                                                                ;
Java HotSpot(TM) Server VM (build 10.0-b22, mixed mode)

[nosql@rhel5 bin]$ ./cassandra -f                                                                                                   :
Segmentation fault (core dumped)  

2,conf/cassandra.yaml中
initial_token:0
[nosql@rhel5 bin]$ ./cassandra -f
 INFO 20:20:12,340 Logging initialized                                                                                              :
 INFO 20:20:12,352 JVM vendor/version: Java HotSpot(TM) Server VM/1.7.0_04                                                          K
 INFO 20:20:12,352 Heap size: 245366784/245366784                                                                                   ?
 INFO 20:20:12,353 Classpath: ./../conf:./../build/classes/main:./../build/classes/thrift:./../lib/antlr-3.2.jar:./../lib/apache-car1
 INFO 20:20:12,356 JNA not found. Native methods will be disabled.                                                                  1
 INFO 20:20:12,374 Loading settings from file:/nosql/cassandra/apache-cassandra-1.0.10/conf/cassandra.yaml                          ?
ERROR 20:20:12,526 Fatal configuration error error                                                                                  ?
while scanning a simple key
 in "", line 22, column 1:
    initial_token:0
    ^
could not found expected ':'

修改為空值時恢復正常

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/18922393/viewspace-731550/,如需轉載,請註明出處,否則將追究法律責任。

相關文章