db1服务器上mmm的过程

来源:互联网 发布:php短信验证 编辑:程序博客网 时间:2024/06/14 18:29

//db1服务器上mmm的过程

  IP:192.168.21.190  (为新机,需要安装mysql5.15+mmm)步骤如下:
  IP:192.168.21.11 --shengyijie_db 为线上库,mysql的安装路径为:/usr/local/mysql
                                                                 /data/mysql/data

 在这里我们共有如下步骤:

 1. 先在新机上安装mysql5.1版本的+mmm (my.cnf配置文件参考192.168.21.11的参数);
 2. 新机导入数据库,配成主主环境;
 3. 在原来的线上机上安装mmm,配置新旧mmm主备环境;
 4. 测试在6:00以后

 
成产库的信息:

--basedir=/usr/local/mysql
--datadir=/data/mysql/data

//安装myslq5.1

tar -xvzf mysql-5.1.51.tar.gz -C /usr/local/src/

cd /usr/local/src/mysql-5.1.51

./configure --prefix=/usr/local/mysql --enable-assembler --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=all --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --with-plugins=max

 

//安装ncurses包
yum list|grep ncurses

yum -y install ncurses-devel.x86_64

yum install ncurses-devel.x86_64

#########################################
 yum install gcc
 yum install gcc*

//安装Mysql

make&&make install

//修改配置文件
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
cp /usr/local/mysql/share/mysql/my-large.cnf /etc/my.cnf
cd /usr/local/mysql

groupadd mysql
useradd -g mysql -s /bin/false -M mysql

chown -R mysql .
chgrp -R mysql . 
bin/mysql_install_db --user=mysql --skip-external-locking
bin/mysqld_safe --user=mysql &


修改root用户的密码:root
select  user ,password ,host from user  WHERE User = 'root' ;

UPDATE user SET Password = password ( 'redhat' ) WHERE User = 'root' ;

 flush privileges ;

//添加路径
export PATH=$PATH:/usr/local/mysql/bin/

#vi ~/.bash_profile
修改PATH行,把/usr/local/mysql/bin添加进去
如:PATH=/usr/local/mysql/bin:$PATH:$HOME/bin


//修改字符集问题

mysql> show variables like 'collation_%';
mysql> show variables like 'character_set_%';

检查后发现都是utf8;

2. 主主搭建

IP:192.168.21.11
[root@localhost ~]# vi /etc/my.cnf
log-bin=mysql-bin
server-id =1
replicate-ignore-db=mysql
replicate-ignore-db=information_schema
slave-skip-errors=all
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1

IP:192.168.21.190
log-bin=mysql-bin
server-id =2
replicate-ignore-db=mysql
replicate-ignore-db=information_schema
log-slave-updates
slave-skip-errors=all
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=2

然后分别重启两个mysqld的服务。
2. 授权用户
IP:192.168.21.11/190
mysql> grant replication slave,file on *.* to 'rep'@192.168.21.190 identified by 'root@centos';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> change master to  master_host='192.168.21.190', master_user='rep',  master_password='root@centos';
Query OK, 0 rows affected (0.01 sec)
IP: 10.200.1.8
mysql> grant replication slave,file on *.* to 'rep'@'192.168.21.11' identified by 'root@centos';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> change master to  master_host='192.168.21.11', master_user='rep',  master_password='root@centos';

导入数据后,实现主主同步:(先吧线上库同步到新库,然后再实现新库与线上库的同步)
//在192.168.21.11上同步到190上
change master to  master_host='192.168.21.190',master_user='rep',master_password='root@centos', master_log_file='mysql-bin.000012', master_log_pos=106;
//在192.168.21.190上同步到11上
change master to  master_host='192.168.21.11',master_user='rep',master_password='root@centos', master_log_file='mysql-bin.000134', master_log_pos=4;


3. 安装搭建MMM步骤:

环境准备:
  db1 IP: 192.168.21.11
  db2 IP: 192.168.21.190
monitor IP: 192.168.21.191

其中db1与db2为主主同步

1. 在db1、db2、monitor上安装MMM
wget http://centos.ustc.edu.cn/epel/6/x86_64/epel-release-6-7.noarch.rpm
rpm -Uvh epel-release-6-7.noarch.rpm
yum install munin
yum -y install mysql-mmm*


2. 配置mmm代理和监控账号的权限
在db1,db2上分别执行:
GRANT REPLICATION CLIENT ON *.* TO 'mmm_monitor'@'192.168.21.%' IDENTIFIED BY '123456';
GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO 'mmm_agent'@'192.168.21.%' IDENTIFIED BY '123456';
flush privileges;

复制代码
防火墙开3306和9989端口
测试阶段先关闭防火墙: service iptables stop

3. 配置mysql-mmm
所有的配置选项都集合在了一个叫/etc/mysql-mmm/mmm_common.conf的单独文件中,系统中所有主机的该文件内容都是一样的, 配置完后不要忘记了拷贝这个文件到所有的主机(包括监控主机)!,内容如下:
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        rep 
    replication_password    root@centos        #同步的密码
    agent_user          mmm_agent        #mmm-agent用户名
    agent_password        123456          #mmm-agent用户密码
</host>

<host db1>
    ip    192.168.21.11        #db1的ip
    mode    master
    peer    db2
</host>

<host db2>
    ip     192.168.21.190      #db2的ip
    mode    master
    peer    db1
</host>

<role writer>
    hosts   db1, db2
    ips    192.168.21.191      #设置写入的虚拟IP
    mode    exclusive
</role>

<role reader>
    hosts   db1, db2
    ips    192.168.21.191     #设置读取的虚拟IP
    mode   exclusive

</role>
复制代码

4. 在各个数据库主机上我们需要编辑/etc/mysql-mmm/mmm_agent.conf文件,根据其他主机的不同更改db1的值(db2就将db1更改成db2…….):
include mmm_common.conf
this db1

5. 在监控主机上我们需要编辑/etc/mysql-mmm/mmm_mon.conf文件:
include mmm_common.conf

<monitor>
    ip                  127.0.0.1
    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.21.11,192.168.21.190           #监控服务器ip
    auto_set_online     10

    # 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        #mmm_monitor用户名
    monitor_password    123456   #mmm_monitor密码
</host>

debug 0
复制代码

6. 启动MMM
启动代理:(在数据库服务器上server1、2)编辑/etc/default/mysql-mmm-agent
[root@localhost mysql-mmm]# vi /etc/default/mysql-mmm-agent
来开启:
ENABLED=1
复制代码
7. 关闭防火墙
service iptables stop;

8. 启动agent:
/etc/init.d/mysql-mmm-agent start
 添加到服务里面代码如下:
1. #cd /etc/init.d/ 
2. #chkconfig mysql-mmm-agent on 
3. #service mysql-mmm-agent start 

注意:不在一个网段上的一定要 给monitor相关用户授权。
9. 启动监控(在监控机上)
/etc/init.d/mysql-mmm-monitor start

10. 利用mmm_control监控mysql服务器状态:
[root@localhost init.d]# mmm_control show


 

 

原创粉丝点击