Mysql cluster
Sissejuhatus
Probleem.
Vaja oleks hajutada mysql serveri koormust ja samal ajal suurendada töökindlust kogu süsteemil.
Lahendus oleks mysql_cluster.
MySQL Cluster combines the world's most popular open source database with a fault tolerant database clustering architecture so you can deliver mission-critical database applications with 99.999% availability.
Näites kasutame kolme serverit
management 192.168.1.10 node1 192.168.1.11 node2 192.168.1.12
install
gentoo
make.conf use="cluster"
emerge mysql
freebsd
cd /usr/ports/databases/mysql50-server make WITH_NDB=yes make install WITH_NDB=yes
seadistamine
management
/etc/config.ini
# file "config.ini" - 2 data nodes and 2 SQL nodes # This file is placed in the startup directory of ndb_mgmd (the # management server) [NDBD DEFAULT] NoOfReplicas= 2 DataDir= /var/lib/mysql-cluster [NDB_MGMD] Hostname= 192.168.1.10 DataDir= /var/lib/mysql-cluster [NDBD] HostName= 192.168.1.11 [NDBD] HostName= 192.168.1.12 [MYSQLD] [MYSQLD]
ndb_mgmd --config-file=/etc/config.ini
FreeBSD's /usr/local/libexec/ndb_mgmd --config-file=/etc/config.ini
node 1
mysql_install mkdir /var/lib/mysql-cluster chown -R mysql:mysql /var/lib/mysql-cluster
/etc/mysql/my.cnf
freebsd serveris /usr/local/etc/my.cnf
[mysql_cluster] ndb-connectstring=192.168.1.10 [mysqld] ndbcluster ndb-connectstring=192.168.1.10 ndbd --initial
mysqld_safe
freebsd puhul /usr/local/libexec/ndbd --initial mõlemas
NB! --initial võtit kasutada vaid esmakordsel startimisel. Edaspidi startida lihtsalt ndbd käsuga
node2
Kõik täiesti sama mis esimeses
mysql_install mkdir /var/lib/mysql-cluster chown -R mysql:mysql /var/lib/mysql-cluster
/etc/mysql/my.cnf
[mysql_cluster] ndb-connectstring=192.168.1.10 [mysqld] ndbcluster ndb-connectstring=192.168.1.10
ndbd --initial
mysqld_safe
kasutamine
management
Käivitame järgneva käsu ja testime kas cluster töötab
localhost ~ # 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.1.11 (Version: 5.0.44, Nodegroup: 0, Master) id=3 @192.168.1.12 (Version: 5.0.45, Nodegroup: 0) [ndb_mgmd(MGM)] 1 node(s) id=1 @192.168.1.10 (Version: 5.0.44) [mysqld(API)] 2 node(s) id=4 @192.168.1.11 (Version: 5.0.44) id=5 @192.168.1.12 (Version: 5.0.45) ndb_mgm>
Teeme testi
mysql use test; CREATE TABLE ctest (i INT) ENGINE=NDBCLUSTER; INSERT INTO ctest () VALUES (1); SELECT * FROM ctest;
Nagu märkasite kasutasin ENGINE=NDBCLUSTER
Engine: ndbcluster Support: YES Comment: Clustered, fault-tolerant, memory-based tables
Et toimiks mysql clustri kasutus tuleb igale tabelile see engine lisada. Et vaikimisi loodavatel tabelitel oleks kasutuses õige engine siis lisada my.cnf'i
default_storage_engine=NDBCLUSTER
Muide kogu mysql cluster on täiesti ilma paroolideta veel. Soovitav on ka need paika seada nüüd.
Lisalugemist
http://www.mysql.com/products/database/cluster/
http://mysql2.mirrors-r-us.net/doc/refman/5.0/en/mysql-cluster-config-example.html
http://onlinesolutionsmysql.blogspot.com/2007/05/q-webinar-part-4-mysql-cluster.html
Ja abivahendiks koormuse jagamisel