
Premetto che per creare un cluster “vero” con una ridondanza “vera” sono necessarie 3 macchine.
a) Nodo dati 1 — es.: IP 192.168.100.101
b) Nodo dati 2 — es.: IP 192.168.100.102
c) Nodo di Management dei 2 nodi — es.: IP 192.168.100.103
Installiamo MySQL su entrambi i nodi dati con il comando:
# sudo apt-get install mysql-server
Durante il setup vi verrà chiesto di inserire la password di root del database. (Importante non perderla)
Passiamo ora ad installare e configurare il Nodo di Management.
Creiamo il seguente file /etc/mysql/ndb_mgmd.cnf con:
# sudo nano /etc/mysql/ndb_mgmd.cnf
e inserite al suo interno le seguenti lines:
[NDBD DEFAULT]
NoOfReplicas=2
DataMemory=80M # How much memory to allocate for data storage
IndexMemory=18M # How much memory to allocate for index storage
# For DataMemory and IndexMemory, we have used the
# default values. Since the “world” database takes up
# only about 500KB, this should be more than enough for
# this example Cluster setup.
[MYSQLD DEFAULT]
[NDB_MGMD DEFAULT]
[TCP DEFAULT]
# Section for the cluster management node
[NDB_MGMD]
# IP address of the management node (this system)
HostName=192.168.100.103# Section for the storage nodes
[NDBD]
# IP address of the first storage node
HostName=192.168.100.101
DataDir=/var/lib/mysql-cluster
BackupDataDir=/var/lib/mysql-cluster/backup
DataMemory=512M
[NDBD]
# IP address of the second storage node
HostName=192.168.100.102
DataDir=/var/lib/mysql-cluster
BackupDataDir=/var/lib/mysql-cluster/backup
DataMemory=512M# one [MYSQLD] per storage node
[MYSQLD]
[MYSQLD]
Passiamo ora a configurare i Nodi dati 1 e 2, quindi la seguente operazione va seguita su entrambi i nodi.
# sudo mkdir /var/lib/mysql-cluster/backup
# sudo chown -R mysql:mysql /var/lib/mysql-cluster
Modifichiamo il file di configurazione di MySQL
#sudo nano /etc/mysql/my.cnf
Inserite sotto la voce [mysqld] le seguenti lines:
[mysqld]
ndbcluster
# IP address del nodo di management
ndb-connectstring=192.168.100.103
cercate la voce [MYSQL_CLUSTER] dovrebbe essere preceduta da un # che lo commenta, rimuovete il # per avere 2 lines come segue:
[MYSQL_CLUSTER]
ndb-connectstring=192.168.100.103 # IP address del nodo di management
Perfetto, vi ricordo che la procedura appena spiegata va eseguita su entrambi i nodi.
Ora passiamo di nuovo al Nodo di management ed eseguite il seguente comando:
# sudo /etc/init.d/mysql-ndb-mgm restart
# sudo /etc/init.d/mysql restart
digitate:
# ndb_mgm
e date il comando:
#show
dovreste vedere qualcosa di questo tipo:
ndb_mgm> show;
Connected to Management Server at: localhost:1186
Cluster Configuration
———————
[ndbd(NDB)] 2 node(s)
id=2 (not connected, accepting connect from 192.168.1.6)
id=3 (not connected, accepting connect from 192.168.1.7)[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.1.5 (Version: 5.0.51)[mysqld(API)] 2 node(s)
id=4 (not connected, accepting connect from any host)
id=5 (not connected, accepting connect from any host)
Significa che il Nodo manager non è ancora in grado di collegarsi ai nodi.
Tornate ai nodi e date su entrambi:
# sudo /etc/init.d/mysql restart
# sudo /etc/init.d/mysql-ndb restart
Bene, ora ritornate sul Nodo di management e ridate il comando “show” , il risultato dovrebbe essere il seguente:
ndb_mgm> show;
Cluster Configuration
———————
[ndbd(NDB)] 2 node(s)
id=2 @192.168.1.6 (Version: 5.0.51, Nodegroup: 0, Master)
id=3 @192.168.1.7 (Version: 5.0.51, Nodegroup: 0)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.1.5 (Version: 5.0.51)
[mysqld(API)] 2 node(s)
id=4 @192.168.1.7 (Version: 5.0.51)
id=5 @192.168.1.6 (Version: 5.0.51)
Perfetto il CLUSTER è OK e funzionante.
Rigrazio il fantastico Blog di Bieg per le informazioni necessarie per questa guida.
Di base mi sono limitato a tradurla per chi ha difficoltà con l’inglese.
Fonte: Bieg Blog
Commenti recenti