ÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄÂþÑÜʽÊý¾Ý¿â
ÔõÑùÔÚlinuxÉÏÉèÖø߿ÉÓõÄÂþÑÜʽÊý¾Ý¿â
ÏÈÈÝ
ÔÚµ±½ñ»¥ÁªÍøʱ´ú£¬Êý¾ÝÁ¿ºÍ»á¼ûÁ¿µÄÒ»Ö±Ôö´ó£¬¶ÔÊý¾Ý¿âµÄ¸ß¿ÉÓÃÐÔºÍÐÔÄÜÌá³öÁ˸ü¸ßµÄÒªÇó¡£ÎªÁËÖª×ãÕâЩÐèÇó£¬ÂþÑÜʽÊý¾Ý¿â³ÉΪÁËÒ»ÖÖÆÕ±é½ÓÄɵĽâ¾ö¼Æ»®¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚlinuxÉÏÉèÖø߿ÉÓõÄÂþÑÜʽÊý¾Ý¿â£¬²¢ÌṩÏìÓ¦µÄ´úÂëʾÀý¡£
È·¶¨ÐèÇóºÍÑ¡ÔñÊý¾Ý¿â
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÃ÷È·ÎÒÃǵÄÐèÇóºÍÑ¡ÔñºÏÊʵÄÂþÑÜʽÊý¾Ý¿â¡£Æ¾Ö¤ÏêϸӦÓó¡¾°£¬ÎÒÃÇ¿ÉÒÔÑ¡ÔñһЩÖøÃûµÄÂþÑÜʽÊý¾Ý¿â£¬ÈçMySQL Cluster¡¢Cassandra»òMongoDBµÈ¡£
×°ÖúÍÉèÖÃÊý¾Ý¿â¼¯Èº
µ±ÎÒÃÇÑ¡ÔñºÃÊý¾Ý¿âºó£¬ÎÒÃÇÐèÒªÔÚLinuxÉÏ×°Öò¢ÉèÖÃÊý¾Ý¿â¼¯Èº¡£ÒÔMySQL ClusterΪÀý£¬ÎÒÃÇ¿ÉÒÔƾ֤ÒÔÏ°취À´²Ù×÷£º
°ì·¨1£º×°ÖÃMySQL ClusterÈí¼þ°ü
ʹÓÃÒÔÏÂÏÂÁî×°ÖÃMySQL ClusterÈí¼þ°ü£º
$ sudo apt-get install mysql-cluster-community-server
µÇ¼ºó¸´ÖÆ
°ì·¨2£º½¨ÉèÉèÖÃÎļþ
ÔÚ×°ÖÃĿ¼Ï½¨ÉèÉèÖÃÎļþmy.cnf£¬ÄÚÈÝÈçÏ£º
[ndbd default] NoOfReplicas = 2 # ÉèÖÃÊý¾Ý¸´ÖƵĸ±±¾Êý DataDir = /var/lib/mysql-cluster # ÉèÖÃÊý¾Ý´æ´¢Ä¿Â¼ [ndbd] NodeId = 1 # ÉèÖýڵãID HostName = 192.168.0.1 # ÉèÖýڵãÖ÷»úÃû DataDir = /usr/local/mysql/data # ÉèÖÃÊý¾Ý´æ´¢Ä¿Â¼ [ndbd] NodeId = 2 # ÉèÖýڵãID HostName = 192.168.0.2 # ÉèÖýڵãÖ÷»úÃû DataDir = /usr/local/mysql/data # ÉèÖÃÊý¾Ý´æ´¢Ä¿Â¼ [ndb_mgmd] NodeId = 3 # ÉèÖýڵãID HostName = 192.168.0.3 # ÉèÖýڵãÖ÷»úÃû DataDir = /var/lib/mysql-cluster # ÉèÖÃÊý¾Ý´æ´¢Ä¿Â¼ [mysqld] NodeId = 4 # ÉèÖýڵãID HostName = 192.168.0.4 # ÉèÖýڵãÖ÷»úÃû [mysqld] NodeId = 5 # ÉèÖýڵãID HostName = 192.168.0.5 # ÉèÖýڵãÖ÷»úÃû
µÇ¼ºó¸´ÖÆ
°ì·¨3£ºÆô¶¯ndb¼¯ÈºÖÎÀíÆ÷
ʹÓÃÒÔÏÂÏÂÁîÆô¶¯ndb¼¯ÈºÖÎÀíÆ÷£º
$ sudo ndb_mgmd -c /etc/mysql-cluster/my.cnf
µÇ¼ºó¸´ÖÆ
°ì·¨4£ºÆô¶¯Êý¾Ý½Úµã
ʹÓÃÒÔÏÂÏÂÁîÆô¶¯Êý¾Ý½Úµã£º
$ sudo ndbd
µÇ¼ºó¸´ÖÆ
°ì·¨5£ºÆô¶¯MySQLЧÀÍÆ÷
ʹÓÃÒÔÏÂÏÂÁîÆô¶¯MySQLЧÀÍÆ÷£º
$ sudo systemctl start mysql
µÇ¼ºó¸´ÖÆ
ÉèÖúÍÖÎÀíÂþÑÜʽÊý¾Ý¿â
Ò»µ©Êý¾Ý¿â¼¯ÈºÀÖ³ÉÆô¶¯£¬ÎÒÃǾͿÉÒÔ¾ÙÐÐÉèÖúÍÖÎÀí¡£ÒÔMySQL ClusterΪÀý£¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´ÉèÖúÍÖÎÀíÂþÑÜʽÊý¾Ý¿â£º
½¨ÉèÊý¾Ý¿â£º
$ mysql -u root -p
µÇ¼ºó¸´ÖÆ
½¨ÉèÊý¾Ý±í£º
mysql> CREATE DATABASE mydatabase; mysql> USE mydatabase; mysql> CREATE TABLE mytable (id INT PRIMARY KEY, name VARCHAR(20));
µÇ¼ºó¸´ÖÆ
²åÈëÊý¾Ý£º
mysql> INSERT INTO mytable VALUES (1, 'John'), (2, 'Mike'), (3, 'Lisa');
µÇ¼ºó¸´ÖÆ
ÅÌÎÊÊý¾Ý£º
mysql> SELECT * FROM mytable;
µÇ¼ºó¸´ÖÆ
¸üÐÂÊý¾Ý£º
mysql> UPDATE mytable SET name = 'Tom' WHERE id = 1;
µÇ¼ºó¸´ÖÆ
ɾ³ýÊý¾Ý£º
mysql> DELETE FROM mytable WHERE id = 2;
µÇ¼ºó¸´ÖÆ
¼à¿ØºÍ¹ÊÕϻָ´
¸ß¿ÉÓõÄÂþÑÜʽÊý¾Ý¿âÐèÒª¾ÙÐÐʵʱ¼à¿ØºÍ¹ÊÕϻָ´¡£ÎÒÃÇ¿ÉÒÔʹÓÃһЩ¼à¿Ø¹¤¾ß£¬ÈçMySQL Enterprise Monitor¡¢Zabbix»òNagiosµÈ£¬À´¼à¿ØÊý¾Ý¿â¼¯ÈºµÄ״̬ºÍÔËÐÐÇéÐΡ£µ±±¬·¢¹ÊÕÏʱ£¬ÎÒÃÇ¿ÉÒÔʹÓÃÏìÓ¦µÄÏÂÁîÀ´¾ÙÐйÊÕϻָ´£¬ÈçMySQL ClusterÖеÄndb_mgmÏÂÁî¡£
×ܽá
ÉèÖø߿ÉÓõÄÂþÑÜʽÊý¾Ý¿âÊÇÒ»¸öÖØ´óµÄÀú³Ì£¬¿ÉÊÇͨ¹ý׼ȷµÄÑ¡ÔñºÍÉèÖã¬ÎÒÃÇ¿ÉÒÔÖª×ã´ó¹æÄ£Êý¾Ý´æ´¢ºÍ¸ß²¢·¢»á¼ûµÄÐèÇó¡£ÔÚLinuxƽ̨ÉÏ£¬ÎÒÃÇ¿ÉÒÔÑ¡ÔñÊʺÏ×Ô¼ºÐèÇóµÄÂþÑÜʽÊý¾Ý¿â£¬²¢Æ¾Ö¤ÏìÓ¦µÄ°ì·¨¾ÙÐÐ×°Öá¢ÉèÖúÍÖÎÀí¡£Í¬Ê±£¬ÎÒÃÇ»¹ÐèҪʹÓüà¿Ø¹¤¾ßÀ´¼à¿ØÊý¾Ý¿â¼¯ÈºµÄ״̬ºÍÔËÐÐÇéÐΣ¬ÒÔ¼°¾ÙÐйÊÕϻָ´²Ù×÷¡£Ï£Íû±¾ÎÄÌṩµÄ´úÂëʾÀýÄܶÔÄãÉèÖÃÂþÑÜʽÊý¾Ý¿âÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄÂþÑÜʽÊý¾Ý¿âµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡