This project sets up Apache Cassandra using Docker and provides a way to interact with it via cqlsh. Below are the instructions on how to get started, including the system requirements and steps for running the project.
- Docker: Ensure Docker is installed on your machine. You can download it from here.
- Docker Compose: Docker Compose is needed to manage multi-container Docker applications. You can find installation instructions here.
- CQLSH (Cassandra Query Language Shell): This tool is bundled with Cassandra and is used to interact with the database.
- Cassandra Driver: Optionally, install the Cassandra driver for Python, Java, or Node.js if you intend to interact with Cassandra programmatically.
- Ensure Docker is running: Make sure Docker is installed and the Docker daemon is up and running. You can verify this by running:
docker --version- Start Cassandra using Docker: This project uses Docker Compose to set up Cassandra. You can start Cassandra by running the following command:
./docker_build.shThis will pull the necessary Docker images and start the containers. The -d flag ensures the containers run in the background.
- Verify Cassandra is running: Once Docker Compose has started Cassandra, you can verify it's running by checking the logs:
docker psAccess cqlsh: To interact with your Cassandra instance, you can either:
- Enter the Cassandra container and run cqlsh directly:
docker exec -it build-cassandra-1 cqlsh- Or run cqlsh directly from your host machine (if cqlsh is installed locally):
cqlsh localhost 9042You can run a CQL script to initialize the database. If you have a CQL file, for example, init-db.cql, you can execute it inside the running Cassandra container:
docker cp /path/to/init-db.cql <cassandra_container_name>:/scripts/init-db.cql
docker exec -it <cassandra_container_name> cqlsh -f /scripts/init-db.cqlThis will execute all the CQL commands in the script to set up your keyspaces, tables, etc.
Example Commands: After accessing cqlsh, you can run basic Cassandra commands like:
- List keyspaces:
DESCRIBE KEYSPACES;
- Create a new keyspace:
CREATE KEYSPACE seo_keyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
- Use a keyspace:
USE seo_keyspace;
- Query a table:
SELECT * FROM seo_page_data;
To stop all services and remove the Docker containers, you can use the following command:
./clean_docker.shThis will stop and remove all the containers defined in your docker-compose.yml file.
Docker Issues: If you encounter issues with Docker not starting or containers failing, try checking the logs using docker-compose logs.
Ports: Ensure that the default Cassandra port (9042) is not blocked or used by another service.
cqlsh Connection Refused: If cqlsh is unable to connect, verify that Cassandra is running, and check the port mappings in your docker-compose.yml file.