Cassandra配置

来源:互联网 发布:音轨软件 编辑:程序博客网 时间:2024/05/16 01:25

1.安装

2.下载Cassandra

选择一个版本下载http://cassandra.apache.org/download/

3.解压

本例中放在/opt/cassandra

tar -zxvf apache-cassandra-0.7.4-bin.tarmv apache-cassandra-0.7.4-bin /opt/cassandra

cassandra的子目录如下:

–/bin : contains all the executables for Windows, Linux and MacOS X
–/conf : contains the logging property files, the password properties file and even more important, the storage configuration file.
–/interface : contains the Thrift interface file.
–/javadoc : contains the Java documentation of the Cassandra database source code.
–/lib : contains the Cassandra and 3rd party libraries used by Cassandra and the Cassandra library itself.

4.修改配置文件/conf/cassandra.yaml

本文中cassandra版本0.7.4配置文件是/conf/cassandra.yaml,网上其它教程中说的/conf/storage-conf.xml应是旧版本的配置文件,内容差不多,格式有些区别。

4.1集群名称

cluster_name: 'Neu Cassandra'

4.2日志、临时文件目录

data_file_directories: – /var/lib/cassandra/data   (数据都存在这)
commitlog_directory: – /var/lib/cassandra/commitlog
saved_caches_directory: – /var/lib/cassandra/saved_caches

这三个目录可以自己修改路径,也可以不修改,但是不修改的话记住要创建这几个文件夹。

4.3 配置集群seed

现有五台机器:192.168.1.16-192.168.1.20

seeds:
- 192.168.1.16
- 192.168.1.17
- 192.168.1.18
- 192.168.1.19
- 192.168.1.20

4.4修改ListenAddress

设为本节点的ip,这个端口控制端口,Cluster的节点通过该端口进行通信。

listen_address: 192.168.1.20

4.5修改ThriftAddress

这个端口监听来自客户端的消息,使用Thrift编程就用这个端口,设为0.0.0.0是监听所有的。

rpc_address: 0.0.0.0

5.配置log4j-server.properies

只需看这行:

log4j.appender.R.File=/var/log/cassandra/system.log

创建这个路径所需的文件夹。

6.下载mx4j

地址:http://mx4j.sourceforge.net/

解压之后,将lib/mx4j-tool.jar复制到/opt/cassandra/lib中

7.运行

在/opt/cassandra打命令bin/cassandra,也可以加到环境变量。

如果看到:INFO – Starting up server gossip,说明启动成功。

8.关闭

启动时加上[-f]会让cassandra在前景启动,使用[ctrl+c]就能停止cassandra。没有加[-f]就会在背景启动,这个时候需要轻质cassandra可以使用bin/stop-server,使用前需要根据本机的情况进行一些修改,未作尝试。

9.工具

nodetool是一个查看集群信息的命令,运行nodetool需要指定host和port,port默认是8080,这个端口是Cassandra的jmx端口,nodetool通过jmx获取集群的信息,端口可以在bin/cassandra.in.sh中修改。例如:

nodetool –host 192.168.1.162 ring 可以看到各节点工作情况

10.cassandra-cli工具

cassandra-cli是一个很好用的客户端命令行,它使用thrift API和服务器进行通信,能完成get/put/remove操作,并能查看配置信息,keyspace描述等。

cassandra-cli需要提供两个参数,host和port,这里的port是thrift的监听端口,默认是9160。

连接:cassandra-cli –host 192.168.1.20 –port 9160

接下来可以使用命令行进行操作了。