主库 192.168.2.121 端口 3306
从库 192.168.2.120 端口 33060
Atlas代理 192.168.2.120 端口 3307
安装包+主从配置文件
链接:https://pan.baidu.com/s/1-h_K-7ytmw6GsYmwZVjR3g
提取码:t179
安装数据库
解压tar包
tar -zxf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
cd /usr/local/
mv mysql-5.6.40-linux-glibc2.12-x86_64 mysql-5.6.40
创建用户
groupadd mysql
useradd -g mysql mysql -s /sbin/nologin
创建文件目录
mkdir -p /data/mysql/
chown -R mysql:mysql /data/
ln -s mysql-5.6.40 mysql
cd /usr/local/mysql/scripts/
初始数据库
yum install autoconf libaio* -y
./mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/ --defaults-file=/etc/my.cnf --user=mysql
cd /usr/local/mysql
cp support-files/mysql.server /etc/init.d/mysql
service mysql start
修改初始数据库密码
mysql -p
首次登陆密码直接回车进入
>use mysql;
>update user set authentication_string=password("新密码") where user="root";
>flush privileges;
>\q
读写分离架构必须是主从复制状态
主从复制: https://www.cnblogs.com/merely/p/9714827.html
读写分离
解压安装--自动安装到/usr/local/
rpm -ivh Atlas-2.2.1.el6.x86_64.rpm
cd /usr/local/mysql-proxy/bin
修改配置文件
(此脚本是配置远程访问连接加密密码)
vim /test.conf
启动Atlas
/usr/local/mysql-proxy/bin/mysql-proxyd test start
访问代理端口数据库
[root@ conf]# mysql -uroot -P3307 -p密码 -h192.168.2.120
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4231
Server version: 5.0.81-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> select @@server_id;
+-------------+
| @@server_id |
+-------------+
| 2 |
+-------------+
1 row in set (0.00 sec)
MySQL [(none)]>
访问Atlas管理端数据库
[root@ conf]# mysql -uadmin -P2345 -p密码-h192.168.2.120
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.99-agent-admin
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> select * from backends;
+-------------+---------------------+-------+------+
| backend_ndx | address | state | type |
+-------------+---------------------+-------+------+
| 1 | 192.168.2.121:3306 | up | rw |
| 2 | 192.168.2.120:33060 | up | ro |
+-------------+---------------------+-------+------+
2 rows in set (0.00 sec)
MySQL [(none)]>