OceanBase Database Proxy (ODP) can forward the data access requests of users to the correct OBServer nodes. The results are returned to the clients through ODP. This topic describes how to install ODP by using the ODP package.
Notice
- After you deploy ODP on a server, ODP provides the proxy service of OceanBase Database by exposing a socket in the format of
ip:port. You can access OceanBase Database through the socket in the same way you access MySQL databases. We recommend that you deploy ODP on an OBServer node. - We recommend that you deploy only one ODP on a server and use port 2883. If you deploy multiple ODP services 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 ODP
Install the ODP RPM package.
$rpm_dirspecifies the directory in which the RPM package is stored.$rpm_namespecifies the name of the RPM package.[root@xxx /]# cd $rpm_dir [root@xxx $rpm_dir]# sudo rpm -ivh $rpm_nameNote
ODP is installed in the `/opt/taobao/install` directory.
For example:
[root@xxx admin]# sudo 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 ODP.
Note
A soft link to ODP can hide the version information, facilitating subsequent operations.
ODP is installed under the /opt/taobao/install directory. The home directory of the obproxy process is
/opt/taobao/install/obproxy, which is a soft link that points to the directory of ODP 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 ODP
Initialize the ODP account
ODP 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 ODP later, you can specify the username and password of the proxyro user in the startup parameters.
Note
ODP can use the proxyro user to access the OceanBase cluster. One proxyro user can be used for accessing one OceanBase cluster.
For 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 '******';
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 ODP
Notice
Start ODP from its home directory as the admin user. Problems may occur if you start ODP from other directories or as other users.
When ODP 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 ODP, the password is the value behindsha1instead of the original value. For example, if the password of the proxyro user is123456, theobserver_sys_passwordparameter must be set to7c4a8d09ca3762af61e59520943dc26494f8941b. - The IP addresses in the sample code are for reference only. You need to enter the actual server IP address.
The parameters are as follows:
Parameter Description -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 ODP 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 ODP 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 ODP starts again because the parameters have been written into the parameter file.
cd /opt/taobao/install/obproxy && bin/obproxyThe operation logs of ODP 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 ODP, you must combine the username, tenant name, and cluster name. 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 ODP parameters
The following part shows the parameter configurations of ODP. 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