《Mysql必读MySQL-MMM安装指南(Multi-Master Replication Manager for MySQL)》要点:
本文介绍了Mysql必读MySQL-MMM安装指南(Multi-Master Replication Manager for MySQL),希望对您有用。如果有疑问,可以联系我们。
MYSQL教程最基本的MMM安装必须至少需要2个数据库服务器和一个监控服务器下面要配置的MySQL Cluster环境包含四台数据库服务器和一台监控服务器,如下:
function | ip | hostname | server id |
---|---|---|---|
monitoring host | 192.168.0.10 | mon | - |
master 1 | 192.168.0.11 | db1 | 1 |
master 2 | 192.168.0.12 | db2 | 2 |
slave 1 | 192.168.0.13 | db3 | 3 |
slave 2 | 192.168.0.14 | db4 | 4 |
MYSQL教程如果是个人学习安装,一下子找5台机器不太容易,可以虚拟机就可以完成.
MYSQL教程 配置完成后,使用下面的虚拟IP访问MySQL Cluster,他们通过MMM分配到不同的服务器.
ip | role | description |
---|---|---|
192.168.0.100 | writer | 应用程序应该连接到这个ip进行写操作 |
192.168.0.101 | reader | 应用程序应该链接到这些ip中的一个进行读操作 |
192.168.0.102 | reader | |
192.168.0.103 | reader | |
192.168.0.104 | reader |
MYSQL教程结构图如下:
MYSQL教程2. Basic configuration of master 1
First we install MySQL on all hosts:
aptitude install mysql-serverThen we edit the configuration file /etc/mysql/my.cnf and add the following lines - be sure to use different server ids for all hosts:
function | description | privileges |
---|---|---|
monitor user | used by the mmm monitor to check the health of the MySQL servers | REPLICATION CLIENT |
agent user | used by the mmm agent to change read-only mode, replication master, etc. | SUPER, REPLICATION CLIENT, PROCESS |
relication user | used for replication | REPLICATION SLAVE |
MYSQL教程Note: We could be more restrictive here regarding the hosts from which the users are allowed to connect: mmm_monitor is used from 192.168.0.10. mmm_agent and replication are used from 192.168.0.11 - 192.168.0.14.
Note: Don't use a replication_password longer than 32 characters
MYSQL教程4. Synchronisation of data between both databases
MYSQL教程I'll assume that db1 contains the correct data. If you have an empty database, you still have to syncronize the accounts we have just created.
First make sure that no one is altering the data while we create a backup.
MYSQL教程Then get the current position in the binary-log. We will need this values when we setup the replication on db2, db3 and db4.
MYSQL教程DON'T CLOSE this mysql-shell. If you close it, the database lock will be removed. Open a second console and type:
MYSQL教程db1$ mysqldump -u root -p --all-databases > /tmp/database-backup.sql
MYSQL教程Now we can remove the database-lock. Go to the first shell:
MYSQL教程(db1) mysql> UNLOCK TABLES;Copy the database backup to db2, db3 and db4.
MYSQL教程Then import this into db2, db3 and db4:
MYSQL教程Then flush the privileges on db2, db3 and db4. We have altered the user-table and mysql has to reread this table.
MYSQL教程On debian and ubuntu, copy the passwords in /etc/mysql/debian.cnf from db1 to db2, db3 and db4. This password is used for starting and stopping mysql.
Both databases now contain the same data. We now can setup replication to keep it that way.
Note: Import just only add records from dump file. You should drop all databases before import dump file.
MYSQL教程5. Setup replication
MYSQL教程Configure replication on db2, db3 and db4 with the following commands:
MYSQL教程Please insert the values return by “show master status” on db1 at the <file> and <position> tags.
Start the slave-process on all 3 hosts:
MYSQL教程Now check if the replication is running correctly on all hosts:
MYSQL教程Now we have to make db1 replicate from db2. First we have to determine the values for master_log_file and master_log_pos:
MYSQL教程Now we configure replication on db1 with the following command:
MYSQL教程Now insert the values return by “show master status” on db2 at the <file> and <position> tags.
MYSQL教程Start the slave-process:
MYSQL教程(db1) mysql> START SLAVE;Now check if the replication is running correctly on db1:
MYSQL教程Replication between the nodes should now be complete. Try it by inserting some data into both db1 and db2 and check that the data will appear on all other nodes.
MYSQL教程6. Install MMM
MYSQL教程Create user
Optional: Create user that will be the owner of the MMM scripts and configuration files. This will provide an easier method to securely manage the monitor scripts.
MYSQL教程useradd --comment "MMM Script owner" --shell /sbin/nologin mmmdMonitoring host
First install dependencies:
MYSQL教程Then fetch the latest mysql-mmm-common*.deb and mysql-mmm-monitor*.deb and install it:
MYSQL教程dpkg -i mysql-mmm-common_*.deb mysql-mmm-monitor*.deb
MYSQL教程Database hosts
On Ubuntu First install dependencies:
MYSQL教程aptitude install liblog-log4perl-perl libmailtools-perl liblog-dispatch-perl iproute libnet-arp-perl libproc-daemon-perl libalgorithm-diff-perl libdbi-perl libdbd-mysql-perlThen fetch the latest mysql-mmm-common*.deb and mysql-mmm-agent*.deb and install it:
MYSQL教程dpkg -i mysql-mmm-common_*.deb mysql-mmm-agent_*.debOn RedHat
MYSQL教程yum install -y mysql-mmm-agentThis will take care of all the dependencies, which may include:
MYSQL教程Installed:
MYSQL教程mysql-mmm-agent.noarch 0:2.2.1-1.el5
MYSQL教程Dependency Installed:
MYSQL教程Configure MMM
MYSQL教程All generic configuration-options are grouped in a separate file called /etc/mysql-mmm/mmm_common.conf. This file will be the same on all hosts in the system:
MYSQL教程<host default>
cluster_interface eth0
pid_path /var/run/mmmd_agent.pid
bin_path /usr/lib/mysql-mmm/
replication_user replication
replication_password replication_password
agent_user mmm_agent
agent_password agent_password
</host>
<host db1>
ip 192.168.0.11
mode master
peer db2
</host>
<host db2>
ip 192.168.0.12
mode master
peer db1
</host>
<host db3>
ip 192.168.0.13
mode slave
</host>
<host db4>
ip 192.168.0.14
mode slave
</host>
MYSQL教程<role writer>
hosts db1, db2
ips 192.168.0.100
mode exclusive
</role>
<role reader>
hosts db1, db2, db3, db4
ips 192.168.0.101, 192.168.0.102, 192.168.0.103, 192.168.0.104
mode balanced
</role>
MYSQL教程Don't forget to copy this file to all other hosts (including the monitoring host).
MYSQL教程On the database hosts we need to edit /etc/mysql-mmm/mmm_agent.conf. Change “db1” accordingly on the other hosts:
MYSQL教程On the monitor host we need to edit /etc/mysql-mmm/mmm_mon.conf:
MYSQL教程<monitor>
ip 127.0.0.1
pid_path /var/run/mmmd_mon.pid
bin_path /usr/lib/mysql-mmm/
status_path /var/lib/misc/mmmd_mon.status
ping_ips 192.168.0.1, 192.168.0.11, 192.168.0.12, 192.168.0.13, 192.168.0.14
</monitor>
MYSQL教程<host default>
monitor_user mmm_monitor
monitor_password monitor_password
</host>
MYSQL教程debug 0
MYSQL教程ping_ips are some ips that are pinged to determine whether the network connection of the monitor is ok. I used my switch (192.168.0.1) and the four database server.
MYSQL教程
7. Start MMM
MYSQL教程
MYSQL教程Start the agents
(On the database hosts)
MYSQL教程Debian/Ubuntu
Edit /etc/default/mysql-mmm-agent to enable the agent:
MYSQL教程ENABLED=1Red Hat
RHEL/Fedora does not enable packages to start at boot time per default policy, so you might have to turn it on manually so the agents will start automatically when server is rebooted:
MYSQL教程chkconfig mysql-mmm-agent onThen start it:
MYSQL教程/etc/init.d/mysql-mmm-agent startStart the monitor
(On the monitoring host) Edit /etc/default/mysql-mmm-monitor to enable the monitor:
MYSQL教程ENABLED=1Then start it:
MYSQL教程/etc/init.d/mysql-mmm-monitor start
MYSQL教程Wait some seconds for mmmd_mon to start up. After a few seconds you can use mmm_control to check the status of the cluster:
MYSQL教程Because its the first startup the monitor does not know our hosts, so it sets all hosts to state AWAITING_RECOVERY and logs a warning message:
MYSQL教程Now we set or hosts online (db1 first, because the slaves replicate from this host):
MYSQL教程参考:http://mysql-mmm.org/mmm2:guide
转载请注明本页网址:
http://www.vephp.com/jiaocheng/2047.html