Zielsetzung
Voraussetzungen
Bitte lesen Sie die in diesem Kapitel aufgeführten Anweisungen zunächst durch und befolgen Sie sie bevor Sie Ihre Arbeit mit dem vorliegenden Howto fortsetzen.
Perl Module
Bitte beachten Sie, dass Sie für die Verwendung von cpan einen c++ compiler benötigen. Installieren Sie daher zuvor das Paket gcc über yum.
- DBI
- HTML::Template
Unter Fedora Core X lassen sich diese Module übrigens auch über yum installieren.
-bash-3.1# yum install perl-DBI perl-DBD-MySQL
mysql wieder mittels yum remove mysql. Anderenfalls werden später bei der Installation Konflikte enstehen.
System
Um einen Rechner in einem sich hinter einer virtuellen IP-Adresse verbergenden Cluster betreiben zu können, muss dieser einige wenige Konfigurationsmerkmale aufweisen. Unter Cluster-Member-Grundlagen finden Sie eine Anleitung zum Erstellen dieser.
Download
Laden Sie von der MySQL Website die folgenden Paket herunter:
- MySQL-server-VERSION.GELIB_VERSION.ARCH.rpm
- MySQL-Max-VERSION.GELIB_VERSION.ARCH.rpm
- MySQL-shared-VERSION.GELIB_VERSION.ARCH.rpm
- MySQL-shared-compat-VERSION.GELIB_VERSION.ARCH.rpm
- MySQL-client-VERSION.GELIB_VERSION.ARCH.rpm
- MySQL-ndb-extra-VERSION.GELIB_VERSION.ARCH.rpm
- MySQL-ndb-management-VERSION.GELIB_VERSION.ARCH.rpm
- MySQL-ndb-storage-VERSION.GELIB_VERSION.ARCH.rpm
- MySQL-ndb-tools-VERSION.GELIB_VERSION.ARCH.rpm
Installation
Alle Server
Installieren Sie die folgenden Pakete:
- MySQL-shared-VERSION.GELIB_VERSION.ARCH.rpm
- MySQL-shared-compat-VERSION.GELIB_VERSION.ARCH.rpm
- MySQL-client-VERSION.GELIB_VERSION.ARCH.rpm
Management Server
Installieren Sie die folgenden Paket:
- MySQL-ndb-extra-VERSION.GELIB_VERSION.ARCH.rpm
- MySQL-ndb-management-VERSION.GELIB_VERSION.ARCH.rpm
- MySQL-ndb-tools-VERSION.GELIB_VERSION.ARCH.rpm
Database Server
Installieren Sie die folgenden Paket:
- MySQL-ndb-storage-VERSION.GELIB_VERSION.ARCH.rpm
SQL Query Server
Installieren Sie die folgenden Paket:
- MySQL-server-VERSION.GELIB_VERSION.ARCH.rpm
- MySQL-Max-VERSION.GELIB_VERSION.ARCH.rpm
- Es ist wichtig, dass Sie in der weiter oben aufgeführten Datei
/etc/my.cnfalle ndb-Parameter auskommentieren. Alternativ können Sie die Datei auch einfach solange umbenennen. - Ferner sollten Sie die beiden Pakete unbedingt einzeln und nach einander installieren, damit Sie zunächst den Anweisung folgen können, welche Ihnen nach der Insallation von MySQL-server angezeigt werden.
Konfiguration
Daten und SQL Server
Distributionsspezifische Konfigurationsdatei unter /etc/my.cnf (/etc/mysql/my.conf) editieren und folgenden Inhalt hinzufügen:
# Options for mysqld process: [MYSQLD] ndbcluster # run NDB engine ndb-connectstring="host=192.168.0.10" # location of MGM node default-storage-engine=NDBCLUSTER # save at cluster for default [MYSQL_CLUSTER] ndb-connectstring="host=192.168.0.10" # location of MGM node
host=XXX eintrag als Wert der ndb_connectstring Variablen definiert werden, wobei diese mittels eines Kommas zu trennen sind.
Management Server
config.ini anlegen:
-bash-3.1# mkdir -p /var/lib/mysql-cluster -bash-3.1# vi /var/lib/mysql-cluster/config.ini
# Options affecting ndbd processes on all data nodes:
[NDBD DEFAULT]
NoOfReplicas=2 # Number of replicas
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.
# TCP/IP options:
[TCP DEFAULT]
portnumber=2202 # This the default; however, you can use any
# port that is free for all the hosts in cluster
# Note: It is recommended beginning with MySQL 5.0 that
# you do not specify the portnumber at all and simply allow
# the default value to be used instead
# Management process options:
[NDB_MGMD]
hostname=192.168.0.10 # Hostname or IP address of MGM node
datadir=/var/lib/mysql-cluster # Directory for MGM node logfiles
# SQL node options:
[MYSQLD]
hostname=192.168.0.20 # Hostname or IP address
# (additional mysqld connections can be
# specified for this node for various
# purposes such as running ndb_restore)
# One [NDBD] section per data node
# Options for data node "A":
[NDBD]
hostname=192.168.0.31 # Hostname or IP address
datadir=/opt # Directory for this data node's datafiles
# Options for data node "B":
[NDBD]
hostname=192.168.0.32 # Hostname or IP address
datadir=/opt # Directory for this data node's datafiles
# Options for data node "C":
[NDBD]
hostname=192.168.0.33 # Hostname or IP address
datadir=/opt # Directory for this data node's datafiles
# Options for data node "D":
[NDBD]
hostname=192.168.0.34 # Hostname or IP address
datadir=/opt # Directory for this data node's datafiles
Erster Start
Management Server
-bash-3.1# ndb_mgmd -f /var/lib/mysql-cluster/config.ini
Storage Server
-bash-3.1# ndbd --initial
SQLQuery Server
-bash-3.1# /etc/init.d/mysqld start
Zugriffsrechte
Initiale Rechte
Sie sollten unbedingt die Zugriffsrechte auf die Datenbanken einschränken. Hierzu müssen Sie das Root-Passwort setzen. Führen Sie hierzu bitte nacheinander die folgenden Kommandos auf jedem der SQL-API-Server aus:
-bash-3.1# mysql -u root mysql -p -bash-3.1# mysql -u root -h mysql-host.mydomain.local mysql -p
Sie werden jeweils nach einem Passwort gefragt werden. Bei ersterem Kommando handelt es sich um das Root-Passwort für den Zugriff über den localhost. Beim zweiten um das beim Zugriff über die öffentliche IP des Servers.
Benutzerverwaltung
Benutzer hinzufügen
Um einen neuen Benutzer hinzuzufügen, genügt die Eingabe der folgenden beiden Kommandos:
mysql> insert into mysql.user (Host,User,Password) values ('%.mydomain.local','MY_USERNAME',PASSWORD('verySecure'));
mysql> FLUSH PRIVILEGES;
Ersetzen Sie hierbei MY_USERNAME mit dem tatsächlichen Benutzername und verySecury mit dem zu verwendenden Password. Ferner müssen Sie den Wert %.mydomain.local entsprechend anpassen, wobei dieser den Platzhalter % kennt, wie im Beispiel zu sehen.
Benutzerrechte setzen
Um einem Benutzer ganz spezifisch Rechte für eine bestimmte Tabelle zu gewähren, müssen die folgenden Kommandos ausgeführt werden.
mysql> GRANT ...
-> ON *.*
-> TO 'myname'@'%.mydomain.com'
-> IDENTIFIED BY 'mypass';
Ersetzen Sie die … hinter GRANT durch die Rechte, welche Sie dem Benutzer gewähren möchten. Mittel ON *.* kann sowohl die Datenbank, wie auch die Tabelle, für welche die Rechte gesetzt werden sollen, definiert werden. In diesem Beispiel werden die Rechte global gesetzt.
Links:
SysInit
NDB_MGMD (Management) Startup Script
Save as „ndb_mgmd“ eg: /etc/init.d/ndb_mgmd
After saving as that file, evecute the following command:
chkconfig –add ndb_mgmd
this will add it to chkconfig making it easy to manage and control for system startup
#!/bin/bash
#
# ndb_mgmd This shell script takes care of starting and stopping
# the MySQL NDB Management server subsystem (ndb_mgmd).
#
# chkconfig: 2345 60 37
# description: MySQL NDB Management Server
# processname: ndb_mgmd
# Source function library.
. /etc/rc.d/init.d/functions
start(){
echo -n "Starting ndb_mgmd: "
/usr/sbin/ndb_mgmd -f /var/lib/mysql-cluster/config.ini
return 0
}
stop(){
echo -n "Shutting down ndb_mgmd: "
killall ndb_mgmd
return 0
}
restart(){
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: {start|stop}"
exit 1
esac
exit $?
NDBD (Storage) Startup Script
Save as „ndbd“ eg: /etc/init.d/ndbd
After saving as that file, evecute the following command:
chkconfig –add ndbd
this will add it to chkconfig making it easy to manage and control for system startup
#!/bin/bash
#
# ndbd This shell script takes care of starting and stopping
# the MySQL NDB cluster server subsystem (ndb_mgmd).
#
# chkconfig: 2345 60 37
# description: MySQL NDB Cluster Server
# processname: ndbd
# Source function library.
. /etc/rc.d/init.d/functions
start(){
echo -n "Starting ndbd: "
/usr/sbin/ndbd
return 0
}
stop(){
echo -n "Shutting down ndbd: "
killall ndbd
return 0
}
restart(){
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: {start|stop}"
exit 1
esac
exit $?
SQL (Query) Startup Script
Save as „mysqld“ eg: /etc/init.d/mysqld
After saving as that file, evecute the following command:
chkconfig –add mysqld
this will add it to chkconfig making it easy to manage and control for system startup
#!/bin/bash
#
# mysqld This shell script takes care of starting and stopping
# the MySQL subsystem (mysqld).
#
# chkconfig: - 64 36
# description: MySQL database server.
# processname: mysqld
# config: /etc/my.cnf
# pidfile: /var/run/mysqld/mysqld.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
prog="MySQL"
# extract value of a MySQL option from /etc/my.cnf
# Usage: get_mysql_option FILE VARNAME DEFAULT
# result is returned in $result
# Ugly as this is, it knows nothing of option file sections ...
get_mysql_option(){
result=`sed -n "s/^[ \t]*$2[ \t]*=[ \t]*//p" "$1" 2>/dev/null | tail -n 1`
if [ -z "$result" ]; then
# not found, use default
result="$3"
else
# found, still have to deal with quoting and end-of-line comments
dequoted=`echo "$result" | sed "s/^'\([^']*\)'.*$/\1/"`
if [ x"$dequoted" != x"$result" ]; then
result="$dequoted"
else
dequoted=`echo "$result" | sed 's/^"\([^"]*\)".*$/\1/'`
if [ x"$dequoted" != x"$result" ]; then
result="$dequoted"
else
result=`echo "$result" | sed 's/^\([^ \t#]*\).*$/\1/'`
fi
fi
fi
}
get_mysql_option /etc/my.cnf datadir "/var/lib/mysql"
datadir="$result"
get_mysql_option /etc/my.cnf socket "$datadir/mysql.sock"
socketfile="$result"
get_mysql_option /etc/my.cnf log-error "/var/log/mysqld.log"
errlogfile="$result"
get_mysql_option /etc/my.cnf pid-file "/var/run/mysqld/mysqld.pid"
mypidfile="$result"
start(){
touch "$errlogfile"
chown mysql:mysql "$errlogfile"
chmod 0640 "$errlogfile"
[ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile"
if [ ! -d "$datadir/mysql" ] ; then
action $"Initializing MySQL database: " /usr/bin/mysql_install_db
ret=$?
chown -R mysql:mysql "$datadir"
if [ $ret -ne 0 ] ; then
return $ret
fi
fi
chown -R mysql:mysql "$datadir"
chmod 0755 "$datadir"
# The reason for explicitly specifying --pid-file is that there may
# be no such entry in my.cnf, and the default behavior will be to not
# create it at all. Likewise, we specify --log-error in case there
# was not an entry in my.cnf.
/usr/bin/mysqld_safe --defaults-file=/etc/my.cnf --pid-file="$mypidfile" --log-error="$errlogfile" >/dev/null 2>&1 &
ret=$?
# Spin for a maximum of N seconds waiting for the server to come up.
# Rather than assuming we know a valid username, accept an "access
# denied" response as meaning the server is functioning.
if [ $ret -eq 0 ]; then
STARTTIMEOUT=30
while [ $STARTTIMEOUT -gt 0 ]; do
RESPONSE=`/usr/bin/mysqladmin -uUNKNOWN_MYSQL_USER ping 2>&1` && break
echo "$RESPONSE" | grep -q "Access denied for user" && break
sleep 1
let STARTTIMEOUT=${STARTTIMEOUT}-1
done
if [ $STARTTIMEOUT -eq 0 ]; then
echo "Timeout error occurred trying to start MySQL Daemon."
action $"Starting $prog: " /bin/false
ret=1
else
action $"Starting $prog: " /bin/true
fi
else
action $"Starting $prog: " /bin/false
fi
[ $ret -eq 0 ] && touch /var/lock/subsys/mysqld
return $ret
}
stop(){
MYSQLPID=`cat "$mypidfile" 2>/dev/null `
if [ -n "$MYSQLPID" ]; then
/bin/kill "$MYSQLPID" >/dev/null 2>&1
ret=$?
if [ $ret -eq 0 ]; then
STOPTIMEOUT=60
while [ $STOPTIMEOUT -gt 0 ]; do
/bin/kill -0 "$MYSQLPID" >/dev/null 2>&1 || break
sleep 1
let STOPTIMEOUT=${STOPTIMEOUT}-1
done
if [ $STOPTIMEOUT -eq 0 ]; then
echo "Timeout error occurred trying to stop MySQL Daemon."
ret=1
action $"Stopping $prog: " /bin/false
else
rm -f /var/lock/subsys/mysqld
rm -f "$socketfile"
action $"Stopping $prog: " /bin/true
fi
else
action $"Stopping $prog: " /bin/false
fi
else
ret=1
action $"Stopping $prog: " /bin/false
fi
return $ret
}
restart(){
stop
start
}
condrestart(){
[ -e /var/lock/subsys/mysqld ] && restart || :
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status mysqld
;;
restart)
restart
;;
condrestart)
condrestart
;;
*)
echo $"Usage: $0 {start|stop|status|condrestart|restart}"
exit 1
esac
exit $?
Ldirectord
Damit der ldirectord daemon in der Lage ist, mit den SQL-API-Servern zu kommunizieren, müssen vie yum die folgenden Pakete installiert werden:
- perl-DBD-MySQL
FROM THE NET
Ok, you need MySQL Max 5 for NDB support? Having trouble getting the server working? Read on..
NOTE: Assumes a stock install of Fedora Core 5
First things first: Install MySQL from RPM from the Fedora Install CD. This does not have the Max extensions but you need a file from this install first.
Next: COPY /etc/init.d/mysqld startup script to a safe location. eg: /safe/mysqld
Then: DOWNLAOD and INSTALL MySQL RPMs from MySQL.org These are: Statically compiled GENERIC RPMs, all of them (NOT linked binaries) NDB Clustering files from the GENERIC dynamically linked RPMs. All of them that say the word „NDB“
Use the command „rpm -Uvh MySQL-*“ to install/upgrade mysql version.
MySQL is now dead.
Now comes the tricky part..
Problem Number 1: The RPM install has removed the startup script file /etc/init.d/mysqld and replaced it with /etc/init.d/mysql and this file is faulty.. Basically it needs more information. Simple fix: DELETE the /etc/init.d/mysql startup script and RE-COPY the /safe/mysqld startup script saved earlier to /etc/init.d/mysqld This file has all the required information.. It just works better..
Problem Number 2: The MySQL User has been removed thanks to the generic RPM.. Need to re-insert user using following commands: (Taken from mysql rpm install script and modified to work)
groupadd -r mysql useradd -M -r -d /var/lib/mysql -s /bin/bash -c „MySQL server“ -g mysql mysql usermod -g mysql mysql
This should now have the MySQL user installed.
Problem Number 3: File permissions do not match new user number, mysql will fail.. Use following commands: chown mysql.mysql /var/run/mysqld chown -R mysql.mysql /var/lib/mysql chown -R mysql.mysql /var/lib/mysql-cluster
Once doing this, use the command: service mysqld restart
You may see failed when stopping the server, this is ok, it may mean you have not started the service before or the RPM install script has stopped the service..
However, a nice little message saying „Starting MySQL Server - OK“ should now show..
running a „ps -a“ you should see 2 processes called „mysqld_safe“ and „mysql-max“
Log in with: mysql mysql -u root -p And once in type: SHOW ENGINES;
You should now see all the Max extensions are now enabled..
XXX
OK. Somehow I managed to get MySQL to start. This is what I did
1. COPY /etc/init.d/mysqld startup script to a safe location. eg: /safe/mysqld
2. Download and install ALL RPMs from http://www.mysql.org/downloads/mysql/5.0.html from (Linux x86 generic RPM (statically linked against glibc 2.2.5) downloads) - Total 7 files
3. Note : Install the server rpm first with the following command :
Quote:
rpm -Uvh MySQL-server-5.0.26-0.i386.rpm --nodeps
4. Continue installing the other 6 rpms, eg. Max, client, libraries, etc...
5. Download and install 4 NDB Cluster RPMs from (Linux x86 generic RPM (dynamically linked) downloads) from the same site
6. Delete /etc/init.d/mysql and copy over the saved mysqld file from item(1) above
7. Add the MySQL group and user
Quote:
groupadd -r mysql
useradd -M -r -d /var/lib/mysql -s /bin/bash -c "MySQL server" -g mysql mysql
usermod -g mysql mysql
8. Change the file permission
Quote:
chown mysql.mysql /var/run/mysqld
chown -R mysql.mysql /var/lib/mysql
chown -R mysql.mysql /var/lib/mysql-cluster
9. Start MySQL
Quote:
/etc/init.d/mysqld start
10. Check whether process is running. You should see 2 process, ie "mysqld_safe" and "mysql-max"
Quote:
ps -a
11. Login to MySQL and check if the MySQL engines
Quote:
mysql -u root -p yourpassword
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8 to server version: 5.0.26-max
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> SHOW ENGINES;