In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
What is Amoeba for you below? Hope to give you some help in practical application, load balancing involves more things, there are not many theories, there are many books online, today we will use the accumulated experience in the industry to do an answer.
What is Amoeba?
Amoeba (amoeba) project, the open source framework began to release an Amoeba for Mysql software in 2008. This software is dedicated to the distributed database front-end proxy layer of MySQL. It mainly acts as the SQL routing function when the application layer accesses MySQL, and focuses on the development of distributed database proxy layer (Database Proxy). It is located between Client and DBServer (s) and is transparent to the client. With load balancing, high availability, SQL filtering, read and write separation, routing to the target database, concurrent requests for multiple database merge results.
Through Amoeba, you can achieve the functions of high availability, load balancing and data slicing of multiple data sources. at present, Amoeba has been used in the production line of many enterprises.
Demand case:
There are three database nodes named Master, Slave1, and Slave2 as follows:
Master: Master (write only)
Slaves:Slave1, Slave2 (2 equal databases. Read-only / load balancing)
The case realizes the high-availability Mysql architecture of database master-slave replication, read-write separation and load balancing between Master and Slaves.
Lab architecture diagram:
System environment:
Deployment of database master-slave replication environment
1. Mster: (10.100.246.241)
Yum install-y mariadb
Systemctl enable mariadb
Systemctl start mariadb
1. Modify mysql configuration
Find the configuration file my.cnf (or my.ini) for the main database, mine is in / etc/mysql/my.cnf, and insert the following two lines in the [mysqld] section:
[mysqld]
Log-bin=mysql-bin / / Open binary log
Server-id=241 / / set server-id
2. Restart the database and reset
Systemctl restart mariadb
Mysql_secure_installation
3. Start mysql, create a user account for synchronization, and grant the corresponding permissions
Open mysql session shell > mysql-uname-ppassword
Create two users, one user is authorized to slave01 and slave02, and the other user is authorized to amoeba CVM
Slave username:slave; password:123456
Amoeba username:amoeba; password:123456
Mysql > CREATE USER slave@'10.100.246.%' IDENTIFIED BY '123456'
Mysql > GRANT REPLICATION SLAVE ON. TO slave@'10.100.246.%' WITH GRANT OPTION
Mysql > GRANT ALL PRIVILEGES ON. TO amoeba@10.100.246.240 IDENTIFIED BY '123456' WITH GRANT OPTION
Mysql > FLUSH PRIVILEGES
4. Check the master status and record the binary file name (mysql-bin.000002) and location (245)
SHOW MASTER STATUS
5. Firewall release service and port
2. Slave01 and slave02: (10.100.246.242)
Note: the slave02 operation steps are the same as slave01 except that the server-id number in the my.cnf configuration is different.
Yum install-y mariadb
Systemctl enable mariadb
Systemctl start mariadb
1. Change the mysql configuration
Locate the my.cnf configuration file and add server-id
[mysqld]
Server-id=242 / / set server-id, which must be unique; slave02 server-id=243
2. Restart the database and reset
Systemctl restart mariadb
Mysql_secure_installation
3. Open a mysql session and execute the synchronous SQL statement (requires hostname of host server, login credentials, name and location of binaries):
CHANGE MASTER TO MASTER_HOST='10.100.246.241', MASTER_USER='slave', MASTER_PASSWORD='123456', MASTER_LOG_FILE='mysql-bin.000002', MASTER_LOG_POS=245
4. Start the slave synchronization process and check the slave status
Mysql > start slave
Mysql > SHOW SLAVE STATUS
5. Establish amoeba users and grant relevant permissions to prepare for the deployment of amoeba (both from the database will be added)
GRANT ALL PRIVILEGES ON. TO amoeba@10.100.246.240 IDENTIFIED BY '123456' WITH GRANT OPTION
Mysql > FLUSH PRIVILEGES
6. Firewall release service and port
JDK environment deployment: (amoeba is written in java, so the running environment running amoeba should install the java environment and configure the environment variables.)
1. Uninstall the OpenJDK and related java files that come with the system
Rpm-aq | grep java
Rpm-e-- nodeps java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64 java-1.7.0-openjdk-1.7.0.141-2.6.10.5.el7.x86_64 java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.5.el7.x86_64 java-1.8.0-openjdk-headless-1.8.0.131-11.b12.el7.x86_64
Java-version
2. Download the latest stable JDK
[note]: the user under which JDK is installed is for which user to use
Download address is
2.1 current latest version download address: http://www.oracle.com/technetwork/java/javase/downloads/index.html
Download address for historical version: http://www.oracle.com/technetwork/java/javase/archive-139210.html
2.2 paste the address to the browser address bar
According to the version and number of system digits, select tar.gz file to download (note: remember to check license)
2.3.After downloading, extract the JDK package locally and upload it to the amoeba server / usr/java directory via winscp (Note: no java directory can be created by yourself)
2.4 Grant execution permissions to files in the / java directory
Chmod ostatx / usr/java/-R
3. Configure JDK environment variables
Paste on the last line of the text as follows:
Note that JAVA_HOME=/usr/java/jdk-11.0.2 is your own directory.
[note]: on CentOS6, JAVAHOME,CentOS7 is {JAVA_HOME}.
Vim / etc/profile
# java environment
Export JAVA_HOME=/usr/java/jdk-11.0.2
Export CLASSPATH=.:$ {JAVA_HOME} / jre/lib/rt.jar:$ {JAVA_HOME} / lib/dt.jar:$ {JAVA_HOME} / lib/tools.jar
Export PATH=$PATH:$ {JAVA_HOME} / bin
4. The environment variable just set takes effect and checks whether the installation is successful.
Source / etc/profile or. / etc/profile
Java-version
Amoeba environment deployment: (10.100.246.240)
I. preparatory work
1. Amoeba is written in java, so the running environment running amoeba should install the java environment and configure the environment variables. The jdk version should be above 1.5, because amoeba is written in jdk1.5; my server java version is 11.0.2
2. Amoeba works on the basis of master-slave synchronization, so the master-slave synchronization function of MySQL should be configured first.
Download and install amoeba
1. Download address: https://sourceforge.net/projects/amoeba/files/Amoeba%20for%20mysql/3.x/
Select the latest version to download; the version I downloaded is: amoeba-mysql-3.0.5-RC-distribution.zip
2. After the download is completed, extract the package locally. After the package is decompressed, upload the amoeba-mysql-3.0.5-RC file to the amoeba server / usr/amoeba directory through the winscp tool (Note: the amoeba directory is created by itself)
3. Grant the directory execution permission
[root@amoeba amoeba] # chmod otakx amoeba-mysql-3.0.5-RC/-R
4. Firewall release port number
We found the conf folder in the amoeba folder, where the only ones we need to configure are dbServers.xml and amoeba.xm
5. Edit the dbServers.xml file under the configuration / amoeba-mysql-3.0.5-RC/conf directory
First of all, let's take a look at the dbServer tag where name is abstractServer, where the abstractive attribute is true, which means that this is an abstract dbServer definition that can be extended by other dbServer definitions, similar to abstract classes, and can be inherited and extended by other classes. We need to manually modify the port (port), database (schema), user name (user), password (password); so how should we fill it in here? I was also very confused when I used it for the first time. In fact, we should fill in the users we created for the amoeba server on master and slave to connect to master and slave databases, so here we should fill in port--3306 (default port unchanged), schema--bob (bob database), user--amoeba (user name), password--123456 (password).
And the dbServer under abstractServer is what we actually need to use. We can write about dbServer according to our own situation. If there are several databases that need to be configured, just fill in a few, in which name can be customized, it is best to write a meaningful name, and parent will fill in abstractServer, because we want to inherit abstractServer, so we can expand on the basis of abstractServer (inheriting attributes such as port,schema,user and password). You only need to add unique attributes.
The case is classified as one master and two slaves, the master is master, the first is slave01, and the second is slave02. In addition to their respective dbServer, we can also create a new dbServer as a database pool to integrate those databases with the same function. Both slave1 and slave2 in the case column are from the database and are responsible for reading operations, so we can put them together for easy call. The attribute loadbalance represents the load balancer, and the default value is 1, which represents the polling algorithm. The poolNames attribute allows us to place those dbServer with common functions, such as slave1,slave2, where different dbServer are separated by English commas.
6. Edit the amoeba.xml file under the configuration / amoeba-mysql-3.0.5-RC/conf directory
After configuring dbSevers.xml, let's configure amoeba.xml. First, let's configure the service tag. There are three points that need to be configured, port,user and password. The default port is 8066, which can be changed by yourself, but do not conflict with the existing port. If it is not necessary, it is not recommended to change it. User and password can be customized without having to be consistent with the users created by master and slave. The port, user name and password here are actually prepared for a virtual mysql link (not real, amoeba servers can not install real mysql databases)
Special note: there is an annotated ipAddress attribute in the service tag, which is used to bind a specific ip that can be linked to a virtual mysql of amoeba. If it is not bound, other servers in the network environment where the amoeba server is located (not tested on the same LAN) can be linked through amoeba's intranet ip, if 127.0.0.1 is bound. Then only the amoeba server can link to the virtual mysql, which needs to be noted.
After the port, user name and password are configured, let's configure the queryRouter tag, which can achieve true read-write separation. The above configuration prepares for the tag. There are three areas where we need to modify manually, namely defaultPool,writePool and readPool. DefaultPool is configured with the default database node, and some statements except SELECT\ UPDATE\ INSERT\ DELETE are executed in defaultPool, which is generally set as the main library. As the name implies, writePool is a database write library. Insert,update and delete operations will be performed in this library, which is generally set as the main library. ReadPool is to write libraries. If it is a single master and single slave, readPool writes the name set by the slave database in dbServers.xml. For example, if it is one master and multiple slaves, the readPool is set to the slave database pool. For example, multiPool in this case is the slave database pool, which contains two slave databases, slave01 and salve02, thus accomplishing the separation of read and write (master and slave) and load balancing (slave and slave). At this point, the configuration of amoeba has been completed.
7. Configure jvm running parameters
Amoeba running in a jdk11.0.2 environment requires that the xss parameter must be greater than 228 to start JVM
So set the parameters in the jvm.properties file under the amoeba installation directory
Vim jvm.properties
JVM_OPTIONS= "- server-Xms512m-Xmx1024m-Xss512k-XX:PermSize=16m-XX:MaxPermSize=96m"
8. Startup script
. / launcher &
9. Add the script to the boot entry
Vim / etc/profile
. / usr/amoeba/amoeba-mysql-3.0.5-RC/bin/launcher &
10. View java services
Netstat-tnlap | grep java
Client authentication
1. Install mariadb software
Yum install-y mariadb
2. Log in to the amoeba server
Mysql-h30.100.246.240-udesktop-P8066-p
3. Test whether the database can write data, and whether the master and slave data are synchronized.
After the client logs in to the database, it goes to the database named bob and inserts a table
MySQL [bob] > CREATE TABLE cisco (id int (10), name varchar (10), type varchar (20))
MySQL [bob] > INSERT INTO cisco VALUE ('1records, records, codes, codes, records, masteries, etc.)
Check whether the established table and the data inserted in the table exist in the master database and the two slave databases. If there is, the write is successful, and the master-slave synchronization is successful.
4. Test and verify whether the two slave databases achieve load balancing (polling)
Slave01: enter the bob database and insert the following data into the cisco table
MariaDB [bob] > INSERT INTO cisco VALUE ('2girls, girls, boys, girls, boys, girls, girls
Slave02: enter the bob database and insert the following data into the cisco table
MariaDB [bob] > INSERT INTO cisco VALUE ('2girls, girls, boys, girls, boys, girls, girls
Desktop: enter the bob database and use the command to view the data in the cisco table. Because it is a polling load, viewing the data in the table will switch data back and forth on slave01 and slave02.
MariaDB [bob] > SELECT * FROM cisco
5. Test and verify whether the read is limited to slave01 and slave02 slave databases.
5.1 temporarily turn off synchronization between slave01 and slave02 and the master database
MariaDB [bob] > STOP SLAVE
5.2 the client inserts a piece of data into the cisco data table. If the client can view the inserted data through the SELECT command and cannot see the data, the experiment is successful.
5.3. synchronize slave01 and slave02 with the main database to verify whether the data can be seen on the client
Slave01 and slave02:MariaDB [bob] > START SLAVE
Desktop:MariaDB [bob] > SELECT * FROM cisco
Read the above about what is Amoeba? If there is anything else you need to know, you can find what you are interested in in the industry information or seek answers from our professional technical engineers, technical engineers have more than ten years of experience in the industry. Official website link www.yisu.com
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.