您的位置:首页 > 运维架构 > Docker

结合docker 快速的构建 Cassandra开发环境

2015-03-04 16:23 344 查看
尝试一门新的技术的时候。可以考虑使用docker 解决环境的依赖,简单方便快捷。

原文出处:http://blog.abhinav.ca/blog/2014/09/15/cassandra-cluster-docker-one-command/

补充一点,下面需要的cql等命令需要自己手动的安装下载地址:http://mirrors.cnnic.cn/apache/cassandra/2.1.3/apache-cassandra-2.1.3-bin.tar.gz

summary:

下面介绍的很简单。

方法1:完全的自动化,博主已经写了一个shell,可以快速的部署

方法2:分成了两部分,部分一 部署一个单节点,单节点作为seed,然后依次添加其余的四个节点,其余四个节点的SEED IP 是当地一个单节点的IP。

剩下的就是怎么去操作 Cassandra,我博客里有另一篇的转载,虽然年代久远,但是还是很简单的。

文章中部分的命令替换

/opt/apache-cassandra-2.1.3/bin/nodetool  --host $SEED_IP status

/opt/apache-cassandra-2.1.3/bin/cqlsh $SEED_IP
[2014-09-16] Update: The command now brings up a 5-node Cassandra cluster in addition to DataStax OpsCenter 5.0.0 and wires it all up together. See the GitHub repo for details. Each
node runs in its own container with the Cassandra process + DataStax Agent while OpsCenter runs in its own container separate from the cluster.

[Original Post]

Run this command to bring up a 5-node Cassandra (2.1.0) cluster locally using Docker.

1

bash <(curl -sL http://bit.ly/docker-cassandra)[/code] 
This will:

1. Pull the 
abh1nav/cassandra:latest
 image.

2. Start the first node with the name 
cass1


3. Start 
cass2..5
 with
the environment variable 
SEED=<ip
of cass1>


Manual mode

If you don’t like or trust the one liner, here’s how to do it manually.


Single Node Setup

To start the first node, pull the latest version of image:

1

docker pull abh1nav/cassandra:latest

Start the first instance:

1

docker run -d --name cass1 abh1nav/cassandra:latest

Grab its IP using:

1

SEED_IP=$(docker inspect -f '{{ .NetworkSettings.IPAddress }}' cass1)

Connect to it using cqlsh:

1

cqlsh $SEED_IP

The expected output is:

12
3
4
5
6

✈ megatron /opt/cassandra
↳ bin/cqlsh $SEED_IPConnected to Test Cluster at 172.17.0.47:9160.
[cqlsh 4.1.1 | Cassandra 2.1.0 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
Use HELP for help.
cqlsh>


Cluster Setup

Once your single node is setup, you can add more nodes using:

12
3
4
5

for name in cass{2..5}; do
echo "Starting node $name"
docker run -d --name $name -e SEED=$SEED_IP abh1nav/cassandra:latest
sleep 10
done

You can watch the cluster form by tailing the logs on 
cass1
:

1

docker logs -f cass1

Once the cluster is up, you can check its status using:

1

nodetool --host $SEED_IP status

The expected output is:

12
3
4
5
6
7
8
9
10
1112

✈ megatron /opt/cassandra
↳ bin/nodetool --host $SEED_IP statusDatacenter: datacenter1=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.17.0.47 54.99 KB 256 37.3% cb925207-ff79-4d1e-84ce-ac6c59353df4 rack1UN 172.17.0.48 85.8 KB 256 39.4% baa1b2c1-8f51-4e20-9c33-44cb5f45a4c0 rack1UN 172.17.0.49 69.35 KB 256 40.1% d1f96d59-c084-4ba3-a717-4269098cc854 rack1UN 172.17.0.50 68.92 KB 256 40.2% d514e844-e07a-4896-ace8-a0b43e25d6fc rack1UN 172.17.0.51 69.39 KB 256 43.0% 464cdf00-39e3-4efe-8a9f-83fc5ba839c9 rack1

Check out the Docker registry page for the image and the GitHub repo to grab the source.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息