标签:date pid exec 配置 copyright 主主 file acl 0.00
MySQL高可用群集主机 | 操作系统 | IP地址 | 只要软件 |
---|---|---|---|
mysql-master1 | Centos 7 x86_64 | 192.168.32.222 | MySQL-MMM |
mysql-master2 | Centos 7 x86_64 | 192.168.32.223 | MySQL-MMM |
mysql-slave1 | Centos 7 x86_64 | 192.168.32.224 | MySQL-MMM |
mysql-slave2 | Centos 7 x86_64 | 192.168.32.225 | MySQL-MMM |
mysql-monitor | Centos 7 x86_64 | 192.168.32.226 | MySQL-MMM |
master1,2 | Centos 7 x86_64 | VIP:192.168.32.221 | MySQL-MMM |
slave1 | Centos 7 x86_64 | VIP1:192.168.32.220 | MySQL-MMM |
slave2 | Centos 7 x86_64 | VIP1:192.168.32.199 | MySQL-MMM |
[root@localhost ~] vim /etc/my.cnf #删除从第一行开始到第九行删除添加下列语句
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1 #server-id每台数据库server值都是唯一的
log-error=/usr/local/mysql/data/mysql_error.log #开启错误日志
general_log=ON #开启访问日志
general_log_file=/usr/local/mysql/data/mysql_general.log
log_bin=mysql-bin #开启二进制日志
slow_query_log=ON #开启慢日志
slow_query_log_file=mysql_slow_query.log
long_query_time=5
log_slave_updates=true
sync_binlog=1 #同步
auto_increment_increment=2 #增量值
auto_increment_offset=1 #起点值
binlog-ignore-db=mysql,information_schema #关闭mysql,information_schema 这两个二进制日志
[root@localhost ~]# systemctl restart mysqld.service #重启数据库
[root@localhost data]# netstat -anpt | grep 3306
tcp6 0 0 :::3306 :::* LISTEN 3074/mysqld
#查看端口有没开启
#先用show master status 查看两台主服务器的二进制日志文件和偏移量
#master1
mysql> show master status;
+------------------+----------+--------------+--------------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+--------------------------+-------------------+
| mysql-bin.000004 | 154 | | mysql,information_schema | |
+------------------+----------+--------------+--------------------------+-------------------+
1 row in set (0.00 sec)
#master2
mysql> show master status;
+------------------+----------+--------------+--------------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+--------------------------+-------------------+
| mysql-bin.000004 | 154 | | mysql,information_schema | |
+------------------+----------+--------------+--------------------------+-------------------+
1 row in set (0.00 sec)
mysql> grant replication slave on *.* to ‘replication‘@‘192.168.32.%‘ identified by ‘123456‘;
Query OK, 0 rows affected, 1 warning (0.03 sec)
mysql> change master to master_host=‘192.168.32.184‘,master_user=‘replication‘,master_passwordd=‘123456‘,master_log_file=‘mysql_bin.000002‘,master_log_pos=154;
Query OK, 0 rows affected, 2 warnings (0.04 sec)
### 开启同步功能 #slave代表开启同步不是代表从服务器,我上面设置的只是个名称与这边的意思不同
mysql> start slave;
Query OK, 0 rows affected (0.03 sec)
mysql> grant replication slave on *.* to ‘replication‘@‘192.168.32.%‘ identified by ‘123456‘;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> change master to master_host=‘192.168.32.151‘,master_user=‘replication‘,master_password=‘123456‘,master_log__file=‘mysql_bin.000004‘,master_log_pos=154;
Query OK, 0 rows affected, 2 warnings (0.02 sec)
#开启同步功能
mysql> start slave;
Query OK, 0 rows affected (0.03 sec)
#查看IO线程和SQL线程是否都已经开启是否显示为yes
mysql>show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.32.151
Master_User: replication
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000005
Read_Master_Log_Pos: 154
Relay_Log_File: localhost-relay-bin.000011
Relay_Log_Pos: 367
Relay_Master_Log_File: mysql-bin.000005
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
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: 154
Relay_Log_Space: 625
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:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 111eb6e9-78dd-11e8-9337-000c2940c252
Master_Info_File: /usr/local/mysql/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
如果只开启了SQL线程而IO线程没有开启
那么检查防火墙有无关闭 增强性安全模块有没有关闭
再执行下列语句
mysql>stop slave; #先停止slave
mysql>reset slave; #刷新slave同步功能
mysql>start slave; #最后再开启然后查看
MariaDB [(none)]> create database info;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| info |
| mysql |
| performance_schema |
| test |
+--------------------+
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| info |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| info |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| info |
| info1 |
| mysql |
| performance_schema |
| test |
+--------------------+
6 rows in set (0.00 sec)
配置ALI云源,然后安装epel-release源。
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all && yum makecache
yum -y install epel-release
yum -y install mysql-mmm*
[root@localhost etc]# cd /etc/mysql-mmm/
[root@localhost mysql-mmm]# vim mmm_common.conf
active_master_role writer
<host default>
cluster_interface ens33 #修改网卡默认是eth0
pid_path /run/mysql-mmm-agent.pid
bin_path /usr/libexec/mysql-mmm/
replication_user replicant #登陆用户是replicat
replication_password 123456 #复制同步登陆密码
agent_user mmm_agent
agent_password 123456 #登陆代理密码
</host>
<host db1>
ip 192.168.32.222 ——> 主服务器1的IP地址
mode master ——>主服务器
peer db2
</host>
<host db2>
ip 192.168.32.223 ——>主服务器2的IP地址
mode master ——>主服务器
peer db1
</host>
<host db3>
ip 192.168.32.224 ——>从服务器1的IP地址
mode slave ——>从服务器
</host>
<host db4>
ip 192.168.32.225 ——>从服务器2的IP地址
mode slave ——>从服务器
</host>
<role writer> #权限可写
hosts db1, db2
ips 192.168.32.221 ——>主服务器1、2的虚拟IP
mode exclusive
</role>
<role reader> #权限可读
hosts db3, db4 #主机名
ips 192.168.32.220 192.168.32.199 #从服务器1、2的虚拟IP
mode balanced
</role>
scp mmm_common.conf root@192.168.32.223:/etc/mysql-mmm/
scp mmm_common.conf root@192.168.32.224:/etc/mysql-mmm/
scp mmm_common.conf root@192.168.32.225:/etc/mysql-mmm/
#修改IP两主两从的IP地址在ping_ips后面,auto_set_online 自动设置在线时长为10秒
<monitor>
ip 127.0.0.1
pid_path /run/mysql-mmm-monitor.pid
bin_path /usr/libexec/mysql-mmm
status_path /var/lib/mysql-mmm/mmm_mond.status
ping_ips 192.168.32.222,192.168.32.223,192.168.32.224,192.168.32.225
auto_set_online 10
cd /etc/mysql-mmm/ //改密码
vi mmm_mon.conf
<host default>
monitor_user mmm_monitor
monitor_password 123456
</host>
#为mmm_agent授权
MariaDB [(none)]> grant super, replication client, process on *.* to ‘mmm_agent‘@‘192.168.32.%‘ identified by ‘123456‘;
Query OK, 0 rows affected (0.01 sec)
#为mmm_moniter授权
MariaDB [(none)]> grant replication client on *.* to ‘mmm_monitor‘@‘192.168.32.%‘ identified by ‘123456‘;
Query OK, 0 rows affected (0.01 sec)
# 刷新
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)
vi /etc/mysql-mmm/mmm_agent.conf
this db1 //根据规划进行逐一调整
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 db4
#开启服务
systemctl start mysql-mmm-agent.service
#设置开机自启动
systemctl enable mysql-mmm-agent.service
#用 mmm_control show 查看各个节点
[root@localhost mysql-mmm]# mmm_control show
db1(192.168.32.222) master/ONLINE. Roles: writer(192.168.32.221)
db2(192.168.32.223) master/ONLINE. Roles:
db3(192.168.32.224) slave/ONLINE. Roles: reader(192.168.32.199)
db4(192.168.32.225) slave/ONLINE. Roles: reader(192.168.32.220)
[root@localhost mysql-mmm]# systemctl stop mariadb.service
[root@localhost mysql-mmm]# mmm_control show
db1(192.168.32.222) master/HARD_OFFLINE. Roles:
db2(192.168.32.223) master/ONLINE. Roles: writer(192.168.32.221)
db3(192.168.32.224) slave/ONLINE. Roles: reader(192.168.32.199)
db4(192.168.32.225) slave/ONLINE. Roles: reader(192.168.32.220)
MariaDB [(none)]> grant all on *.* to ‘testdba‘@‘192.168.32.222‘ identified by ‘123456‘;
MariaDB [(none)]> flush privileges;
#客户端登陆虚拟IP
[root@localhost ~]# mysql -utestdba -p -h 192.168.32.221
Enter password: #设置代理授权是的登陆密码
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 1358
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
#在客户端创建数据库,测试同步
MariaDB [(none)]> create database info; #在客户端创建的
Query OK, 1 row affected (0.01 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| info |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
#在服务端查询
MariaDB [(none)]> show databases; #db1
+--------------------+
| Database |
+--------------------+
| information_schema |
| info |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]> show databases; #db2
+--------------------+
| Database |
+--------------------+
| information_schema |
| info |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]> show databases; #db3
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| info |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]> show databases; #db4
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| info |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
#在客户端创建就是在主服务器上创建从服务器同步
[root@localhost mysql-mmm]# mmm_control show
db1(192.168.32.222) master/ONLINE. Roles:
db2(192.168.32.223) master/ONLINE. Roles: writer(192.168.32.221)
db3(192.168.32.224) slave/ONLINE. Roles: reader(192.168.32.199), reader(192.168.32.220)
db4(192.168.32.225) slave/HARD_OFFLINE. Roles:
标签:date pid exec 配置 copyright 主主 file acl 0.00
原文地址:http://blog.51cto.com/13645280/2147198