作為系統管理員,我們傾向於管理多個 MYSQLServer 實例。因此,我們需要找到更好的方式來管理這組mysql服務器,使其更簡單、更集中。在我的環境中,5 個不同的 MySQL 數據庫服務器在不同的服務器位置運行。它獨立運行,不處於集群模式,因此您需要一個平台來完全管理這些數據庫服務器。
PHPmyAdmin 可以通過對配置文件進行一些更改來做到這一點。您需要允許連接到每個數據庫服務器上的 MySQL 用戶和主機。這是我想要做的設置:
要在 ubuntu 上安裝 phpmyadmin,需要正確安裝和配置三個主要包 apache、MySQL 和 php。
1. Apache2安裝配置
2.安裝mysql
3.PHP安裝
假設您的服務器上已經安裝了正在運行的 LAMP。
安裝完apache2、mysql、php後,就可以進行下一步安裝和配置phpmyadmin了。
環境
本教程中的步驟要求用戶在 VPS 上具有 root 權限。
本教程中使用的變量是:
網絡服務器IP:192.168.1.150
PHPmyAdmin 目錄:/etc/phpmyadmin
用戶:phpmaroot
密碼:pmappass123!
安裝 phpmyadmin
在管理 MYSQL 服務器的 svr1.webserver 上安裝 phpmyadmin
apt-get install phpmyadmin
創建一個root用戶來管理phpmyadmin
此步驟是可選的。當然,您也可以以 root 身份登錄 phpmyadmin。
mysql> CREATE USER 'phpmaroot'@'%' IDENTIFIED BY 'pmapass123!'; mysql> GRANT ALL PRIVILEGES ON *.* TO [email protected]'%';
修改mysql服務器上的my.cnf
確保所有數據庫服務器都在偵聽所有外部可訪問的 IP。為方便起見,如果您在 my.cnf 文件中(通常在 /etc 下)找到以下行,請將其刪除或註釋掉。
#bind-address=127.0.0.1 #bind-address=localhost
使 MySql 可訪問
為了方便區分 MySQL 服務器,建議將服務器的主機名添加到 Web Server/PHPmyAdmin 服務器/etc/hosts 文件中。按照上述要求,我在我的 Web 服務器 /etc/hosts 中添加了以下行。
vi /etc/hosts
[email protected]:/etc/phpmyadmin# vi /etc/hosts 127.0.0.1 localhost 127.0.1.1 i-svr.dev i-svr svr2.mysql 192.168.1.90 svr3.mysql 192.168.1.91 svr4.mysql 192.168.1.92 svr5.mysql 192.168.1.93 svr6.mysql 192.168.1.94
修改phpmyadmin配置文件
您需要創建一個包含上述所有數據庫服務器的 PHPmyAdmin 配置文件。將以下配置示例複製到活動配置文件中。
cp /etc/phpmyadmin/config.inc.php /etc/phpmyadmin/config.inc.php.bak
始終進行備份
找到下一行並取消註釋。
//$cfg['Servers'][$i]['AllowNoPassword'] = TRUE; $cfg['Servers'][$i]['AllowNoPassword'] = TRUE;
此文件中還顯示以下行:
/* Authentication type */ //$cfg['Servers'][$i]['auth_type'] = 'cookie'; /* Server parameters */ //$cfg['Servers'][$i]['host'] = 'localhost'; //$cfg['Servers'][$i]['connect_type'] = 'tcp'; //$cfg['Servers'][$i]['compress'] = false; /* Select mysqli if your server has it */ //$cfg['Servers'][$i]['extension'] = 'mysql';
在上述行的開頭添加以下代碼。
/* Authentication type */ $cfg['Servers'][$i]['auth_type'] = 'cookie'; /* Server parameters */ $cfg['Servers'][$i]['host'] = 'svr2.mysql'; $cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['compress'] = false; /* Select mysqli if your server has it */ $cfg['Servers'][$i]['extension'] = 'mysql'; $cfg['Servers'][$i]['AllowNoPassword'] = false; /* * Second server */ $i++; /* Authentication type */ $cfg['Servers'][$i]['auth_type'] = 'cookie'; /* Server parameters */ $cfg['Servers'][$i]['host'] = 'svr3.mysql'; $cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['compress'] = false; /* Select mysqli if your server has it */ $cfg['Servers'][$i]['extension'] = 'mysql'; $cfg['Servers'][$i]['AllowNoPassword'] = false; /* * Third server */ $i++; /* Authentication type */ $cfg['Servers'][$i]['auth_type'] = 'cookie'; /* Server parameters */ $cfg['Servers'][$i]['host'] = 'svr4.mysql'; $cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['compress'] = false; /* Select mysqli if your server has it */ $cfg['Servers'][$i]['extension'] = 'mysql'; $cfg['Servers'][$i]['AllowNoPassword'] = false; /* * Fourth server */ $i++; /* Authentication type */ $cfg['Servers'][$i]['auth_type'] = 'cookie'; /* Server parameters */ $cfg['Servers'][$i]['host'] = 'svr5.mysql'; $cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['compress'] = false; /* Select mysqli if your server has it */ $cfg['Servers'][$i]['extension'] = 'mysql'; $cfg['Servers'][$i]['AllowNoPassword'] = false; /* * Fifth server */ $i++; /* Authentication type */ $cfg['Servers'][$i]['auth_type'] = 'cookie'; /* Server parameters */ $cfg['Servers'][$i]['host'] = 'svr6.mysql'; $cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['compress'] = false; /* Select mysqli if your server has it */ $cfg['Servers'][$i]['extension'] = 'mysql'; $cfg['Servers'][$i]['AllowNoPassword'] = false;
您現在可以在 https://192.168.1.150/phpmyadmin 從 Web 瀏覽器打開 PHPmyAdmin。您可以使用上面創建的 phpmaroot 用戶來選擇和訪問要連接的 MySQL 服務器。