自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

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

數(shù)據(jù)庫 MySQL 數(shù)據(jù)庫運(yùn)維
在這里我們將跳出原有的RedHat系統(tǒng),講解Ubuntu系統(tǒng)上如何配置MySQL集群的問題。希望對大家有所幫助。

大家在網(wǎng)上都能找到都是RedHat系統(tǒng)等等,對Ubuntu系統(tǒng)MySQL集群就沒有介紹文章

我現(xiàn)在寫寫Ubuntu這個MySQL集群方法。新手不要罵我,呵呵。

介紹網(wǎng)絡(luò)環(huán)境:

測試環(huán)境:

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

ndbd: 數(shù)據(jù)庫節(jié)點。

mysqld –ndb-cluster: MySQL服務(wù)器節(jié)點,程序直接訪問的是這臺機(jī)器的IP。默認(rèn)端口仍是3306。

ndbd_mgm ndbd_mgmd:管理節(jié)點。管理/查看各庫節(jié)點和服務(wù)器節(jié)點的狀態(tài)。

二、集群方案

1.管理節(jié)點:server3(192.168.245.13)

2.存儲節(jié)點:server1(192.168.245.11),server2(192.168.245.12)

3.SQL節(jié)點:server1(192.168.245.11),server2(192.168.245.12),server3(192.168.245.13)

三、mysql安裝和配置

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

2.配置這三臺服務(wù)器上配置my.cnf,這三臺服務(wù)器都要配置

  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結(jié)束——————————————————— 

主要在:[mysqld]下添加:

  1. ndbcluster  
  2. ndb-connectstring=192.168.245.13 

和添加

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

上面三臺服務(wù)器都要一樣

2.配置ndb_mgmd.cnf(192.168.245.13服務(wù)器上配置)

復(fù)制/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. ——————-結(jié)束———— 

先啟動:

13服務(wù)器:

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

然后啟動

11.12服務(wù)器

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

最后啟動,13.11.12服務(wù)器mysql服務(wù)

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

測試:

13服務(wù)器上:

  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簇內(nèi)操作數(shù)據(jù)的方式?jīng)]有太大的區(qū)別。

執(zhí)行這類操作時應(yīng)記住三點

1.表必須用ENGINE=NDB或ENGINE=NDBCLUSTER選項創(chuàng)建,或用ALTER TABLE選項更改,以使用NDB Cluster存儲引擎在 Cluster內(nèi)復(fù)制它們。如果使用mysqldump的輸出從已有數(shù)據(jù)庫導(dǎo)入表,可在文本編輯器中打開SQL腳本,并將該選項添加到任何表創(chuàng)建語句,或用這類選項之一替換任何已有的ENGINE(或TYPE)選項。

2.另外還請記住,每個NDB表必須有一個主鍵。如果在創(chuàng)建表時用戶未定義主鍵,NDB Cluster存儲引擎將自動生成隱含的主鍵。(注釋:該隱含 鍵也將占用空間,就像任何其他的表索引一樣。由于沒有足夠的內(nèi)存來容納這些自動創(chuàng)建的鍵,出現(xiàn)問題并不罕見)。

3.當(dāng)你在一個節(jié)點上運(yùn)行create database mydb;你去其他sql node上執(zhí)行show databases;將不能看到mydb,你需要創(chuàng)建它,然后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數(shù)據(jù)庫集群進(jìn)行正確配置步驟
  2. MySQL 集群在Server1與Server2上如何安裝MySQL
  3. MySQL集群配置
  4. MySQL集群自動安裝腳本
  5. MySQL觸發(fā)器如何正確使用

 

責(zé)任編輯:彭凡 來源: Ubuntu社區(qū)
相關(guān)推薦

2014-06-30 09:27:17

UbuntuTomcat集群

2011-09-07 13:33:51

ubuntuUbuntu Twea

2018-04-03 13:31:53

LinuxUbuntu 16.0msmtp

2022-09-14 11:31:37

MySQL數(shù)據(jù)庫管理系統(tǒng)

2010-08-17 15:08:48

MySQL集群

2015-09-06 09:55:51

UbuntuHHVM

2019-04-28 10:00:11

UbuntuLinuxMySQL

2011-05-24 09:33:40

UbuntuOpenStackNova

2011-01-12 09:59:28

Ubuntu Serviptables

2011-01-14 14:00:19

GanetiLinux集群虛擬化

2011-03-10 11:06:02

Ubuntu搭建LAMP

2020-12-26 14:48:21

UbuntuLinuxDeb文件

2011-08-31 17:55:06

2011-01-21 17:43:13

2013-04-18 15:53:46

SLURM開源分布式資源管理

2010-07-13 09:46:09

TomcatUbuntu 10.0

2023-09-24 19:24:18

UbuntuVSCodium

2022-08-05 22:02:07

UbuntuLinuxVim

2019-07-05 09:45:19

UbuntuLinux釋放空間

2021-04-09 10:58:51

UbuntuLinuxWindows 10
點贊
收藏

51CTO技術(shù)棧公眾號