OneProxy分库分表的搭建
发表于:2025-01-22 作者:千家信息网编辑
千家信息网最后更新 2025年01月22日,实验环境:前期准备的三个节点的环形复制master1:192.168.8.57master2:192.168.8.58master3:192.168.8.59oneproxy:192.168.8.63
千家信息网最后更新 2025年01月22日OneProxy分库分表的搭建实验环境:
前期准备的三个节点的环形复制
master1:192.168.8.57
master2:192.168.8.58
master3:192.168.8.59
oneproxy:192.168.8.63
1、下载oneproxy,地址:http://www.onexsoft.com/
上传至192.168.8.63,解压到/usr/local
2、修改文件描述符65535
vi /etc/security/limits.conf
soft nofile 65535
hard nofile 65535
vi /etc/sysctl.conf
fs.file-max=655350
net.ipv4.ip_local_port_range=1025 65000
net.ipv4.tcp_tw_reuse=1
3、创建加密密码
[root@oneproxy bin]# ./mysqlpwd mysql
F1F2E852DCCD764DFA90870C3AF7D6C9D71E7E1B
4、修改demo.sh
目录中的demo.sh是初次启动脚本,修改ONEPROXY_HOME
[root@oneproxy oneproxy]# cat demo.sh
#/bin/bash
#
export ONEPROXY_HOME=/usr/local/oneproxy
ulimit -c unlimited
# valgrind --leak-check=full \
${ONEPROXY_HOME}/bin/oneproxy --defaults-file=${ONEPROXY_HOME}/conf/proxy.conf
5、修改oneproxy.service
oneproxy.service是启动脚本,修改ONEPROXY_HOME
[root@oneproxy oneproxy]# cat oneproxy.service
#!/bin/bash
# chkconfig: - 30 21
# description: OneProxy service.
# Source Function Library
. /etc/init.d/functions
# OneProxy Settings
ONEPROXY_HOME=/usr/local/oneproxy
ONEPROXY_SBIN="${ONEPROXY_HOME}/bin/oneproxy"
ONEPROXY_CONF="${ONEPROXY_HOME}/conf/proxy.conf"
ONEPROXY_PID="${ONEPROXY_HOME}/log/oneproxy.pid"
RETVAL=0
prog="OneProxy"
start() {
echo -n $"Starting $prog ... "
daemon $ONEPROXY_SBIN --defaults-file=$ONEPROXY_CONF
RETVAL=$?
echo
}
stop() {
echo -n $"Stopping $prog ... "
if [ -e ${ONEPROXY_PID} ]; then
daemon kill -INT $(cat ${ONEPROXY_PID})
RETVAL=$?
fi
echo
}
restart(){
stop
sleep 1
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
RETVAL=1
esac
exit $RETVAL
6、配置OneProxy
root@oneproxy conf]# cat proxy.conf
[oneproxy]
keepalive = 1
event-threads = 1
log-file = log/oneproxy.log
pid-file = log/oneproxy.pid
lck-file = log/oneproxy.lck
#proxy-license = A2FF461456A67F28,D2F6A5AD70C9042D
#proxy-auto-readonly = 1
#proxy-forward-clientip = 1
#proxy-trans-debug = 1
proxy-address = :3307
admin-address = :4040
mysql-version = 5.7.18
proxy-master-addresses.1 = 192.168.8.57:3306@group1
proxy-master-addresses.2 = 192.168.8.58:3306@group2
proxy-master-addresses.3 = 192.168.8.59:3306@group3
proxy-user-list = test/F1F2E852DCCD764DFA90870C3AF7D6C9D71E7E1B@test
#proxy-user-list2 = root/F1F2E852DCCD764DFA90870C3AF7D6C9D71E7E1B@test
#proxy-user-group = test:root/F1F2E852DCCD764DFA90870C3AF7D6C9D71E7E1B@test
proxy-charset = utf8_bin
proxy-group-policy.1 = group1:master-only
proxy-group-policy.2 = group2:master-only
proxy-group-policy.3 = group3:master-only
proxy-secure-client.1 = 192.168.8.57
proxy-secure-client.2 = 192.168.8.58
proxy-secure-client.3 = 192.168.8.59
#remote-address.1 = 192.168.1.119:4041
proxy-httptitle = OneProxy Monitor
proxy-httpserver = :8080
proxy-part-tables.1 = conf/part.txt
7、配置part.txt
[root@oneproxy conf]# cat part.txt
[
{
"table" : "steven",
"pkey" : "id",
"type" : "int",
"method" : "hash",
"partitions" :
[
{ "suffix" : "_0", "group": "group1" },
{ "suffix" : "_1", "group": "group2" },
{ "suffix" : "_2", "group": "group3" }
]
}
]
8、启动oneproxy
[root@oneproxy conf]#./oneproxy.service start
Starting OneProxy ... [ OK ]
9、分库分表的功能测试
客户端连接OneProxy的3307端口,在test下创建steven表。
mysql -utest -pmysql -h292.168.8.63 -P3307 test
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 103
Server version: 5.7.18 OneProxy-6.2.0 (OneXSoft)
Copyright (c) 2000, 2017, 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> create table steven(
id int(10) unsigned NOT NULL AUTO_INCREMENT,
a1 int(10) NOT NULL DEFAULT '0',
a2 int(10) unsigned DEFAULT NULL,
a5 int(10) unsigned NOT NULL DEFAULT '0',
a3 timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
a4 varchar(200) NOT NULL DEFAULT '',
PRIMARY KEY(id),
KEY idx_a1(a1),
KEY idx_a2(a2))ENGINE=InnoDB;
10、向steven表插入测试数据
insert into steven(id,a1,a2,a5,a4) values(1,1,1,1,'1');
insert into steven(id,a1,a2,a5,a4) values(2,2,2,2,'2');
insert into steven(id,a1,a2,a5,a4) values(3,3,3,3,'3');
insert into steven(id,a1,a2,a5,a4) values(4,4,4,4,'4');
insert into steven(id,a1,a2,a5,a4) values(5,5,5,5,'5');
insert into steven(id,a1,a2,a5,a4) values(6,6,6,6,'6');
insert into steven(id,a1,a2,a5,a4) values(7,7,7,7,'7');
insert into steven(id,a1,a2,a5,a4) values(8,8,8,8,'8');
insert into steven(id,a1,a2,a5,a4) values(9,9,9,9,'9');
11、查看各个节点数据:
mysql> show databases;
+----------+
| Database |
+----------+
| group3 |
| group1 |
| group2 |
+----------+
3 rows in set (0.00 sec)
mysql> use group1;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+--------------------------------+
| Tables_in_test |
+--------------------------------+
| oneproxy_replication_timestamp |
| steven_0 |
| steven_1 |
| steven_2 |
+--------------------------------+
4 rows in set (0.00 sec)
mysql> select * from steven_0
-> ;
+----+----+------+----+---------------------+----+
| id | a1 | a2 | a5 | a3 | a4 |
+----+----+------+----+---------------------+----+
| 3 | 3 | 3 | 3 | 2018-03-07 10:08:43 | 3 |
| 6 | 6 | 6 | 6 | 2018-03-07 10:08:43 | 6 |
| 9 | 9 | 9 | 9 | 2018-03-07 10:08:44 | 9 |
+----+----+------+----+---------------------+----+
3 rows in set (0.00 sec)
mysql> select * from steven_1
-> ;
+----+----+------+----+---------------------+----+
| id | a1 | a2 | a5 | a3 | a4 |
+----+----+------+----+---------------------+----+
| 1 | 1 | 1 | 1 | 2018-03-07 10:08:44 | 1 |
| 4 | 4 | 4 | 4 | 2018-03-07 10:08:44 | 4 |
| 7 | 7 | 7 | 7 | 2018-03-07 10:08:44 | 7 |
+----+----+------+----+---------------------+----+
3 rows in set (0.00 sec)
mysql> select * from steven_2;
+----+----+------+----+---------------------+----+
| id | a1 | a2 | a5 | a3 | a4 |
+----+----+------+----+---------------------+----+
| 2 | 2 | 2 | 2 | 2018-03-07 10:08:43 | 2 |
| 5 | 5 | 5 | 5 | 2018-03-07 10:08:43 | 5 |
| 8 | 8 | 8 | 8 | 2018-03-07 10:08:43 | 8 |
+----+----+------+----+---------------------+----+
3 rows in set (0.01 sec)
前期准备的三个节点的环形复制
master1:192.168.8.57
master2:192.168.8.58
master3:192.168.8.59
oneproxy:192.168.8.63
1、下载oneproxy,地址:http://www.onexsoft.com/
上传至192.168.8.63,解压到/usr/local
2、修改文件描述符65535
vi /etc/security/limits.conf
soft nofile 65535
hard nofile 65535
vi /etc/sysctl.conf
fs.file-max=655350
net.ipv4.ip_local_port_range=1025 65000
net.ipv4.tcp_tw_reuse=1
3、创建加密密码
[root@oneproxy bin]# ./mysqlpwd mysql
F1F2E852DCCD764DFA90870C3AF7D6C9D71E7E1B
4、修改demo.sh
目录中的demo.sh是初次启动脚本,修改ONEPROXY_HOME
[root@oneproxy oneproxy]# cat demo.sh
#/bin/bash
#
export ONEPROXY_HOME=/usr/local/oneproxy
ulimit -c unlimited
# valgrind --leak-check=full \
${ONEPROXY_HOME}/bin/oneproxy --defaults-file=${ONEPROXY_HOME}/conf/proxy.conf
5、修改oneproxy.service
oneproxy.service是启动脚本,修改ONEPROXY_HOME
[root@oneproxy oneproxy]# cat oneproxy.service
#!/bin/bash
# chkconfig: - 30 21
# description: OneProxy service.
# Source Function Library
. /etc/init.d/functions
# OneProxy Settings
ONEPROXY_HOME=/usr/local/oneproxy
ONEPROXY_SBIN="${ONEPROXY_HOME}/bin/oneproxy"
ONEPROXY_CONF="${ONEPROXY_HOME}/conf/proxy.conf"
ONEPROXY_PID="${ONEPROXY_HOME}/log/oneproxy.pid"
RETVAL=0
prog="OneProxy"
start() {
echo -n $"Starting $prog ... "
daemon $ONEPROXY_SBIN --defaults-file=$ONEPROXY_CONF
RETVAL=$?
echo
}
stop() {
echo -n $"Stopping $prog ... "
if [ -e ${ONEPROXY_PID} ]; then
daemon kill -INT $(cat ${ONEPROXY_PID})
RETVAL=$?
fi
echo
}
restart(){
stop
sleep 1
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
RETVAL=1
esac
exit $RETVAL
6、配置OneProxy
root@oneproxy conf]# cat proxy.conf
[oneproxy]
keepalive = 1
event-threads = 1
log-file = log/oneproxy.log
pid-file = log/oneproxy.pid
lck-file = log/oneproxy.lck
#proxy-license = A2FF461456A67F28,D2F6A5AD70C9042D
#proxy-auto-readonly = 1
#proxy-forward-clientip = 1
#proxy-trans-debug = 1
proxy-address = :3307
admin-address = :4040
mysql-version = 5.7.18
proxy-master-addresses.1 = 192.168.8.57:3306@group1
proxy-master-addresses.2 = 192.168.8.58:3306@group2
proxy-master-addresses.3 = 192.168.8.59:3306@group3
proxy-user-list = test/F1F2E852DCCD764DFA90870C3AF7D6C9D71E7E1B@test
#proxy-user-list2 = root/F1F2E852DCCD764DFA90870C3AF7D6C9D71E7E1B@test
#proxy-user-group = test:root/F1F2E852DCCD764DFA90870C3AF7D6C9D71E7E1B@test
proxy-charset = utf8_bin
proxy-group-policy.1 = group1:master-only
proxy-group-policy.2 = group2:master-only
proxy-group-policy.3 = group3:master-only
proxy-secure-client.1 = 192.168.8.57
proxy-secure-client.2 = 192.168.8.58
proxy-secure-client.3 = 192.168.8.59
#remote-address.1 = 192.168.1.119:4041
proxy-httptitle = OneProxy Monitor
proxy-httpserver = :8080
proxy-part-tables.1 = conf/part.txt
7、配置part.txt
[root@oneproxy conf]# cat part.txt
[
{
"table" : "steven",
"pkey" : "id",
"type" : "int",
"method" : "hash",
"partitions" :
[
{ "suffix" : "_0", "group": "group1" },
{ "suffix" : "_1", "group": "group2" },
{ "suffix" : "_2", "group": "group3" }
]
}
]
8、启动oneproxy
[root@oneproxy conf]#./oneproxy.service start
Starting OneProxy ... [ OK ]
9、分库分表的功能测试
客户端连接OneProxy的3307端口,在test下创建steven表。
mysql -utest -pmysql -h292.168.8.63 -P3307 test
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 103
Server version: 5.7.18 OneProxy-6.2.0 (OneXSoft)
Copyright (c) 2000, 2017, 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> create table steven(
id int(10) unsigned NOT NULL AUTO_INCREMENT,
a1 int(10) NOT NULL DEFAULT '0',
a2 int(10) unsigned DEFAULT NULL,
a5 int(10) unsigned NOT NULL DEFAULT '0',
a3 timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
a4 varchar(200) NOT NULL DEFAULT '',
PRIMARY KEY(id),
KEY idx_a1(a1),
KEY idx_a2(a2))ENGINE=InnoDB;
10、向steven表插入测试数据
insert into steven(id,a1,a2,a5,a4) values(1,1,1,1,'1');
insert into steven(id,a1,a2,a5,a4) values(2,2,2,2,'2');
insert into steven(id,a1,a2,a5,a4) values(3,3,3,3,'3');
insert into steven(id,a1,a2,a5,a4) values(4,4,4,4,'4');
insert into steven(id,a1,a2,a5,a4) values(5,5,5,5,'5');
insert into steven(id,a1,a2,a5,a4) values(6,6,6,6,'6');
insert into steven(id,a1,a2,a5,a4) values(7,7,7,7,'7');
insert into steven(id,a1,a2,a5,a4) values(8,8,8,8,'8');
insert into steven(id,a1,a2,a5,a4) values(9,9,9,9,'9');
11、查看各个节点数据:
mysql> show databases;
+----------+
| Database |
+----------+
| group3 |
| group1 |
| group2 |
+----------+
3 rows in set (0.00 sec)
mysql> use group1;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+--------------------------------+
| Tables_in_test |
+--------------------------------+
| oneproxy_replication_timestamp |
| steven_0 |
| steven_1 |
| steven_2 |
+--------------------------------+
4 rows in set (0.00 sec)
mysql> select * from steven_0
-> ;
+----+----+------+----+---------------------+----+
| id | a1 | a2 | a5 | a3 | a4 |
+----+----+------+----+---------------------+----+
| 3 | 3 | 3 | 3 | 2018-03-07 10:08:43 | 3 |
| 6 | 6 | 6 | 6 | 2018-03-07 10:08:43 | 6 |
| 9 | 9 | 9 | 9 | 2018-03-07 10:08:44 | 9 |
+----+----+------+----+---------------------+----+
3 rows in set (0.00 sec)
mysql> select * from steven_1
-> ;
+----+----+------+----+---------------------+----+
| id | a1 | a2 | a5 | a3 | a4 |
+----+----+------+----+---------------------+----+
| 1 | 1 | 1 | 1 | 2018-03-07 10:08:44 | 1 |
| 4 | 4 | 4 | 4 | 2018-03-07 10:08:44 | 4 |
| 7 | 7 | 7 | 7 | 2018-03-07 10:08:44 | 7 |
+----+----+------+----+---------------------+----+
3 rows in set (0.00 sec)
mysql> select * from steven_2;
+----+----+------+----+---------------------+----+
| id | a1 | a2 | a5 | a3 | a4 |
+----+----+------+----+---------------------+----+
| 2 | 2 | 2 | 2 | 2018-03-07 10:08:43 | 2 |
| 5 | 5 | 5 | 5 | 2018-03-07 10:08:43 | 5 |
| 8 | 8 | 8 | 8 | 2018-03-07 10:08:43 | 8 |
+----+----+------+----+---------------------+----+
3 rows in set (0.01 sec)
数据
脚本
节点
测试
配置
分库
分表
三个
前期
功能
功能测试
地址
客户
客户端
密码
文件
环境
环形
目录
端口
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
java数据库选择查询
PC无法与部署服务器通信
网络安全对国际体系的影响
经济类数据库分类
软件开发遇到职业瓶颈
sql2000数据库安全性
新网域名阿里云服务器
天津市软件开发公司电话
月神殿服务器
西安网络技术支持招聘
热血江湖80版数据库中文官方版
普陀区优势软件开发产品介绍
c语言写管理系统有数据库
如何欺骗邮箱服务器
网络技术工程师招聘信息
米家服务器宕机
vb精简版6.0可以数据库
网络技术的应用带来的影响
检索数据库名称怎么查看
网络安全工程师行业领军
嵌入式软件开发和测试
数据与数据库安全策略
软件开发公司工资多少
服务器ftp传文件
网络安全前辈给的建议心得
软件开发客户满意度
软件开发哲学
特朗普科技互联网
数据库备份软件排名
无线网络安全是指