OBProxy can forward the data access requests of users to the correct OBServers. The results are returned to the clients through OBProxy. This topic describes how to install OBProxy by using the OBProxy RPM package.
Notice
- After you deploy OBProxy on a server, OBProxy provides the proxy service of OceanBase Database by exposing a socket in the format of IP address:port. You can access OceanBase Database through the socket in the same way you access MySQL databases. We recommend that you deploy OBProxy on an OBServer.
- We recommend that you deploy only one OBProxy on a server and use port 2883. If you deploy multiple OBProxies on the same server, you need to specify different ports and configuration file paths for differentiation. You can set the port number to 3306, 1521, or other numbers.
Install OBProxy
Install the OBProxy RPM package.
You can run the following commands to install OBProxy.
$rpm_dirspecifies the directory that stores the RPM package.$rpm_namespecifies the name of the RPM package.[root@xxx /]# cd $rpm_dir [root@xxx $rpm_dir]# rpm -ivh $rpm_nameNote
OBProxy is installed under the
/opt/taobao/installdirectory.Example:
[root@xxx admin]# rpm -ivh obproxy-3.2.3-20220310201314.el7.x86_64.rpm Preparing... ################################# [100%] Updating / installing... 1:obproxy-3.2.3-20220310201314.el7 ################################# [100%](Optional) Create a soft link to OBProxy.
Note
A soft link to OBProxy can hide the version information, facilitating subsequent operations.
OBProxy is installed under the
/opt/taobao/installdirectory. The home directory of the obproxy process is/opt/taobao/install/obproxy, which is a soft link that points to the directory of OBProxy of the corresponding version.[root@xxx admin]# su - admin -bash-4.2$ cd /opt/taobao/install -bash-4.2$ sudo ln -s obproxy-3.2.3 obproxy -bash-4.2$ ll total 8 drwxr-xr-x 9 root root 4096 Mar 22 10:24 ajdk-8.3.6-b129 lrwxrwxrwx 1 root root 13 Apr 28 10:25 obproxy -> obproxy-3.2.3 drwxr-xr-x 4 admin admin 4096 Apr 27 17:56 obproxy-3.2.3 -- Change the owner and group of the obproxy process to admin. [root@xxx install]# chown -R admin:admin obproxy [root@xxx install]# ll total 8 drwxr-xr-x 9 root root 4096 Mar 22 10:24 ajdk-8.3.6-b129 lrwxrwxrwx 1 admin admin 13 Apr 28 10:25 obproxy -> obproxy-3.2.3 drwxr-xr-x 4 admin admin 4096 Apr 27 17:56 obproxy-3.2.3Establish an operation log directory for the obproxy process.
The operation log directory of the obproxy process points to
/home/admin/logs/obproxy/logthrough a soft link.[root@xxx admin]# su - admin -bash-4.2$ mkdir -p /home/admin/logs/obproxy/log -bash-4.2$ for t in {log};do ln -s /opt/taobao/install/obproxy/$t /home/admin/logs/obproxy/log/$t; done -bash-4.2$ tree /opt/taobao/install/obproxy /opt/taobao/install/obproxy |-- bin | |-- obp_xflush.py | |-- obproxy | |-- obproxyd.sh | `-- unzip.py |-- log -> /home/admin/logs/obproxy/log |-- minidump -> /home/admin/logs/obproxy/minidump |-- start_obproxy.sh `-- tools |-- dump_syms |-- log4cplus.conf |-- minidump.sh |-- minidump_stackwalk `-- obproxy.sym 3 directories, 11 files
Initialize OBProxy
Initialize the OBProxy account
OBProxy needs to communicate with the backend OBServer node. Therefore, you need to create a user (proxyro) under the sys tenant of the OceanBase cluster and specify a password for the user. When you start OBProxy later, you can specify the username and password of the proxyro user in the startup parameters.
Note
OBProxy can use the proxyro user to access the OceanBase cluster. One OceanBase cluster corresponds to one proxyro user.
Example:
Create the proxyro user and grant the SELECT privilege to the user.
$ obclient -h127.1 -uroot@sys -P2881 -p -c -A
Enter password:
obclient> CREATE USER proxyro IDENTIFIED BY '**1***';
Query OK, 0 rows affected
obclient> GRANT SELECT ON *.* TO proxyro;
Query OK, 0 rows affected
obclient> SHOW GRANTS FOR proxyro;
+----------------------------------+
| Grants for proxyro@% |
+----------------------------------+
| GRANT SELECT ON *.* TO 'proxyro' |
+----------------------------------+
1 row in set
Start OBProxy
Notice
Start OBProxy from its home directory as the admin user. Problems may occur if you start OBProxy from other directories or as other users.
When OBProxy starts, it needs to know the target OceanBase cluster, which is specified by the
rootservice_listparameter.The following section takes a three-replica OceanBase cluster as an example.
[root@xxx admin]# su - admin -bash-4.2$ cd /opt/taobao/install/obproxy && bin/obproxy -r "10.10.10.1:2881;10.10.10.2:2881;10.10.10.3:2881" -p 2883 -o "observer_sys_password=$sha1_value,enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false" -c obdemoNote
- Replace the password in
$sha1_valuewith the actual password. When you set the startup parameter of OBProxy, the password is the value behindsha1instead of the original value. - The IP addresses in the sample code are for reference only. You need to enter the actual server IP address.
Parameters:
Parameter Note -rThe IP address and port number of the OBServer. -pThe service port number, which is usually set to 2883.-cThe name of the cluster. -oThe hardware or kernel parameter configuration. - Replace the password in
(Optional) If the OCP web service has been simulated, the API address can also be specified when OBProxy starts.
-bash-4.2$ cd /opt/taobao/install/obproxy && bin/obproxy -p 2883 -c obdemo -o "obproxy_config_server_url=http://10.10.10.1:8088/services?Action=GetObProxyConfig&User_ID=alibaba-inc&uid=ocpmaster,enable_cluster_checkout=false,enable_strict_kernel_release=false,enable_metadb_used=false"After OBProxy starts, you can check whether the obproxy process exists.
-bash-4.2$ ps -ef|grep obproxyYou can kill the obproxy process to stop it.
kill -9 `pidof obproxy`You do not need to specify the parameters again when OBProxy starts again because the parameters have been written into the parameter file.
cd /opt/taobao/install/obproxy && bin/obproxyThe operation logs of OBProxy are stored in
/opt/taobao/install/obproxy/log, that is,/home/admin/logs/obproxy/log.[root@xxx obproxy]# ll log lrwxrwxrwx 1 admin admin 28 Apr 27 17:56 log -> /home/admin/logs/obproxy/log
OceanBase Database connection example
When you connect to OceanBase Database through OBProxy, you must combine the cluster name, instance name, and username. Valid format: Username@Tenant name#Cluster name or Cluster name:Tenant name:Username.
$ obclient -h10.10.10.1 -uroot@sys#obdemo -P2883 -p -c -A oceanbase
Enter password:
or
$ obclient -h10.10.10.1 -uobdemo:sys:root -P2883 -p -c -A oceanbase
Enter password:
Adjust OBProxy parameters
The following part shows the parameter configurations of OBProxy. You can adjust the parameter configurations to reduce the operation log volume or CPU consumption as needed.
obclient> ALTER PROXYCONFIG SET slow_proxy_process_time_threshold='1000ms';
Query OK, 0 rows affected
obclient> ALTER PROXYCONFIG SET xflush_log_level=ERROR;
Query OK, 0 rows affected
obclient> ALTER PROXYCONFIG SET syslog_level=WARN;
Query OK, 0 rows affected
obclient> ALTER PROXYCONFIG SET enable_compression_protocol=false;
Query OK, 0 rows affected
obclient> SHOW PROXYCONFIG LIKE '%compress%'\G
*************************** 1. row ***************************
name: enable_compression_protocol
value: False
info: if enabled, proxy will use compression protocol with server
need_reboot: false
visible_level: USER
*************************** 2. row ***************************
name: enable_syslog_file_compress
value: False
info: Whether to enable archive log compression
need_reboot: false
visible_level: SYS
2 rows in set