实验拓扑图:
MySQL主从同步:
一、安装NTP服务,同步时间
1、在MySQL主服务器上安装NTP服务
[root@master ~]# yum install ntp -y
.........//省略过程
[root@master ~]#
2、修改NTP服务配置文件
[root@master ~]# vim /etc/ntp.conf
server 127.127.52.0 //本地时钟源
fudge 127.127.52.0 stratum 8 //设置时间层级为8
[root@master ~]#
3、开启服务NTP服务,关闭防火墙
[root@master ~]# systemctl start ntpd //开启服务
[root@master ~]# systemctl stop firewalld.service //关闭防火墙
[root@master ~]# setenforce 0 //关闭增强性安全功能
4、在MySQL从服务器1上,安装NTP服务,向主服务器同步时间
[root@slave1 ~]# yum install ntp ntpdate -y
........//省略过程
[root@slave1 ~]# systemctl start ntpd //开启服务
[root@slave1 ~]# systemctl stop firewalld.service //关闭防火墙
[root@slave1 ~]# setenforce 0 //关闭增强性安全功能
[root@slave1 ~]# /usr/sbin/ntpdate 192.168.52.133 //同步时间
22 Nov 14:43:50 ntpdate[46222]: the NTP socket is in use, exiting
[root@slave1 ~]#
5、在MySQL从服务器2上,安装NTP服务,向主服务器同步时间
[root@slave2 ~]# yum install ntp ntpdate -y
........//省略过程
[root@slave2 ~]# systemctl start ntpd //开启服务
[root@slave2 ~]# systemctl stop firewalld.service //关闭防火墙
[root@slave2 ~]# setenforce 0 //关闭增强性安全功能
[root@slave2 ~]# /usr/sbin/ntpdate 192.168.52.133 //同步时间
22 Nov 14:46:12 ntpdate[69300]: the NTP socket is in use, exiting
[root@slave2 ~]#
二、源码编译安装MySQL服务
1、将宿主机上的工具包共享出去
2、将MySQL源码包解压到“/opt/”目录下
[root@master ~]# mkdir /mnt/tools //创建目录
[root@master ~]# mount.cifs //192.168.100.50/tools /mnt/tools/ //挂载共享目录
Password for root@//192.168.100.50/tools:
[root@master ~]# cd /mnt/tools/MySQL/
[root@master MySQL]# ls
amoeba-mysql-binary-2.2.0.tar.gz jdk-6u14-linux-x64.bin mysql-5.7.17.tar.gz
boost_1_59_0.tar.gz mysql-5.5.24.tar.gz
[root@master MySQL]# tar zxvf mysql-5.5.24.tar.gz -C /opt/ //解压
........//省略过程
3、安装编译所需环境包
[root@master MySQL]# cd /opt/mysql-5.5.24/
[root@master mysql-5.5.24]# yum -y install \
> ncurses \
> ncurses-devel \
> bison \
> cmake \
> make \
> gcc \
> gcc-c++
4、创建mysql用户和安装目录
[root@master mysql-5.5.24]# useradd -s /sbin/nologin mysql //创建用户
[root@master mysql-5.5.24]# mkdir /usr/local/mysql //创建目录
[root@master mysql-5.5.24]#
5、配置MySQL服务
[root@master mysql-5.5.24]# cmake \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ //安装路径
> -DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock \ //定义sock文件连接数据库文件
> -DDEFAULT_CHARSET=utf8 \ //指定字符集,utf8支持中文字符
> -DDEFAULT_COLLATION=utf8_general_ci \ //指定字符集默认
> -DWITH_EXTRA_CHARSETS=all \ //指定额外支持的其它字符集
> -DWITH_MYISAM_STORAGE_ENGINE=1 \ //存储引擎
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_MEMORY_STORAGE_ENGINE=1 \
> -DWITH_READLINE=1 \
> -DENABLED_LOCAL_INFILE=1 \
> -DMYSQL_DATADIR=/home/mysql \ //指定数据文件目录
> -DMYSQL_USER=mysql \ //用户
> -DMSQL_TCP_PROT=3306 //端口
6、编译安装MySQL
[root@master mysql-5.5.24]# make && make install
.........//省略过程
[root@master mysql-5.5.24]#
7、对MySQL服务进行相关优化
[root@master mysql-5.5.24]# chown -R mysql.mysql /usr/local/mysql/ //修改属主属组
[root@master mysql-5.5.24]#
[root@master mysql-5.5.24]# vim /etc/profile //进入环境变量配置文件
export PATH=$PATH:/usr/local/mysql/bin/ //添加mysql环境变量
[root@master mysql-5.5.24]# source /etc/profile //重新加载文件
[root@master mysql-5.5.24]#
[root@master mysql-5.5.24]# cp support-files/my-medium.cnf /etc/my.cnf //复制配置文件
cp: overwrite ‘/etc/my.cnf’? yes
[root@master mysql-5.5.24]# cp support-files/mysql.server /etc/init.d/mysqld //复制管理文件
[root@master mysql-5.5.24]#
[root@master mysql-5.5.24]# chmod 755 /etc/init.d/mysqld //添加执行权限
[root@master mysql-5.5.24]# chkconfig --add /etc/init.d/mysqld //让service服务能识别mysqld
[root@master mysql-5.5.24]# chkconfig mysqld --level 35 on //在级别3、5中启动
[root@master mysql-5.5.24]#
8、初始化数据库
[root@master mysql-5.5.24]# /usr/local/mysql/scripts/mysql_install_db \
> --user=mysql \ //用户
> --ldata=/var/lib/mysql \
> --basedir=/usr/local/mysql \ //工作目录
> --datadir=/home/mysql //数据目录
9、修改管理文件
[root@master mysql-5.5.24]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql //指定工作目录
datadir=/home/mysql //指定数据目录
10、开启MySQL服务
[root@master mysql-5.5.24]# service mysqld start
Starting MySQL.. SUCCESS!
[root@master mysql-5.5.24]#
11、测试登录数据库
[root@master mysql-5.5.24]# mysqladmin -u root password 'abc123' //设置登录用户密码
[root@master mysql-5.5.24]# mysql -u root -pabc123 //登录数据库
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.24-log Source distribution
Copyright (c) 2000, 2011, 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> \q //退出
Bye
[root@master mysql-5.5.24]#
12、在从服务器slave1上安装MySQL数据库(过程同上,不多解释)
[root@slave1 ~]# mkdir /mnt/tools
[root@slave1 ~]# mount.cifs //192.168.100.50/tools /mnt/tools/
Password for root@//192.168.100.50/tools:
[root@slave1 ~]# cd /mnt/tools/MySQL/
[root@slave1 MySQL]# ls
amoeba-mysql-binary-2.2.0.tar.gz jdk-6u14-linux-x64.bin mysql-5.7.17.tar.gz
boost_1_59_0.tar.gz mysql-5.5.24.tar.gz
[root@slave1 MySQL]# tar zxvf mysql-5.5.24.tar.gz -C /opt/
.......//省略过程
[root@slave1 MySQL]# cd /opt/mysql-5.5.24/
[root@slave1 mysql-5.5.24]# useradd -s /sbin/nologin mysql
[root@slave1 mysql-5.5.24]# yum -y install \
> ncurses \
> ncurses-devel \
> bison \
> cmake \
> make \
> gcc \
> gcc-c++
..........//省略过程
[root@slave1 mysql-5.5.24]# cmake \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
> -DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DWITH_EXTRA_CHARSETS=all \
> -DWITH_MYISAM_STORAGE_ENGINE=1 \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_MEMORY_STORAGE_ENGINE=1 \
> -DWITH_READLINE=1 \
> -DENABLED_LOCAL_INFILE=1 \
> -DMYSQL_DATADIR=/home/mysql \
> -DMYSQL_USER=mysql \
> -DMSQL_TCP_PROT=3306
...........//省略过程
[root@slave1 mysql-5.5.24]# make && make install
...........//省略过程
[root@slave1 mysql-5.5.24]# chown -R mysql.mysql /usr/local/mysql/
[root@slave1 mysql-5.5.24]#
[root@slave1 mysql-5.5.24]# vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin/
[root@slave1 mysql-5.5.24]# source /etc/profile
[root@slave1 mysql-5.5.24]#
[root@slave1 mysql-5.5.24]# cp support-files/my-medium.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? yes
[root@slave1 mysql-5.5.24]# cp support-files/mysql.server /etc/init.d/mysqld
[root@slave1 mysql-5.5.24]#
[root@slave1 mysql-5.5.24]# chmod 755 /etc/init.d/mysqld
[root@slave1 mysql-5.5.24]# chkconfig --add /etc/init.d/mysqld
[root@slave1 mysql-5.5.24]# chkconfig mysqld --level 35 on
[root@slave1 mysql-5.5.24]#
[root@slave1 mysql-5.5.24]# /usr/local/mysql/scripts/mysql_install_db \
> --user=mysql \
> --ldata=/var/lib/mysql \
> --basedir=/usr/local/mysql \
> --datadir=/home/mysql
.............//省略过程
[root@slave1 mysql-5.5.24]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/home/mysql
[root@slave1 mysql-5.5.24]# service mysqld start
Starting MySQL.. SUCCESS!
[root@slave1 mysql-5.5.24]#
[root@slave1 mysql-5.5.24]# mysqladmin -u root password 'abc123'
[root@slave1 mysql-5.5.24]# mysql -uroot -pabc123
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.24-log Source distribution
Copyright (c) 2000, 2011, 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> quit
Bye
[root@slave1 mysql-5.5.24]#
13、在从服务器slave2上安装MySQL数据库(过程同上,不多解释)
[root@slave2 ~]# mkdir /mnt/tools
[root@slave2 ~]# mount.cifs //192.168.100.50/tools /mnt/tools/
Password for root@//192.168.100.50/tools:
[root@slave2 ~]# cd /mnt/tools/MySQL/
[root@slave2 MySQL]# ls
amoeba-mysql-binary-2.2.0.tar.gz jdk-6u14-linux-x64.bin mysql-5.7.17.tar.gz
boost_1_59_0.tar.gz mysql-5.5.24.tar.gz
[root@slave2 MySQL]# tar zxvf mysql-5.5.24.tar.gz -C /opt/
...........//省略过程
[root@slave2 MySQL]# cd /opt/mysql-5.5.24/
[root@slave2 mysql-5.5.24]# useradd -s /sbin/nologin mysql
[root@slave2 mysql-5.5.24]# yum -y install \
> ncurses \
> ncurses-devel \
> bison \
> cmake \
> make \
> gcc \
> gcc-c++
...........//省略过程
[root@slave2 mysql-5.5.24]# cmake \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
> -DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DWITH_EXTRA_CHARSETS=all \
> -DWITH_MYISAM_STORAGE_ENGINE=1 \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_MEMORY_STORAGE_ENGINE=1 \
> -DWITH_READLINE=1 \
> -DENABLED_LOCAL_INFILE=1 \
> -DMYSQL_DATADIR=/home/mysql \
> -DMYSQL_USER=mysql \
> -DMSQL_TCP_PROT=3306
...........//省略过程
[root@slave2 mysql-5.5.24]# make && make install
...........//省略过程
[root@slave2 mysql-5.5.24]# chown -R mysql.mysql /usr/local/mysql/
[root@slave2 mysql-5.5.24]#
[root@slave2 mysql-5.5.24]# vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin/
[root@slave2 mysql-5.5.24]# source /etc/profile
[root@slave2 mysql-5.5.24]#
[root@slave2 mysql-5.5.24]# cp support-files/my-medium.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? yes
[root@slave2 mysql-5.5.24]# cp support-files/mysql.server /etc/init.d/mysqld
[root@slave2 mysql-5.5.24]#
[root@slave2 mysql-5.5.24]# chmod 755 /etc/init.d/mysqld
[root@slave2 mysql-5.5.24]# chkconfig --add /etc/init.d/mysqld
[root@slave2 mysql-5.5.24]# chkconfig mysqld --level 35 on
[root@slave2 mysql-5.5.24]#
[root@slave2 mysql-5.5.24]# /usr/local/mysql/scripts/mysql_install_db \
> --user=mysql \
> --ldata=/var/lib/mysql \
> --basedir=/usr/local/mysql \
> --datadir=/home/mysql
...........//省略过程
[root@slave2 mysql-5.5.24]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/home/mysql
[root@slave2 mysql-5.5.24]# service mysqld start
Starting MySQL.. SUCCESS!
[root@slave2 mysql-5.5.24]#
[root@slave2 mysql-5.5.24]# mysqladmin -u root password 'abc123'
[root@slave2 mysql-5.5.24]# mysql -uroot -pabc123
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.24-log Source distribution
Copyright (c) 2000, 2011, 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> \q
Bye
[root@slave2 mysql-5.5.24]#
三、配置MySQL主服务器主从同步
1、修改MySQL主服务器配置文件
[root@master mysql-5.5.24]# vim /etc/my.cnf
log-bin=master-bin //日志文件
log-slave-updates=true //允许从服务器同步
server-id = 11 //服务器id
[root@master mysql-5.5.24]# service mysqld restart //重启服务
Shutting down MySQL. SUCCESS!
Starting MySQL.. SUCCESS!
[root@master mysql-5.5.24]#
2、创建一个myslave用户来让从服务器同步时使用
[root@master mysql-5.5.24]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.24-log Source distribution
Copyright (c) 2000, 2011, 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> grant replication slave on *.* to 'myslave'@'192.168.52.%' identified by '123456';
//创建同步用户
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show master status; //查看主服务器状态
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-bin.000008 | 338 | | |
+-------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
mysql> quit //退出
Bye
[root@master mysql-5.5.24]#
四、配置MySQL从服务器1主从同步
1、修改MySQL主服务器配置文件
[root@slave1 mysql-5.5.24]# vim /etc/my.cnf
server-id = 22 //服务器id
relay-log=relay-log-bin //中继日志
relay-log-index=slave-relay-bin.index //中继日志索引
[root@slave1 mysql-5.5.24]# service mysqld restart //重启服务
Shutting down MySQL. SUCCESS!
Starting MySQL.. SUCCESS!
[root@slave1 mysql-5.5.24]#
2、进入数据库,开启从服务器功能
[root@slave1 mysql-5.5.24]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.24-log Source distribution
Copyright (c) 2000, 2011, 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> change master to master_host='192.168.52.133',master_user='myslave',master_password='123456',master_log_file='master-bin.000008',master_log_pos=338;
//配置需要进行同步的MySQL主服务器的IP地址、同步用户、用户密码、日志文件、位置节点
Query OK, 0 rows affected (0.01 sec)
mysql> start slave; //开启从服务器的同步服务
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status\G; //查看状态
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.52.133
Master_User: myslave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000008
Read_Master_Log_Pos: 338
Relay_Log_File: relay-log-bin.000002
Relay_Log_Pos: 254
Relay_Master_Log_File: master-bin.000008
Slave_IO_Running: Yes //确认开启
Slave_SQL_Running: Yes //确认开启
..............//省略部分内容
Master_Server_Id: 11
1 row in set (0.00 sec)
ERROR:
No query specified
mysql>
五、配置MySQL从服务器2主从同步
1、修改MySQL主服务器配置文件
[root@slave2 mysql-5.5.24]# vim /etc/my.cnf
server-id = 23 //服务id
relay-log=relay-log-bin //中继日志
relay-log-index=slave-relay-bin.index //中继日志索引
[root@slave2 mysql-5.5.24]# service mysqld restart //重启服务
Shutting down MySQL. SUCCESS!
Starting MySQL.. SUCCESS!
[root@slave2 mysql-5.5.24]#
2、进入数据库,开启从服务器功能
[root@slave2 mysql-5.5.24]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.24-log Source distribution
Copyright (c) 2000, 2011, 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> change master to master_host='192.168.52.133',master_user='myslave',master_password='123456',master_log_file='master-bin.000008',master_log_pos=338;
//配置需要进行同步的MySQL主服务器的IP地址、同步用户、用户密码、日志文件、位置节点
Query OK, 0 rows affected (0.03 sec)
mysql> start slave; //开启从服务器的同步服务
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G; //查看状态
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.52.133
Master_User: myslave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000008
Read_Master_Log_Pos: 338
Relay_Log_File: relay-log-bin.000002
Relay_Log_Pos: 254
Relay_Master_Log_File: master-bin.000008
Slave_IO_Running: Yes //确认开启
Slave_SQL_Running: Yes //确认开启
...........//省略部分内容
Master_Server_Id: 11
1 row in set (0.00 sec)
ERROR:
No query specified
mysql>
六、验证主从同步
1、查看master服务器的数据库
mysql> show databases; //查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| #mysql50#.mozilla |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
mysql>
2、查看slave1服务器的数据库
mysql> show databases; //查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| #mysql50#.mozilla |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.01 sec)
mysql>
3、查看slave2服务器的数据库
mysql> show databases; //查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| #mysql50#.mozilla |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.01 sec)
mysql>
4、在master服务器创建一个master数据库
mysql> create database master; //创建数据库master
Query OK, 1 row affected (0.00 sec)
mysql> show databases; //查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| #mysql50#.mozilla |
| master | //创建成功
| mysql |
| performance_schema |
| test |
+--------------------+
6 rows in set (0.00 sec)
mysql>
5、再次查看slave1服务器的数据库
mysql> show databases; //查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| #mysql50#.mozilla |
| master | //同步成功
| mysql |
| performance_schema |
| test |
+--------------------+
6 rows in set (0.00 sec)
mysql>
6、再次查看slave2服务器的数据库
mysql> show databases; //查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| #mysql50#.mozilla |
| master | //同步成功
| mysql |
| performance_schema |
| test |
+--------------------+
6 rows in set (0.00 sec)
mysql>
MySQL动静分离
一、安装jdk
1、关闭amoeba服务器防火墙
[root@amoeba ~]# systemctl stop firewalld.service //关闭防火墙
[root@amoeba ~]# setenforce 0 //关闭增强性安全功能
[root@amoeba ~]#
2、安装jdk1.6
[root@amoeba ~]# mkdir /mnt/tools //创建挂载目录
[root@amoeba ~]# mount.cifs //192.168.100.50/tools /mnt/tools/ //挂载共享目录
Password for root@//192.168.100.50/tools:
[root@amoeba ~]# cd /mnt/tools/MySQL/
[root@amoeba MySQL]# ls
amoeba-mysql-binary-2.2.0.tar.gz jdk-6u14-linux-x64.bin mysql-5.7.17.tar.gz
boost_1_59_0.tar.gz mysql-5.5.24.tar.gz
[root@amoeba MySQL]# cp jdk-6u14-linux-x64.bin /usr/local/ //复制
[root@amoeba MySQL]# cd /usr/local/
[root@amoeba local]# ls
bin games jdk-6u14-linux-x64.bin lib64 sbin src
etc include lib libexec share
[root@amoeba local]# ./jdk-6u14-linux-x64.bin //直接执行
..............//省略介绍信息,回车即可
Do you agree to the above license terms? [yes or no]
yes //同意条款
Press Enter to continue.....
Done.
[root@amoeba local]#
3、重新命名jdk目录
[root@amoeba local]# ls
bin games jdk1.6.0_14 lib libexec share
etc include jdk-6u14-linux-x64.bin lib64 sbin src
[root@amoeba local]# mv jdk1.6.0_14/ /usr/local/jdk1.6
[root@amoeba local]# ls
bin games jdk1.6 lib libexec share
etc include jdk-6u14-linux-x64.bin lib64 sbin src
[root@amoeba local]#
4、配置环境变量
[root@amoeba local]# vim /etc/profile
export JAVA_HOME=/usr/local/jdk1.6
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/bin/:$PATH:$HOME/bin
export AMOEBA_HOME=/usr/local/amoeba
export PATH=$PATH:$AMOEBA_HOME/bin
[root@amoeba local]# source /etc/profile //重新加载文件,让配置生效
[root@amoeba local]#
二、安装amoeba
1、解压amoeba压缩包
[root@amoeba local]# mkdir /usr/local/amoeba //创建工作目录
[root@amoeba local]# cd - //回到到上次切换过来目录
/mnt/tools/MySQL
[root@amoeba MySQL]# tar zxvf amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/amoeba/ //解压
2、修改目录权限
[root@amoeba MySQL]# cd - //回到切换前目录
/usr/local
[root@amoeba local]# chmod -R 755 /usr/local/amoeba/ //修改目录权限,-R表示递归
[root@amoeba local]# /usr/local/amoeba/bin/amoeba
amoeba start|stop //表示安装成功
[root@amoeba local]#
3、分别给三台MySQL服务器添加amoeba服务器的访问权限
MySQL主服务器:master
mysql> grant all on *.* to test@'192.168.52.%' identified by '123abc';
//添加一个test用户
Query OK, 0 rows affected (0.01 sec)
mysql>
MySQL从服务器:slave1
mysql> grant all on *.* to test@'192.168.52.%' identified by '123abc';
//添加一个test用户
Query OK, 0 rows affected (0.00 sec)
mysql>
MySQL从服务器:slave2
mysql> grant all on *.* to test@'192.168.52.%' identified by '123abc';
//添加一个test用户
Query OK, 0 rows affected (0.00 sec)
mysql>
4、修改配置文件“amoeba.xml”
[root@amoeba local]# cd /usr/local/amoeba/
[root@amoeba amoeba]# vim conf/amoeba.xml
30 amoeba //客户端用来访问amoeba的用户
31
32 123456 //用户密码
115 master //默认MySQL池
116
117
118 master //写入数据池
119 slaves //读取数据池
[root@amoeba amoeba]#
5、修改配置文件“dbServers.xml”
[root@amoeba amoeba]# vim conf/dbServers.xml
26 test //用来访问数据库的用户
27
28
29 123abc //用户密码
42
43
44
45 //配置MySQL主服务器名
46
47
48 192.168.52.133 //配置主服务器IP地址
49
50
51
52 //配置MySQL从服务器名
53
54
55 192.168.52.134 //配置从服务器IP地址
56
57
58
59 //配置MySQL从服务器名
60
61
62 192.168.52.148 //配置从服务器IP地址
63
64
65
66 //数据池名
67
68
69 1
70
71