網頁

2014年1月2日 星期四

MySQL --- How to install & configure MySQL cluster by Auto-Installer (part 1)

Since MySQL Cluster NDB 7.3.1 or later version, we can install it by using the web-based graphical configuration. Although MySQL Official Website supply some information for the reference (# 1), it is a little difficult for the beginner to realize how to do it.
Based on the following list, I will introduce you how to install & configure the related nodes step by step.
Role
IP Address Host
Management Node 1 10.10.101.71 Remote Host
Management Node 2 10.10.101.72 Setup Host
SQL Node 1 10.10.101.71 Remote Host
SQL Node 2 10.10.101.72 Setup Host
Data Node 1 10.10.101.73 Remote Host
Data Node 2 10.10.101.74 Remote Host

Prerequisite for running the MySQL Cluster Auto-Installer
[ALL hosts]
Disable SELINUX and Firewall daemon
For avoiding any exception, we will disable SELUNUX on all hosts that change the SELINUX configuration file by modifying the /etc/sysconfig/selinux file.ScreenHunter_45also disable firewall daemon on all hosts.ScreenHunter_46
Download MySQL Cluster GPL source
To realize what the 32 bit or 64 bit system is installed on CentOS by using the uname –ri command. The result is 64 bit version because we can see x86_64 number.ScreenHunter_01To download the latest MySQL Cluster GPL binary archive from MySQL Download site by selecting the right platform and version next to click Download button.
ScreenHunter_11Of course, we also can download it by using the wget command.ScreenHunter_02
Extract the archive and Create a symbolic link
To change the directory containing the download file next to unpack the archive by using the tar -C /usr/local –xzvf ./mysql-cluster-gpl-7.3.3-linux-glibc2.5-x86_64.tar.gz command.ScreenHunter_02To create a symbolic link name mysql to the extracted directory by using the ln -s /usr/local/mysql-cluster-gpl-7.3.3-linux-glibc2.5-x86_64 mysql commandScreenHunter_03
Create mysql account and group
Based on MySQL security policy, we have to create the dedicated account and group for delegating the permission to install & execute MySQL.
In the moment, I will create a new mysql account & group so that firstly check whether there is already existing account mysql in the /etc/passwd file and group mysql in the /etc/group file.ScreenHunter_09If it doesn’t present, please create a new mysql group by running the groupadd mysql command and add a new mysql user that belong to this group by using the useradd –g mysql mysql command.

Set mysql password
Due to we will use SSH as authentication, the mysql user running the Auto-Installer muse have right to the remote host so that need to set new password for mysql account.ScreenHunter_25

Set the mysql permission on the MySQL and data directory
To change the mysql directory to be owned by root but be in the mysql group by using the chown –R root:mysql . command.ScreenHunter_24Due to the MySQL data will be install on the /home/mysql directory, it has right permission to mysql account & group on this directory so that doesn’t do anything now.(# 2)ScreenHunter_23
Install required software on setup & remote host
[Setup host]
It will trigger the Auto-Installer mechanism so that it require the Python 2.6 or newer version that can be downloaded from http://python.org/download/
ScreenHunter_05
If we intend to deploy MySQL Cluster nodes on remote hosts, we have to include the Pycrypto and Paramiko libraries (# 3).
ScreenHunter_04ScreenHunter_05Where to download the new version besides using the yum command?
The Pycrypto 2.6 or newer version that can be downloaded from https://www.dlitz.net/software/pycrypto/ and Paramiko 1.7.7.1 or newer version that can be downloaded from http://www.lag.net/paramiko/

When the above software is ready that is installed on the setup host, we will switch to the mysql/bin directory and start browser-based Auto-Installer for MySQL Cluster by using the ./ndb_setup.py –N 10.10.101.72 command. (# 4)ScreenHunter_01
[Remote host]
If we want to deploy MySQL Cluster nodes to the remote hosts, we have to confirm whether the SSH server package has already been installed on the remote hosts.ScreenHunter_07In general, the OpenSSH server is installed by default on Linux system or we want to chose the alternative software from http://en.wikipedia.org/wiki/Comparison_of_SSH_servers.

Install required software on SQL Node
[SQL node]
If the role of the host belong to SQL node, we also need to install libaio library by using the yum install libaio command.ScreenHunter_43
Installation for creating new MySQL cluster
In client environment as Windows platform, we will load a web browser as Opera or Microsoft Internet Explorer and key in the URL http://10.10.101.72:8081/welcome.html next to click Create New MySQL Cluster link.ScreenHunter_09
In Define cluster screen, we have to set Cluster property as Cluster name, Host list, Application type, Write load and SSH property depend on choose Key-Based SSH or enter User and Password credentials.ScreenHunter_28
In Define hosts screen, the system will automatically retrieve the platform name, amount of memory, number of CPU cores, and MySQL Cluster install & data directory and to fill these in the grid. In the moment, we need to change MySQL Cluster install & data directory to apply to our environment.ScreenHunter_41
In Define processes screen, the default setting of processes based on the number of hosts is defined for us at first. Of course, we can change the default process and assign each management node, data node, or SQL/API node to a specific host. In the moment, we accept the suggestion next to click Next button.ScreenHunter_30
In Define Processes Parameters screen, it organizes a process tree by node type and group it to label as Management Layer, Data Layer, SQL Layer and API Layer.
If we want to edit attribute for any process, we can enable Show advanced configuration option check box so that some information is visible in the right pane. In the moment, we accept the suggestion next to click Next button.ScreenHunter_31
In Deploy configuration screen, we will click Deploy and start cluster button to create necessary directories and distribute configuration files, start all cluster processes.ScreenHunter_32If the node is started, we will see the green color that express the running status of the process. As to the other color, yellow if it is starting or stopping and red if the process is stopped.ScreenHunter_35Finally, the Cluster will be started if the progress is normal.ScreenHunter_38
Post-Installation for completing MySQL Cluster deployment
Set initial mysql root account & passwordBy default, the root account only permits connection from the local host and the initial password is empty when the MySQL is installed freshly. For security reason, we have to manually set MySQL root password because the CentOS doesn’t remind us to do it.

How to set the password of the initial root account for local access?
To display which accounts exits in the mysql.user table and check whether their password are empty by using the SELECT User, Host, Password FROM mysql.user; commandScreenHunter_10To assigning “single” root account, we can execute the SET PASSWORD FOR 'root'@'localhost' = PASSWORD('password'); command. So does that we can see the password has encrypted value.ScreenHunter_11If we want to assign a password to “all” root accounts, we can execute the UPDATE mysql.user SET Password = PASSWORD('newpassword') WHERE User = 'root';  and  FLUSH PRIVILEGES; command.ScreenHunter_15
How to assign or remove Anonymous account password for local access?
For assign Anonymous account password, the instruction is similar as the above example by using the SET PASSWORD FOR ''@'localhost' = PASSWORD('password'); command.ScreenHunter_16As to remove Anonymous account, we can execute the DROP USER ''@'host_name'; commandScreenHunter_17
How to enable root account remote access to mysql all database?
To grant all privileges to the mysql root account from anywhere, we can execute the GRANT ALL PRIVILEGES ON *.* to ‘root’@'%' IDENTIFIED BY 'rootpassword'; command.
ScreenHunter_19
After the root password has been set, we have to key in the appropriate password if we want to connect to MySQL system.ScreenHunter_12

Check database/table/column value consistent in the different node
[Verify Database]
To login to SQL Node 1, we will create a new database by using the create database <DATABASENAME> command.ScreenHunter_01To login to SQL Node 2, we will see this new database by using the show database command.ScreenHunter_02
[Verify Table]
To login to SQL Node 1, we will create a new database by using the create table <TABLENAME> with ndbcluster parameter commandScreenHunter_03To login to SQL Node 2, we will see this new table by using the show tables from <DATABASENAME> command.

[Verify Column Value]
To login to SQL Node 1, we will insert some value to a new table by using the insert into <TABLENAME> with value parameter commandScreenHunter_05To login to SQL Node 2, we will see this new value by using the select from <DATABASENAME>.<TABLENAME> command.


Until now, this new MySQL Cluster has already been implemented successfully and its function is normal now.

Reference :
(# 1) The MySQL Cluster Auto-Installer
(# 2) If the mysql data will be located on the specific location, we have to change the database files in this data directory to be owned by the mysql user and group.ScreenHunter_33(# 3) How to know the python paramiko & pycrypto module exist and the function is normal?
In Python, we can verify it by using import paramiko and dir (paramiko) commandScreenHunter_10and by using import Crypto and dir (Crypto) commandScreenHunter_11(# 4) ndb_setup.py command line tool

9 則留言:

  1. Excellent tutorial - helped me out a lot! Thanks dude :)

    回覆刪除
  2. Thank you for creating this. It helped me a lot!

    回覆刪除
  3. 作者已經移除這則留言。

    回覆刪除
  4. Hello Mr.Davidwa Wang

    Thanks for the excellent tutorial.

    I have this problem

    Cannot locate nbd_mgmd in /usr/local/mysql/[bin .........] on host 192.168.2.1

    回覆刪除
  5. Hi, I followed same tutorial. I have finished setup properly. Just an issue with
    remote hosts try to access the servers from eclipse.
    I was not able to succeded in running below command.
    GRANT ALL PRIVILEGES ON *.* TO ‘root’@'%' IDENTIFIED BY 'rootpassword'; It is raising


    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''root'@'%' IDENTIFIED BY 'rootpassword'' at line 1

    and some times it says again

    ERROR 1045 (28000): Access denied for user 'root'@'pahslin15.icp.internal.com' (using password: YES)

    It is a blocker for me. Please do the needful.

    回覆刪除
  6. The actual isuue is, Ihave written a java program to connect to Mysql server which in running on linux. When I run exception says, host is not allowed to connect to Mysql server. and some times,

    java.sql.SQLException: Access denied for user 'root'@'pundel0511d-016.icp.internal.com' (using password: YES)

    and here pundel0511d-016.icp.internal.com is my computername or windows host name.

    Please help on this.

    回覆刪除
  7. I think is a great document, congrats..!! You help me a lot.

    回覆刪除
  8. Ah! I forgot give you Thanks..!! Well, Thank you so much..!! Do you published the part two about this? Where can I take it a look? Thanks again.

    回覆刪除

Since 2010 Design by Davidwa
©Copyright Davidwa Inc. All rights reserved.