(Optional) Deploy ODP

2024-06-28 05:30:29  Updated

OceanBase Database Proxy (ODP), also known as OBProxy, is a database proxy middleware provided by OceanBase. ODP supports connection pool management, load balancing, and failovers. ODP is an optional component. You can determine whether to deploy it based on your application requirements and scenarios.

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 address: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 instance on a server and use port 2883. If you deploy multiple ODPs 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 port numbers.

Procedure

Step 1: Install the ODP RPM package

In the following commands, $rpm_dir specifies the directory in which the RPM package is stored, and $rpm_name specifies the name of the RPM package.

[root@xxx /]# cd $rpm_dir
[root@xxx $rpm_dir]# rpm -ivh $rpm_name

Note

The ODP software is installed by default in the /opt/taobao/install directory. If you need to specify another directory, you can do so by setting the --prefix parameter. For example, to install in the /home/admin directory, set rpm -ivh --prefix=/home/admin $rpm_name.

Here is an example:

[root@xxx admin]# rpm -ivh obproxy-4.0.0-20230109154442.el7.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:obproxy-4.0.0-20230109154442.el7 ################################# [100%]

Step 2: Configure directories

  1. (Optional) Create a soft link to ODP.

    Note

    A soft link to ODP can hide the version information, facilitating subsequent operations.

    ODP is installed in 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$ ls
    ajdk-8.3.6-b129  obproxy-4.0.0
    # Create a soft link to ODP.
    -bash-4.2$ sudo ln -s obproxy-4.0.0 obproxy
    [sudo] password for admin:
    -bash-4.2$ ll
    total 8
    drwxr-xr-x 9 root  root  4096 Sep 26 15:24 ajdk-8.3.6-b129
    lrwxrwxrwx 1 root  root    13 Jan 29 16:51 obproxy -> obproxy-4.0.0
    drwxr-xr-x 5 admin admin 4096 Jan 29 16:42 obproxy-4.0.0
    
    -- 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 Sep 26 15:24 ajdk-8.3.6-b129
    lrwxrwxrwx 1 admin admin   13 Jan 29 16:51 obproxy -> obproxy-4.0.0
    drwxr-xr-x 5 admin admin 4096 Jan 29 16:42 obproxy-4.0.0
    
  2. Establish an operation log directory for the obproxy process.

    The operation log directory of the obproxy process points to /home/admin/logs/obproxy/log through a soft link.

    [root@xxx admin]# su - admin
    # Create a log directory
    -bash-4.2$ mkdir -p /home/admin/logs/obproxy/log
    # View the obproxy process directory
    -bash-4.2$ tree /opt/taobao/install/obproxy
    /opt/taobao/install/obproxy
    |-- bin
    |   |-- obp_xflush.py
    |   |-- obproxy
    |   |-- obproxyd.sh
    |   `-- unzip.py
    |-- lib
    |   |-- libgpr.so.7
    |   |-- libgrpc++.so.1
    |   |-- libgrpc++_cronet.so.1
    |   |-- libgrpc.so.7
    |   |-- libgrpc_cronet.so.7
    |   |-- libobproxy_so.so
    |   |-- libprotobuf.so.18
    |   `-- libstdc++.so.6
    |-- 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, 20 files
    

Step 3: 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.

Here is an example:

Create the proxyro user and grant the SELECT privilege to the user.

$obclient -hxxx.xxx.xxx.1 -P2881 -uroot@sys -p******

obclient [(none)]> CREATE USER proxyro IDENTIFIED BY '******';
Query OK, 0 rows affected

obclient [(none)]> GRANT SELECT ON *.* TO proxyro;
Query OK, 0 rows affected

obclient [(none)]> SHOW GRANTS FOR proxyro;
+----------------------------------+
| Grants for proxyro@%             |
+----------------------------------+
| GRANT SELECT ON *.* TO 'proxyro' |
+----------------------------------+
1 row in set

Step 4: 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.

  1. When ODP starts, it needs to know the target OceanBase cluster, which is specified by the rootservice_list parameter.

    Here is an example:

    cd /opt/taobao/install/obproxy && bin/obproxy -r "xxx.xxx.xxx.1:2881;xxx.xxx.xxx.2:2881;xxx.xxx.xxx.3:2881" -p 2883 -o "observer_sys_password=$sha1_value,enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false" -c tenant_name
    

    Note

    • Replace the password in $sha1_value with the actual password. When you set the startup parameter of ODP, the password is the value behind sha1 instead of the original value. For example, if the password of the proxyro user is 123456, the observer_sys_password parameter must be set to 7c4a8d09ca3762af61e59520943dc26494f8941b.
    • The IP addresses in the sample code are for reference only. You need to enter the actual server IP address.

    The parameters are described in the following table:

    Parameter Description
    -r The IP address and port of the OBServer node.
    -p The service port number, which is usually set to 2883.
    -c The name of the cluster.
    -o The hardware or kernel parameter configuration.

    Here is an example:

    [root@xxx admin]# su - admin
    -bash-4.2$ cd /opt/taobao/install/obproxy && bin/obproxy -r "xxx.xxx.xxx.1:2881" -p 2883 -o "observer_sys_password=7c4a8d09ca3762af61e59520943dc26494f8941b,enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false" -c test3241
    bin/obproxy -r xxx.xxx.xxx.1:2881 -p 2883 -o observer_sys_password=7c4a8d09ca3762af61e59520943dc26494f8941b,enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false -c test3241
    rs list: xxx.xxx.xxx.1:2881
    listen port: 2883
    optstr: observer_sys_password=7c4a8d09ca3762af61e59520943dc26494f8941b,enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false
    cluster_name: test3241
    
  2. After ODP starts, you can check whether the obproxy process exists.

    ps -ef|grep obproxy
    

    Here is an example:

    [root@xxx admin]# ps -ef|grep obproxy
    admin     79111      0  6 17:32 ?        00:00:58 bin/obproxy -r xxx.xxx.xxx.1:2881 -p 2883 -o observer_sys_password=7c4a8d09ca3762af61e59520943dc26494f8941b,enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false -c test3241
    

What to do next

Connect to OceanBase Database

When you connect to OceanBase Database through ODP, you must combine the username, tenant name, and cluster name. The format is Username@Tenant name#Cluster name or Cluster name:Tenant name:Username.

Here is an example:

  • Use Username@Tenant name#Cluster name to connect to OceanBase Database.

    [admin@xxx /home/admin]
    $obclient -hxxx.xxx.xxx.1 -P2883 -uroot@sys#test3241 -p******
    Welcome to the OceanBase.  Commands end with ; or \g.
    ...
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    obclient [(none)]>
    
  • Use Cluster name:Tenant name:Username to connect to OceanBase Database.

    [admin@xxx /home/admin]
    $obclient -hxxx.xxx.xxx.1 -P2883 -utest3241:sys:root -p******
    Welcome to the OceanBase.  Commands end with ; or \g.
    ...
    Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    obclient [(none)]>
    

(Optional) Adjust ODP parameters

You can set parameters such as the operation log volume or CPU consumption based on the server specifications by modifying ODP parameters.

The following example shows the parameter configurations of ODP. You can adjust the parameter configurations to decrease the operation log volume or CPU consumption.

obclient [(none)]> ALTER PROXYCONFIG SET slow_proxy_process_time_threshold='1000ms';
Query OK, 0 rows affected

obclient [(none)]> ALTER PROXYCONFIG SET xflush_log_level=ERROR;
Query OK, 0 rows affected

obclient [(none)]> ALTER PROXYCONFIG SET syslog_level=WARN;
Query OK, 0 rows affected

obclient [(none)]> ALTER PROXYCONFIG SET enable_compression_protocol=false;
Query OK, 0 rows affected

obclient [(none)]> 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

References

Contact Us