MySQL集群在Ubuntu 9.0上的配置方法

大家在网上都能找到都是RedHat系统等等,对Ubuntu系统MySQL集群就没有介绍文章

我现在写写Ubuntu这个MySQL集群方法。新手不要骂我,呵呵。

介绍网络环境:

测试环境:

  1. Server1: ndbd 192.168.245.11  
  2. Server2: ndbd 192.168.245.12  
  3. Server3: mysqld –ndb-cluster 192.168.245.13 

ndbd: 数据库节点。

mysqld –ndb-cluster: MySQL服务器节点,程序直接访问的是这台机器的IP。默认端口仍是3306。

ndbd_mgm ndbd_mgmd:管理节点。管理/查看各库节点和服务器节点的状态。

二、集群方案

1.管理节点:server3(192.168.245.13)

2.存储节点:server1(192.168.245.11),server2(192.168.245.12)

3.SQL节点:server1(192.168.245.11),server2(192.168.245.12),server3(192.168.245.13)

三、mysql安装和配置

1.安装,sudo apt-get install mysql-server

2.配置这三台服务器上配置my.cnf,这三台服务器都要配置

  1. vim /etc/mysql/my.cnf  
  2. —————————————–my.cnf开始——————————————–  
  3. Ubuntu@ubuntu:~$ cat /etc/mysql/my.cnf  
  4. #  
  5. # The MySQL database server configuration file.  
  6. #  
  7. # You can copy this to one of:  
  8. # - “/etc/mysql/my.cnf” to set global options,  
  9. # - “~/.my.cnf” to set user-specific options.  
  10. #  
  11. # One can use all long options that the program supports.  
  12. # Run program with –help to get a list of available options and with  
  13. # –print-defaults to see which it would actually understand and use.  
  14. #  
  15. # For explanations see  
  16. # http://dev.mysql.com/doc/mysql/en/serve ... ables.html  
  17.  
  18. # This will be passed to all mysql clients  
  19. # It has been reported that passwords should be enclosed with ticks/quotes  
  20. # escpecially if they contain “#” chars…  
  21. # Remember to edit /etc/mysql/debian.cnf when changing the socket location.  
  22. [client]  
  23. port = 3306 
  24. socket = /var/run/mysqld/mysqld.sock  
  25.  
  26. # Here is entries for some specific programs  
  27. # The following values assume you have at least 32M ram  
  28.  
  29. # This was formally known as [safe_mysqld]. Both versions are currently parsed.  
  30. [mysqld_safe]  
  31. socket = /var/run/mysqld/mysqld.sock  
  32. nice = 0 
  33.  
  34. [mysqld]  
  35. #  
  36. # * Basic Settings  
  37. #  
  38.  
  39. #  
  40. # * IMPORTANT  
  41. # If you make changes to these settings and your system uses apparmor, you may  
  42. # also need to also adjust /etc/apparmor.d/usr.sbin.mysqld.  
  43. #  
  44.  
  45. user = mysql 
  46. pid-file = /var/run/mysqld/mysqld.pid  
  47. socket = /var/run/mysqld/mysqld.sock  
  48. port = 3306 
  49. basedir = /usr  
  50. datadir = /var/lib/mysql  
  51. tmpdir = /tmp  
  52. language = /usr/share/mysql/english  
  53. skip-external-locking  
  54. #  
  55. # Instead of skip-networking the default is now to listen only on  
  56. # localhost which is more compatible and is not less secure.  
  57. bind-address = 127.0.0.1  
  58. #  
  59. # * Fine Tuning  
  60. #  
  61. key_buffer = 16M 
  62. max_allowed_packet = 16M 
  63. thread_stack = 128K 
  64. thread_cache_size = 8 
  65. #max_connections = 100 
  66. #table_cache = 64 
  67. #thread_concurrency = 10 
  68. #  
  69. # * Query Cache Configuration  
  70. #  
  71. query_cache_limit = 1M 
  72. query_cache_size = 16M 
  73. #  
  74. # * Logging and Replication  
  75. #  
  76. # Both location gets rotated by the cronjob.  
  77. # Be aware that this log type is a performance killer.  
  78. #log = /var/log/mysql/mysql.log  
  79. #  
  80. # Error logging goes to syslog. This is a Debian improvement   
  81. #  
  82. # Here you can see queries with especially long duration  
  83. #log_slow_queries = /var/log/mysql/mysql-slow.log  
  84. #long_query_time = 2 
  85. #log-queries-not-using-indexes  
  86. #  
  87. # The following can be used as easy to replay backup logs or for replication.  
  88. # note: if you are setting up a replication slave, see README.Debian about  
  89. # other settings you may need to change.  
  90. #server-id = 1 
  91. #log_bin = /var/log/mysql/mysql-bin.log  
  92. expire_logs_days = 10 
  93. max_binlog_size = 100M 
  94. #binlog_do_db = include_database_name 
  95. #binlog_ignore_db = include_database_name 
  96. #  
  97. # * BerkeleyDB  
  98. #  
  99. # Using BerkeleyDB is now discouraged as its support will cease in 5.1.12.  
  100. skip-bdb  
  101. #  
  102. # * MyISAM  
  103. #  
  104. # MyISAM is enabled by default with a 10MB datafile in /var/lib/mysql/.  
  105. # Read the manual for more MyISAM related options. There are many!  
  106. # You might want to disable MyISAM to shrink the mysqld process by circa 100MB.  
  107. #skip-innodb  
  108. #  
  109. # * Security Features  
  110. #  
  111. # Read the manual, too, if you want chroot!  
  112. chroot = /var/lib/mysql/  
  113. #  
  114. # For generating SSL certificates I recommend the OpenSSL GUI “tinyca”.  
  115. #  
  116. ssl-ca=/etc/mysql/cacert.pem  
  117. ssl-cert=/etc/mysql/server-cert.pem  
  118. ssl-key=/etc/mysql/server-key.pem  
  119.  
  120. ndbcluster  
  121. ndb-connectstring=192.168.245.13  
  122.  
  123. [mysqldump]  
  124. quick  
  125. quote-names  
  126. max_allowed_packet = 16M 
  127.  
  128. [mysql]  
  129. #no-auto-rehash # faster start of mysql but no tab completition  
  130.  
  131. [isamchk]  
  132. key_buffer = 16M 
  133.  
  134. #  
  135. # * NDB Cluster  
  136. #  
  137. # See /usr/share/doc/mysql-server-*/README.Debian for more information.  
  138. #  
  139. # The following configuration is read by the NDB Data Nodes (ndbd processes)  
  140.  
  141. # not from the NDB Management Nodes (ndb_mgmd processes).  
  142. #  
  143. [MYSQL_CLUSTER]  
  144.  
  145. ndb-connectstring=192.168.245.13  
  146.  
  147. #  
  148. # * IMPORTANT: Additional settings that can override those from this file!  
  149. # The files must end with ‘.cnf’, otherwise they’ll be ignored.  
  150. #  
  151. !includedir /etc/mysql/conf.d/  
  152.  
  153. Ubuntu@ubuntu:~$  
  154. ———————————my.cnf结束——————————————————— 

主要在:[mysqld]下添加:

  1. ndbcluster  
  2. ndb-connectstring=192.168.245.13 

和添加

  1. [MYSQL_CLUSTER]  
  2. ndb-connectstring=192.168.245.13 

上面三台服务器都要一样

2.配置ndb_mgmd.cnf(192.168.245.13服务器上配置)

复制/usr/share/doc/mysql-server-5.0/examples/ndb_mgmd.cnf到/etc/mysql/ndb_mgmd.cnf

编辑ndb_mgmd.cnf

  1. ——————-开始————  
  2. Ubuntu@ubuntu:~$ cat /etc/mysql/ndb_mgmd.cnf  
  3. [NDBD DEFAULT]  
  4. NoOfReplicas=2 
  5. DataMemory=10MB 
  6. IndexMemory=25MB 
  7. MaxNoOfTables=256 
  8. MaxNoOfOrderedIndexes=256 
  9. MaxNoOfUniqueHashIndexes=128 
  10.  
  11. [MYSQLD DEFAULT]  
  12. [NDB_MGMD DEFAULT]  
  13. [TCP DEFAULT]  
  14. [NDB_MGMD]  
  15. Id=1 # the NDB Management Node (this one)  
  16. HostName=192.168.245.13  
  17. DataDir= /var/lib/mysql-cluster  
  18.  
  19. [NDBD]  
  20. Id=2 # the first NDB Data Node  
  21. HostName=192.168.245.11  
  22. DataDir= /var/lib/mysql-cluster  
  23.  
  24. [NDBD]  
  25. Id=3 # the second NDB Data Node  
  26. HostName=192.168.245.12  
  27. DataDir=/var/lib/mysql-cluster  
  28.  
  29. [MYSQLD]  
  30. Id=4 # the first SQL node  
  31. HostName=192.168.245.13  
  32. [MYSQLD]  
  33. Id=5 # the first SQL node  
  34. HostName=192.168.245.11  
  35. [MYSQLD]  
  36. Id=6 # the first SQL node  
  37. HostName=192.168.245.12  
  38.  
  39. Ubuntu@ubuntu:~$  
  40.  
  41. ——————-结束———— 

先启动:

13服务器:

  1. sudo /etc/init.d/mysql-ndb-mgm start 

然后启动

11.12服务器

  1. sudo /etc/init.d/mysql-ndb start 

最后启动,13.11.12服务器mysql服务

  1. sudo /etc/init.d/mysql start 

测试:

13服务器上:

  1. neo@mgm:~$ ndb_mgm  
  2. – NDB Cluster — Management Client –  
  3. ndb_mgm> show  
  4. Connected to Management Server at: localhost:1186  
  5. Cluster Configuration  
  6. ———————  
  7. [ndbd(NDB)] 2 node(s)  
  8. id=2 @192.168.245.11 (Version: 5.0.51, Nodegroup: 0)  
  9. id=3 @192.168.245.12 (Version: 5.0.51, Nodegroup: 0, Master)  
  10.  
  11. [ndb_mgmd(MGM)] 1 node(s)  
  12. id=1 @192.168.245.13 (Version: 5.0.51)  
  13.  
  14. [mysqld(API)] 2 node(s)  
  15. id=4 @192.168.245.13 (Version: 5.0.51)  
  16. id=5 @192.168.245.11 (Version: 5.0.51)  
  17. id=5 @192.168.245.12 (Version: 5.0.51)  
  18.  
  19. ndb_mgm> 

与没有使用簇的MySQL相比,在MySQL簇内操作数据的方式没有太大的区别。

执行这类操作时应记住三点

1.表必须用ENGINE=NDB或ENGINE=NDBCLUSTER选项创建,或用ALTER TABLE选项更改,以使用NDB Cluster存储引擎在 Cluster内复制它们。如果使用mysqldump的输出从已有数据库导入表,可在文本编辑器中打开SQL脚本,并将该选项添加到任何表创建语句,或用这类选项之一替换任何已有的ENGINE(或TYPE)选项。

2.另外还请记住,每个NDB表必须有一个主键。如果在创建表时用户未定义主键,NDB Cluster存储引擎将自动生成隐含的主键。(注释:该隐含 键也将占用空间,就像任何其他的表索引一样。由于没有足够的内存来容纳这些自动创建的键,出现问题并不罕见)。

3.当你在一个节点上运行create database mydb;你去其他sql node上执行show databases;将不能看到mydb,你需要创建它,然后use mydb; show tables;你将看到同步的表。

  1. SQL Node 1  
  2. neo@sql:~$ mysql -uroot -p  
  3. Enter password:  
  4. Welcome to the MySQL monitor. Commands end with ; or g.  
  5. Your MySQL connection id is 7  
  6. Server version: 5.0.51a-3Ubuntu5.1 (Ubuntu)  
  7.  
  8. Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.  
  9.  
  10. mysql> create database cluster;  
  11. Query OK, 1 row affected (0.00 sec)  
  12.  
  13. mysql> use cluster  
  14. Database changed  
  15. mysql> create table city( id mediumint unsigned not null auto_increment primary key, 
  16. name varchar(20) not null default ” ) engine = ndbcluster default  
  17.  
  18. charset utf8;  
  19. Query OK, 0 rows affected (1.07 sec)  
  20.  
  21. mysql> insert into city values(1, ‘Shenzhen’);  
  22. Query OK, 1 row affected (0.12 sec)  
  23.  
  24. mysql> insert into city values(2, ‘Guangdong’);  
  25. Query OK, 1 row affected (0.00 sec)  
  26.  
  27. SQL Node 2  
  28.  
  29. neo@sql:~$ mysql -uroot -p  
  30. Enter password:  
  31. Welcome to the MySQL monitor. Commands end with ; or g.  
  32. Your MySQL connection id is 7  
  33. Server version: 5.0.51a-3Ubuntu5.1 (Ubuntu)  
  34.  
  35. Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.  
  36.  
  37. mysql> show databases;  
  38. ——————–   
  39. | Database |  
  40. ——————–   
  41. | information_schema |  
  42. | example |  
  43. | mydb |  
  44. | mysql |  
  45. | neo |  
  46. ——————–   
  47. 6 rows in set (0.13 sec)  
  48.  
  49. mysql> create database cluster;  
  50. Query OK, 1 row affected (0.00 sec)   
  51. mysql> show databases;  
  52. ——————–   
  53. | Database |  
  54. ——————–   
  55. | information_schema |  
  56. | cluster |  
  57. | example |  
  58. | mydb |  
  59. | mysql |  
  60. | neo |  
  61. ——————–   
  62. 6 rows in set (0.13 sec)  
  63.  
  64. mysql> use cluster;  
  65. Reading table information for completion of table and column names  
  66. You can turn off this feature to get a quicker startup with -A  
  67.  
  68. Database changed  
  69. mysql> show tables;  
  70. ——————-   
  71. | Tables_in_cluster |  
  72. ——————-   
  73. | city |  
  74. ——————-   
  75. 1 row in set (0.01 sec)  
  76.  
  77. mysql> select * from city;  
  78. —- ———–   
  79. | id | name |  
  80. —- ———–   
  81. | 1 | Shenzhen |  
  82. | 2 | Guangdong |  
  83. —- ———–   
  84. 2 rows in set (0.03 sec)  
  85.  
  86. mysql> 

【编辑推荐】 

  1. MySQL数据库集群进行正确配置步骤
  2. MySQL 集群在Server1与Server2上如何安装MySQL
  3. MySQL集群配置
  4. MySQL集群自动安装脚本
  5. MySQL触发器如何正确使用

 

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/305562.html<

(0)
运维的头像运维
上一篇2025-05-26 06:16
下一篇 2025-05-26 06:17

相关推荐

  • 个人主题怎么制作?

    制作个人主题是一个将个人风格、兴趣或专业领域转化为视觉化或结构化内容的过程,无论是用于个人博客、作品集、社交媒体账号还是品牌形象,核心都是围绕“个人特色”展开,以下从定位、内容规划、视觉设计、技术实现四个维度,详细拆解制作个人主题的完整流程,明确主题定位:找到个人特色的核心主题定位是所有工作的起点,需要先回答……

    2025-11-20
    0
  • 社群营销管理关键是什么?

    社群营销的核心在于通过建立有温度、有价值、有归属感的社群,实现用户留存、转化和品牌传播,其管理需贯穿“目标定位-内容运营-用户互动-数据驱动-风险控制”全流程,以下从五个维度展开详细说明:明确社群定位与目标社群管理的首要任务是精准定位,需明确社群的核心价值(如行业交流、产品使用指导、兴趣分享等)、目标用户画像……

    2025-11-20
    0
  • 香港公司网站备案需要什么材料?

    香港公司进行网站备案是一个涉及多部门协调、流程相对严谨的过程,尤其需兼顾中国内地与香港两地的监管要求,由于香港公司注册地与中国内地不同,其网站若主要服务内地用户或使用内地服务器,需根据服务器位置、网站内容性质等,选择对应的备案路径(如工信部ICP备案或公安备案),以下从备案主体资格、流程步骤、材料准备、注意事项……

    2025-11-20
    0
  • 如何企业上云推广

    企业上云已成为数字化转型的核心战略,但推广过程中需结合行业特性、企业痛点与市场需求,构建系统性、多维度的推广体系,以下从市场定位、策略设计、执行落地及效果优化四个维度,详细拆解企业上云推广的实践路径,精准定位:明确目标企业与核心价值企业上云并非“一刀切”的方案,需先锁定目标客户群体,提炼差异化价值主张,客户分层……

    2025-11-20
    0
  • PS设计搜索框的实用技巧有哪些?

    在PS中设计一个美观且功能性的搜索框需要结合创意构思、视觉设计和用户体验考量,以下从设计思路、制作步骤、细节优化及交互预览等方面详细说明,帮助打造符合需求的搜索框,设计前的规划明确使用场景:根据网站或APP的整体风格确定搜索框的调性,例如极简风适合细线条和纯色,科技感适合渐变和发光效果,电商类则可能需要突出搜索……

    2025-11-20
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注