Cassandra Apache : Problems execution cassandra -f - cassandra

I would to know if it's an obligation to execute cassandra -f for use cassandra-cli or cqlsh ??? Because, i tested connection to cassandra-cli --host 127.0.0.1 --port 9160 or cqlsh and i have a message error : connection failed to localhost/9160

The -f option is a FLAG, so no you don't have to supply it when starting cassandra.
What does -f get used for?
Depends on the OS but its used for choosing whether to run the process in the foreground / background.
In Windows
-f means you will run the process in the background. Simply calling cassandra.bat means the process starts in the foreground. E.g:
cassandra.bat # cassandra runs in foreground (i.e.) you see logdata in the terminal
cassandra.bat -f # cassandra runs in background
In UNIX based OSs (linux / osx)
Supplying the -f flag means you run the process in the foreground. Not supplying it means the process will start in the background. E.g:
cassandra.bat # cassandra runs in background, you wont see anything in the terminal
cassandra.bat -f # cassandra runs in foreground
Back to the error
This means that cassandra isn't running. Start the task manager / activity monitor and verify that Cassandra is executing as a process / service. And also if you want to connect cqlsh / cassandra-cli to a local server without specifying the localhost ip address you can simply type:
path/to/cassandra/bin/cqlsh -3 # the -3 means you use CQL3
path/to/cassandra/bin/cassandra-cli

Related

Fastest way to stop and start cassandra nodes before updates

What would be the best way how to stop Cassandra nodes before application updates and database updates, and to afterwards start them? Currently I'm going through each node VM and stopping them using the command sudo service cassandra stop and then after the update is done, I'm doing the same, just starting them with command sudo service cassandra start. With few nodes it's OK, but I have 20 nodes on a server, and it takes some time to do that.
Is there any better/more efficient way to do that?
There are so many ways to do this - use for loop in shell + ssh, use pssh, etc. You just need to remember that it's better to perform rolling restart of the individual Cassandra nodes, so you need to have to wait until Cassandra starts again. Something like:
for host in `cat your-host-list.txt`; do
ssh user#${host} 'sudo service cassandra stop && your_update_command && sudo service cassandra start
done
or slightly easier with pssh:
pssh -l user -h your-host-list.txt -p 1 -t 0 'sudo service cassandra stop && your_update_command && sudo service cassandra start
-p 1 tells to execute only one command in parallel
t 0 instructs to wait for execution without timeout

How to list/kill running commands in cassandra

I want to run a COPY command on my Cassandra cluster (v3.0.9).
In case my shell exits, how can I later on list running commands, get their status and possibly kill/stop it?
Create a cql file with your COPY command
Run it through cqlsh using -f flag (cqlsh -f ) with nohup. Details here.
Then it will be available to ps and kill.

How to check that Cassandra is ready

I have a Cassandra running in a Docker and I want to launch a CQL script when the database is ready. I tried checking the port to detect when it's ready :
while ! nc -z localhost 7199; do
sleep 1
done
echo "Cassandra is ready"
cqlsh -f ./createTables.cql
But the port is opened before the database is really ready, and the cqlsh therefore fails. How to properly check the Cassandra status and launch the script ? Thanks in advance.
First you need to wait on another port - 9042 - this is a port that is used by CQLSH.
Another approach could be also waiting for execution of sqlsh instead of nc (or as a second step, because nc is much faster to execute). For example, you can use something like commands:
while ! cqlsh -e 'describe cluster' ; do
sleep 1
done
to wait until Cassandra is ready...

Cassandra Start up

I am new to the Cassandra database. I have downloaded Cassandra and set the JAVA_HOME. When I try to run, the following exception is thrown:
Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: 7199; nested exception is:
java.net.BindException: Address already in use: JVM_Bind.
Can anyone assist me with this issue?
For those who are facing the same problem using Ubuntu OS a solution can be to kill CassandraDaemon :
pkill -f CassandraDaemon
When you launch for the first time the command "cassandra -f" background daemon is running so Ctrl^C doesn't stop the process.
You could check if cassandra is running by checking the port
lsof -i :9160
if you got a result back that means it is running
If you want to kill it , do kill -9 "then the pid you got from the last step"
if you want to see the ongoing log run
cassandra -f when you start cassandra
I appears that Cassandra is already running in the background. Try connecting using cassandra-cli.
ps -ax | grep cassandra, take note of the process id
kill <pid>
sudo ./cassandra
Port 7199 is the default Cassandra's JMX port( used for monitoring).
In case you are trying to run multiple instances on one physical machine, modify $CASSANDRA_HOME/conf/cassandra-env.sh configuration file and set different port, for example 7299
JMX_PORT="7299"
I am writing the same but for windows developer command prompt :
Let say its showing issue with 9042 port
netstat -ano | findstr : 9042
List all the process using port 9042
taskkill /PID 237979 /F
here 237979 is the processid which is using port 9042
Download the TCPView from http://technet.microsoft.com/en-us/sysinternals/bb897437
Open the TCPView application and sort the output by Port
Click on the record which points to Port - 7199
Right click and "End Process"
Now, run the Cassandra.bat and it should work.

stop cassandra server on mac os x

How do I stop cassandra server running on a single node in my mac os x?
Cassandra script doesn't have -stop option. Only way other than restart the mac os x, was to do a "ps" and find the java process which had arguments for cassandra and use kill -9 to kill the process.
But trying to restart cassandra after that still throws
Error: Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: 7199; nested exception is:
java.net.BindException: Address already in use.
Anybody seen it? Any quick solutions?
If you've installed cassandra via homebrew, use brew info cassandra and it will tell you how to load/unload cassandra using launchctl. This worked better for me than the other answers here.
Commands
brew info cassandra To see status of cassandra
brew services start cassandra To start cassandra
brew services stop cassandra To stop cassandra
EDIT: I actually find this much more useful.
Open terminal and type:
$ ps -ax | grep cassandra
gives you a list of pids running with the name cassandra.
Use the PID number to kill the process for example here is a returned value:
708 ttys000 0:03.10 /usr/bin/java -ea -javaagent:Downloads/Web/Cassandra/dsc-cassandra-1.1.0/bin/
$ kill 708
Old post:
After posting my comment I found a stop-server script in the BIN.
You have to open up the script and comment out the code if you want to use that script. But here is what it says inside the script.
echo "please read the stop-server script before use"
# if you are using the cassandra start script with -p, this
# is the best way to stop:
kill `cat <pidfile>`
# otherwise, you can run something like this, but
# this is a shotgun approach and will kill other processes
# with cassandra in their name or arguments too:
# user=`whoami`
# pgrep -u $user -f cassandra | xargs kill -9
Found this solution elsewhere which seems to work!
pkill -f 'java.*cassandra'
Worth a try!
This works on the Ubuntu I have. Not on MacOS!
On Mac one more is ps -af | grep cassandra and then using kill. But, it does not work sometimes!
Another approach is to see which OS process has the Cassandra port open, like this:
lsof -i :9160
Sample output:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 30253 aswan 214u IPv4 0xffffff80190dcc20 0t0 TCP *:netlock1 (LISTEN)
Then you can use "kill -9 [pid]" on that process.
You can use Cassandra's nodetool command, as well.
nodetool drain
The documentation doesn't say anything about it shutting down, but it works reliably for me with a single node, local server. It generally takes a few seconds to finish the shutdown, however.
kill -9 ` acx | grep -i cassandra | awk '{print$1}' `
I'm using the new Datastax Enterprise 5.0 version, and it, at least, offers a simple enough command for stopping Cassandra:
dse cassandra-stop
It takes a few moments to shut down, but it works for me.

Resources