Friday, June 27, 2014

Manage multiple MySql server using single phpmyadmin

As a System Administrator, we tend to manage a number of MYSQL Server instance. So we need to find a better way of managing this set of mysql server into much a easier and centralized way. In my environment, I have 5 different MySQL database servers running separately under different server location. Since it run standalone and not in cluster mode, I need to have one platform to manage these database servers altogether.
PHPmyAdmin is able to do this, with some changes on the configuration files. You just need to allow the MySQL user and host on every database server to be connected to. The setup that I am going to do will be as below:
phpmyadmin-multiple-mysql
Inorder to install phpmyadmin on ubuntu, you need 3 main packages apache , MySQL and php has to be installed and configured properly.
1. Apache2 installation and configuration
2. Mysql installation
3. PHP installation
I’m assuming you have already installed a running LAMP on your server.
After installing apache2, mysql and php, you can continue with the below steps to install and configure phpmyadmin

SET UP

The steps in this tutorial require the user to have root privileges on your VPS.
Variables being used in this tutorial are:
Web Server IP: 192.168.1.150
PHPmyAdmin directory: /etc/phpmyadmin
User: phpmaroot
Password: pmapass123!

Install phpmyadmin

We will going to install phpmyadmin on svr1.webserver, and this server will going to manage our MYSQL servers
  1. apt-get install phpmyadmin

Create root user to manage phpmyadmin

This step is optional, ofcourse we may use root to login on phpmyadmin.
  1. mysql> CREATE USER 'phpmaroot'@'%' IDENTIFIED BY 'pmapass123!';
  2. mysql> GRANT ALL PRIVILEGES ON *.* TO phpmaroot@'%';

Modify my.cnf of mysql servers

Make sure all database servers are listening to all IP which accessible from outside. To simplify this, just remove or comment if you find following lines in your my.cnf file (usually located under /etc) :
  1. #bind-address=127.0.0.1
  2. #bind-address=localhost

Make MySql accessible

To differentiate our MySQL servers easily, better we add the servers’ hostname into Web Server/PHPmyAdmin server /etc/hosts file. Based on my requirements above, I will add following line into the web server /etc/hosts:
  1. vi /etc/hosts
  1. root@i-svr:/etc/phpmyadmin# vi /etc/hosts
  2. 127.0.0.1 localhost
  3. 127.0.1.1 i-svr.dev i-svr
  4.  
  5. svr2.mysql 192.168.1.90
  6. svr3.mysql 192.168.1.91
  7. svr4.mysql 192.168.1.92
  8. svr5.mysql 192.168.1.93
  9. svr6.mysql 192.168.1.94

Modify phpmyadmin configuration file

We need to create PHPmyAdmin configuration files to include all databases server as above. Copy the configuration example as below to the active configuration file:
  1. cp /etc/phpmyadmin/config.inc.php /etc/phpmyadmin/config.inc.php.bak
always make a backup
Find and uncomment the line below:
  1. //$cfg['Servers'][$i]['AllowNoPassword'] = TRUE;
  2. $cfg['Servers'][$i]['AllowNoPassword'] = TRUE;
Inside this file you will also see following line:
  1. /* Authentication type */
  2. //$cfg['Servers'][$i]['auth_type'] = 'cookie';
  3. /* Server parameters */
  4. //$cfg['Servers'][$i]['host'] = 'localhost';
  5. //$cfg['Servers'][$i]['connect_type'] = 'tcp';
  6. //$cfg['Servers'][$i]['compress'] = false;
  7. /* Select mysqli if your server has it */
  8. //$cfg['Servers'][$i]['extension'] = 'mysql';
Append the code below on top of the above lines:
  1. /* Authentication type */
  2. $cfg['Servers'][$i]['auth_type'] = 'cookie';
  3. /* Server parameters */
  4. $cfg['Servers'][$i]['host'] = 'svr2.mysql';
  5. $cfg['Servers'][$i]['connect_type'] = 'tcp';
  6. $cfg['Servers'][$i]['compress'] = false;
  7. /* Select mysqli if your server has it */
  8. $cfg['Servers'][$i]['extension'] = 'mysql';
  9. $cfg['Servers'][$i]['AllowNoPassword'] = false;
  10.  
  11. /*
  12. * Second server
  13. */
  14. $i++;
  15. /* Authentication type */
  16. $cfg['Servers'][$i]['auth_type'] = 'cookie';
  17. /* Server parameters */
  18. $cfg['Servers'][$i]['host'] = 'svr3.mysql';
  19. $cfg['Servers'][$i]['connect_type'] = 'tcp';
  20. $cfg['Servers'][$i]['compress'] = false;
  21. /* Select mysqli if your server has it */
  22. $cfg['Servers'][$i]['extension'] = 'mysql';
  23. $cfg['Servers'][$i]['AllowNoPassword'] = false;
  24.  
  25. /*
  26. * Third server
  27. */
  28. $i++;
  29. /* Authentication type */
  30. $cfg['Servers'][$i]['auth_type'] = 'cookie';
  31. /* Server parameters */
  32. $cfg['Servers'][$i]['host'] = 'svr4.mysql';
  33. $cfg['Servers'][$i]['connect_type'] = 'tcp';
  34. $cfg['Servers'][$i]['compress'] = false;
  35. /* Select mysqli if your server has it */
  36. $cfg['Servers'][$i]['extension'] = 'mysql';
  37. $cfg['Servers'][$i]['AllowNoPassword'] = false;
  38.  
  39. /*
  40. * Fourth server
  41. */
  42. $i++;
  43. /* Authentication type */
  44. $cfg['Servers'][$i]['auth_type'] = 'cookie';
  45. /* Server parameters */
  46. $cfg['Servers'][$i]['host'] = 'svr5.mysql';
  47. $cfg['Servers'][$i]['connect_type'] = 'tcp';
  48. $cfg['Servers'][$i]['compress'] = false;
  49. /* Select mysqli if your server has it */
  50. $cfg['Servers'][$i]['extension'] = 'mysql';
  51. $cfg['Servers'][$i]['AllowNoPassword'] = false;
  52.  
  53. /*
  54. * Fifth server
  55. */
  56. $i++;
  57. /* Authentication type */
  58. $cfg['Servers'][$i]['auth_type'] = 'cookie';
  59. /* Server parameters */
  60. $cfg['Servers'][$i]['host'] = 'svr6.mysql';
  61. $cfg['Servers'][$i]['connect_type'] = 'tcp';
  62. $cfg['Servers'][$i]['compress'] = false;
  63. /* Select mysqli if your server has it */
  64. $cfg['Servers'][$i]['extension'] = 'mysql';
  65. $cfg['Servers'][$i]['AllowNoPassword'] = false;
Now you should be able to open the PHPmyAdmin via web browser at http://192.168.1.150/phpmyadmin . You can select MySQL servers you want to connect and access it using phpmaroot user as created above.
phpmyadmin-multiple-mysql-actual

0 comments: