日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

从零开始配置MySQL MMM

發(fā)布時(shí)間:2024/8/26 数据库 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 从零开始配置MySQL MMM 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

?下面要配置的MySQL Cluster環(huán)境包含四臺(tái)數(shù)據(jù)庫服務(wù)器和一臺(tái)管理服務(wù)器,如下:

function IPServer Nameserver id
monitor192.168.84.174--
master192.168.85.167db11
master192.168.85.169db22
slave192.168.85.171db33
slave192.168.85.168db44

? ? ? ? ? ? 配置完成后,使用下面的虛擬IP訪問MySQL Cluster

IProle
192.168.85.200writer
192.168.85.201reader
192.168.85.202reader
192.168.85.203reader


? ? ? ??一、配置MySQL Relication

? ? ? ??1. 安裝MySQL

? ? ? ? 通過yum命令直接安裝了mysql5.1.52。

? ? ? ??2. 修改配置文件/etc/my.cnf

? ? ? ? 要將添加的內(nèi)容放在配置文件的[mysqld]部分,如下:? ? ? ??

[plain]?view plaincopyprint?
  • [mysqld]??
  • datadir=/var/lib/mysql??
  • socket=/var/lib/mysql/mysql.sock??
  • user=mysql??
  • ??
  • #下面為新添加的內(nèi)容??
  • default-storage-engine?=?innodb??
  • ??
  • replicate-ignore-db?=?mysql??
  • binlog-ignore-db????=?mysql??
  • ??
  • server-id???????????=?1??
  • log-bin?????????????=?/var/log/mysql/mysql-bin.log??
  • log_bin_index???????=?/var/log/mysql/mysql-bin.log.index??
  • relay_log???????????=?/var/log/mysql/mysql-bin.relay??
  • relay_log_index?????=?/var/log/mysql/mysql-bin.relay.index??
  • expire_logs_days????=?10??
  • max_binlog_size?????=?100M??
  • log_slave_updates???=?1??

  • ? ? ? ?注意:

    ? ? ? ?1)server-id在每臺(tái)服務(wù)器上的值都是不一樣,在這里依次為1、2、3、4。

    ? ? ? ?2)因?yàn)樵谶@里把log文件配置到了/var/log/mysql下,而mysql默認(rèn)的目錄是在/var/lib/mysql,所以首先要新建mysql文件夾,然后用chown -R mysql.mysql mysql命令將mysql的所有者修改為用戶mysql。其次要保證,mysql文件夾的權(quán)限755(即-rwxr-xr-x)。

    ? ? ? ?如果沒有修改權(quán)限和所有者,重啟服務(wù)時(shí)就會(huì)在錯(cuò)誤日志中出現(xiàn)找不到mysql-bin.log或者mysql-bin.log.index的錯(cuò)誤(/usr/libexec/mysqld: File '/var/log/mysql/mysql-bin.log.index' not found (Errcode: 13))。

    ? ? ? ?3. 重新啟動(dòng)mysql服務(wù)

    ? ? ? ?在完成了對(duì)my.cnf的修改后,通過service mysqld restart重新啟動(dòng)mysql服務(wù)。在正確啟動(dòng)后,可以通過如下方式檢查配置是否正確:

    ? ? ? ?1)登錄mysql,執(zhí)行show master status,看是否有如下輸出:

    +------------------+----------+--------------+------------------+
    | File ? ? ? ? ? ? | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +------------------+----------+--------------+------------------+
    | mysql-bin.000001 | ? ? ?106 | ? ? ? ? ? ? ?| mysql ? ? ? ? ? ?|
    +------------------+----------+--------------+------------------+

    ? ? ? ? 2)到/var/log/mysql目錄下,看是否產(chǎn)生了類似mysql-bin.000001和mysql-bin.log.index的文件。


    ? ? ? ?二、新建同步數(shù)據(jù)庫需要的用戶

    ? ? ? ?使用mysql-mmm時(shí)一共需要三個(gè)用戶: replication、mmm_agent和mmm_monitor(管理服務(wù)器上用來監(jiān)控cluster狀態(tài)的用戶,所以可以限定只能從管理服務(wù)器登錄)。使用下面三條命令新建這三個(gè)用戶并分配相應(yīng)的權(quán)限:

    [sql]?view plaincopyprint?
  • GRANT?REPLICATION?CLIENT?????????????????ON?*.*?TO?'mmm_monitor'@'192.168.84.%'?IDENTIFIED?BY?'monitor';??
  • GRANT?SUPER,?REPLICATION?CLIENT,?PROCESS?ON?*.*?TO?'mmm_agent'@'192.168.85.%'???IDENTIFIED?BY?'agent';??
  • GRANT?REPLICATION?SLAVE??????????????????ON?*.*?TO?'replication'@'192.168.85.%'?IDENTIFIED?BY?'replication';??

  • ? ? ?? 三、同步主從數(shù)據(jù)庫

    ? ? ??1. 從主數(shù)據(jù)庫服務(wù)器導(dǎo)出當(dāng)前數(shù)據(jù)庫內(nèi)容? ? ??

    [sql]?view plaincopyprint?
  • mysql>?FLUSH?TABLES?WITH?READ?LOCK;??
  • mysql>?SHOW?MASTER?STATUS;??
  • +------------------+----------+--------------+------------------+??
  • |?File?????????????|?Position?|?Binlog_Do_DB?|?Binlog_Ignore_DB?|??
  • +------------------+----------+--------------+------------------+??
  • |?mysql-bin.000001?|??????106?|??????????????|?mysql????????????|??
  • +------------------+----------+--------------+------------------+??

  • ? ? ? ? 注意保留上述信息,后面還會(huì)用到。另外,不要結(jié)束當(dāng)前mysql控制臺(tái),重新打開一個(gè)窗口,導(dǎo)出數(shù)據(jù)庫。

    ? ? ? ? # mysqldump -uroot -proot --all-databases > db01_20111005.sql

    ? ? ? ? 釋放鎖

    [html]?view plaincopyprint?
  • mysql>?UNLOCK?TABLES;??
  • ? ? ? ? 2. 將導(dǎo)出的sql文件導(dǎo)入到其他幾臺(tái)數(shù)據(jù)庫服務(wù)器上 。首先通過scp復(fù)制過去:

    [html]?view plaincopyprint?
  • #?scp?db01_20111005.sql?root@192.168.85.167:/root/??

  • ? ? ? ?在其他幾臺(tái)服務(wù)其上導(dǎo)入改SQL文件:

    [html]?view plaincopyprint?
  • #?mysql?-uroot?-proot?<?db01_20111005.sql??

  • ? ? ?? 3. 啟動(dòng)從數(shù)據(jù)庫SLAVE進(jìn)程。

    [sql]?view plaincopyprint?
  • mysql>?flush?privileges;??
  • Query?OK,?0?rows?affected?(0.00?sec)??
  • ??
  • mysql>?CHANGE?MASTER?TO?master_host='192.168.85.167',?master_port=3306,?master_user='replication',master_password='replication',?master_log_file='mysql-bin.000001',?master_log_pos=106;??
  • Query?OK,?0?rows?affected?(0.07?sec)??
  • ??
  • mysql>?start?slave;??
  • Query?OK,?0?rows?affected?(0.00?sec)??
  • ??
  • mysql>?show?slave?status\G??
  • ***************************?1.?row?***************************??
  • ???????????????Slave_IO_State:?Waiting?for?master?to?send?event??
  • ??????????????????Master_Host:?192.168.85.180??
  • ??????????????????Master_User:?replication??
  • ??????????????????Master_Port:?3306??
  • ????????????????Connect_Retry:?60??
  • ??????????????Master_Log_File:?mysql-bin.000001??
  • ??????????Read_Master_Log_Pos:?106??
  • ???????????????Relay_Log_File:?mysql-bin.000003??
  • ????????????????Relay_Log_Pos:?251??
  • ????????Relay_Master_Log_File:?mysql-bin.000001??
  • ?????????????Slave_IO_Running:?Yes??
  • ????????????Slave_SQL_Running:?Yes??
  • ??????????????Replicate_Do_DB:??
  • ??????????Replicate_Ignore_DB:?mysql??
  • ???????????Replicate_Do_Table:??
  • ???????Replicate_Ignore_Table:??
  • ??????Replicate_Wild_Do_Table:??
  • ??Replicate_Wild_Ignore_Table:??
  • ???????????????????Last_Errno:?0??
  • ???????????????????Last_Error:??
  • ?????????????????Skip_Counter:?0??
  • ??????????Exec_Master_Log_Pos:?106??
  • ??????????????Relay_Log_Space:?400??
  • ??????????????Until_Condition:?None??
  • ???????????????Until_Log_File:??
  • ????????????????Until_Log_Pos:?0??
  • ???????????Master_SSL_Allowed:?No??
  • ???????????Master_SSL_CA_File:??
  • ???????????Master_SSL_CA_Path:??
  • ??????????????Master_SSL_Cert:??
  • ????????????Master_SSL_Cipher:??
  • ???????????????Master_SSL_Key:??
  • ????????Seconds_Behind_Master:?0??
  • Master_SSL_Verify_Server_Cert:?No??
  • ????????????????Last_IO_Errno:?0??
  • ????????????????Last_IO_Error:??
  • ???????????????Last_SQL_Errno:?0??
  • ???????????????Last_SQL_Error:??
  • 1?row?in?set?(0.00?sec)??

  • ? ? ? ?? 4. 將db02作為master,db01作為slave,重復(fù)1-3。


    ? ? ? ??四、安裝MMM

    ? ? ? ? 在管理服務(wù)器和數(shù)據(jù)庫服務(wù)器上分別要運(yùn)行mysql-mmm monitor和agent程序。下面分別安裝:

    ? ? ? ??1. 安裝監(jiān)控程序

    ? ? ? ? ?在管理服務(wù)器(192.168.84.174)上,執(zhí)行下面命令:

    [plain]?view plaincopyprint?
  • #?yum?-y?install?mysql-mmm-monitor*??

  • ? ? ? ? ?與monitor依賴的所有文件也會(huì)隨之安裝,但是有一個(gè)例外perl-Time-HiRes,所以還需要執(zhí)行下面的命令:

    [plain]?view plaincopyprint?
  • #?yum?-y?install?perl-Time-HiRes*??

  • ? ? ? ? ? 2. 安裝代理程序

    ? ? ? ? ?在數(shù)據(jù)庫服務(wù)器上執(zhí)行下面的命令:

    [plain]?view plaincopyprint?
  • #?yum?-y?install?mysql-mmm-agent*??

  • ? ? ? ?? ?五、配置MMM
    ? ? ? ?? 1. 編輯mmm_common.conf

    ? ? ? ? ?完成安裝后,所有的配置文件都放到了/etc/mysql-mmm/下面。管理服務(wù)器和數(shù)據(jù)庫服務(wù)器上都要包含一個(gè)共同的文件mmm_common.conf,內(nèi)容如下:

    [plain]?view plaincopyprint?
  • active_master_role??????writer??
  • ??
  • <host?default>??
  • ????cluster_interface???????eth0??
  • ??
  • ????pid_path????????????????/var/run/mysql-mmm/mmm_agentd.pid??
  • ????bin_path????????????????/usr/libexec/mysql-mmm/??
  • ??
  • ????replication_user????????replication??
  • ????replication_password????replication??
  • ??
  • ????agent_user??????????????mmm_agent??
  • ????agent_password??????????agent??
  • </host>??
  • ??
  • <host?db1>??
  • ????ip??????192.168.85.167??
  • ????mode????master??
  • ????peer????db2??
  • </host>??
  • ??
  • <host?db2>??
  • ????ip??????192.168.85.169??
  • ????mode????master??
  • ????peer????db1??
  • </host>??
  • ??
  • <host?db3>??
  • ????ip??????192.168.85.171??
  • ????mode????slave??
  • </host>??
  • ??
  • <host?db4>??
  • ????ip??????192.168.85.168??
  • ????mode????slave??
  • </host>??
  • ??
  • <role?writer>??
  • ????hosts???db1,?db2??
  • ????ips?????192.168.85.200??
  • ????mode????exclusive??
  • </role>??
  • ??
  • <role?reader>??
  • ????hosts???db2,?db3,?db4??
  • ????ips?????192.168.85.201,?192.168.85.202,?192.168.85.203??
  • ????mode????balanced??
  • </role>??
  • ? ? ? ? 可以在db1上編輯該文件后,通過scp命令分別復(fù)制到monitor、db2、db3和db4上。


    ? ? ? ? ?2. 編輯mmm_agent.conf。 在數(shù)據(jù)庫服務(wù)器上,還有一個(gè)mmm_agent.conf需要修改,其內(nèi)容是:

    [plain]?view plaincopyprint?
  • include?mmm_common.conf??
  • ??
  • #?The?'this'?variable?refers?to?this?server.??Proper?operation?requires??
  • #?that?'this'?server?(db1?by?default),?as?well?as?all?other?servers,?have?the??
  • #?proper?IP?addresses?set?in?mmm_common.conf.??
  • this?db1??
  • 最后一行的db1,在不同的數(shù)據(jù)庫服務(wù)器上要分別改為db2、db3和db4,否則代理就會(huì)無法啟動(dòng)。

    ? ? ? ??3. 編輯mmm_mon.confg。在管理服務(wù)器上,修改mmm_mon.conf文件,修改后內(nèi)容為:

    [plain]?view plaincopyprint?
  • include?mmm_common.conf??
  • ??
  • <monitor>??
  • ????ip??????????????????192.168.84.174??
  • ????pid_path????????????/var/run/mysql-mmm/mmm_mond.pid??
  • ????bin_path????????????/usr/libexec/mysql-mmm??
  • ????status_path?????????/var/lib/mysql-mmm/mmm_mond.status??
  • ????ping_ips????????????192.168.85.167,?192.168.85.169,?192.168.85.171,?192.168.85.168??
  • ????auto_set_online?????60??
  • ??
  • ????#?The?kill_host_bin?does?not?exist?by?default,?though?the?monitor?will??
  • ????#?throw?a?warning?about?it?missing.??See?the?section?5.10?"Kill?Host??
  • ????#?Functionality"?in?the?PDF?documentation.??
  • ????#??
  • ????#?kill_host_bin?????/usr/libexec/mysql-mmm/monitor/kill_host??
  • ????#??
  • </monitor>??
  • ??
  • <host?default>??
  • ????monitor_user????????mmm_monitor??
  • ????monitor_password????monitor??
  • </host>??
  • ??
  • debug?0??

  • ? ? ? ? ? 六、啟動(dòng)MMM

    ? ? ? ??1. 在數(shù)據(jù)庫服務(wù)器上啟動(dòng)代理程序

    [plain]?view plaincopyprint?
  • #?cd?/etc/init.d/??
  • #?chkconfig?mysql-mmm-agent?on??
  • #?service?mysql-mmm-agent?start??

  • ? ? ? ?? 2. 在管理服務(wù)器上啟動(dòng)監(jiān)控程序

    [plain]?view plaincopyprint?
  • #?cd?/etc/init.d/??
  • #?chkconfig?mysql-mmm-monitor?on??
  • #?service?mysql-mmm-monitor?start??
  • ? ? ? 啟動(dòng)后,稍等幾秒,可以通過mmm_control程序查看狀態(tài):

    [plain]?view plaincopyprint?
  • #?mmm_control?show??
  • ??db1(192.168.85.167)?master/ONLINE.?Roles:?writer(192.168.85.200)??
  • ??db2(192.168.85.169)?master/ONLINE.?Roles:?reader(192.168.85.202)??
  • ??db3(192.168.85.171)?slave/ONLINE.?Roles:?reader(192.168.85.203)??
  • ??db4(192.168.85.168)?slave/ONLINE.?Roles:?reader(192.168.85.201)??

  • ? ? ? ? 七、遇到兩個(gè)問題
    ? ? ? ? 1. 監(jiān)控程序服務(wù)器無法啟動(dòng)

    ? ? ? ? ?在管理服務(wù)器上,一切都完成后,通過mmm_control查看狀態(tài),得到下面的錯(cuò)誤信息:ERROR: Can't connect to monitor daemon!?通過編輯/etc/mysql-mmm/mmm_mon.conf文件將debug 0改為debug 1,打開監(jiān)控程序的debug狀態(tài)。重新啟動(dòng)監(jiān)控程序(service mysql-mmm-monitor restart),就會(huì)看到詳細(xì)的錯(cuò)誤信息,找不到Perl Time HiRes庫。執(zhí)行yum -y install perl-Time-HiRes*就可以解決。

    ? ? ? ?2. 防火墻問題導(dǎo)致Warning: agent on host db1 is not reachable.

    ? ? ? ?控制臺(tái)程序正確啟動(dòng)后,再次執(zhí)行mmm_control show,卻看到下面的輸出:

    [plain]?view plaincopyprint?
  • #?Warning:?agent?on?host?db1?is?not?reachable??
  • #?Warning:?agent?on?host?db2?is?not?reachable??
  • #?Warning:?agent?on?host?db3?is?not?reachable??
  • #?Warning:?agent?on?host?db4?is?not?reachable??
  • ??db1(192.168.85.167)?master/ONLINE.?Roles:??
  • ??db2(192.168.85.169)?master/ONLINE.?Roles:??
  • ??db3(192.168.85.171)?slave/ONLINE.?Roles:??
  • ??db4(192.168.85.168)?slave/ONLINE.?Roles:??

  • ? ? ? ?再次打開debug,發(fā)現(xiàn)了下面的錯(cuò)誤信息:

    2011/10/07 13:38:45 DEBUG Sending command 'GET_AGENT_STATUS()' to db4 (192.168.85.167:9989)
    2011/10/07 13:38:45 ERROR The status of the agent on host 'db4' could not be determined (answer was: 0).

    ? ? ? ?通過telnet 192.168.85.167 9989下面檢查網(wǎng)絡(luò)連接,得到了No route to host的錯(cuò)誤信息。登錄db1,通過setup程序里的Firewall configuration關(guān)閉Firewall(這不是一個(gè)好主意)。同樣,關(guān)閉db2、db3和db4上的防火墻,再次重啟監(jiān)控程序,一切回到正常狀態(tài)!


    ? ? 參考文章:

    ? ??MySQL MMM 官方安裝文檔?http://mysql-mmm.org/mmm2:guide?

    ? ? MMM Manual?http://mysql-mmm.org/mysql-mmm.html

    總結(jié)

    以上是生活随笔為你收集整理的从零开始配置MySQL MMM的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。