24
votes

I'm newbie in the Ubutu(linux) + Cassandra.

I tested Cassandra on my ubuntu machine with OpenJdk. There are some nice articles to explain how to install a Cassandra on ubuntu, so I could do that. I changed some config values and checked it run correctly.

And, I decided to remove the cassandra and reinstall for getting the clean one.

[What-I-Do]

I uninstall Cassandra with following steps:

  1. uninstall Cassandra using apt-get

    apt-get remove cassandra

  2. remove data/log/ directories

    rm -rf /var/lib/cassandra

    rm -rf /var/log/cassandra

    rm -rf /etc/cassandra

After that I tried to install new cassandra

apt-get install cassandra

[Error-Message]

sudo cassandra -f

Exception in thread "main" java.lang.ExceptionInInitializerError Caused by: java.lang.RuntimeException: Couldn't figure out log4j configuration: log4j-server.properties

at org.apache.cassandra.service.AbstractCassandraDaemon.initLog4j(AbstractCassandraDaemon.java:86)

at org.apache.cassandra.thrift.CassandraDaemon.(CassandraDaemon.java:62) Could not find the main class: org.apache.cassandra.thrift.CassandraDaemon. Program will exit.`

and there are no files under "/var/lib/cassandra", "/var/log/cassandra" and "/etc/cassandra" directories OTL.

I want to know, what I miss.

6
for the record other people and myself have had trouble with the log4j configuration. There are some tips stackoverflow.com/questions/6574093/cassandra-starting-issue but I haven't gotten to the bottom of it yetCrowie
I did all your uninstall step and then I ran sudo apt-get purge cassandra. Then install it and it works for me now.mythicalprogrammer

6 Answers

11
votes

I was able to completely uninstall Cassandra by doing the following:

apt-get remove cassandra

--- removing the cassandra directories

rm -rf /var/lib/cassandra
rm -rf /var/log/cassandra
rm -rf /etc/cassandra

However, after doing the above, there are still some things left behind, and if you were to try to reinstall it after doing this, it does not work, because the install detects those remaining files and believes you still have an installation of the software. You will get a new set of directories, but they will be empty. So, you need to remove all the additional stuff. There are directories and files that need to be manually removed.

--- finding the remaining Cassandra files

find / -name 'cassandra' 

or,

find / -name '*cassandra*'

(ALL remaining files on the system need to be removed or a few directories are left empty or not even created at all).

The above command will return a listing of files and directories left behind. Remove them.

Now, you should be able to do:

apt-get update

followed by:

apt-get install cassandra

After doing this, I got a full new installation, and upon starting Cassandra, it did all the first-time startup stuff and got up and running.

If you get a GPG error about signatures not being verified because of a public key, that needs to be set up before the install statement.

7
votes

AFAIK, your uninstall steps were correct.

Check the permissions on each of those directories. In my installs of Cassandra 1.1.6 on Ubuntu 10.04, /etc/cassandra is owned by root, and /var/lib/cassandra and /var/log/cassandra are owned by the cassandra user and group.

Also, you should be using the init script to start cassandra, like this:

sudo service cassandra start

instead of starting directly with sudo.

I've seen permissions get messed up when manually running cassandra as root and not as the cassandra user, which is what the init script takes care of for you.

7
votes

Datastax provides a bash script for this very purpose:

https://docs.datastax.com/en/ddac/doc/datastax_enterprise/install/uninstallDDAC.html?hl=uninstall%2Ccassandra

Heres the script code:

# Stop services
/etc/init.d/cassandra stop
/etc/init.d/dse stop
/etc/init.d/opscenter-agent stop

# Remove packages
PACKAGES=(dsc dsc1.1 dsc12 dsc20 cassandra apache-cassandra1 dsc-demos \
dse dse-libhadoop-native dse-libhadoop dse-libcassandra dse-hive dse-libhive dse-pig \
dse-libpig dse-demos dse-libsqoop dse-libtomcat dse-liblog4j dse-libsolr dse-libmahout dse-full)
DEB_PACKAGES=(python-cql python-thrift-basic)
RPM_PACKAGES=(python26-cql python26-thrift)
if [ `which dpkg` ]; then
PLIST=(${PACKAGES[@]} ${DEB_PACKAGES[@]})
dpkg -P ${PLIST[*]}
rm -rf /etc/apt/sources.list.d/datastax.list
else
PLIST=(${PACKAGES[@]} ${RPM_PACKAGES[@]})
yum -y remove ${PLIST[*]}
rm -rf  /etc/yum.repos.d/datastax.repo
fi

# Cleanup log and configuration files
rm -rf /var/lib/cassandra/* /var/log/{cassandra,hadoop,hive,pig}/* /etc/{cassandra,dse}/* \
/usr/share/{dse,dse-demos} /etc/default/{dse,cassandra}

to reinstall, simply run this script, then install cassandra again, as if for the first time.

EDIT: it seems their script is slightly out of date. I had to add dsc20 to the list of PACKAGES.

EDIT 2: link went bad (was http://www.datastax.com/documentation/opscenter/3.2/webhelp/#opsc/online_help/opscRemovingPackages_t.html, thanks Daisuke Aramaki for finding an up-to-date link)

2
votes

Actually the issue is that cassandra could not start up as it is not finding the file named "log4j-server.properties" in its configuration directory, to resolve the issue you have there, no need to reinstall it again but instead simply do the following to resolve the issue:

1) Download the tarball file from here.

2) Extract it:

$ tar -xzvf apache-cassandra-1.2.5.tar.bin.gz

3) Check where is the configuration path of cassandra. you could get the config path from file named "/usr/share/cassandra/cassandra.in.sh", check out the key named "CASSANDRA_CONF".

$ gedit /usr/share/cassandra/cassandra.in.sh

4) copy the missing files manually from the extracted package (step 2) from a directory named "conf"

$ sudo cp extracted_cassandra/conf/cassandra.yaml /etc/cassandra
$ sudo cp extracted_cassandra/conf/log4j-server.properties /etc/cassandra

Hints:

  • For more info. how to install cassandra debian package, check this
  • For more info. how to install cassandra from their repository, check this

  • If you want to re-install it, simply you could do the following:

    $ sudo apt-get remove cassandra

    $ sudo apt-get install cassandra

2
votes

As I also encounted the same XML error here's another answer. The error is also detailed on this SO post where OP couldn't start Cassandra. I followed your steps to uninstall and the steps on this article to reinstall.


What I did - What I learnt

The problem must have had something to do with C* versions. The link I provided, which I originally used, led me to install using this command:

deb http://www.apache.org/dist/cassandra/debian 10x main 


Instead of that, I upgraded my command to point to Cassandra Debian Version 11 (11x). E.g.

deb http://www.apache.org/dist/cassandra/debian 11x main 

I also uninstalled everything Cassandra wise, restarted, and forced through new versions of Cassandra


Resources

For another (older) source of installing Cassandra on Ubuntu try Vineet Daniel's Installing Cassandra on Ubuntu

2
votes
  1. remove the installed cassandra package and configration files:

    sudo apt-get purge "cassandra-*" "datastax-*"

  2. Remove the library and log directories:

    sudo rm -r /var/lib/cassandra

    sudo rm -r /var/log/cassandra