MyCat
Install MyCat
introduce:
Mycat is an open source database middleware used to provide high availability, load balancing and sharding capabilities.
Step 1: Install Java environment
First, you need to install the Java environment on the server. Open a terminal and run the following command:
sudo yum install java-1.8.0-openjdk-devel
Step 2: Download and unzip Mycat
- Download the latest version of the Mycat compressed package on the Mycat official website, URL: Mycat official website or directly use the command to download on the server
wget
:
# 下载Mycat压缩包
wget http://dl.mycat.org.cn/2.0/install-template/mycat2-install-template-1.21.zip
- Enter the directory you downloaded in the terminal and run the following command to decompress the file:
tar -zxvf mycat2-install-template-1.21.zip
The following error may occur when using tar
decompression because the file contains multiple compressed packages:
Solution: Use unzip
or p7zip
to decompress.
unzip mycat2-install-template-1.21.zip
Step 3: Configure Mycat
- Enter the decompressed Mycat directory:
cd mycat/lib/
- Download the dependency package or copy the downloaded dependency package to the directory:
# 直接下载依赖包
wget http://dl.mycat.org.cn/2.0/1.21-release/mycat2-1.21-release-jar-with-dependencies.jar
# 复制
cp mycat2-1.21-release-jar-with-dependencies.jar mycat/lib/
- Edit the configuration file
conf
in the directoryserver.xml
:
vim mycat/conf/datasources/prototypeDs.datasource.json
- Configure the mysql connection as the master database. The only things that need to be modified are
url
: ,user
andpassword
:
{
"dbType":"mysql",
"idleTimeout":60000,
"initSqls":[],
"initSqlsGetConnection":true,
"instanceType":"READ_WRITE",
"maxCon":1000,
"maxConnectTimeout":3000,
"maxRetryCount":5,
"minCon":1,
"name":"prototypeDs",
"password":"Ddz@5201413",
"type":"JDBC",
"url":"jdbc:mysql://114.132.156.12:3306/ddz_test?useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=UTF-8",
"user":"root",
"weight":0
}
Enter :wq!
to save and exit.
Step 4: Start Mycat
mycat/bin/
Start the Mycat server using the following command in the directory :
sh mycat start
There may be a startup failure:
the reason is that the permissions of the two files wrapper-linux-x86-64 and wrapper-linux-x86-32 are incorrectly set.
# 查看文件权限
ls -l /home/mycat/bin/./wrapper-linux-x86-64
ls -l /home/mycat/bin/./wrapper-linux-x86-32
# 设置文件权限
chmod +x /home/mycat/bin/./wrapper-linux-x86-64
chmod +x /home/mycat/bin/./wrapper-linux-x86-32
或给/bin文件赋权限
chmod -R 777 bin/
After setting up, enter mycat/bin/
the directory and execute the startup command:
cd mycat/bin/
./mycat start
- After confirming that Mycat starts successfully, use the following command to check whether the Myat process is running:
ps -ef | grep mycat
Step 5: Connect and test Mycat
- Use the MySQL client to connect to the Mycat server, example:
mysql -h114.132.156.12 -P8066 -uroot -p
- After entering the password and successfully connecting to the Myat server, you can execute SQL statements for testing.
Conclusion:
By following the above steps, Mycat was successfully installed and configured on CentOS 7 and able to connect and test the Mycat server. This will provide high availability, load balancing and sharding capabilities for your database management, improving database efficiency and performance.
ProxySql
Install ProxySql
introduce:
ProxySQL is a high-performance MySQL proxy server used for load balancing, failover and query filtering. In this blog, we will explain how to install and configure ProxySQL on CentOS 7.9.
Step 1: Update your system
First, update all packages on your system using the following command:
sudo yum update
Step 2: Install ProxySQL
Add the ProxySQL software repository:
sudo yum install -y https://github.com/sysown/proxysql/releases/download/v2.5.0/proxysql-2.5.0-1-centos7.x86_64.rpm
Install proxysql package:
sudo yum install proxysql
Step 3: Configure ProxySQL
Edit the ProxySQL configuration file:
sudo vi /etc/proxysql/proxysql.cnf
mysql_servers
Add the details of the MySQL backend in the section :
mysql_servers =
(
{
address = '127.0.0.1',
port = 3306,
hostgroup = 10,
max_connections = 100,
max_replication_lag = 5,
use_ssl = 0
}
)
Step 4: Start ProxySQL
Start the ProxySQL service:
sudo systemctl start proxysql
sudo systemctl enable proxysql
Step 5: Use ProxySQL
Connect to the ProxySQL administrator command line interface:
mysql -u admin -p -h 127.0.0.1 -P 6032 --prompt='ProxySQLAdmin>'
Configure user, host, and port mapping on the ProxySQL administrator command line interface:
INSERT INTO mysql_users (username, password, default_hostgroup) VALUES ('user', 'password', 10);
LOAD MYSQL USERS TO RUNTIME;
SAVE MYSQL USERS TO DISK;
INSERT INTO mysql_servers (hostgroup_id, hostname, port) VALUES (10, '127.0.0.1', 3306);
LOAD MYSQL SERVERS TO RUNTIME;
SAVE MYSQL SERVERS TO DISK;
INSERT INTO mysql_query_rules (active, match_pattern, destination_hostgroup) VALUES (1, '^SELECT.*', 10);
LOAD MYSQL QUERY RULES TO RUNTIME;
SAVE MYSQL QUERY RULES TO DISK;
Now you can use ProxySQL to proxy MySQL queries.
Conclusion:
Installing ProxySQL proxy MySQL on CentOS 7.9 is a simple process, just follow the steps in this article. Using ProxySQL can improve the load balancing and failover capabilities of the MySQL server, while also filtering and redirecting queries.