MySQL主从复制与读写分离

Centos01配置安装NTP时间服务器
[root@centos01 ~]# yum -y install ntp
在这里插入图片描述

修改ntp主配置文件
[root@centos01 ~]# vim /etc/ntp.conf
restrict 192.168.100.10 mask 255.255.255.0 nomodify notrap
server 127.127.1.0
fudge 127.127.1.0 stratum 8
在这里插入图片描述

重启服务并设置开机自启
[root@centos01 ~]# systemctl restart ntpd
[root@centos01 ~]# systemctl enable ntpd
在这里插入图片描述

Centos01安装配置主MySQL
[root@centos01 ~]# yum -y install cmake.x86_64 ncurses-devel.x86_64
在这里插入图片描述

[root@centos01 ~]# groupadd mysql
[root@centos01 ~]# useradd -M -s /sbin/nologin -g mysql mysql
[root@centos01 ~]# tar zxvf /mnt/mysql-5.5.22.tar.gz -C /usr/src/
[root@centos01 ~]# cd /usr/src/mysql-5.5.22/
[root@centos01 mysql-5.5.22]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
-DWITH_EXTRA_CHARSETS=all -DSYSCONFIGIR=/etc
[root@centos01 mysql-5.5.22]# make && make install
[root@centos01 mysql-5.5.22]# cp support-files/my-medium.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? yes
[root@centos01 mysql-5.5.22]# cp support-files/mysql.server /etc/init.d/mysqld
[root@centos01 mysql-5.5.22]# chmod +x /etc/init.d/mysqld
[root@centos01 mysql-5.5.22]# chkconfig --add mysqld
[root@centos01 mysql-5.5.22]# chkconfig --level 35 mysqld on
[root@centos01 ~]# vim /etc/profile
在这里插入图片描述

[root@centos01 ~]# source /etc/profile
[root@centos01 ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/
local/mysql --datadir=/usr/local/mysql/data
[root@centos01 ~]# chown -R mysql:mysql /usr/local/mysql/
[root@centos01 ~]# systemctl start mysqld
[root@centos01 ~]# netstat -anptu | grep mysqld
在这里插入图片描述

[root@centos01 ~]# vim /etc/my.cnf
在这里插入图片描述

设置密码
[root@centos01 ~]# mysqladmin -uroot password
[root@centos01 ~]# mysql -uroot -ppwd@123
在这里插入图片描述

主mysql创建主从复制账户
[root@centos01 ~]# mysql -uroot -ppwd@123
mysql> grant replication slave on . to ‘slave’@‘192.168.100.%’ identified by ‘pwd@123’;
在这里插入图片描述

mysql> show master status;

在这里插入图片描述

Centos02安装msql服务后
[root@centos02 ~]# vim /etc/my.cnf
在这里插入图片描述

[root@centos02 ~]# systemctl restart mysqld
mysql> change master to master_host=‘192.168.100.10’,master_user=‘slave’,master_password=‘pwd@123’,
master_log_file=‘mysql-bin.000005’,master_log_pos=263;
在这里插入图片描述

mysql> start slave;
在这里插入图片描述

mysql> show slave status\G;
在这里插入图片描述

Centos03和centos02相同操作
验证主从复制
Centos01编写内容两台从主机也有
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

Centos04安装配置读写分离
[root@centos04 ~]# mv /mnt/jdk-6u14-linux-x64.bin ./
[root@centos04 ~]# ./jdk-6u14-linux-x64.bin //一直回车然后yes
[root@centos04 ~]# mv jdk1.6.0_14/ /usr/local/jdk1.6
指定amoeba位置
[root@centos04 ~]# mkdir /usr/local/amoeba
[root@centos04 ~]# tar zxvf /mnt/amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/amoeba/
配置环境变量
[root@centos04 ~]# vim /etc/profile.d/jdk.sh
在这里插入图片描述

[root@centos04 ~]# source /etc/profile.d/jdk.sh
创建读写分离账号
mysql> grant all on . to ‘test’@‘192.168.100.%’ identified by ‘pwd@123’;
在这里插入图片描述

[root@centos04 ~]# vim /etc/hosts
在这里插入图片描述

[root@centos04 ~]# scp /etc/hosts root@192.168.100.10:/etc/
[root@centos04 ~]# scp /etc/hosts root@192.168.100.20:/etc/
[root@centos04 ~]# scp /etc/hosts root@192.168.100.30:/etc/
[root@centos04 ~]# scp /etc/hosts root@192.168.100.50:/etc/

[root@centos04 ~]# vim /usr/local/amoeba/conf/amoeba.xml
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

[root@centos04 ~]# vim /usr/local/amoeba/conf/dbServers.xml
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

验证读写分离
Centos05安装MySQL客户端
[root@centos05 ~]# yum -y install mariadb
[root@centos05 ~]# mysql -uamoeba -ppwd@123 -h 192.168.100.40 -p8066
创建表格主从都可以查看到
创建aaa
在这里插入图片描述

填写内容
在这里插入图片描述

主从都有记录
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

关闭从只有主可以看到
在这里插入图片描述
在这里插入图片描述

重新启动从服务查看即可

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值