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
填写内容
主从都有记录
关闭从只有主可以看到
重新启动从服务查看即可