Home Database Mysql Tutorial MySQL集群配置实践:双服务器防止系统崩溃

MySQL集群配置实践:双服务器防止系统崩溃

Jun 07, 2016 pm 02:52 PM
mysql practice collapse server Notice system Configuration prevent cluster

注意!虽然这是基于2台服务器的MySQL集群,但也必须有额外的第三台服务器作为管理节点,但这台服务器可以在集群启动完成后关闭。同时需要注意的是并不推荐在集群启动完成后关闭作为管理节点的服务器。尽管理论上可以建立基于只有2台服务器的MySQL集群,但是

  注意!虽然这是基于2台服务器的MySQL集群,但也必须有额外的第三台服务器作为管理节点,但这台服务器可以在集群启动完成后关闭。同时需要注意的是并不推荐在集群启动完成后关闭作为管理节点的服务器。尽管理论上可以建立基于只有2台服务器的MySQL集群,但是这样的架构,一旦一台服务器宕机之后集群就无法继续正常工作了,这样也就失去了集群的意义了。出于这个原因,就需要有第三台服务器作为管理节点运行。另外,可能很多朋友都没有3台服务器的实际环境,可以考虑在VMWare或其他虚拟机中进行实验。

  下面假设这3台服务的情况:

  Server1: mysql1.vmtest.net 192.168.0.1  
  Server2: mysql2.vmtest.net 192.168.0.2  
  Server3: mysql3.vmtest.net 192.168.0.3 

  Servers1和Server2作为实际配置MySQL集群的服务器。对于作为管理节点的Server3则要求较低,只需对Server3的系统进行很小的调整并且无需安装MySQL,Server3可以使用一台配置较低的计算机并且可以在Server3同时运行其他服务。二、在Server1和Server2上安装MySQL

  =================================从[url][/url]上下载mysql-max-4.1.9-pc-linux-gnu-i686.tar.gz注意:必须是max版本的MySQL,Standard版本不支持集群部署!以下步骤需要在Server1和Server2上各做一次

  # mv mysql-max-4.1.9-pc-linux-gnu-i686.tar.gz /usr/local/  
  # cd /usr/local/  
  # groupadd mysql  
  # useradd -g mysql mysql  
  # tar -zxvf mysql-max-4.1.9-pc-linux-gnu-i686.tar.gz  
  # rm -f mysql-max-4.1.9-pc-linux-gnu-i686.tar.gz  
  # mv mysql-max-4.1.9-pc-linux-gnu-i686 mysql  
  # cd mysql  
  # scripts/mysql_install_db --user=mysql
  # chown -R root .  
  # chown -R mysql data  
  # chgrp -R mysql .  
  # cp support-files/mysql.server /etc/rc.d/init.d/mysqld  
  # chmod +x /etc/rc.d/init.d/mysqld  
  # chkconfig --add mysqld 

  此时不要启动MySQL!

  安装并配置管理节点服务器(Server3)

  =====================================作为管理节点服务器,Server3需要ndb_mgm和ndb_mgmd两个文件:从[url][/url]上下载mysql-max-4.1.9-pc-linux-gnu-i686.tar.gz

  # mkdir /usr/src/mysql-mgm  
  # cd /usr/src/mysql-mgm  
  # tar -zxvf mysql-max-4.1.9-pc-linux-gnu-i686.tar.gz  
  # rm mysql-max-4.1.9-pc-linux-gnu-i686.tar.gz  
  # cd mysql-max-4.1.9-pc-linux-gnu-i686  
  # mv bin/ndb_mgm .  
  # mv bin/ndb_mgmd .  
  # chmod +x ndb_mg*  
  # mv ndb_mg* /usr/bin/  
  # cd  
  # rm -rf /usr/src/mysql-mgm 

  现在开始为这台管理节点服务器建立配置文件:

  # mkdir /var/lib/mysql-cluster  
  # cd /var/lib/mysql-cluster 

  # vi config.ini在config.ini中添加如下内容:

  [NDBD DEFAULT]  
  NoOfReplicas=2
  [MYSQLD DEFAULT]  
  [NDB_MGMD DEFAULT]  
  [TCP DEFAULT]  
  # Managment Server  
  [NDB_MGMD]  
  HostName=192.168.0.3 #管理节点服务器Server3的IP地址
  # Storage Engines
  

  [NDBD]


  HostName=192.168.0.1 #MySQL集群Server1的IP地址
  DataDir= /var/lib/mysql-cluster
  

  [NDBD]


  

  HostName=192.168.0.2 #MySQL集群Server2的IP地址


  

  DataDir=/var/lib/mysql-cluster


  

  # 以下2个[MYSQLD]可以填写Server1和Server2的主机名。


  

  # 但为了能够更快的更换集群中的服务器,推荐留空,否则更换服务器后必须对这个配置进行更改。


  

  [MYSQLD]


  

  [MYSQLD]保存退出后,启动管理节点服务器Server3:


  

  # ndb_mgmd

  启动管理节点后应该注意,这只是管理节点服务,并不是管理终端。因而你看不到任何关于启动后的输出信息。四、配置集群服务器并启动MySQL

  =============================在Server1和Server2中都需要进行如下改动:

  # vi /etc/my.cnf  
  [mysqld]  
  ndbcluster  
  ndb-connectstring=192.168.0.3 #Server3的IP地址  
  [mysql_cluster]  
  ndb-connectstring=192.168.0.3 #Server3的IP地址保存退出后,建立数据目录并启动MySQL:  
  # mkdir /var/lib/mysql-cluster  
  # cd /var/lib/mysql-cluster  
  # /usr/local/mysql/bin/ndbd --initial  
  # /etc/rc.d/init.d/mysqld start可以把/usr/local/mysql/bin/ndbd加到/etc/rc.local中实现开机启动。 

  注意:只有在第一次启动ndbd时或者对Server3的config.ini进行改动后才需要使用--initial参数!

  五、检查工作状态

  ================回到管理节点服务器Server3上,并启动管理终端:

  # /usr/bin/ndb_mgm键入show命令查看当前工作状态:(下面是一个状态输出示例)  
  [root@mysql3 root]# /usr/bin/ndb_mgm  
  -- NDB Cluster -- Management Client --  
  ndb_mgm> show  
  Connected to Management Server at: localhost:1186  
  Cluster Configuration  
  ---------------------  
  [ndbd(NDB)] 2 node(s)  
  id=2 @192.168.0.1 (Version: 4.1.9, Nodegroup: 0, Master)  
  id=3 @192.168.0.2 (Version: 4.1.9, Nodegroup: 0)  
  [ndb_mgmd(MGM)] 1 node(s)  
  id=1 @192.168.0.3 (Version: 4.1.9)  
  [mysqld(API)] 2 node(s)  
  id=4 (Version: 4.1.9)  
  id=5 (Version: 4.1.9)  
  ndb_mgm>

  如果上面没有问题,现在开始测试MySQL:注意,这篇文档对于MySQL并没有设置root密码,推荐你自己设置Server1和Server2的MySQL root密码。在Server1中:

  # /usr/local/mysql/bin/mysql -u root -p  
  > use test;  
  > CREATETABLE ctest (i INT) ENGINE=NDBCLUSTER;  
  > INSERTINTO ctest () VALUES (1);  
  > SELECT * FROM ctest; 

  应该可以看到1 row returned信息(返回数值1)。如果上述正常,则换到Server2上重复上面的测试,观察效果。如果成功,则在Server2中执行INSERT再换回到Server1观察是否工作正常。如果都没有问题,那么恭喜成功!六、破坏性测试

  ==============将Server1或Server2的网线拔掉,观察另外一台集群服务器工作是否正常(可以使用SELECT查询测试)。测试完毕后,重新插入网线即可。如果你接触不到物理服务器,也就是说不能拔掉网线,那也可以这样测试:在Server1或Server2上:

  # ps aux   grep ndbd将会看到所有ndbd进程信息:

  root 5578 0.0 0.3 6220 1964 ? S 03:14 0:00 ndbd

  root 5579 0.0 20.4 492072 102828 ? R 03:14 0:04 ndbd

  root 23532 0.0 0.1 3680 684 pts/1 S 07:59 0:00 grep ndbd然后杀掉一个ndbd进程以达到破坏MySQL集群服务器的目的:

  # kill -9 5578 5579之后在另一台集群服务器上使用SELECT查询测试。并且在管理节点服务器的管理终端中执行show命令会看到被破坏的那台服务器的状态。测试完成后,只需要重新启动被破坏服务器的ndbd进程即可:

  # ndbd

  注意!前面说过了,此时是不用加--inital参数的!至此,MySQL集群就配置完成了!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Huawei's Qiankun ADS3.0 intelligent driving system will be launched in August and will be launched on Xiangjie S9 for the first time Huawei's Qiankun ADS3.0 intelligent driving system will be launched in August and will be launched on Xiangjie S9 for the first time Jul 30, 2024 pm 02:17 PM

On July 29, at the roll-off ceremony of AITO Wenjie's 400,000th new car, Yu Chengdong, Huawei's Managing Director, Chairman of Terminal BG, and Chairman of Smart Car Solutions BU, attended and delivered a speech and announced that Wenjie series models will be launched this year In August, Huawei Qiankun ADS 3.0 version was launched, and it is planned to successively push upgrades from August to September. The Xiangjie S9, which will be released on August 6, will debut Huawei’s ADS3.0 intelligent driving system. With the assistance of lidar, Huawei Qiankun ADS3.0 version will greatly improve its intelligent driving capabilities, have end-to-end integrated capabilities, and adopt a new end-to-end architecture of GOD (general obstacle identification)/PDP (predictive decision-making and control) , providing the NCA function of smart driving from parking space to parking space, and upgrading CAS3.0

PHP's big data structure processing skills PHP's big data structure processing skills May 08, 2024 am 10:24 AM

Big data structure processing skills: Chunking: Break down the data set and process it in chunks to reduce memory consumption. Generator: Generate data items one by one without loading the entire data set, suitable for unlimited data sets. Streaming: Read files or query results line by line, suitable for large files or remote data. External storage: For very large data sets, store the data in a database or NoSQL.

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

Always new! Huawei Mate60 series upgrades to HarmonyOS 4.2: AI cloud enhancement, Xiaoyi Dialect is so easy to use Always new! Huawei Mate60 series upgrades to HarmonyOS 4.2: AI cloud enhancement, Xiaoyi Dialect is so easy to use Jun 02, 2024 pm 02:58 PM

On April 11, Huawei officially announced the HarmonyOS 4.2 100-machine upgrade plan for the first time. This time, more than 180 devices will participate in the upgrade, covering mobile phones, tablets, watches, headphones, smart screens and other devices. In the past month, with the steady progress of the HarmonyOS4.2 100-machine upgrade plan, many popular models including Huawei Pocket2, Huawei MateX5 series, nova12 series, Huawei Pura series, etc. have also started to upgrade and adapt, which means that there will be More Huawei model users can enjoy the common and often new experience brought by HarmonyOS. Judging from user feedback, the experience of Huawei Mate60 series models has improved in all aspects after upgrading HarmonyOS4.2. Especially Huawei M

How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values ​​to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

How to use MySQL stored procedures in PHP? How to use MySQL stored procedures in PHP? Jun 02, 2024 pm 02:13 PM

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

See all articles