ebook img

Expert Apache Cassandra Administration PDF

482 Pages·2018·4.5 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Expert Apache Cassandra Administration

Expert Apache Cassandra Administration Install, configure, optimize, and secure Apache Cassandra databases — Sam R. Alapati Expert Apache Cassandra Administration Sam R. Alapati Expert Apache Cassandra Administration Sam R. Alapati Flower Mound, Texas, USA ISBN-13 (pbk): 978-1-4842-3125-8 ISBN-13 (electronic): 978-1-4842-3126-5 https://doi.org/10.1007/978-1-4842-3126-5 Library of Congress Control Number: 2017962948 Copyright © 2018 by Sam R. Alapati This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Cover image designed by Freepik Managing Director: Welmoed Spahr Editorial Director: Todd Green Acquisitions Editor: Jonathan Gennick Development Editor: Laura Berendson Technical Reviewer: Carlos Rolo Coordinating Editor: Jill Balzano Copy Editor: Mary Behr Compositor: SPi Global Indexer: SPi Global Artist: SPi Global Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer- sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail [email protected], or visit www.apress.com/ rights-permissions. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book's product page, located at www.apress.com/9781484231258. For more detailed information, please visit www.apress.com/source-code. Printed on acid-free paper I dedicate this book to the memory of Ibrahim Khan, a great cricketer and a greater human being. The lessons I learned from “Khan Sahib” a long time ago still guide me. Table of Contents About the Author ....................................................................................................xix About the Technical Reviewer ................................................................................xxi Acknowledgments ................................................................................................xxiii Part I: Introduction, Installation, and Configuration .......................................1 Chapter 1: Apache Cassandra: An Introduction ........................................................3 What Is Cassandra? ����������������������������������������������������������������������������������������������������������������������3 Open Source Database ������������������������������������������������������������������������������������������������������������4 Fault Tolerance ������������������������������������������������������������������������������������������������������������������������4 High Performance ��������������������������������������������������������������������������������������������������������������������5 Distributed Configuration and High Resiliency ������������������������������������������������������������������������5 Flexibility ���������������������������������������������������������������������������������������������������������������������������������5 Use of Commodity Servers ������������������������������������������������������������������������������������������������������6 Ease of Management ���������������������������������������������������������������������������������������������������������������6 Highly Scalable ������������������������������������������������������������������������������������������������������������������������6 It’s Good Old SQL! ��������������������������������������������������������������������������������������������������������������������7 Problems Posed by Relational Databases �������������������������������������������������������������������������������������7 RDMSs and Big Data����������������������������������������������������������������������������������������������������������������7 The Rise of NoSQL Databases �����������������������������������������������������������������������������������������������������10 Key-Value Databases �������������������������������������������������������������������������������������������������������������10 Document Databases ������������������������������������������������������������������������������������������������������������10 Column Family Databases �����������������������������������������������������������������������������������������������������11 Graph Databases �������������������������������������������������������������������������������������������������������������������11 Special Capabilities of Cassandra �����������������������������������������������������������������������������������������������12 Distributed and Decentralized Database �������������������������������������������������������������������������������12 Log-Structured Storage Engine ���������������������������������������������������������������������������������������������13 v Table of ConTenTs Locally Managed Storage ������������������������������������������������������������������������������������������������������13 Ability to Handle Multiple Types of Data ��������������������������������������������������������������������������������13 Row-Oriented ������������������������������������������������������������������������������������������������������������������������14 Consistency, ACID Requirements, the CAP Theorem, and BASE ��������������������������������������������������14 The ACID Requirements ���������������������������������������������������������������������������������������������������������14 The CAP Theorem ������������������������������������������������������������������������������������������������������������������15 Cassandra’s Drawbacks ��������������������������������������������������������������������������������������������������������������18 Problems with Querying Data ������������������������������������������������������������������������������������������������18 Problems with Writing Data ���������������������������������������������������������������������������������������������������19 Who Should Use Cassandra? �������������������������������������������������������������������������������������������������19 Cassandra Optimizations ������������������������������������������������������������������������������������������������������������20 Data Caches ��������������������������������������������������������������������������������������������������������������������������20 Compression ��������������������������������������������������������������������������������������������������������������������������20 Bloom Filters �������������������������������������������������������������������������������������������������������������������������21 Compaction ���������������������������������������������������������������������������������������������������������������������������21 Is Cassandra Appropriate for You? ����������������������������������������������������������������������������������������������21 Cassandra Data Modeling Essentials ������������������������������������������������������������������������������������������22 Structure Your Data by the Queries ���������������������������������������������������������������������������������������23 Avoid Updates and Deletes ����������������������������������������������������������������������������������������������������23 Evenly Distribute Your Data ���������������������������������������������������������������������������������������������������23 Avoid Querying Across Partitions�������������������������������������������������������������������������������������������23 What a Cassandra Administrator Ought to Know ������������������������������������������������������������������������23 Cassandra Tools ���������������������������������������������������������������������������������������������������������������������24 Acquiring Parallel Remote Tools ��������������������������������������������������������������������������������������������24 Understanding Failure Scenarios in a Cassandra Database ��������������������������������������������������25 Monitoring and Alerting ���������������������������������������������������������������������������������������������������������25 Tuning the Java Virtual Machine ��������������������������������������������������������������������������������������������25 A Quick Introduction to the Architecture of Cassandra ���������������������������������������������������������������26 Understanding Cassandra-Specific Concepts �����������������������������������������������������������������������26 How Cassandra Stores Its Data ���������������������������������������������������������������������������������������������31 An Overview of Cassandra’s Data Model �������������������������������������������������������������������������������31 vi Table of ConTenTs DataStax and Cassandra �������������������������������������������������������������������������������������������������������������32 DataStax Enterprise ���������������������������������������������������������������������������������������������������������������32 DataStax Development Tools �������������������������������������������������������������������������������������������������33 Summary�������������������������������������������������������������������������������������������������������������������������������������34 Chapter 2: Installing Cassandra and Getting Started with CQL Shell .....................35 Installing Apache Cassandra �������������������������������������������������������������������������������������������������������35 Planning the Installation ��������������������������������������������������������������������������������������������������������35 Prerequisites for Installing Cassandra �����������������������������������������������������������������������������������36 Installing Cassandra ��������������������������������������������������������������������������������������������������������������38 Configuring Cassandra ����������������������������������������������������������������������������������������������������������������42 Location of the cassandra�yaml File ��������������������������������������������������������������������������������������43 Minimal Configuration Properties You Must Set ��������������������������������������������������������������������43 Configuring the Firewall ��������������������������������������������������������������������������������������������������������45 Exploring the CQL Shell ���������������������������������������������������������������������������������������������������������������45 Starting the CQL Shell �����������������������������������������������������������������������������������������������������������46 Time Zones in cqlsh ���������������������������������������������������������������������������������������������������������������46 Getting Help in the CQL Shell �������������������������������������������������������������������������������������������������46 Command Line CQL Shell Options �����������������������������������������������������������������������������������������48 Cassandra Installation Directories ����������������������������������������������������������������������������������������������52 The bin Directory �������������������������������������������������������������������������������������������������������������������53 The tools Directory ����������������������������������������������������������������������������������������������������������������54 The lib Directory ��������������������������������������������������������������������������������������������������������������������54 The conf Directory �����������������������������������������������������������������������������������������������������������������54 The Javadoc Directory �����������������������������������������������������������������������������������������������������������55 Starting and Stopping Cassandra �����������������������������������������������������������������������������������������������55 Starting Cassandra ����������������������������������������������������������������������������������������������������������������55 Checking Cassandra’s Status ������������������������������������������������������������������������������������������������57 Starting and Stopping with the service Command ����������������������������������������������������������������61 Clearing Cassandra Data �������������������������������������������������������������������������������������������������������62 Verifying the Cassandra Version ��������������������������������������������������������������������������������������������63 vii Table of ConTenTs Configuring cqlsh ������������������������������������������������������������������������������������������������������������������������63 Configuring Through the cqlshrc Config File �������������������������������������������������������������������������63 Configuring by Specifying Options at the Command Line �����������������������������������������������������64 Finding the Versions ��������������������������������������������������������������������������������������������������������������64 Cqlsh Options ������������������������������������������������������������������������������������������������������������������������64 Putting Cassandra Through Its Paces �����������������������������������������������������������������������������������������65 Connecting to the CQL Shell ��������������������������������������������������������������������������������������������������65 Creating a Keyspace ��������������������������������������������������������������������������������������������������������������66 Creating a Table ���������������������������������������������������������������������������������������������������������������������66 Inserting Test Data �����������������������������������������������������������������������������������������������������������������67 Querying the Table �����������������������������������������������������������������������������������������������������������������67 Getting the History of Your Commands ����������������������������������������������������������������������������������67 Summary�������������������������������������������������������������������������������������������������������������������������������������68 Chapter 3: Deploying a Cassandra Cluster .............................................................69 Planning a Cluster Deployment ���������������������������������������������������������������������������������������������������69 Using cassandra-stress for Planning a Production Deployment �������������������������������������������69 Choosing Memory ������������������������������������������������������������������������������������������������������������������70 Choosing CPUs ����������������������������������������������������������������������������������������������������������������������70 Network Considerations ��������������������������������������������������������������������������������������������������������70 Choosing Storage ������������������������������������������������������������������������������������������������������������������70 Choosing Production Settings for a Linux Server ������������������������������������������������������������������73 Installing PDSH ����������������������������������������������������������������������������������������������������������������������77 Initializing a Cassandra Multi-Node Cluster (Single and Multiple Datacenters) ��������������������������78 Prerequisites �������������������������������������������������������������������������������������������������������������������������79 Configuring the Cluster ����������������������������������������������������������������������������������������������������������81 Initializing the Cluster with Multiple Datacenters ������������������������������������������������������������������84 Starting and Stopping the Multi-Node Cluster �����������������������������������������������������������������������84 The Startup Process of the Nodes in a Cluster ����������������������������������������������������������������������86 Common Errors When Starting Out ����������������������������������������������������������������������������������������87 viii Table of ConTenTs Running Cassandra on Amazon EC2 �������������������������������������������������������������������������������������������90 Using Trusted AMIs ����������������������������������������������������������������������������������������������������������������90 Setting Up the AWS Instances for Cassandra ������������������������������������������������������������������������91 Installing Cassandra ��������������������������������������������������������������������������������������������������������������93 Configuring the Cassandra Cluster ����������������������������������������������������������������������������������������95 Summary�������������������������������������������������������������������������������������������������������������������������������������96 Part II: The Data Model, Cluster Architecture, and the Cassandra Query Language ................................................................................97 Chapter 4: Cassandra Data Modeling, and the Reading and Writing of Data ..........99 Cassandra and Relational Databases: Major Differences ���������������������������������������������������������100 Data-Driven vs� Query-Driven Data Modeling ����������������������������������������������������������������������100 Table Linkages and Referential Integrity �����������������������������������������������������������������������������101 Sort Differences �������������������������������������������������������������������������������������������������������������������101 Duplicating Data ������������������������������������������������������������������������������������������������������������������101 What Is Data Modeling? ������������������������������������������������������������������������������������������������������������102 Analyzing Your Requirements ����������������������������������������������������������������������������������������������102 Conceptual Modeling: Identifying the Entities and the Relationships Among Them ������������103 Reviewing the Queries You Want to Use ������������������������������������������������������������������������������103 Logical Modeling �����������������������������������������������������������������������������������������������������������������105 Physical Data Modeling �������������������������������������������������������������������������������������������������������105 Cassandra Data Modeling Rules �����������������������������������������������������������������������������������������������105 The Two Basic Rules ������������������������������������������������������������������������������������������������������������106 Modeling Around Queries and Not Around Relations �����������������������������������������������������������107 Performance Limitations of Cassandra �������������������������������������������������������������������������������������108 Write Limitations �����������������������������������������������������������������������������������������������������������������108 Read Limitations ������������������������������������������������������������������������������������������������������������������109 The Concept of Eventual Consistency ���������������������������������������������������������������������������������������110 Consistency Conflict Resolution �����������������������������������������������������������������������������������������111 Repairing Data ���������������������������������������������������������������������������������������������������������������������111 ix Table of ConTenTs How Cassandra Writes Data ������������������������������������������������������������������������������������������������������112 Writing to the Commit Log to Protect the Changes �������������������������������������������������������������112 Writing to the Memtable for Durability ��������������������������������������������������������������������������������114 Writing to the SSTables for Durable Storage �����������������������������������������������������������������������117 The Write Request Flow �������������������������������������������������������������������������������������������������������119 Reading Data �����������������������������������������������������������������������������������������������������������������������������125 The Cassandra Read Path����������������������������������������������������������������������������������������������������127 How Write Patterns Affect Reads �����������������������������������������������������������������������������������������128 Cassandra Transactions and the ACID Properties ��������������������������������������������������������������������129 Atomicity �����������������������������������������������������������������������������������������������������������������������������129 Isolation �������������������������������������������������������������������������������������������������������������������������������130 Durability �����������������������������������������������������������������������������������������������������������������������������130 Handling Consistency ����������������������������������������������������������������������������������������������������������������130 Write Consistency ����������������������������������������������������������������������������������������������������������������131 Calculating the Quorum �������������������������������������������������������������������������������������������������������135 Read Consistency ����������������������������������������������������������������������������������������������������������������136 Configuring the Consistency Level ��������������������������������������������������������������������������������������139 Three Types of Read Requests ��������������������������������������������������������������������������������������������140 Testing the Performance of Consistency Levels ������������������������������������������������������������������142 Ensuring Atomicity with Batch Operations ��������������������������������������������������������������������������������143 Configuring Batch Operations ����������������������������������������������������������������������������������������������144 Batch Operations in Single and Multiple Partitions �������������������������������������������������������������144 When Batch Operations Are Good ����������������������������������������������������������������������������������������145 Lightweight Transactions ����������������������������������������������������������������������������������������������������������146 Performing Lightweight Transactions ��������������������������������������������������������������������������������������146 How Lightweight Transactions Work �����������������������������������������������������������������������������������147 Caution When Using Lightweight Transactions ��������������������������������������������������������������������147 Summary�����������������������������������������������������������������������������������������������������������������������������������148 Chapter 5: Cassandra Architecture.......................................................................149 Basic Cluster Terminology ���������������������������������������������������������������������������������������������������������149 Replica Placement Strategy ������������������������������������������������������������������������������������������������152 x

Description:
Follow this handbook to build, configure, tune, and secure Apache Cassandra databases. Start with the installation of Cassandra and move on to the creation of a single instance, and then a cluster of Cassandra databases.Cassandra is increasingly a key player in many big data environments, and this b
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.