---
title: "cassandra分布式安装"
author: "windowboy"
date: "2015-11-03T20:01:15Z"
tags: []
categories: ["数据库"]
slug: "cassandra"
draft: false
lastmod: "2015-11-03T20:01:15Z"
id: 2254217
url: "https://windowboy.iteye.com/blog/2254217"
---

**1.下载 cassandra 建议安装镜像文件**

    wget  http://mirror.bit.edu.cn/apache/cassandra/2.2.3/apache-cassandra-2.2.3-bin.tar.gz;

**2.解压文件**

    tar  -zxvf apache-cassandra-2.2.3-bin.tar.gz

**3. 修改配置文件  cassandra安装路径下  /conf/cassandra.yaml**

      配置项如下：

      1&gt; cluster\_name: '集群名称Cluster'

      2&gt; data\_file\_directories:

                  - /path/cassandra/data   ---数据文件存储位置

      3&gt; commitlog\_directory: /path/cassandra/commitlog                 -- commitlog文件存储位置

      4&gt; saved\_caches\_directory: /path/cassandra/saved\_caches          ---saved\_caches 存储位置

       5&gt;  seed\_provider:

                    # Addresses of hosts that are deemed contact points.

                    # Cassandra nodes use this list of hosts to find each other and learn

                    # the topology of the ring.  You must change this if you are running

                    # multiple nodes!

             - class\_name: org.apache.cassandra.locator.SimpleSeedProvider

              parameters:

                    # seeds is actually a comma-delimited list of addresses.

                     # Ex: "&lt;ip1&gt;,&lt;ip2&gt;,&lt;ip3&gt;"

                     - seeds: "192.168.1.10"       ---配置集群的masterIP，可以设置多个

         6&gt;listen\_address: 192.168.1.10  ---配置当前机器的IP，如果是 slave机器就配置slave机器IP，matser就配置 matserIP

 

4.拷贝配置好的包分别到机器的机器里面

     在分布式中分别在安装包的  bin目录下启动

     ./cassandra -f &

   如果要执行 cql 功能，类似 sql

   ./cqlsh  Ip(分布式需要IP，其他的不需要)

 

 **cql操作的基本语法**

 

**创建 keysapce**

```
CREATE KEYSPACE Excelsior
           WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3};

CREATE KEYSPACE Excalibur
           WITH replication = {'class': 'NetworkTopologyStrategy', 'DC1' : 1, 'DC2' : 3}
            AND durable_writes = false;
```

```
删除 keyspace 
```

```
DROP KEYSPACE myApp;
```

```

```

```
创建表
```

```
CREATE TABLE 
```

```
Excelsior.
```

```
test(
```

```
    pk  int,
```

```
    t text,
```

```
    v text,
```

```
    s text
```

```
    PRIMARY KEY (pk)
```

```
)
```

```
创建索引
```

```
create index test (t);
```

```
删除索引
```

```

```

```
DROP INDEX userIndex;

DROP INDEX userkeyspace.address_index;
```

```

```

```
新增数据
```

```

```

```
INSERT INTO test(pk, t, v, s) VALUES (0, 0, 'val0', 'static0');
```

```

```

具体的操作请网上搜索