Cassandra the environment to build

Source: Internet
Author: User
Tags cassandra mkdir log4j

Recently NoSQL compare fire, I also recently toss a hand; Cassandra0.6.3 if just let it run, then directly ignore the following content. I want to see the source code, so there are the following steps.

1, download src;

2, set Java_home

Configure environment variables under Linux system, I add under/etc/profile:

java_home=/usr/lib/jvm/java-6-sun-1.6.0.19

Path= $JAVA _home/bin: $PATH

Classpath=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar

Export Java_home

Export PATH

Export CLASSPATH

Finally, the implementation of Source/etc/profile makes the environment variable effective immediately;

/* You can use printenv java_home to see if the JAVA environment variable is in effect * *

(The java_home can be set directly in cassandra.in.sh when running Cassandra)

3, will eclipse in the creation of Cassandra Project;

Executes the ant build, and if executed successfully, a build successfu occurs;

Switch workspace to the top level of the current source code, and then create a new Java project, in the new wizard, contents Select Create Project from existing source, and then select the source file directory in the directory ; Click to complete;

If you do not set up a directory on the workspace as the Cassandra Source, the steps are as follows:

A new Java project, in the new wizard, contents selects Create Project from existing source, and then selects the source file directory in the directory;

(b) Select Import in the menu and import the folder into the project;

C Modify the properties of project:

① The Lib directory and the JUnit directory in libraries in Java build path;

② Modify the Sources directory structure as follows:

Note that when you add a direct build, you will see access restriction ... Error, the solution is to delete the JRE first in Build-path and then join the JRE. If still not, empty the project and build should be no problem.

Another solution is as follows: Windows->preferences->java->compiler->errors/warnings->deprecated and trstricted Api- >forbidden Reference (Access rules):->change to Warning

4, need to set the Eclipse VM options;

One of the ways to set up the Web is as follows:

-dstorage-config=/home/sunmoonone/dev/projects/nosql/cassandra-trunk/conf

-dcassandra-foreground

-ea-xmx1g

My VM setup options are directly copied Cassandra-in-sh, as follows:

-ea

-xms256m

-xmx1g

-xx:+useparnewgc

-xx:+useconcmarksweepgc

-xx:+cmsparallelremarkenabled

-xx:survivorratio=8

-xx:maxtenuringthreshold=1

-xx:+heapdumponoutofmemoryerror

-dcom.sun.management.jmxremote.port=8080

-dcom.sun.management.jmxremote.ssl=false

-dcom.sun.management.jmxremote.authenticate=false

-dcassandra-dstorage-config=conf-dcassandra-foreground=yes

But there's only one more last line.

5, add Classpath

Classpath settings can refer to the cassandra.in.sh.

Note: Be sure to add the $cassandra_home/build/classes, otherwise the nodetool ring or some other operation will appear abnormal.

6, modify the configuration; (the default is OK, just customize a special folder I feel more convenient)

!! Log4j.properties

Log4j.appender.r.file=/cassandra/log/system.log

!! Storage-conf.xml

/cassandra/commitlog

/cassandra/data

There is a problem with permissions under Linux, so you need to do some extra work, mainly using chmod to change permissions.

#:~$ CD/

#:/$ sudo mkdir Cassandra

#:/$ sudo chmod 777 Cassandra

#:/$ CD Cassandra

#:/cassandra$ mkdir Log

#:/cassandra$ mkdir Commitlog

#:/cassandra$ mkdir Data

To test for success, you can first select Org.apache.cassandra.thrift.CassandraDaemon, start the Java application, and if prompted by: INFO 11:11:43,716 Cassandra starting Up ... Indicates that you have successfully deployed. Run bin/cassandra-cli--host localhost--port 9160 at this time

You should see the following output:

Connected to localhost/9160

Welcome to Cassandra CLI.

Type ' help ' or '? '. Type ' quit ' or ' exit ' to quit.

Cassandra>

After the prompt, enter:

Cassandra> set keyspace1.standard2[' jsmith ' [' a '] = ' John '

Server response: Value inserted.

Note: If you write bin/cassandra-cli under Windows instead of BIN/CASSANDRA-CLI, you will get an error. Cassandra Cluster configuration

The above demonstrates the configuration of a single node, and when configuring a cluster, several parameters need to be modified.

0.0.0.0

The online spread of this practice configuration is to let listenaddress empty, but I did not succeed after the experiment, I do not know why. So I am still honest in listenaddress write the native IP address, and thriftaddress directly leave blank or 0.0.0.0 is also possible!

In addition, seed is used to form the ring, so just select a few machines as seed.

For example, I have 165, 1662 machines, 165 machines as seed, then the configuration on the 165 machine is as follows:

10.6.0.165

0.0.0.0//Direct blank can also be

10.6.0.165

The configuration on the 166 machine is as follows:

10.6.0.166

0.0.0.0//Direct blank can also be

10.6.0.165

So, after running./cassandra-f starts the service, the display on the 10.6.0.166 machine is:

INFO 17:03:57,308 starting up server gossip

INFO 17:03:57,518 Binding Thrift Service to/10.6.0.166:9160

INFO 17:03:57,527 Cassandra starting up ...

INFO 17:05:19,607 node/10.6.0.165 is now part of the cluster

INFO 17:05:20,627 inetaddress/10.6.0.165 is

What appears on the 10.6.0.165 machine is:

INFO 17:05:25,451 node/10.6.0.166 is now part of the cluster

INFO 17:05:25,897 inetaddress/10.6.0.166 is now

Performed on 166 machines: bin/cassandra-cli--host 10.6.0.165--port 9160, prompted as follows:

Connected to: ' Test Cluster ' on 10.6.0.165/9160

Welcome to Cassandra CLI.

Type ' help ' or '? '. Type ' quit ' or ' exit ' to quit.

Cassandra>

The instructions are unblocked.

But I ran into a problem: executing on the 166 machine.

> Bin/nodetool-host 10.6.0.165 Ring

> Bin/nodetool-host 10.6.0.165 Info

Error connecting to remote JMX agent! are all present.

However, performing bin/nodetool-host 10.6.0.166 info on 166 can result in normal results:

20048728023891424315226852193001833590

load:4.26 KB

Generation no:1277802237

Uptime (seconds): 1308

Heap Memory (MB): 2.77/1023.81

Executed on 166. The result of the/nodetool-h 10.6.0.166 ring appears:

Address Status Load Range ring

20048728023891424315226852193001833590

10.6.0.165 up 3.21 KB 11922828268088146370628700125677415661 |<--|

10.6.0.166 up 3.82 KB 20048728023891424315226852193001833590 |-->|

Note: If you specify the port number by-port, you must fill in the correct port number 8080, and if written as 9160, the node will be down.

In addition, if the source code is compiled and run in the bin directory./nodetool-h 10.6.0.166 Ring throws an exception, check to see if Classpath is correct.

This question can refer to: Http://wiki.apache.org/cassandra/JmxGotchas, namely:

If you run into issues connecting via jconsole to the Jmxinterface port from a remote machine, it would be the JVM option '- Djava.rmi.server.hostname '. This could need to being set to a particular interface like '-djava.rmi.server.hostname= $IP ' (where $IP is the IP address of th E interface can reach from the remote machine). Java defaults to the IP addresses of "localhost" which is mostly likely don't what you want.

You could also run into issues connecting to the JMX interface (even locally) because by default JMX binds to IPV6 if it ' s a vailable (Netstat-nap | grep 8080). This has also solved by passing '-djava.rmi.server.hostname= $IP ' explicitly as a JVM option. This would prompt JMX to bind to the given IPV4 IP addresses so that nodetool can access it.

Cassandra Programming

First Cassandra Code instance

The first Cassandra code package org.apache.cassandra.aict;

Import java.io.UnsupportedEncodingException;

Import Java.util.Date;

Import java.util.List;

Import Org.apache.cassandra.thrift.Cassandra;

Import Org.apache.cassandra.thrift.Column;

Import Org.apache.cassandra.thrift.ColumnOrSuperColumn;

Import org.apache.cassandra.thrift.ColumnParent;

Import Org.apache.cassandra.thrift.ColumnPath;

Import Org.apache.cassandra.thrift.ConsistencyLevel;

Import org.apache.cassandra.thrift.InvalidRequestException;

Import org.apache.cassandra.thrift.NotFoundException;

Import Org.apache.cassandra.thrift.SlicePredicate;

Import Org.apache.cassandra.thrift.SliceRange;

Import org.apache.cassandra.thrift.TimedOutException;

Import org.apache.cassandra.thrift.UnavailableException;

Import org.apache.thrift.TException;

Import Org.apache.thrift.protocol.TBinaryProtocol;

Import Org.apache.thrift.protocol.TProtocol;

Import Org.apache.thrift.transport.TSocket; Import Org.apache.thrift.transport.TTransport;

public class Cassandraclientdemo {public static final String UTF8 = "UTF8"; public static void Main (string[] args) throws Unsupportedencodingexception, Invalidrequestexception, 

Unavailableexception, Timedoutexception, Texception, notfoundexception {ttransport tr = new Tsocket ("localhost", 9160);

Tprotocol proto = new Tbinaryprotocol (TR);

Cassandra.client Client = new Cassandra.client (proto);

Tr.open ();

String keyspace = "Keyspace1";

String columnfamily = "Standard1";

String Keyuserid = "1";

Insert Data long timestamp = System.currenttimemillis ();

Columnpath colpathname = new Columnpath (columnfamily);

Colpathname.setcolumn ("FullName". GetBytes (UTF8));

Client.insert (Keyspace, Keyuserid, Colpathname, "Chris goffinet". GetBytes (UTF8), timestamp, consistencylevel.one);

Columnpath colpathage = new Columnpath (columnfamily);

Colpathage.setcolumn ("Age". GetBytes (UTF8)); Client.insert (Keyspace, Keyuserid, Colpathage, "a". GetBytes (UTF8), timestamp, consistencylevel.one);

Read single column System.out.println (' single column: ');

Column col = client.get (keyspace, Keyuserid, Colpathname, Consistencylevel.one). GetColumn ();

SYSTEM.OUT.PRINTLN ("Column name:" + new String (Col.name, UTF8));

SYSTEM.OUT.PRINTLN ("column value:" + New String (Col.value, UTF8));

SYSTEM.OUT.PRINTLN ("column timestamp:" + new Date (Col.timestamp));

Read entire row slicepredicate predicate = new Slicepredicate ();

Slicerange Slicerange = new Slicerange ();

Slicerange.setstart (new byte[0]);

Slicerange.setfinish (new byte[0]);

Predicate.setslice_range (Slicerange);

System.out.println ("/nrow:");

Columnparent parent = new Columnparent (columnfamily);

List results = Client.get_slice (Keyspace, Keyuserid, parent, predicate, consistencylevel.one);

for (Columnorsupercolumn result:results) {column column = Result.column;

System.out.println (new String (Column.name, UTF8) + "->" + new String (Column.value, UTF8));

} tr.close (); }

}

Advantages and Disadvantages

Advantages: Simple and efficient

Disadvantage: The function is simple, cannot provide the connection pool, the error processing and so on function, is not suitable for directly in the production environment use

Reference documents:

Http://blog.csdn.net/gpcuster/archive/2010/06/06/5651960.aspx

Http://blog.sina.com.cn/s/blog_4a87727d0100g093.html

Http://blog.csdn.net/gpcuster/archive/2010/03/23/5410173.aspx

Http://blog.csdn.net/gpcuster/archive/2010/03/27/5423479.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.