mysql主从配置以及基于amoeba实现读写分离

时间:2022-09-20 14:59:39
 mysql主从配置以及基于amoeba实现读写分离
首先硬件设备 :ubuntu12.04 server 64
三台主机ip地址:master 192.168.1.8   slave 192.168.1.15
         amoeda  192.168.1.16
软件版本: mysql 5.5   java6  amoeba 3.0.5
首先配置mysql主从关系
a,安装配置master节点
root@i-70bl6kfl:~# apt-get install mysql-server
b, 配置master
root@i-zvjoik10:~# vi /etc/mysql/my.cnf 
bind-address            = 0.0.0.0
[mysqld]
server-id=1
log_bin=/var/log/mysql/mysql-bin.log
c,同理安装slave节点并配置
# vi /etc/mysql/my.cnf 
bind-address            = 0.0.0.0
[mysqld]
log_bin           = /var/log/mysql/mysql-bin.log
server_id         = 2
relay_log         =mysql-relay-bin
log_slave_updates = 1
d,在主从节点上都赋予mysql远程访问权限
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; 
Query OK, 0 rows affected (0.00 sec)


mysql>  FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
查看master信息
mysql> show master status; 
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |      342 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
slave中启动 Master - Slave 复制功能。 
分别执行以下命令 
Sql代码  收藏代码
mysql> slave stop
    -> ;
Query OK, 0 rows affected, 1 warning (0.00 sec)


mysql> change master to
    -> master_host='192.168.1.8',
    -> master_user='root',
    -> master_password='123456',
    -> master_log_file='mysql-bin.000001',
    -> master_log_pos=342;
Query OK, 0 rows affected (0.02 sec)
mysql> start slave;  
Query OK, 0 rows affected (0.00 sec) 
e,执行完后,测试下主从是否配置成功 在主节点上创建个数据库
mysql> create database  anchora;
然后安装proxy amoeba;
a,在amoeba上安装java环境
apt-get install openjdk-6-jre-headless
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64
root@i-70bl6kfl:~# source  /etc/profile
b,安装amoeba
把下载的压缩包解压完了之后放到 /usr/local/ 目录下即可。
# mkdir  /usr/local/amoeba
root@i-70bl6kfl:/usr/local/amoeba# unzip amoeba-mysql-3.0.5-RC-distribution.zip 
root@i-70bl6kfl:/usr/local/amoeba# /bin/cp amoeba-mysql-3.0.5-RC/*  /usr/local/amoeba/
bin/cp: omitting directory `amoeba-mysql-3.0.5-RC/benchmark'
/bin/cp: omitting directory `amoeba-mysql-3.0.5-RC/bin'
/bin/cp: omitting directory `amoeba-mysql-3.0.5-RC/conf'
/bin/cp: omitting directory `amoeba-mysql-3.0.5-RC/lib'
root@i-70bl6kfl:/usr/local/amoeba# /bin/cp -rf amoeba-mysql-3.0.5-RC/*  /usr/local/amoeba
我们用到dbServer.xml 和 amoeba.xml
a,修改可以访问的ip(这里所有的ip都可以访问)
root@i-70bl6kfl:/usr/local/amoeba/conf# vi access_list.conf 
#218.85.*.*:no
127.0.0.1:yes
b,配置dbSerers.xml实现其代理 入口数据库为anchora我刚才创建的
root@i-70bl6kfl:/usr/local/amoeba/conf# vi dbServers.xml 
修改20-28行
                        <!-- mysql port -->
                         <property name="port">3306</property>


                        <!-- mysql schema -->
                        <property name="schema">anchora</property>


                        <!-- mysql user -->
                        <property name="user">root</property>


                        <property name="password">123456</property>
46-53行的mysql主从服务器的数据库的ip
        <dbServer name="server1"  parent="abstractServer">
                <factoryConfig>
                        <!-- mysql ip -->
                        <property name="ipAddress">192.168.1.8</property>
                </factoryConfig>
        </dbServer>


        <dbServer name="server2"  parent="abstractServer">
                <factoryConfig>
                        <!-- mysql ip -->
                        <property name="ipAddress">192.168.1.15</property>
                </factoryConfig>
        </dbServer>


c,配置 amoeba.xml 在这里可以修端口代理密码和读写分离。
root@i-70bl6kfl:/usr/local/amoeba/conf# vi amoeba.xml 
30行
               <property name="password">123456</property>

86行   
                <property name="writePool">server1</property>
                <property name="readPool">server2</property>
保存推出,启动amoeba
root@i-70bl6kfl:/usr/local/amoeba/bin# ./launcher
然后远程测试连接
root@i-70bl6kfl:~# mysql -u root -p  -h 192.168.1.16 --port 8066
Enter password: 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 


参考文档
http://www.iteye.com/topic/1113437
http://bbs.linuxtone.org/thread-24935-1-1.html