cassandra集群安装
gzip -d apache-cassandra-1.2.6-bin.tar.gz tar xvf apache-cassandra-1.2.6-bin.tar 单机安装配置 1.配置log4j-server.properties
需要配置log4j.appender.R.File=/market/cassandra/apache-cassandra-1.2.6/log/cassandra.log
2.配置data_file_directories:存放数据库数据文件的目录路径(不是文件路径) data_file_directories:/market/cassandra/apache-cassandra-1.2.6/data
commitlog_directory:存放提交日志的目录路径。 commitlog_directory:/market/cassandra/apache-cassandra-1.2.6/commitlog
saved_caches_directory:缓存文件夹路径 saved_caches_directory:/market/cassandra/apache-cassandra-1.2.6/saved_caches
3.启动cassandra cd ../bin ./cassandra -f
集群安装配置
cluster_name:集群名,所有集群里的节点,这个配置必须相同 默认'Test Cluster' seeds:这是种子节点。 172.21.1.36 cassandra是一个p2p式的分布式数据库,没有所谓的中心节点。但为了保证节点能找到集群,你必须告诉它至少一台已经在集群内的节点IP。这样通过这个节点,它能找到集群内的所有节点,为了保证健壮性,尽量将集群里所有节点的seeds配置成一样的 seeds:'172.21.1.36,172.21.0.36,172.21.3.172'
listen_address:其它节点与自己通信的IP,这里必须设置为自己的主机IP。若设置为localhost或127.0.0.1,则可能其它节点无法与自己通信。 listen_address:172.21.1.36
rpc_address:这里设置其它节点上的客户端能否与自己的服务端通信。设置为0.0.0.0表示任何节点上的客户端都可以与自己通信,否则只允许本机客户端与自己通信 rpc_address:0.0.0.0
启动./cassandra,报错 xss = -ea -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=42 -Xms1715M -Xmx1715M -Xmn100M -XX:+HeapDumpOnOutOfMemoryError -Xss180k $ Error: Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: 7199; nested exception is: java.net.BindException: Address already in use
cassandra未关闭 netstat -an | grep ':7199' kill -9 进程id
nodetool是一个查看集群信息的命令,运行nodetool需要指定host和port,port默认是8080,这个端口是Cassandra的jmx端口,nodetool通过jmx获取集群的信息,端口可以在bin/cassandra.in.sh中修改.
ring命令用于查看集群的节点信息,ring来源于consistent hash,在consistent hash中,各个节点组成一个环,通常称为ring。 ring命令的输出中包括当前集群的节点,各个节点的状态(Up还是Down),节点的load(数据量),节点在ring上的位置等信息 ./nodetool -h 172.21.3.172 ring
cfstats命令 cfstats — 查看各个column family的详细信息,包括读写次数、响应时间、memtable、sstable等 ./nodetool -h 172.21.3.172 cfstats
tpstats命令 tpstats命令输出当前集群的各种连接池的使用状态.包括数据一致性,消息池,提交池,内存表提交池,写操作的池等等 ./nodetool -h 172.21.3.172 tpstats
./nodetool -h 172.21.3.172 info
flush命令或repair命令 flush命令是将某keyspace中的缓存区数据提交,所以必须有在flush命令后提交一个keySpace的参数,否则命令不能执行. Java代码
./nodetool -h 172.21.3.172 flush system
命令行,所有命令都要以;结束
./cassandra-cli -h 172.1.3.172
cd命令切换到Cassandra的bin目录下,./cassandra-cli启动cassandra-cli。
connect 172.21.3.172/9160;连接本地机器所在的集群
show keyspaces;显示集群中现有的keyspace use xxxx;
进入keyspace xxxx
create column family xxxx;创建column family xxxx
drop keyspace xxxx;删除keyspace xxxx
create keyspace xxxx;创建keyspace xxxx
use keyspace 打开keyspace(类似数据库中库)
show schema 显示该库中的表结构 list columnFamily 查看表的数据集
set columnFamily=columnValue 插入指定的key和列的值 get columnFamily: 取得指定表和key的数据
// 创建库 CREATE KEYSPACE testDb with placement_strategy = 'SimpleStrategy' and strategy_options = {replication_factor:3};// 复制因子为3份
创建表 create column family custGroups with column_type = 'Standard' and comparator = 'UTF8Type' and default_validation_class = 'BytesType' and key_validation_class = 'UTF8Type' AND column_metadata =;