云平台是个好东西,MySQL-mmm的典型配置是需要五台机器,一台作为mmm admin,两台master,两台slave。一下子找五台机器真不容易,何况还要安装同样的操作系统。而有了cloud,简单几步就有了完备的实验环境:四台数据库服务器和一台管理服务器(Memory:8G,CPU:2G,Disk:128G,64bit RHEL6)。在此,向为付出辛劳搭建云平台的同事们表示由衷的感谢:-)下面言归正传,开始全新的MySQL mmm之旅。
下面要配置的MySQL Cluster环境包含四台数据库服务器和一台管理服务器,如下:
function |
IP | Server Name | server id |
---|---|---|---|
monitor | 192.168.84.174 | - | - |
master | 192.168.85.167 | db1 | 1 |
master | 192.168.85.169 | db2 | 2 |
slave | 192.168.85.171 | db3 | 3 |
slave | 192.168.85.168 | db4 | 4 |
配置完成后,使用下面的虚拟IP访问MySQL Cluster
IP | role |
---|---|
192.168.85.200 | writer |
192.168.85.201 | reader |
192.168.85.202 | reader |
192.168.85.203 | reader |
一、配置MySQL Relication
1. 安装MySQL
通过yum命令直接安装了mysql5.1.52。
2. 修改配置文件/etc/my.cnf
要将添加的内容放在配置文件的[mysqld]部分,如下:
代码如下:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
#下面为新添加的内容
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在每台服务器上的值都是不一样,在这里依次为1、2、3、4。
2)因为在这里把log文件配置到了/var/log/mysql下,而mysql默认的目录是在/var/lib/mysql,所以首先要新建mysql文件夹,然后用chown -R mysql.mysql mysql命令将mysql的所有者修改为用户mysql。其次要保证,mysql文件夹的权限755(即-rwxr-xr-x)。
如果没有修改权限和所有者,重启服务时就会在错误日志中出现找不到mysql-bin.log或者mysql-bin.log.index的错误(/usr/libexec/mysqld: File '/var/log/mysql/mysql-bin.log.index' not found (Errcode: 13))。
3. 重新启动mysql服务
在完成了对my.cnf的修改后,通过service mysqld restart重新启动mysql服务。在正确启动后,可以通过如下方式检查配置是否正确:
1)登录mysql,执行show master status,看是否有如下输出:
代码如下:
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 106 | | mysql |
+------------------+----------+--------------+------------------+
2)到/var/log/mysql目录下,看是否产生了类似mysql-bin.000001和mysql-bin.log.index的文件。
二、新建同步数据库需要的用户
使用mysql-mmm时一共需要三个用户: replication、mmm_agent和mmm_monitor(管理服务器上用来监控cluster状态的用户,所以可以限定只能从管理服务器登录)。使用下面三条命令新建这三个用户并分配相应的权限:
代码如下:
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';
三、同步主从数据库
1. 从主数据库服务器导出当前数据库内容
代码如下:
mysql> FLUSH TABLES WITH READ LOCK;
mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 106 | | mysql |
+------------------+----------+--------------+------------------+
注意保留上述信息,后面还会用到。另外,不要结束当前mysql控制台,重新打开一个窗口,导出数据库。
代码如下:
# mysqldump -uroot -proot --all-databases > db01_20111005.sql
释放锁
代码如下:
mysql> UNLOCK TABLES;
2. 将导出的sql文件导入到其他几台数据库服务器上。首先通过scp复制过去:
代码如下:
# scp db01_20111005.sql root@192.168.85.167:/root/
在其他几台服务其上导入改SQL文件:
代码如下:
# mysql -uroot -proot
3. 启动从数据库SLAVE进程。
代码如下:
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,重复1-3。
四、安装MMM
在管理服务器和数据库服务器上分别要运行mysql-mmm monitor和agent程序。下面分别安装:
1. 安装监控程序
在管理服务器(192.168.84.174)上,执行下面命令:
代码如下:
# yum -y install mysql-mmm-monitor*
与monitor依赖的所有文件也会随之安装,但是有一个例外perl-Time-HiRes,所以还需要执行下面的命令:
代码如下:
# yum -y install perl-Time-HiRes*
2. 安装代理程序
在数据库服务器上执行下面的命令:
代码如下:
# yum -y install mysql-mmm-agent*
五、配置MMM
1. 编辑mmm_common.conf
完成安装后,所有的配置文件都放到了/etc/mysql-mmm/下面。管理服务器和数据库服务器上都要包含一个共同的文件mmm_common.conf,内容如下:
代码如下:
active_master_role writer
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
ip 192.168.85.167
mode master
peer db2
ip 192.168.85.169
mode master
peer db1
ip 192.168.85.171
mode slave
ip 192.168.85.168
mode slave
hosts db1, db2
ips 192.168.85.200
mode exclusive
hosts db2, db3, db4
ips 192.168.85.201, 192.168.85.202, 192.168.85.203
mode balanced
可以在db1上编辑该文件后,通过scp命令分别复制到monitor、db2、db3和db4上。
2. 编辑mmm_agent.conf。在数据库服务器上,还有一个mmm_agent.conf需要修改,其内容是:
代码如下:
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,在不同的数据库服务器上要分别改为db2、db3和db4,否则代理就会无法启动。
3. 编辑mmm_mon.confg。在管理服务器上,修改mmm_mon.conf文件,修改后内容为:
代码如下:
include mmm_common.conf
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_user mmm_monitor
monitor_password monitor
debug 0
六、启动MMM
1. 在数据库服务器上启动代理程序
代码如下:
# cd /etc/init.d/
# chkconfig mysql-mmm-agent on
# service mysql-mmm-agent start
2. 在管理服务器上启动监控程序
代码如下:
# cd /etc/init.d/
# chkconfig mysql-mmm-monitor on
# service mysql-mmm-monitor start
启动后,稍等几秒,可以通过mmm_control程序查看状态:
代码如下:
# 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)
七、遇到两个问题
1. 监控程序服务器无法启动
在管理服务器上,一切都完成后,通过mmm_control查看状态,得到下面的错误信息:ERROR: Can't connect to monitor daemon! 通过编辑/etc/mysql-mmm/mmm_mon.conf文件将debug 0改为debug 1,打开监控程序的debug状态。重新启动监控程序(service mysql-mmm-monitor restart),就会看到详细的错误信息,找不到Perl Time HiRes库。执行yum -y install perl-Time-HiRes*就可以解决。
2. 防火墙问题导致Warning: agent on host db1 is not reachable.
控制台程序正确启动后,再次执行mmm_control show,却看到下面的输出:
代码如下:
# 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,发现了下面的错误信息:
代码如下:
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下面检查网络连接,得到了No route to host的错误信息。登录db1,通过setup程序里的Firewall configuration关闭Firewall(这不是一个好主意)。同样,关闭db2、db3和db4上的防火墙,再次重启监控程序,一切回到正常状态!
参考文章:
MySQL MMM 官方安装文档 http://mysql-mmm.org/mmm2:guide
MMM Manual http://mysql-mmm.org/mysql-mmm.html

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

Vue框架下,如何快速搭建统计图表系统在现代网页应用中,统计图表是必不可少的组成部分。Vue.js作为一款流行的前端框架,提供了很多便捷的工具和组件,能够帮助我们快速搭建统计图表系统。本文将介绍如何利用Vue框架以及一些插件来搭建一个简单的统计图表系统。首先,我们需要准备一个Vue.js的开发环境,包括安装Vue脚手架以及一些相关的插件。在命令行中执行以下命

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

玩家在雾锁王国中进行游戏时可以收集不同的材料用来建造建筑,有很多玩家想知道野地搭建筑吗,雾锁王国能野地是不能搭建筑的,必须要在祭坛的范围内才可以搭建。雾锁王国能野地搭建筑吗答:不能。1、雾锁王国能野地是不能搭建筑的。2、建筑必须要在祭坛的范围内才可以搭建。3、玩家可以自行放置灵火祭坛,但一旦离开了范围,将无法进行建筑搭建。4、我们也可以直接在山上挖个洞当做我们的家,这样不用耗建筑材料。5、玩家自己搭建的建筑中,存在舒适度机制,也就是说,内饰越好,舒适度越高。6、高舒适度将为玩家带来属性加成,例如

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。

在mysql中,是否需要commit取决于存储引擎:1、若是不支持事务的存储引擎,如myisam,则不需要使用commit;2、若是支持事务的存储引擎,如innodb,则需要知道事务是否自动提交,因此需要使用commit。

CentOS7下搭建web服务器的网络安全加固技巧web服务器是现代互联网的重要组成部分,因此保护web服务器的安全性非常重要。通过加固网络安全,可以减少风险和避免潜在的攻击。本文将介绍在CentOS7上搭建web服务器时常用的网络安全加固技巧,并提供相应的代码示例。更新系统和软件首先,确保你的系统和软件是最新版本。可以使用以下命令更

在当下信息充斥的时代,社交媒体平台已经成为人们获取和分享信息的主要途径。对于个人和企业而言,建立一个有效的账号网络以实现信息的最大传播和提升影响力,已成为亟需解决的挑战。一、账号矩阵怎么搭建?1.明确目标人群在构建账号矩阵之前,关键是明确目标受众,深入了解他们的需求、兴趣和消费习惯,这样才能制定更具针对性的内容策略。2.选择合适的平台根据目标人群的特点,选择适合的社交媒体平台进行布局。目前主流的社交媒体平台有微博、微信、抖音、快手等,每个平台都有其独特的用户群体和传播特点,需要根据实际情况进行选


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.