ny3259 发表于 2018-10-6 11:28:02

mysql系列之9--------mmm高可用集群

  mmm高可用集群介绍:
  高可用集群介绍:主备模式,当主不能提供服务的时候备用主机接替它提供服务。
  这个过程对于客户端是透明的。
  一、前期准备工作
  1、准备五台linux服务器:主(192.168.4.122),主备(192.168.4.123)
  从(192.168.4.126),从(192.168.4.127),管理主机(192.168.4.128)
  四台主机做主从的用户名:tongbu,密码:123456
  2、主和主备做成相互的主从模式,两台从服务器做成主备的从
  3、IP规划,write-vip=192.168.4.100,read-vip=192.168.4.101/192.168.4.102
  二、安装配置 Mysql-mmm
  1、安装:首先安装依赖包:yum -y install perl-*
  cd mysql-mmm-2.2.1/
  make install   //进入解压后的目录,然后直接安装
  2、配置文件说明:cd /etc/mysql-mmm
  mmm_agent.conf             //数据节点主机文件(四台mysql服务器)
  mmm_common.conf       //公共配置文件 (五台主机都需要)
  mmm_mon.conf            //管理主机文件(192.168.4.128)
  mmm_tools.conf         //管理工具
  3、修改数据节点的配置文件:mmm_agent.conf(四台mysql服务器修改)
  include mmm_common.conf    //加载文件
  this db1      //定义在集群中的名称
  名称规划:根据角色和ip地址来命名
  master122,master123,slave126,slave127
  4、修改管理节点的配置(192.168.4.128)mmm_mon.conf
  1 include mmm_common.conf
  2
  3
  4         ip                      192.168.4.128                               //监控本机的IP地址
  5         pid_path                /var/run/mmm_mond.pid
  6         bin_path                /usr/lib/mysql-mmm/
  7         status_path             /var/lib/misc/mmm_mond.status
  8         ping_ips                192.168.4.122, 192.168.4.123, 192.168.4.126, 192.168.4.127 //被监控的IP地址
  9
  10
  11
  12         monitor_user                  monitor   //监控数据库的用户名,用来监测四台数据库服务是否正常
  13         monitor_password            123456   //上面的用户名需在122那台主机上添加授权
  14
  5、修改公共配置文件:mmm_common.conf(五台主机都需要)
  在一台主机上修改,然后传送给其它四台主机
  active_master_role      writer
  
  cluster_interface         eth0
  pid_path                     /var/run/mmm_agentd.pid
  bin_path                     /usr/lib/mysql-mmm/
  replication_user             tongbu   //本机用于主从同步的用户
  replication_password   123456
  agent_user                     agent   //代理程序去检测的用户名
  agent_password             123456
  
  
  ip                              192.168.4.122
  mode                         master   //模式
  peer                           master123//身份对等的主机
  
  
  ip                              192.168.4.123
  mode                         master
  peer                           master122
  
  
  ip                              192.168.4.126
  mode                         slave
  
  
  ip                              192.168.4.127
  mode                         slave
  
  
  hosts                         master122, master123
  ips                           192.168.4.100   //两台主备的虚拟IP
  mode                         exclusive//独占模式
  
  
  hosts                         slave126, slave127
  ips                           192.168.4.101, 192.168.4.102
  mode                         balanced //均衡模式
  
  6、在4.122主机上添加两个授权帐号: monitor, agent

  grant replication client on *.* to monitor@'%'>
  grant replication client,process,super on *.* to agent@'%'>  三、启动数据节点服务和管理节点主机上的mmm_monitor服务
  1、在五台主机上安装启动的依赖包:下面三个rpm包或者tar包
  解决启动agent服务的依赖包:
  Algorithm-Diff-1.1902.tar.gz
  perl-Log-Log4perl-1.26-1.el6.rf.noarch.rpm
  Proc-Daemon-0.03.tar.gz
  2、安装上面的三个包
  yum -y install gccgcc-c++
  cd mysql-mmm/
  tar -zxf Algorithm-Diff-1.1902.tar.gz
  cd Algorithm-Diff-1.1902/
  perl Makefile.PL
  make
  make install
  cd ..
  rpm -ivh perl-Log-Log4perl-1.26-1.el6.rf.noarch.rpm
  tar -zxf Proc-Daemon-0.03.tar.gz
  cd Proc-Daemon-0.03/
  perl Makefile.PL
  make
  make install
  3、安装获取VIP的软件包:Net-ARP-1.0.8.tgz(在四台mysql服务上安装)
  gunzip Net-ARP-1.0.8.tgz
  tar -xf Net-ARP-1.0.8.tar
  cd Net-ARP-1.0.8/
  perl Makefile.PL
  make && make install
  4、启动agent服务:在五台服务器上启动
  /etc/init.d/mysql-mmm-agent start   //启动服务
  netstat -ntulp | grep 9989//查看端口号,查看服务是否启动
  cat /var/log/mysql-mmm/mmm_agentd.log //启动日志
  5、启动管理节点主机上的mmm_monitor服务
  /etc/init.d/mysql-mmm-monitor start//启动
  netstat -ntulp | grep 9988    //查看是否启动
  ls /var/log/mysql-mmm/mmm_mond.log //日志文件
  6、在管理主机上,查看监控信息:mmm_control show
  master122(192.168.4.122) master/AWAITING_RECOVERY. Roles:
  master123(192.168.4.123) master/AWAITING_RECOVERY. Roles:
  slave126(192.168.4.126) slave/AWAITING_RECOVERY. Roles:
  slave127(192.168.4.127) slave/AWAITING_RECOVERY. Roles:
  7、设置在线: mmm_controlset_online四台都需要设置
  mmm_control set_online master122
  mmm_control set_online master123
  mmm_control set_online slave126
  mmm_control set_online slave127
  设置完成后查看:mmm_control show
  master122(192.168.4.122) master/ONLINE. Roles: writer(192.168.4.100)
  master123(192.168.4.123) master/ONLINE. Roles:
  slave126(192.168.4.126) slave/ONLINE. Roles: reader(192.168.4.101)
  slave127(192.168.4.127) slave/ONLINE. Roles: reader(192.168.4.102)
  如何查看IP:
  ip addr show | grep 192.168.4. //可以看到获取到了两个ip地址
  四、测试
  1、在数据节点上添加访问数据库的连接用户,只需要在4.122上创建一个授权帐号

  grant all on *.* to admin@'%'>  2、客户端测试:
  mysql -h192.168.4.100 -uadmin -p123456
  登陆上去后,增删改查数据库,然后在四台mysql
  服务器上验证是否正确
  3、手动把4.122这台主mysql服务器停掉,
  看在客户端是否能访问,增删改查等。
  4、4.122手动起来后,首先需要设置在线:mmm_control set_online master122
  但是VIP对应的还是4.123,不会自动切换过去,
  必须要先把4.123:mmm_control set_offline master123,
  这样4.122才会获得VIP

页: [1]
查看完整版本: mysql系列之9--------mmm高可用集群