Cassandra #01 เริ่มต้นใช้งาน
Cassandra เป็นระบบ Database ที่เหมาะสำหรับการ Scalability และให้ High Availability โดยไปลดประสิทธิภาพ มีความทนทานสูง (Fault Tolerance) โดยสามารถใช้งานเครื่องคอมพิวเตอร์ทั่วไปๆ (Commodity Hardware) หรือ ใช้งาน Cloud Infrastructure สำหรับงานที่มีความสำคัญได้ (Mission Critical) สามารถกระจายสำเนา (Replication) ข้าม Data Center ได้อีกด้วย [1][3] ในบทความนี้ จะแสดงการติดตั้งบน Ubuntu 16.04 เพียงเครื่องเดียวก่อน และให้เห็นวิธีการติดต่อตัวฐานข้อมูล การส่ง Query เบื้องต้น # echo “deb http://www.apache.org/dist/cassandra/debian 310x main” | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list # curl https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add – # sudo apt-get update # sudo apt-get install cassandra ต่อไป วิธีการส่งคำสั่งไปยัง Cassandra จะใช้งานผ่าน cqlsh (Cassandra Query Language Shell) # cqlsh -C Connected to Test Cluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra 3.10 | CQL spec 3.4.4 | Native protocol v4] Use HELP for help. cqlsh> ใน Cassandra จะเรียก Database ว่า Keyspace วิธีที่จะดูว่ามี Keyspace อะไรอยู่บ้าง ใช้คำสั่ง [2] cqlsh> DESCRIBE keyspaces; system_schema system_auth system system_distributed system_traces สั่งสร้าง Keyspace ชื่อ test ด้วยคำสั่งต่อไปนี้ cqlsh> CREATE KEYSPACE test WITH REPLICATION = {‘class’ : ‘SimpleStrategy’, ‘replication_factor’ : 3}; เนื่องจาก Cassandra มีลักษณะพิเศษที่ไม่เหมือนกับ Database Servers อื่นๆ ก็คือเรื่องการ Replication ตั้งแต่เริ่มต้น ในคำสั่งข้างต้น จะบอกว่า ระบบจากสร้าง 3 สำเนา เป็นหลัก (จะกล่าวรายละเอียดในตอนต่อๆไป) ต่อไป สั่งสร้าง Table ชื่อ table1 csqlsh> use test; cqlsh:test> create table table1 ( … id text primary key, … age int, … firstname text, … lastname text … ); คำสั่งในการ Insert ข้อมูล cqlsh:test> INSERT INTO table1 (id, age, firstname, lastname) VALUES ( ‘000001’, 10, ‘John’,