#写入大于读取,主多;读取大于写入,从多
#配置master
vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
symbolic-links=0
log-bin=mysql-bin #仅master上开启
server-id=20
/etc/init.d/mysqld restart
mysql -uroot -e "select @@server_id"-p #查看mysql的编号
cd /data/mysql/
mysqlbinlog mysql-bin.000001 -vv ##查看二进制日志
#配置slave1
vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
symbolic-links=0
server-id=10
/etc/init.d/mysqld restart
#配置slave2
vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
symbolic-links=0
server-id=30
/etc/init.d/mysqld restart
sql复制代码
CREATE USER 'wyh'@'%' IDENTIFIED BY '123'; ##生成专门用来做复制的用户,此用户是用于slave端做认证用
GRANT REPLICATION SLAVE ON *.* TO repl@'%'; ##对这个用户进行授权
SHOW MASTER STATUS; ##查看master的状态
#slave上的配置
CHANGE MASTER TO MASTER_HOST='172.25.254.10',MASTER_USER='wyh',MASTER_PASSWORD='123',MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=350;
start slave;
SHOW SLAVE STATUS\G;
#将数据库为一主两从模式,清除之前的实验痕迹
[root@mysql1 ~]# /etc/init.d/mysqld stop
[root@mysql1 ~]# rm -fr /data/mysql/*
[root@mysql1 ~]# ps aux | grep mysql
mysqlro+ 28247 0.0 0.3 520980 12496 ? Ssl 19:48 0:00 /usr/bin/mysqlrouter
root 28570 0.0 0.0 113416 1600 pts/0 S 20:20 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql1.timinglee.org.pid
mysql 28963 0.5 5.5 1658680 213840 pts/0 Sl 20:20 0:02 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mysql1.timinglee.org.err --pid-file=/data/mysql/mysql1.timinglee.org.pid --socket=/data/mysql/mysql.sock
root 29084 0.0 0.0 112824 980 pts/0 S+ 20:29 0:00 grep --color=auto mysql
[root@mysql1 ~]# kill -9 28247
[root@mysql1 ~]# kill -9 28570
[root@mysql1 ~]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
server-id=10
log-bin=mysql-bin
gtid_mode=ON
log_slave_updates=ON
enforce-gtid-consistency=ON
symbolic-links=0
[root@mysql1 ~]# mysqld --user mysql --initialize
[root@mysql1 ~]# /etc/init.d/mysqld start
[root@mysql1 ~]# mysql_secure_installation
#master中配置
[root@mysql1 ~]# mysql -uroot -p
mysql> CREATE USER 'repl'@'%' IDENTIFIED BY '123';
mysql> GRANT REPLICATION SLAVE ON *.* TO repl@'%';
mysql> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
mysql> SET GLOBAL rpl_semi_sync_master_enabled = 1;
mysql> create user root@'%' identified by '123';
mysql> grant all on *.* to root@'%';
#slave中配置
mysql> CHANGE MASTER TO MASTER_HOST='172.25.254.10',MASTER_USER='repl',MASTER_PASSWORD='123', MASTER_AUTO_POSITION=1;
mysql> start slave;
mysql> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
mysql> SET GLOBAL rpl_semi_sync_slave_enabled =1;
mysql> STOP SLAVE IO_THREAD;
mysql> START SLAVE IO_THREAD;
mysql> SHOW STATUS LIKE 'Rpl_semi_sync%';
bash复制代码
unzip MHA-7.zip
cd MHA-7/
yum install *.rpm -y #安装需要软件
#将节点所需软件传输
scp mha4mysql-node-0.58-0.el7.centos.noarch.rpm root@172 .25.254.10:/root
mha4mysql-node-0.58-0.el7.centos.noarch.rpm 100% 35KB 4.0MB/s 00:00
scp mha4mysql-node-0.58-0.el7.centos.noarch.rpm root@172 .25.254.20:/root
mha4mysql-node-0.58-0.el7.centos.noarch.rpm 100% 35KB 14.0MB/s 00:00
scp mha4mysql-node-0.58-0.el7.centos.noarch.rpm root@172 .25.254.30:/root
mha4mysql-node-0.58-0.el7.centos.noarch.rpm 100% 35KB 4.9MB/s 00:00
#vim /etc/ssh/sshd_config
#systemctl restart sshd #传输速度慢时可以修改其中的DNS
#在节点处安装软件
yum install mha4mysql-node-0.58-0.el7.centos.noarch.rpm
tar zxf mha4mysql-manager-0.58.tar.gz -C /etc/masterha
cd mha4mysql-manager-0.58/samples/conf/
[root@mysql-mha conf]# ls
app1.cnf masterha_default.cnf
[root@mysql-mha conf]# cat masterha_default.cnf app1.cnf > /etc/masterha/app1.cnf
[root@mysql-mha conf]# cd /etc/masterha/
[root@mysql-mha masterha]# vim app1.cnf
#免密认证
[root@mysql-mha ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): #直接回车
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): #直接回车
Enter same passphrase again: #直接回车
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:0oVq2T4RO7u8XCfvsIeyQ3rtSDwqQ3BjuUpWcO00aZQ root@mysql-mha.timinglee.org
The key's randomart image is:
+---[RSA 2048]----+
| o.o |
| . . E . |
| o = .o . |
| . * .= + |
| = o= S |
| o o. +.+ |
| o o oB.+.. |
| . o .=+*o*. |
| o..B*ooo |
+----[SHA256]-----+
[root@mysql-mha ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.10
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '172.25.254.10 (172.25.254.10)' can't be established.
ECDSA key fingerprint is SHA256:I/mAOn2BwkS3J9C80hAyJ8Bc9RBFMgCnaIq7JNJr2Cs.
ECDSA key fingerprint is MD5:ce:93:6e:55:45:d5:1e:62:a3:a5:eb:4b:bd:f5:67:12.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.25.254.10's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@172.25.254.10'"
and check to make sure that only the key(s) you wanted were added.
[root@mysql-mha ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.20
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '172.25.254.20 (172.25.254.20)' can't be established.
ECDSA key fingerprint is SHA256:I/mAOn2BwkS3J9C80hAyJ8Bc9RBFMgCnaIq7JNJr2Cs.
ECDSA key fingerprint is MD5:ce:93:6e:55:45:d5:1e:62:a3:a5:eb:4b:bd:f5:67:12.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.25.254.20's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@172.25.254.20'"
and check to make sure that only the key(s) you wanted were added.
[root@mysql-mha ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.30
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '172.25.254.30 (172.25.254.30)' can't be established.
ECDSA key fingerprint is SHA256:I/mAOn2BwkS3J9C80hAyJ8Bc9RBFMgCnaIq7JNJr2Cs.
ECDSA key fingerprint is MD5:ce:93:6e:55:45:d5:1e:62:a3:a5:eb:4b:bd:f5:67:12.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.25.254.30's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@172.25.254.30'"
and check to make sure that only the key(s) you wanted were added.
#地址解析
[root@mysql-mha ~]# vim /etc/hosts
tar zxf redis-7.4.0.tar.gz #解压安装包
dnf install gcc make initscripts -y #安装依赖
cd redis-7.4.0/
make && make install #安装
cd utils/
vim install_server.sh #编辑启动模式
./install_server.sh
vim /etc/redis/6379.conf 编辑配置文件
/etc/init.d/redis_6379 start #启动服务
/etc/init.d/redis_6379 restart
redis-cli #进入数据库