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

数据库 MySQL 数据库运维
在这里我们将跳出原有的RedHat系统,讲解Ubuntu系统上如何配置MySQL集群的问题。希望对大家有所帮助。

大家在网上都能找到都是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触发器如何正确使用

 

责任编辑:彭凡 来源: Ubuntu社区
相关推荐

2011-09-07 13:33:51

ubuntuUbuntu Twea

2014-06-30 09:27:17

UbuntuTomcat集群

2018-04-03 13:31:53

LinuxUbuntu 16.0msmtp

2022-09-14 11:31:37

MySQL数据库管理系统

2010-08-17 15:08:48

MySQL集群

2015-09-06 09:55:51

UbuntuHHVM

2019-04-28 10:00:11

UbuntuLinuxMySQL

2011-01-12 09:59:28

Ubuntu Serviptables

2011-01-14 14:00:19

GanetiLinux集群虚拟化

2011-05-24 09:33:40

UbuntuOpenStackNova

2011-08-31 17:55:06

2011-03-10 11:06:02

Ubuntu搭建LAMP

2020-12-26 14:48:21

UbuntuLinuxDeb文件

2010-07-13 09:46:09

TomcatUbuntu 10.0

2011-01-21 17:43:13

2019-07-05 09:45:19

UbuntuLinux释放空间

2021-04-09 10:58:51

UbuntuLinuxWindows 10

2013-04-18 15:53:46

SLURM开源分布式资源管理

2023-09-24 19:24:18

UbuntuVSCodium

2014-09-11 11:32:21

Ubuntu运维
点赞
收藏

51CTO技术栈公众号