Deploy ODP by using the CLI

2025-01-24 01:53:30  Updated

OceanBase Database Proxy (ODP) can forward data access requests of users to correct OBServer nodes. The results are returned to the clients through ODP. This topic describes how to install ODP on the CLI by using the RPM package.

You can also deploy ODP in the following ways:

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 number. You can access OceanBase Database by using 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 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 numbers.

  • The sample IP addresses in this topic are masked. You must specify the actual IP addresses of your servers.

Prepare the environment

  • Architecture: x86_64 or ARM.

  • Operating system: Linux Red Hat (x86_64) of version 5, 6, 7, or later.

  • CPU: ODP occupies about 70% of the resources of a CPU core during operation.

  • Memory: ODP occupies about 100 MB of memory during operation.

  • Disk space: The disk space is determined by your data size. We recommend that you use a disk that has 10 GB or more of space.

  • OceanBase cluster: For more information, see Overview.

Install ODP

  1. Run the following commands as the root user to grant or revoke the write privilege on the sudoers file:

    # Grant the write privilege on the sudoers file.
    chmod u+w /etc/sudoers
    echo 'admin ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
    
    # Revoke the write privilege on the sudoers file.
    chmod u-w /etc/sudoers
    
  2. Run the following commands to install the RPM package of ODP:

    -bash-4.2$ cd $rpm_dir
    -bash-4.2$ sudo rpm -ivh $rpm_name
    

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

    Note

    • You can contact OceanBase Technical Support to obtain the latest ODP RPM package, or go to the OceanBase Download Center to search for OceanBase Database Proxy and download the corresponding ODP RPM package based on your requirements.

    • The default installation directory is /opt/taobao/install for ODP Enterprise Edition and /home/admin for ODP Community Edition.

    Here is an example:

    -bash-4.2$ sudo rpm -ivh obproxy-4.0.0-20221103165243.el7.x86_64.rpm
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:obproxy-4.0.0-20221103165243.el7 ################################# [100%]
    
  3. (Optional) Create soft links to ODP.

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

    The installation directory of ODP is /opt/taobao/install. The home directory of the ODP process is /opt/taobao/install/obproxy, which is a soft link that points to the directory of ODP of the corresponding version.

    -bash-4.2$ cd /opt/taobao/install
    -bash-4.2$ sudo ln -s obproxy-4.0.0 obproxy
    -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 Nov 14 12:03 obproxy -> obproxy-4.0.0
    drwxr-xr-x 4 admin admin 4096 Nov 14 11:59 obproxy-4.0.0
    
    # Change the owner and group of the ODP process to admin.
    -bash-4.2$ sudo chown -R admin:admin obproxy
    -bash-4.2$ ll
    total 8
    drwxr-xr-x 9 root  root  4096 Sep 26 15:24 ajdk-8.3.6-b129
    lrwxrwxrwx 1 admin admin   13 Nov 14 12:03 obproxy -> obproxy-4.0.0
    drwxr-xr-x 4 admin admin 4096 Nov 14 11:59 obproxy-4.0.0
    

Initialize ODP

ODP needs to communicate with the backend OBServer node. Therefore, you must create the proxyro user and specify the password for ODP in the sys tenant of the OceanBase cluster. If you start ODP later, you can specify the username and password of the proxyro user in the startup parameters.

Note

ODP uses the proxyro user to access the OceanBase cluster. One proxyro user can be used for accessing one OceanBase cluster.

To check whether a proxyro user exists in the cluster, perform the following steps:

  1. Log in to the cluster by creating an IP address-based direct connection.

    obclient -h10.10.10.1 -uroot@sys -P2881 -p -c
    
  2. Run the following command to query the users in the sys tenant:

    obclient> select user,password from mysql.user;
    

    If the output shows that a proxyro user already exists, you can directly start ODP. If the output shows that no proxyro user exists, run the command to create one.

  3. Create a proxyro user.

    Here is an example:

    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

You can use either of the following methods to start an ODP process:

  • Specify the -r parameter in the process startup command to query the RootServer information of the OceanBase cluster.

    This method does not require other configurations and is usually used in the development and debugging phase. If the RootService list in the OceanBase cluster changes after you start ODP by using this method, you need to manually modify the setting of the rootservice_list parameter and restart ODP for the change to take effect.

  • Specify the obproxy_config_server_url parameter in the process startup command to query the RootServer information of the OceanBase cluster.

    This method requires the obproxy_config_server_url parameter, thus relying on the startup of the config server. We recommend that you use this method to start an ODP.

Notice

To start the ODP, log in as the admin user and run the startup command in the home directory of the ODP software. The ODP startup fails if you log in as other users or run the startup command in other directories.

Procedure

  1. Log in as the admin user to the server that hosts the ODP to be started.

  2. Run the following command in the directory where the ODP is installed to start the ODP.

    Note

    Before you start the ODP, you can run the ./bin/obproxy -h command to query the startup parameters of the ODP.

    1. Method 1: Run the following command to specify the -r option in the startup command:

      ./bin/obproxy -p <obproxy_port> -s <rpc_port> -r <'ip:port'> -n <appname> -o -c <cluster_name>
      

      The parameters are described as follows:

      • -p: specifies the port number listened to by ODP. The MySQL client uses this port to access OceanBase Database. The parameter is required at initial startup. You do not need to specify this parameter in subsequent startups or upgrades.

      • -s: specifies the remote procedure call (RPC) service listening port.

      • -r: specifies the IP address and port number of the RootServer in the specified OceanBase cluster. The port is the SQL port of the OBServer node, not the RPC port.

      • -n: specifies the application name of the ODP to be started. This parameter is optional.

        You can use the app_name parameter to change the application name of the ODP. The default value is undefined.

      • -o: specifies the hardware or kernel parameter settings. If you do not specify this parameter, the default system settings are used.

      • -c: specifies the OceanBase cluster.

      Here is an example:

      [admin@001 obproxy]$ ./bin/obproxy -p 2883 -s 2885 -r'10.10.10.1:2881;10.10.10.2:2881;10.10.10.3:2881' -o observer_sys_password=$sha1_value,obproxy_sys_password=$sha1_value,enable_cluster_checkout=false,proxy_id=1,client_session_id_version=2 -n test -c mycluster
      

      Notice

      • observer_sys_password must be the password of the proxyro user of OceanBase Database. obproxy_sys_password is the password of the root@proxysys account for logging in to the ODP.

      • Replace the password in $sha1_value with the actual password. The password is an SHA1-hashed value rather than the original value. For example, if the password of the proxyro user is 123456, the observer_sys_password parameter must be set to 7c4a8d09ca3762af61e59520943dc26494f8941b.

      • In this example, proxy_id is set to 1. You can set proxy_id to any value within the range 0 to 8191, except 2. Make sure that the specified value is not duplicate with that of other ODPs. For more information, see proxy_id.

    2. Method 2: Run the following command to specify the obproxy_config_server_url parameter in the startup command:

      ./bin/obproxy -p <obproxy_port> -s <rpc_port> -n <appname> -o obproxy_config_server_url='your_config_url'
      

      The parameters are described as follows:

      • -p: specifies the port number listened to by the ODP. The MySQL client uses this port to access OceanBase Database. The parameter is required at initial startup. You do not need to specify this parameter in subsequent startups or upgrades.

      • -s: specifies the RPC service listening port.

      • -n: specifies the application name.

        You can use the app_name parameter to change the application name of the ODP. The default value is undefined.

      • -o: specifies the hardware or kernel parameter settings. If you do not specify this parameter, the default system settings are used.

      • obproxy_config_server_url: specifies the URL of the config server.

      Here is an example:

      [admin@001 obproxy]$ ./bin/obproxy -p 2883 -s 2885 -n test -o obproxy_config_server_url='http://xx.xx.xx.xx:8877/obproxy_config',observer_sys_password=$sha1_value,obproxy_sys_password=$sha1_value,proxy_id=1,client_session_id_version=2
      

      Notice

      • observer_sys_password must be the password of the proxyro user of OceanBase Database. obproxy_sys_password is the password of the root@proxysys account for logging in to the ODP.

      • Replace the password in $sha1_value with the actual password. The password is an SHA1-hashed value rather than the original value. For example, if the password of the proxyro user is 123456, the observer_sys_password parameter must be set to 7c4a8d09ca3762af61e59520943dc26494f8941b.

      • In this example, proxy_id is set to 1. You can set proxy_id to any value within the range 0 to 8191, except 2. Make sure that the specified value is not duplicate with that of other ODPs. For more information, see proxy_id.

  3. Run the following command to check whether the ODP process exists:

    [admin@001 ~]$ ps -ef | grep obproxy
    

Note

The operation logs of ODP are stored in /opt/taobao/install/obproxy/log, namely, /home/admin/logs/obproxy/log.

OceanBase Database connection example

When you connect to OceanBase Database through ODP, you must combine the cluster name, instance name, and username. Four formats are supported and the first two are commonly used.

  • User_name@Tenant_name#Cluster_name
  • Cluster_name:Tenant_name:User_name
  • Cluster_name-Tenant_name-User_name
  • Cluster_name.Tenant_name.User_name
$ obclient -h10.10.10.1 -uroot@sys#mycluster -P2883 -p -c -A
Enter password:
# Alternatively, use the following command:
$ obclient -h10.10.10.1 -umycluster:sys:root -P2883 -p -c -A
Enter password:

FAQ

Symptom: The following error is returned when ODP is used to connect to OceanBase Database:

ERROR 2013 (HY000): Lost connection to MySQL server at 'reading authorization packet', system error: 0

Possible causes: The password specified by the observer_sys_password parameter in ODP is inconsistent with the password of the proxyro user in OceanBase Database. As a result, ODP cannot use this user account to communicate with an OBServer node.

Solution: Use either of the following two methods based on the actual situation:

  1. Connect to OceanBase Database directly, and change the password of the proxyro user to the one that you set for the observer_sys_password parameter when you start ODP.

    ALTER USER proxyro IDENTIFIED BY 'password';
    
  2. Log in to ODP with the root@proxysys account and change the password of proxyro@sys. Then, restart ODP.

    alter proxyconfig set observer_sys_password = 'password';
    

Notice

In the preceding statement, the value of password must be the original password rather than the SHA1-hash value of the password.

Contact Us