设为首页 收藏本站
查看: 896|回复: 0

[经验分享] 部署MySQL高可用集群

[复制链接]

尚未签到

发表于 2018-10-10 10:31:33 | 显示全部楼层 |阅读模式
  部署mysql高可用集群。
  mysql  MMM   +  mysql主从同步
  实验拓扑
  监控主机pc9
  -------> 从pc5(pc7从)
  主pc8(pc7从) -----> 主pc7(pc8从)
  -------> 从pc6(pc7从)
  一,安装MySQL
  ... ...
  1.1,配置四台服务器的主配置文件/etc/my.cnf
  主pc8配置:
  [root@pc8 ~]# vim /etc/my.cnf
  [mysqld]
  log-bin=master8     #开启二进制log日志
  server_id=8
  主pc7配置:
  [root@pc7 ~]# vim /etc/my.cnf
  [mysqld]
  log-bin=master7
  server_id=7
  log-slave-updates    开启级连复制功能
  从pc6配置:
  [root@pc6 ~]# cat /etc/my.cnf
  [mysqld]
  server_id=6
  从pc5配置:
  [root@pc5 ~]# cat /etc/my.cnf
  [mysqld]
  server_id=5
  1.2,四台服务器都要重启mysql服务:
  # /etc/init.d/mysql restart
  3.1,首次登入需要修改密码
  [root@pc8 ~]# cat /root/.mysql_secret       //初始密码存放路径
  # The random password set for the root user at Thu Mar  2 11:15:58 2017 (local time): m9vGqj2s
  [root@pc8 ~]# mysql -hlocalhost -uroot -pm9vGqj2s
  mysql> set password for root@"localhost"=password("123");    //修改初始密码
  Query OK, 0 rows affected (0.00 sec)
  3.2,分别在PC8和PC7服务器创建从服务器授权:

  mysql> grant   replication  slave  on  *.*  to slaveuser@"%" >  3.3,配置pc7为pc8的从服务器:
  [root@pc8 ~]# mysql -hlocalhost -uroot -p123
  mysql> show master status;
  +----------------+----------+--------------+------------------+----------
  | File           | Position | Binlog_Do_DB | Binlog_Ignore_DB
  +----------------+----------+--------------+------------------+----------
  | master8.000004 |      120 |              |                  |                |
  +----------------+----------+--------------+------------------+----------
  3.4,在PC7配置master服务器:
  [root@pc7 ~]# mysql -uroot -p123
  mysql> stop slave;
  Query OK, 0 rows affected, 1 warning (0.00 sec)
  mysql> change master to
  -> master_host="192.168.4.8",
  -> master_user="slaveuser",
  -> master_password="123",
  -> master_log_file="master8.000004",
  -> master_log_pos=120;
  Query OK, 0 rows affected, 2 warnings (0.39 sec)
  mysql> start slave;
  Query OK, 0 rows affected (0.05 sec)
  mysql> show slave status\G;
  Slave_IO_Running: Yes
  Slave_SQL_Running: Yes
  -------------------------------------------------------------------------
  主从同步的工作过程
  Slave_IO_Running: Yes
  IO线程:负责把主数据库服务器binlog日志里的sql命令拷贝到本机的中继日志文件里。
  IO线程  No状态的原因?
  从数据库服务器连接不上主数据库服务器:
  ping
  iptables
  selinux
  连接的授权用户
  binlog日志文件指定错误
  binlog日志pos点位置错误
  查看报错信息
  Last_IO_Error:  报错信息
  修改错误:
  stop  slave;
  change  master   to    选项="值",选项="值",;
  start  slave;
  -----------------------------------------------------------------------
  Slave_SQL_Running: Yes
  SQL线程:执行本机中继日志文件里的sql命令,把数据写进本机的库里。
  IO线程  No状态的原因?
  执行本机中继日志文件里的sql命令时,本机没有命令使用到的库 表 或字段。
  查看报错信息
  Last_SQL_Error:   报错信息
  ls  /var/lib/mysql/
  master.info    记录连接主数据库服务器配置信息
  relay-log.info  记录中继日志信息文件
  mail-relay-bin.00000x   中继日志文件
  mail-relay-bin.index      中继日志的索引文件
  ----------------------------------------------------------------------
  测试:
  4.1,在PC8中创建一个数据库。
  mysql> create database test008;
  Query OK, 1 row affected (0.01 sec)
  4.2,到PC5-7看是否同步。
  mysql> show databases;
  +--------------------+
  | Database           |
  +--------------------+
  | information_schema |
  | db001              |
  | db002              |
  | db007              |
  | mysql              |
  | performance_schema |
  | test               |
  | test008            |
  | webdb              |
  +--------------------+
  9 rows in set (0.06 sec)
  =================================================
  三,安装MySQL-MMM
  软件介绍:MySQL主主复制管理器
  监控、故障转移    一套脚本套件(perl)
  提供2种服务:
  mmm-monitor: 负责所有的监控工作, 决定故障节点的移除或恢复 。
  mmm-agent :  运行在MySQL服务器上,提供简单远程服务集、提供给监控节点。
  -------------------------------------------------------------------------
  1.1,在所以主机上安装mysql mmm 软件 (4台数据库服务器 +  监控服务器)
  #tar  -zxvf  mysql-mmm-2.2.1.tar.gz
  #cd mysql-mmm-2.2.1
  #make install
  #cd /etc/mysql-mmm
  #ls  *.conf
  mmm_agent.conf   mmm-agent服务的主配置文件(数据库主机)
  mmm_mon.conf     mmm-monitor服务的主配置文件(监控主机)
  mmm_common.conf  公信息配置文件,在所有主机上都要配置
  mmm_tools.conf
  1.2,在4台数据库服务器上做如下授权

  mysql>grant  replication client,process,super on *.*  to     agent@"%" >
  mysql>grant  replication client  on *.*  to     monitor@"%" >  -------------------------------------------------------------------------
  [root@pc5 mysql-mmm]# ls
  mmm_agent.conf  mmm_common.conf  mmm_mon.conf  mmm_tools.conf
  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            slaveuser
  replication_password        123
  agent_user              agent
  agent_password          123
  
  
  ip                192.168.4.8
  mode              master
  peer              master7
  
  
  ip                192.168.4.7
  mode              master
  peer              master8
  
  
  ip                192.168.4.6
  mode              slave
  
  
  ip                192.168.4.5
  mode              slave
  
  
  hosts              master8, master7
  ips                192.168.4.101
  mode               exclusive
  
  
  hosts            slave6, slave5
  ips              192.168.4.102, 192.168.4.103
  mode             balanced
  
  -----------------------------------------------------------------------
  mmm_agent.conf   mmm-agent服务的主配置文件(数据库主机)
  [root@pc5 mysql-mmm]# cat  mmm_agent.conf
  include mmm_common.conf
  this slave5
  -------------------------------------------------------------------------
  mmm_mon.conf     mmm-monitor服务的主配置文件(监控主机)
  [root@pc9 mysql-mmm]# cat mmm_mon.conf
  include mmm_common.conf
  
  ip            192.168.4.9                        //本机IP
  pid_path        /var/run/mmm_mond.pid
  bin_path        /usr/lib/mysql-mmm/
  status_path        /var/lib/misc/mmm_mond.status
  ping_ips        192.168.4.5, 192.168.4.6, 192.168.4.8, 192.168.4.7      //要监控的数据库服务器
  
  
  monitor_user            monitor               //需数据库授权
  monitor_password        123
  
  debug 0           0|1  报错时开机可以设置为1,方便查看报错信息
  =========================================================================
  1.3,在所以主机上 安装服务运行时依赖的软件包。
  tar -zxvf Algorithm-Diff-1.1902.tar.gz
  cd Algorithm-Diff-1.1902
  perl Makefile.PL
  make
  make install
  rpm -ivh  --nodeps perl-Log-Log4perl-1.26-1.el6.rf.noarch.rpm
  tar -zxvf Proc-Daemon-0.03.tar.gz
  cd Proc-Daemon-0.03
  perl Makefile.PL
  make
  make install
  1.4,在4台数据库服务器上安装获取虚拟Ip地址程序。
  #yum  -y  install  gcc   gcc-c++
  #gunzip  Net-ARP-1.0.8.tgz
  #tar -xvf Net-ARP-1.0.8.tar
  #cd  Net-ARP-1.0.8
  #perl   Makefile.PL
  #make
  #make  install
  1.5,启动服务
  1 启动数据库服务器上mmm-agent 服务
  [root@pc8 mysql-mmm]# /etc/init.d/mysql-mmm-agent start
  Daemon bin: '/usr/sbin/mmm_agentd'
  Daemon pid: '/var/run/mmm_agentd.pid'
  Starting MMM Agent daemon... Ok
  [root@stu mysql-mmm]# netstat -utnalp  | grep agent
  tcp        0      0 172.40.50.171:9989          0.0.0.0:*                   LISTEN      24009/mmm_agentd
  [root@pc8 mysql-mmm]# netstat -utnalp  | grep :9989
  tcp        0      0 172.40.50.171:9989          0.0.0.0:*       LISTEN      24009/mmm_agentd
  日志文件  /var/log/mysql-mmm/mmm_agentd.log
  -------------------------------------------------------------------------
  2  启动监控服务器上mmm-monitor 服务
  [root@pc9 mysql-mmm]# /etc/init.d/mysql-mmm-monitor start
  Daemon bin: '/usr/sbin/mmm_mond'
  Daemon pid: '/var/run/mmm_mond.pid'
  Starting MMM Monitor daemon: Ok
  [root@pc9 mysql-mmm]# netstat -utnalp  | grep :9988
  tcp        0      0 172.40.50.177:9988          0.0.0.0:*      LISTEN      23544/mmm_mond
  3.查看数据库服务器的状态:
  [root@pc9 mysql-mmm]# mmm_control show
  [root@pc9 mysql-mmm]# mmm_control set_online master8
  [root@pc9 mysql-mmm]# mmm_control set_online master7
  [root@pc9 mysql-mmm]# mmm_control set_online slave5
  [root@pc9 mysql-mmm]# mmm_control set_online slave6
  [root@pc9 mysql-mmm]# mmm_control show
  master7(192.168.4.7) master/ONLINE. Roles:
  master8(192.168.4.8) master/ONLINE. Roles: writer(192.168.4.101)
  slave5(192.168.4.5) slave/ONLINE. Roles: reader(192.168.4.103)
  slave6(192.168.4.6) slave/ONLINE. Roles: reader(192.168.102)
  -------------------------------------------------------------------------
  4.查看虚拟ip地址
  [root@pc8 ~]# ip addr show | grep eth0
  2: eth0:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
  inet 192.168.4.8/24 brd 192.168.4.255 scope global eth0
  inet 192.168.4.101/32 scope global eth0
  ======================================================


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-619861-1-1.html 上篇帖子: MySQL 各种超时参数的含义 下篇帖子: MySQL微观结构
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表