Install Cassandra on Linux
Prerequisites
Before
installing Cassandra make sure the following prerequisites are met:
·
Root or sudo access to the install machine.
·
Oracle Java SE Runtime Environment (JRE)
·
Java Native Access (JNA) is required
for production installations.
Check which version of Java is
installed by running the following command in a terminal window:
java -version
echo $JAVA_HOME
To install Cassandra, download the binary files from
the website, unpack them:
tar -xvzf
apache-cassandra-1.2.16-bin.tar.gz
mv apache-cassandra-1.2.16
~/cassandra
Configure Cassandra
Open the cassandra.yaml:
file, which will be available in the
<installation-directory>/conf
directory of Cassandra.
$
vi cassandra.yaml
The above command opens the cassandra.yaml file.
Verify the following configurations.
By
default, these values will be set to the specified directories.
·
data_file_directories “/var/lib/cassandra/data”
·
commitlog_directory “/var/lib/cassandra/commitlog”
·
saved_caches_directory “/var/lib/cassandra/saved_caches”
Note: To run a single-node test
cluster of Cassandra, you aren’t
going to need to change anything on the
cassandra.yaml file.
Simply
run:
./bin/cassandra
Next, make sure that the folders Cassandra accesses, such as the
log folder,
exists and that Cassandra has the right to write on it:
mkdir
/var/lib/cassandra
mkdir
/var/log/cassandra
chown -R
$USER:$GROUP /var/lib/cassandra
chown -R
$USER:$GROUP /var/log/cassandra
Now set Cassandra’s variables by running:
export
CASSANDRA_HOME=~/cassandra
export
PATH=$PATH:$CASSANDRA_HOME/bin
Running Cassandra
To start Cassandra, open the terminal window, navigate to
Cassandra
home directory/home, where you
unpacked Cassandra, and run
the
following command to start your Cassandra server.
$ cd
$CASSANDRA_HOME
$./bin/cassandra
-f
Using the –f option tells Cassandra to stay in the foreground
instead of
running as a background process.
If everything goes fine, you can see the Cassandra server
starting.
And then run:
./bin/cassandra-cli
and if it says "Connected to: 'Test Cluster'", you are
now running your
single-node cluster.