国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

OneProxy簡單實現(xiàn)讀寫分離與分庫分表

whinc / 1972人閱讀

摘要:實現(xiàn)讀寫分離環(huán)境主機主機中間件一配置主從略注意關閉三端防火墻,也可以開放端口,數(shù)據(jù)庫端口,連接端口,管理端口當配置同步之后需要在主機創(chuàng)建庫并添加的連接用戶會自動到數(shù)據(jù)庫在數(shù)據(jù)庫中設置項,只讀模式,不會影響同步復制的功能,它可以限定普通用戶進

OneProxy實現(xiàn)Mysql讀寫分離

環(huán)境:

master主機:192.168.1.10
slave主機:192.168.1.12
oneproxy中間件:192.168.1.11

一、配置主從(略)

①注意關閉三端防火墻,也可以開放端口,數(shù)據(jù)庫端口3306,oneproxy連接端口3307,oneproxy管理端口4041

②當配置同步之后需要在master主機創(chuàng)建test庫并添加oneproxy的連接用戶會自動replication到slave數(shù)據(jù)庫
mysql>create database test;
mysql>grant select,delete,insert,update,create on test.* to oneproxy@"%" identified by "123.com";

③在slave數(shù)據(jù)庫中設置read_only項,read_only=1只讀模式,不會影響slave同步復制的功能,它可以限定普通用戶進行數(shù)據(jù)修改的操作,但不會限定具有super權限的用戶的數(shù)據(jù)修改操作,這里開啟它讓oneproxy自動識別讀寫服務器
mysql>show variables like ‘%read_only%’;

Variable_name Value
innodb_read_only OFF
read_only OFF
super_read_only OFF
tx_read_only OFF

mysql>set global read_only = 1;

二、配置OneProxy中間件

步驟:
①安裝oneproxy
[root@192 ~ ]# wget http://www.onexsoft.com/softw...
[root@192 ~ ]# tar zxf oneproxy-rhel6-linux64-v6.2.0-ga.tar.gz -C /usr/local

②在預啟動腳本中修改oneproxy目錄
[root@192 ~ ]# vim /usr/local/oneproxy/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

③修改啟動腳本oneproxy目錄
[root@192 ~ ]# vim /usr/local/oneproxy/oneproxy.service

....
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"
....

④獲取oneproxy加密后的密文密碼
[root@192 ~]# cd /usr/local/oneproxy/bin
[root@192 bin]# ls
mysqlpwd oneproxy
[root@192 bin]# ./mysqlpwd 123.com
7FB703DA3682A0CCC20168D44E8A7E92FE676A51

⑤修改oneproxy主配文件
[root@192 ~ ]# vim /usr/local/oneproxy/conf/proxy.conf

[oneproxy]
#proxy-license              = A2FF461456A67F28,D2F6A5AD70C9042D
keepalive = 1
event-threads = 4
proxy-group-policy = test:read-slave
log-file = log/oneproxy.log
pid-file = log/oneproxy.pid
lck-file = log/oneproxy.lck
proxy-auto-readonly = 1
proxy-forward-clientip = 1
proxy-trans-debug = 1
mysql-version = 5.7.18
proxy-master-addresses.1 = 192.168.1.10:3306@test
proxy-slave-addresses.2 = 192.168.1.12:3306@test
proxy-user-list = oneproxy/7FB703DA3682A0CCC20168D44E8A7E92FE676A51@test
proxy-part-template = conf/template.txt
proxy-part-tables.1      = conf/part.txt
proxy-part-tables.2      = conf/part2.txt
proxy-part-tables.3      = conf/cust1.txt
proxy-charset            = utf8_bin
proxy-secure-client = 127.0.0.1
proxy-httpserver = :8080
proxy-httptitle = OneProxy Monitor

上述中:

proxy-auto-readonly:自動切換讀寫角色
proxy-group-policy:預定義策略,對應真實要管理的數(shù)據(jù)庫
proxy-user-list:指明連接數(shù)據(jù)庫用戶密文密碼要與真實數(shù)據(jù)庫用戶密碼對應@符后指的是數(shù)據(jù)庫

⑥啟動oneproxy
[root@192 oneproxy]# chmod +x demo.sh
[root@192 oneproxy]# ./demo.sh
[root@192 oneproxy]# ./oneproxy.service start
Starting OneProxy ... [ OK ]
[root@192 conf]# ss -anpt | grep 3307
LISTEN 0 128 :3307 :* users:(("oneproxy",pid=3401,fd=11))
[root@192 conf]# ss -anpt | grep 4041
LISTEN 0 128 :4041 :* users:(("oneproxy",pid=3401,fd=13))

⑦訪問oneproxy管理網(wǎng)頁
輸入http://oneproxy_ip:8080
默認用戶名admin,密碼OneProxy

⑧驗證
使用客戶端登錄oneproxy連接端口3307
[root@192 ~]# mysql -uoneproxy -p123.com -h 192.168.1.11 -P3307
mysql> create table test.tb (id int);
ERROR 1044 (42000): Access denied due to security policy, DDL disabled or DML restricted!
由于oneproxy為了安全起見,初始靜止了DDl語句,需要去到4041管理端口打開底層數(shù)據(jù)庫權限
[root@192 ~]# mysql -uadmin -pOneProxy -P4041 -h 192.168.1.11
mysql> set gaccess test 0 ;
[root@192 ~]# mysql -uoneproxy -p123.com -h 192.168.1.11 -P3307
mysql> create table test.tb (id int);
mysql> insert into test.tb values(1);
mysql> insert into test.tb values(2);
.....多插入幾條
mysql> select * from test.tb;
.....多查看幾次

觀察管理網(wǎng)頁master和slave中query的變化,讀負載的增加與寫負載的增加,驗證成功

OneProxy實現(xiàn)Mysql分庫分表

環(huán)境:

master主機:192.168.1.12
oneproxy中間件:192.168.1.11

思路:

客戶端→oneproxy→master主機
          ↘       ↓
             test庫→user表→user_0子表
                          →user_1子表
                          →user_2子表
                          →user_3子表
一、配置master主機

步驟:
①分配連接用戶權限并創(chuàng)建數(shù)據(jù)庫
mysql> grant all on . to oneproxy@"%" identified by "123.com";
mysql>create database test;

②關閉防火墻或開啟端口
[root@192 ~]# systemctl stop firewalld

二、配置OneProxy中間件

安裝部署過程略

步驟:
①配置proxy.conf
[root@192 ~ ]# vim /usr/local/oneproxy/conf/proxy.conf

[oneproxy]
#proxy-license              = A2FF461456A67F28,D2F6A5AD70C9042D
keepalive = 1
event-threads = 4
proxy-group-policy.1 = test:master-only
proxy-group-security = test:0
log-file = log/oneproxy.log
pid-file = log/oneproxy.pid
lck-file = log/oneproxy.lck
proxy-forward-clientip = 1
proxy-trans-debug = 1
mysql-version = 5.7.18
proxy-master-addresses.1 = 192.168.1.12:3306@test
proxy-user-list = oneproxy/7FB703DA3682A0CCC20168D44E8A7E92FE676A51@test
proxy-part-template = conf/template.txt
proxy-part-tables.1      = conf/part.txt
proxy-part-tables.2      = conf/part2.txt
proxy-part-tables.3      = conf/cust1.txt
proxy-charset            = utf8_bin
proxy-httpserver = :8080
proxy-httptitle = OneProxy Monitor

②配置part2.txt

[
{
    "table" : "user",
    "pkey" : "id",
    "type" : "int",
    "method" : "hash",
    "partitions" :
      [
        { "suffix" : "_0", "group": "test" },
        { "suffix" : "_1", "group": "test" },
        { "suffix" : "_2", "group": "test" },
        { "suffix" : "_3", "group": "test"}
      ]
  }
]

③啟動oneproxy
[root@192 oneproxy]# sh demo.sh
[root@192 oneproxy]# ./oneproxy.service start
Starting OneProxy ... [ OK ]
[root@192 oneproxy]# ss -anpt | grep 3307
LISTEN 0 128 :3307 :* users:(("oneproxy",pid=37997,fd=11))
[root@192 oneproxy]# ss -anpt | grep 4041
LISTEN 0 128 :4041 :* users:(("oneproxy",pid=37997,fd=13))
如果端口查詢不到,請查看oneproxy日志文件oneproxy.log,如果沒有日志記錄,則可能主配或part文件有錯誤

三、驗證

步驟:
①從客戶端登錄連接端口
[root@192 ~]# mysql -h 192.168.1.11 -u oneproxy -p123.com -P3307
mysql>show databases;

Database
test

②插入數(shù)據(jù)
mysql>create table user(id int ,c1 int);
mysql>insert into user(id,c1) values (1,1);
mysql>insert into user(id,c1) values (2,2);
mysql>insert into user(id,c1) values (3,3);
mysql>insert into user(id,c1) values (4,4);
mysql>insert into user(id,c1) values (5,5);
mysql>select * from user;

id c1
4 4
1 1
5 5
2 2
3 3

③回到master主機查看存儲位置
[root@192 ~]# mysql
mysql> use test
mysql> show tables ;

Tables_in_test
user
user_0
user_1
user_2
user_3

mysql> select * from user_0;

id c1
4 4

1 row in set (0.00 sec)

mysql> select * from user_1;

id c1
1 1
5 5

2 rows in set (0.00 sec)

mysql> select * from user_2;

id c1
2 2

1 row in set (0.00 sec)

mysql> select * from user_3;

id c1
3 3

1 row in set (0.00 sec)

通過oneproxy實現(xiàn)了分離數(shù)據(jù),驗證成功

文章版權歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://specialneedsforspecialkids.com/yun/27268.html

相關文章

  • 數(shù)據(jù)庫的分庫分表

    摘要:如成千上萬的螞蟻完成一項搬運工作縱向擴展又叫垂直擴展,擴展一個點的能力支撐更大的請求。如利用個人的能力,如蜘蛛俠逼?;疖噮⒖挤謳旆直淼幕舅枷? 一 概念:什么是分庫分表(sharding) 1 將集中于單一節(jié)點的數(shù)據(jù)拆分并分別存儲到多個數(shù)據(jù)庫或表,稱為分庫分表 2 數(shù)據(jù)切分分為兩種方式,垂直切分和水平切分 3 分庫:因為表多導致數(shù)據(jù)過多使用垂直切分,垂直切分就是根據(jù)業(yè)務的耦合性,將關聯(lián)...

    elarity 評論0 收藏0

發(fā)表評論

0條評論

whinc

|高級講師

TA的文章

閱讀更多
最新活動
閱讀需要支付1元查看
<