- 1.2 卸载系统自带的mariadb-server、mariadb软件包(如果有的话),清理/etc/my.cnf配置文件,此配置文件由RHEL自带的mariadb-libs库提供
root@monitor ~]# yum -y remove mariadb-server mariadb
[root@monitor ~]# rpm -qf /etc/my.cnf
[root@monitor ~]# mv /etc/my.cnf /etc/my.cnf.old
- 1.3 在bundle的整合包中,并不是所有的rpm包都会用到,将一些重复的删除。
安装mysql时可能会缺少某些依赖包,需提前单独安装
[root@monitor ~]# cd pan/`
[root@monitor pan]# tar xvf mysql-5.7.17.tar
[root@monitor pan]# yum -y install perl-Data-Dumper perl-JSON perl-Time-HiRes #安装依赖包
[root@monitor pan]# rpm -Uvh mysql-community-*.rpm #升级安装
[root@monitor pan]# systemctl restart mysqld
[root@monitor pan]# systemctl enable mysqld
[root@monitor pan]# netstat -antpu | grep mysql #查看端口
- 1.4 连接MySQL服务器、修改密码永久配置文件
[root@monitor pan]# vim /etc/my.cnf
[root@monitor pan]# systemctl restart mysqld
[root@monitor pan]# grep "y password" /var/log/mysqld.log
[root@monitor pan]# mysqladmin -u root -p'ny26skpNZ#j ' password '123456'
- 1.5 数据库授权部分为了方便试验我们直接允许所有地址访问了,真实环境需谨慎
mysql> grant replication slave on *.* to slaveuser@"%" identified by "123456"; #主从同步授权
Query OK, 0 rows affected (0.00 sec)
mysql> grant replication client on *.* to monitor@"%" identified by "123456"; #MMM所需架构用户授权
Query OK, 0 rows affected (0.06 sec)
mysql> grant replication client,process,super on *.* to agent@"%" identified by "123456"; #MMM所需架构用户授权
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on *.* to root@"%" identified by "123456"; #测试用户授权
Query OK, 0 rows affected (0.00 sec)
- 2.1 开启主数据库binlog日志、设置server_id
- 2.2 master1主机操作
[root@master1 ~]# vim /etc/my.cnf
[root@master1 ~]# systenctl restart mysqld`
- 2.3 master2主机操作
[root@master2 ~]# vim /etc/my.cnf
[root@master2 ~]# systenctl restart mysqld
** - 2.4 slave1设置:**
[root@slave1 ~]# vim /etc/my.cnf`
[root@slave1~]# systenctl restart mysqld`
- 2.5 slave2设置:
[root@slave2 ~]# vim /etc/my.cnf
[root@slave2~]# systenctl restart mysqld
- 2.6 配置主从从从关系,配置master2、slave1、slave2成为master1的从服务器,
[root@master1 ~]# mysql -uroot -p123456
[root@master2~]# mysql -uroot -p123456
- 2.8 设置slave1为master1从:
[root@slave1**~]# mysql -uroot -p123456
[root@slave2~]# mysql -uroot -p123456
- 2.10 配置主主从从关系,将master1配置为master2的从,查看master2的binlog使用信息:
[root@master2**~]# mysql -uroot -p123456
[root@master1**~]# mysql -uroot -p123456`
- 3.1 步骤一:安装`MySQL-MMM
[root@monitor ~]yum -y install mariadb-server
master1,master2,slave1,slave2,monitor
)均需安装[root@master1 ~]# yum -y install gcc* perl*
[root@master1 mysql-mmm]# cd /root/pan/ #切换到文件目录
[root@master1 mysql-mmm]# unzip mysql-mmm.zip #解压ZIP包
[root@master1 mysql-mmm]# cd mysql-mmm
[root@master1 mysql-mmm]# rpm -ivh perl-Log-Log4perl-1.26-1.el6.rf.noarch.rpm
[root@master1 mysql-mmm]# tar -zxvf Algorithm-Diff-1.1902.tar.gz
[root@master1 mysql-mmm]# cd Algorithm-Diff-1.1902/
[root@master1 Algorithm-Diff-1.1902]# perl Makefile.PL && make && make install
[root@master1 Algorithm-Diff-1.1902]# cd /root/pan/mysql-mmm/
[root@master1 mysql-mmm]# tar -zxvf Proc-Daemon-0.03.tar.gz
[root@master1 mysql-mmm]# cd Proc-Daemon-0.03/
[root@master1 Proc-Daemon-0.03]# perl Makefile.PL && make && make install
[root@master1 Proc-Daemon-0.03]# cd /root/pan/mysql-mmm/
[root@master1 mysql-mmm]#gunzip Net-ARP-1.0.8.tgz
[root@master1 mysql-mmm]# tar xvf Net-ARP-1.0.8.tar
[root@master1 mysql-mmm]# cd Net-ARP-1.0.8/
[root@master1 Net-ARP-1.0.8]# perl Makefile.PL && make && make install
[root@master1 Net-ARP-1.0.8]# cd /root/pan/mysql-mmm/
[root@master1 mysql-mmm] # tar xvf mysql-mmm-2.2.1.tar.gz
[root@master1 mysql-mmm] cd mysql-mmm-2.2.1/
[root@master1 mysql-mmm-2.2.1]# make && make install
- 3.2 步骤二:修改配置文件
[root@master1 ~]# vim /etc/mysql-mmm/mmm_common.conf
active_master_role writer
<host default>
cluster_interface eth0 #设置主从同步的用户
pid_path /var/run/mmm_agentd.pid
bin_path /usr/lib/mysql-mmm/
replication_user slaveuser #设置主从同步的用户
replication_password 123456 #设置主从同步用户密码
agent_user agent #mmm-agent控制数据库用户
agent_password 123456 #mmm-agent控制数据库用户密码
</host>
<host master1> #设置第一个主服务器
ip 192.168.4.10 #master1 IP 地址
mode master
peer 123456 #指定另外一台主服务器
</host>
<host master2> #指定另外一台主服务器
ip 192.168.4.11
mode master
peer 123456
</host>
<host slave1> #设置第一台从服务器
ip 192.168.4.12 slave1 IP 地址
mode slave #本段落配置的是slave服务器
</host>
<host slave2>
ip 192.168.4.13
mode slave
</host>
<role writer> #设置写入服务器工作模式
hosts master1,master2 #提供写的主服务器
ips 192.168.4.200 #设置VIP地址
mode exclusive #排他模式
</role>
<role reader> #设置读取服务器工作模式
hosts slave1,slave2 #提供读的服务器信息
ips 192.168.4.201,192.168.4.202 #多个虚拟IP
mode balanced #均衡模式
</role>
[root@master1 ~]#
[root@monitor ~]# vim /etc/mysql-mmm/mmm_mon.conf
include mmm_common.conf
<monitor>
ip 192.168.4.100 #设置管理主机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.10,192.168.4.11,192.168.4.12,192.168.4.13
#设置被监控数据库
</monitor>
<host default>
monitor_user monitor #监控数据库MySQL用户
monitor_password 123456 #监控数据库MySQL用户密码
</host>
debug 0
[root@monitor ~]#
3.23 修改客户端配置文件
3.231master1配置
[root@master1 ~]# vim /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
this master1
[root@master2 ~]# vim /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
this master2
[root@slave1 ~]# vim /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
this slave1
[root@slave2 ~]# vim /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
this slave2
3.3 启动MMM集群架构
master1操作:
[root@master1 ~]# /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@master2 ~]# /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@master2 ~]# /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@slave2 ~]# /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@monitor ~]# /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
3.4设置集群中服务器为online状态
控制命令只能在管理端monitor服务器上执行。
3.41查看当前集群中各服务器状态:
[root@monitor ~]# mmm_control show
master1(192.168.4.10) master/AWAITING_RECOVERY. Roles:
master2(192.168.4.11) master/AWAITING_RECOVERY. Roles:
slave1(192.168.4.12) slave/AWAITING_RECOVERY. Roles:
slave2(192.168.4.13) slave/AWAITING_RECOVERY. Roles:
[root@monitor ~]# mmm_control set_online master1
OK: State of 'master1' changed to ONLINE. Now you can wait some time and check its new roles!
[root@monitor ~]# mmm_control set_online master2
OK: State of 'master2' changed to ONLINE. Now you can wait some time and check its new roles!
[root@monitor ~]# mmm_control set_online slave1
OK: State of 'slave1' changed to ONLINE. Now you can wait some time and check its new roles!
[root@monitor ~]# mmm_control set_online slave2
OK: State of 'slave2' changed to ONLINE. Now you can wait some time and check its new roles!
[root@monitor ~]#
[root@monitor ~]# mmm_control show
master1(192.168.4.10) master/ONLINE. Roles: writer(192.168.4.200)
master2(192.168.4.11) master/ONLINE. Roles:
slave1(192.168.4.12) slave/ONLINE. Roles: reader(192.168.4.201)
slave2(192.168.4.13) slave/ONLINE. Roles: reader(192.168.4.202)
[root@monitor ~]#
3.5测试MySQL-MMM架构
3.51客户机安装MySQL-client软件包
[root@client ~]# tar xvf MySQL-5.6.15-1.el6.x86_64.rpm-bundle.tar
.. ..
[root@client ~]# rpm -ivh MySQL-client-5.6.15-1.el6.x86_64.rpm
.. ..
[root@client ~]# mysql -h192.168.4.200 -uroot -ppwd123 -e "show databases"
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| tarena |
| test |
+--------------------+
[root@client ~]#
[root@client ~]# mysql -h192.168.4.201 -uroot -ppwd123 -e "show databases"
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| tarena |
| test |
+--------------------+
[root@client ~]#
[root@client ~]# mysql -h192.168.4.202 -uroot -ppwd123 -e "show databases"
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| tarena |
| test |
+--------------------+
[root@client ~]#
[root@master1 ~]# service mysql stop #停止master1上服务
Shutting down MySQL.... [确定]
[root@master1 ~]#
[root@monitor ~]# mmm_control show #查看集群内服务器状态
master1(192.168.4.10) master/HARD_OFFLINE. Roles:
master2(192.168.4.11) master/ONLINE. Roles: writer(192.168.4.200)
slave1(192.168.4.12) slave/ONLINE. Roles: reader(192.168.4.201)
slave2(192.168.4.13) slave/ONLINE. Roles: reader(192.168.4.202)
[root@monitor ~]#
[root@client ~]# mysql -h192.168.4.200 -uroot -ppwd123 -e "show databases" #访问虚拟IP测试
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| tarena |
| test |
+--------------------+
[root@client ~]#