接上一篇文章OceanBase 1.4 集群手动安装步骤,继续开始OceanBase 1.4集群的学习。
一步一步学习OceanBase系列 本篇是第二篇 安装和配置obproxy,使用obproxy连接ob集群
五、安装和配置obproxy
OceanBase是分布式数据库,应用的数据可能分布在任一节点上并且不固定,所以应用不可能知道数据在哪个节点或者记录所有节点IP。
这时就需要一个反向代理OBProxy在OceanBase集群前面提供SQL路由功能。应用通过OBProxy访问OceanBase集群,OBProxy就是数据库的代表。
5.1.创建OBProxy专用用户
OBProxy需要跟OceanBase集群保持通信,所以需要在sys租户里提前创建好账户。
登录sys租户创建obproxy的内部用户(请复制下面SQL不要改动)。
$ mysql -h127.1 -uroot@sys -P2881 -p -A
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 2147549195
Server version: 5.6.25 OceanBase 1.4.60 (r1571952-758a58e85846f9efb907b1c14057204cb6353846) (Built Mar 9 2018 14:32:07)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> CREATE USER proxyro IDENTIFIED BY password '*e9c2bcdc178a99b7b08dd25db58ded2ee5bff050' ;
Query OK, 0 rows affected (0.01 sec)
MySQL [(none)]> GRANT SELECT ON *.* to proxyro;
Query OK, 0 rows affected (0.01 sec)
MySQL [(none)]> show grants for proxyro;
+----------------------------------+
| Grants for proxyro |
+----------------------------------+
| GRANT SELECT ON *.* TO 'proxyro' |
+----------------------------------+
1 row in set (0.00 sec)
MySQL [(none)]>
5.2.安装OBProxy的软件
root用户安装RPM包,默认obproxy安装目录在/opt/taobao/install 下。
# rpm -ivh obproxy-1.3.3-1506155.el7.x86_64.rpm
# chown -R admin:admin /opt/taobao
# tree /opt
/opt
└── taobao
└── install
└── obproxy
├── bin
│ ├── obproxy
│ ├── obproxyd.sh
│ ├── obp_xflush.py
│ └── unzip.py
├── etc
├── log -> /home/admin/logs/obproxy/log
├── minidump -> /home/admin/logs/obproxy/minidump
└── tools
├── dump_syms
├── minidump.sh
├── minidump_stackwalk
└── obproxy.sym
6 directories, 10 files
#
5.3.admin用户,启动OBProxy
OBProxy启动跟OBServer启动类似
注意:
其中 -r指定的是rootservice list地址,格式稍微不同,不需要RPC Port信息,只需要observer inner_port。-p指定OBProxy的监听端口。 -c指定ob集群名称
# su - admin
$ cd /opt/taobao/install/obproxy
$ bin/obproxy -r "192.168.0.151:2881;192.168.0.43:2881;192.168.0.41:2881" -p 2883 -o "enable_strict_kernel_release=false,enable_cluster_checkout=false" -c obdemo
listen port: 2883
optstr: enable_strict_kernel_release=false,enable_cluster_checkout=false
cluster_name: obdemo
$
$ ps -ef|grep obproxy
admin 22122 1 2 11:51 ? 00:00:00 bin/obproxy -r 192.168.0.151:2881;192.168.0.43:2881;192.168.0.41:2881 -p 2883 -o enable_strict_kernel_release=false,enable_cluster_checkout=false -c obdemo
admin 22134 9410 0 11:52 pts/0 00:00:00 grep --color=auto obproxy
$
5.4.配置obproxy参数
$ mysql -h192.168.0.151 -uroot@sys#obdemo -P2883 -p -c -A oceanbase
Enter password:
下面是obproxy的一些参数配置用于减少运行日志量,根据实际情况修改。
show proxyconfig like '%compress%';
alter proxyconfig set enable_metadb_used=False;
alter proxyconfig set enable_proxy_scramble=True;
alter proxyconfig set proxy_mem_limited=2G;
alter proxyconfig set log_dir_size_threshold=10G;
alter proxyconfig set slow_proxy_process_time_threshold='1000ms';
alter proxyconfig set xflush_log_level=ERROR;
alter proxyconfig set syslog_level=WARN;
alter proxyconfig set enable_compression_protocol=false;
5.5.使用OBProxy连接ob集群
通过OBProxy连接OceanBase集群的命令有两种格式,区别在于用户名的格式。如:[用户名]@[租户名]#[集群名] 或 [集群名]:[租户名]:[用户名]。
mysql -h192.168.0.151 -uroot@sys#obdemo -P2883 -padmin123 -c -A oceanbase
或
mysql -h192.168.0.151 -uobdemo:sys:root -P2883 -padmin123 -c -A oceanbase
示例:
$ mysql -h192.168.0.151 -uroot@sys#obdemo -P2883 -padmin123 -c -A oceanbase
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 1048578
Server version: 5.6.25 OceanBase 1.4.60 (r1571952-758a58e85846f9efb907b1c14057204cb6353846) (Built Mar 9 2018 14:32:07)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [oceanbase]> select version();
+-----------+
| version() |
+-----------+
| 1.4.60 |
+-----------+
1 row in set (0.00 sec)
MySQL [oceanbase]> show databases;
+--------------------+
| Database |
+--------------------+
| oceanbase |
| information_schema |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
MySQL [oceanbase]> exit
Bye
$
$ mysql -h192.168.0.151 -uobdemo:sys:root -P2883 -padmin123 -c -A oceanbase
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 1048579
Server version: 5.6.25 OceanBase 1.4.60 (r1571952-758a58e85846f9efb907b1c14057204cb6353846) (Built Mar 9 2018 14:32:07)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [oceanbase]> select version();
+-----------+
| version() |
+-----------+
| 1.4.60 |
+-----------+
1 row in set (0.00 sec)
MySQL [oceanbase]> show databases;
+--------------------+
| Database |
+--------------------+
| oceanbase |
| information_schema |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
MySQL [oceanbase]> exit
Bye
$
本次obproxy的安装配置使用,到此结束。
一步一步学习OceanBase系列
下一篇准备体验ob集群的租户使用。。
下次实操继续更新~~~~~
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。