Home Database Mysql Tutorial 基于amoeba实现mysql数据库的读写分离/负载均衡

基于amoeba实现mysql数据库的读写分离/负载均衡

Jun 07, 2016 pm 05:37 PM
mysql Read and write separation

更多博文请关注:没有伞的孩子必须努力奔跑(www.xuchanggang.cn)一、Amoeba的简述:[来自百度百科]Amoeba是一个以MySQL为底层数据存储,并对应用提供MySQL协议接

      当前测试环境使用的amoeba软件下载地址:

      amoeba参考手册:

      amoeba项目代码:

  (4).简要原理图:

spacer.gif

222358593.jpg

2.我们这里将amoeba相关软件放在/tmp目录下,这里我们先配置JDK

# 解压JDK软件到/usr/local目录下 [root@centos tmp]# tar -xf jdk-7u15-linux-x64.tar.gz -C /usr/local/ # 进入相应目录,并建立java目录 [root@centos tmp]# cd /usr/local/ [root@centos local]# mkdir java # 将解压出来的内容移到java目录 [root@centos local]# mv jdk1.7.0_15/* java # 设置java环境变量 [root@centos local]# echo 'export JAVA_HOME=/usr/local/java' >> ~/.bashrc [root@centos local]# . ~/.bashrc # 测试jdk是否正确安装 [root@centos local]# java -version # ******************************* # 以下这个方法设置JDK[在下面设置amoeba时,会覆盖,所以这里的配置文件,以最下面amoeba的配置为准] [root@centos java]# echo $JAVA_HOME [root@centos java]# vim /etc/profile # 在末尾添加 export JAVA_HOME=/usr/locla/java export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH [root@centos java]# source /etc/profile # *******************************

3.配置amoeba中的dbServer.xml(后端mysql 服务器连接配置)

[root@centos java]# cd /tmp/ # 建立相应amoeba目录 [root@centos tmp]# mkdir /usr/local/amoeba # 将压缩包解压到指定目录 [root@centos tmp]# tar -xf amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/amoeba [root@centos tmp]# cd /usr/local/amoeba/ [root@centos amoeba]# cd conf/ # 准备修改配置文件 #/* 以下部分为注解 #/* Amoeba总共有7个配置文件,分别如下: #/* Amoeba主配置文件($AMOEBA_HOME/conf/amoeba.xml),用来配置Amoeba服务的基本参数,如Amoeba主机地址、端口、认证方式、用于连接的用户名、密码、线程数、超时时间、其他配置文件的位置等。 #/* 数据库服务器配置文件($AMOEBA_HOME/conf/dbServers.xml),用来存储和配置Amoeba所代理的数据库服务器的信息,如:主机IP、端口、用户名、密码等。 #/* 切分规则配置文件($AMOEBA_HOME/conf/rule.xml),用来配置切分规则。 #/* 数据库函数配置文件($AMOEBA_HOME/conf/functionMap.xml),用来配置数据库函数的处理方法,Amoeba将使用该配置文件中的方法解析数据库函数。 #/* 切分规则函数配置文件($AMOEBA_HOME/conf/ruleFunctionMap.xml),用来配置切分规则中使用的用户自定义函数的处理方法。 #/* 访问规则配置文件($AMOEBA_HOME/conf/access_list.conf),用来授权或禁止某些服务器IP访问Amoeba。 #/* 日志规格配置文件($AMOEBA_HOME/conf/log4j.xml),用来配置Amoeba输出日志的级别和方式。 # 配置后端mysql 服务器连接[dbServer.xml] [root@centos conf]# vim dbServers.xml .........................(省略) ${defaultManager} 64 128 # 设置 mysql 数据库的端口 3306 # 设置缺省的数据库,当连接amoeba时,操作表必须显式的指定数据库名,即采用dbname.tablename的方式, # 不支持 use dbname指定缺省库,因为操作会调度到各个后端dbserver kongzhong # 设置amoeba连接后端数据库服务器的账号和密码,需在后端数据库器上创建该用户,并授权amoeba连接 kongzhong123 kongzhong123 # 最大连接数[默认] 500 # 最大空闲连接数[默认] 500 10 600000 600000 true true true # 设置一个后端的dbServer,名为master ,,这个可以随便取,但是为了明确其含义,最好给予特殊含义的单词,这里是主DB SERVER # 设置这台DB server 的ip地址 192.168.1.102 # 再设置一台后端mysql数据库,这里叫slave,名字需要唯一[这里可以创建N个后端数据库,只要复制下面...] # 设置这台DB server 的ip地址 192.168.1.100 # 指定一个虚拟的dbServer,将上面定义的dbserver加入这个虚拟的dbserver,相当于组成一个组[这里我们将读的数据库组成一个组] # 这里 需要将 改成自己想要取的名字,这个名字也需要有含义,后面会用到 # 选择调度算法 1 是轮询 2 是权重 3 是HA 这里选择1 轮询 1 # 负载均衡,slave1,slave2当成2个服务器进行调度,这模拟量加权的调度算法。 # 注意这里使用的dbserver必须是已经定义了的,可以写多个,如slave1,slave2 slave
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL: The Ease of Data Management for Beginners MySQL: The Ease of Data Management for Beginners Apr 09, 2025 am 12:07 AM

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

How to open phpmyadmin How to open phpmyadmin Apr 10, 2025 pm 10:51 PM

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

How to create navicat premium How to create navicat premium Apr 09, 2025 am 07:09 AM

Create a database using Navicat Premium: Connect to the database server and enter the connection parameters. Right-click on the server and select Create Database. Enter the name of the new database and the specified character set and collation. Connect to the new database and create the table in the Object Browser. Right-click on the table and select Insert Data to insert the data.

MySQL and SQL: Essential Skills for Developers MySQL and SQL: Essential Skills for Developers Apr 10, 2025 am 09:30 AM

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

How to create a new connection to mysql in navicat How to create a new connection to mysql in navicat Apr 09, 2025 am 07:21 AM

You can create a new MySQL connection in Navicat by following the steps: Open the application and select New Connection (Ctrl N). Select "MySQL" as the connection type. Enter the hostname/IP address, port, username, and password. (Optional) Configure advanced options. Save the connection and enter the connection name.

How to recover data after SQL deletes rows How to recover data after SQL deletes rows Apr 09, 2025 pm 12:21 PM

Recovering deleted rows directly from the database is usually impossible unless there is a backup or transaction rollback mechanism. Key point: Transaction rollback: Execute ROLLBACK before the transaction is committed to recover data. Backup: Regular backup of the database can be used to quickly restore data. Database snapshot: You can create a read-only copy of the database and restore the data after the data is deleted accidentally. Use DELETE statement with caution: Check the conditions carefully to avoid accidentally deleting data. Use the WHERE clause: explicitly specify the data to be deleted. Use the test environment: Test before performing a DELETE operation.

How to use single threaded redis How to use single threaded redis Apr 10, 2025 pm 07:12 PM

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

See all articles