×ðÁú¿­Ê±

ÔõÑùÔÚLinuxÉÏÉèÖÃÂþÑÜʽÊý¾Ý¿â

ÔõÑùÔÚlinuxÉÏÉèÖÃÂþÑÜʽÊý¾Ý¿â

Ëæ×ÅÊý¾ÝÁ¿ºÍÊý¾ÝÐèÇóµÄÔöÌí £¬¹Å°åµÄµ¥½ÚµãÊý¾Ý¿âÒѾ­ÎÞ·¨Öª×ãÏÖ´úÓ¦ÓõÄÐèÇó¡£ÂþÑÜʽÊý¾Ý¿âµÄ·ºÆðΪº£Á¿Êý¾ÝµÄÖÎÀíºÍÅÌÎÊÌṩÁËÒ»ÖÖ½â¾ö¼Æ»®¡£±¾ÎĽ«ÖصãÏÈÈÝÔõÑùÔÚlinuxÉÏÉèÖÃÂþÑÜʽÊý¾Ý¿â £¬²¢ÌṩһЩ¾­µäµÄ´úÂëʾÀý¡£

×°ÖÃÂþÑÜʽÊý¾Ý¿âÈí¼þ

Ê×ÏÈ £¬ÎÒÃÇÐèҪѡÔñÒ»ÖÖºÏÊʵÄÂþÑÜʽÊý¾Ý¿âÈí¼þ¡£³£¼ûµÄÂþÑÜʽÊý¾Ý¿âÈí¼þÓÐHadoop¡¢Cassandra¡¢MongoDBµÈ¡£±¾ÎÄÒÔCassandraΪÀý¾ÙÐÐÑÝʾ¡£

ÔÚLinuxÉÏ×°ÖÃCassandraºÜÊǼòÆÓ¡£ÎÒÃÇ¿ÉÒÔͨ¹ýapt»òyumµÈ°ü¹ÜÀíÆ÷¾ÙÐÐ×°Öá£

ÀýÈç £¬ÔÚUbuntuÉÏ £¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁî¾ÙÐÐ×°Öãº

sudo apt-get install cassandra

µÇ¼ºó¸´ÖÆ

ÉèÖÃÂþÑÜʽÊý¾Ý¿â¼¯Èº

ÔÚÂþÑÜʽÊý¾Ý¿âÖÐ £¬Í¨³£Óжà¸ö½Úµã×é³ÉÒ»¸ö¼¯Èº¡£Ã¿¸ö½Úµã¶¼ÈÏÕæ´æ´¢Ò»²¿·ÖÊý¾Ý £¬²¢ÌṩÅÌÎÊЧÀÍ¡£ÎªÁËÉèÖÃÂþÑÜʽÊý¾Ý¿â¼¯Èº £¬ÎÒÃÇÐèÒªÉèÖÃÒ»¸öÖ÷½Úµã £¬ÆäËû½Úµã½«×÷Ϊ´Ó½Úµã¼ÓÈ뼯Ⱥ¡£

Ê×ÏÈ £¬ÎÒÃÇÐèÒª±à¼­CassandraµÄÉèÖÃÎļþcassandra.yaml £¬¸ÃÎļþͨ³£Î»ÓÚ/etc/cassandraĿ¼Ï¡£ÎÒÃÇ¿ÉÒÔʹÓÃÎı¾±à¼­Æ÷·­¿ª¸ÃÎļþ £¬²¢¾ÙÐÐÈçÏÂÐ޸ģº

cluster_name: 'my_cluster'
seed_provider:
  - class_name: org.apache.cassandra.locator.SimpleSeedProvider
    parameters:
         - seeds: "Ö÷½ÚµãIPµØµã"

µÇ¼ºó¸´ÖÆ

ÆäÖÐ £¬cluster_nameÌåÏÖ¼¯ÈºµÄÃû³Æ £¬¿ÉÒÔí§ÒâÈ¡Ãû¡£seed_providerÌåÏÖÖÖ×ӽڵ㣨Ö÷½Úµã£©ÌṩÕß £¬ÎÒÃÇÐèÒª½«Ö÷½ÚµãµÄIPµØµãÌ滻ΪÏÖʵµÄIPµØµã¡£

½ÓÏÂÀ´ £¬ÎÒÃÇÐèÒªÔÚÿ¸ö½ÚµãÉϾÙÐÐÏàͬµÄÉèÖá£Ö»Ð轫Ö÷½ÚµãµÄIPµØµãÉèÖÃΪÆäËû½ÚµãµÄseed_provider¼´¿É¡£ÔÚÿ¸ö½ÚµãÉÏÉúÑÄÉèÖÃÎļþ²¢ÖØÆôCassandraЧÀÍ¡£

½¨ÉèÂþÑÜʽÊý¾Ý¿â±í

ÔÚÂþÑÜʽÊý¾Ý¿âÖÐ £¬Êý¾Ýͨ³£ÒÔ±íµÄÐÎʽ×éÖ¯´æ´¢¡£ÎªÁ˽¨Éè±í £¬ÔÚCassandraÏÂÁîÐнçÃ棨cqlsh£©ÖÐÖ´ÐÐÒÔÏÂÏÂÁ

CREATE KEYSPACE my_keyspace
WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};

USE my_keyspace;

CREATE TABLE my_table (
    id INT PRIMARY KEY,
    name TEXT,
    age INT
);

µÇ¼ºó¸´ÖÆ

ÒÔÉÏÏÂÁ½¨ÉèÒ»¸öÃûΪmy_keyspaceµÄ¼ü¿Õ¼ä £¬²¢Ôڸüü¿Õ¼äϽ¨ÉèÒ»¸öÃûΪmy_tableµÄ±í¡£±íÖаüÀ¨id¡¢nameºÍageÈý¸öÁÐ £¬ÆäÖÐidÁб»½ç˵ΪÖ÷¼ü¡£

²åÈëºÍÅÌÎÊÊý¾Ý

ͨ¹ýÒÔÏ´úÂëʾÀý £¬ÎÒÃÇ¿ÉÒÔ²åÈëºÍÅÌÎÊÊý¾Ý£º

from cassandra.cluster import Cluster

cluster = Cluster(['½ÚµãIPµØµã'])
session = cluster.connect('my_keyspace')

# ²åÈëÊý¾Ý
insert_query = "INSERT INTO my_table (id, name, age) VALUES (?, ?, ?)"
session.execute(insert_query, (1, 'Alice', 25))

# ÅÌÎÊÊý¾Ý
select_query = "SELECT * FROM my_table WHERE id = ?"
result = session.execute(select_query, (1,))

for row in result:
    print(row.name, row.age)

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂëʾÀýʹÓÃPythonµÄcassandra-driver¿â¾ÙÐÐÊý¾Ý²Ù×÷¡£Ê×ÏÈ £¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸öCluster¹¤¾ß £¬ÆäÖаüÀ¨ËùÓнڵãµÄIPµØµã¡£È»ºó £¬Í¨¹ýCluster¹¤¾ß½¨ÉèÒ»¸öSession¹¤¾ß £¬²¢Ö¸¶¨Ê¹Óõļü¿Õ¼ä£¨my_keyspace£©¡£½ÓÏÂÀ´ £¬ÎÒÃÇ¿ÉÒÔʹÓÃexecuteÒªÁìÖ´ÐÐCQLÅÌÎÊÓï¾ä¡£

Êý¾ÝÂþÑܺ͸ºÔØƽºâ

ÂþÑÜʽÊý¾Ý¿â»á½«Êý¾ÝÂþÑܵ½²î±ðµÄ½ÚµãÉÏ £¬ÒÔʵÏÖ¸ºÔØƽºâºÍ¸ß¿ÉÓÃÐÔ¡£ÔÚCassandraÖÐ £¬Êý¾ÝµÄÂþÑÜÊÇ»ùÓÚ¹þÏ£·ÖÇøµÄ £¬Ëü½«Êý¾ÝÔȳƵØÂþÑܵ½²î±ðµÄ½ÚµãÉÏ¡£

ΪÁËÌá¸ßÅÌÎÊÐÔÄÜ £¬ÎÒÃÇ¿ÉÒÔ½¨É踴ºÏË÷Òý»òʹÓ÷ÖÇø¼ü¾ÙÐÐÅÌÎÊ¡£¸´ºÏË÷Òý¿ÉÒÔÔÚ¶à¸öÁÐÉϽ¨ÉèË÷Òý £¬ÒÔ¼ÓËÙÅÌÎÊËÙÂÊ¡£·ÖÇø¼ü¾öÒéÁËÊý¾ÝÔÚ½Úµã¼äµÄÂþÑÜ £¬ºÏÀíÑ¡Ôñ·ÖÇø¼ü¿ÉÒÔÌá¸ß¸ºÔØƽºâЧ¹û¡£

×ܽá

±¾ÎÄÏÈÈÝÁËÔõÑùÔÚlinuxÉÏÉèÖÃÂþÑÜʽÊý¾Ý¿â £¬²¢ÌṩÁËCassandra×÷ΪʾÀý¡£Í¨¹ýÉèÖÃÂþÑÜʽÊý¾Ý¿â¼¯Èº¡¢½¨Éè±í¡¢²åÈëºÍÅÌÎÊÊý¾Ý £¬ÎÒÃÇ¿ÉÒÔ³ä·ÖʹÓÃÂþÑÜʽÊý¾Ý¿âµÄÓÅÊÆ £¬Öª×ã´ó¹æÄ£Êý¾Ý´æ´¢ºÍÅÌÎʵÄÐèÇó¡£ÒÔÏÂÊDZ¾ÎÄÉæ¼°µ½µÄÒªº¦°ì·¨ºÍʾÀý´úÂ룺

×°ÖÃÂþÑÜʽÊý¾Ý¿âÈí¼þ£º

sudo apt-get install cassandra

ÉèÖÃÂþÑÜʽÊý¾Ý¿â¼¯Èº£º

±à¼­CassandraÉèÖÃÎļþ²¢ÉèÖÃseed_provider²ÎÊý¡£

½¨ÉèÂþÑÜʽÊý¾Ý¿â±í£º

ÔÚCassandraÏÂÁîÐнçÃæÖ´ÐÐCREATE KEYSPACEºÍCREATE TABLEÓï¾ä¡£

²åÈëºÍÅÌÎÊÊý¾Ý£º

ʹÓÃcassandra-driver¿âÖ´ÐÐÊý¾Ý²Ù×÷¡£

Ï£Íû±¾ÎÄÄܹ»×ÊÖú¶ÁÕßÏàʶÂþÑÜʽÊý¾Ý¿âµÄÉèÖúÍʹÓÃÒªÁì £¬²¢ÄÜÔÚLinuxÇéÐÎÏÂ˳Ëì´î½¨ÂþÑÜʽÊý¾Ý¿â¼¯Èº¡£

ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÉÏÉèÖÃÂþÑÜʽÊý¾Ý¿âµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±ÊµÊ±ÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿