You can deploy oblogproxy by using the installation package or using the source code. This topic describes how to deploy oblogproxy by using the installation package.
Background information
oblogproxy is a proxy service for managing incremental logs of OceanBase Database. It is a part of OceanBase Migration Service (OMS). Designed based on obcdc, oblogproxy provides links for applications to access and manage real-time incremental logs of OceanBase Database.
oblogproxy allows you to subscribe to incremental logs in isolated networks and supports multiple access methods. You can perform the following steps to configure and use oblogproxy.
Install oblogproxy
Notice
- You do not need to specify information about OceanBase clusters when you configure oblogproxy. Technically, oblogproxy can subscribe to multiple OceanBase clusters when it is connected to all OBServer nodes by using the specified account and password of the sys tenant of each cluster. For security, the account and password are not exposed to oblogclient users.
- oblogproxy is stateless. It obtains information about databases and tables for data subscription from oblogclient. The information such as the timestamps of incremental logs is also stored by oblogclient. When oblogproxy resumes the connection to an OBServer node after disconnection, it is equivalent to creating a new connection.
- oblogproxy consumes a large amount of memory. We recommend that you deploy oblogproxy and the OBServer nodes on different servers to avoid affecting the database performance.
Download and install oblogproxy
You can download the package of oblogproxy V1.1.0 from the GitHub open-source community.
Decompress the package to the installation directory, which is /usr/local in this example.
Run the following command to decompress the package:
tar -zxf oblogproxy-ce-for-4x-xxxx.tar.gz -C /usr/local
After decompression, specify the temporary environment variables.
Specify the path for running logproxy.
export PATH=$PATH:/usr/local/oblogproxy/binSpecify the dependency path.
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/oblogproxy/liboblog
Configure the sys tenant
For security, you must specify the username and password of a user for oblogproxy. Only a user in the sys tenant of OceanBase Database can be connected.
Notice
The username here does not contain the cluster name or tenant name.
sh run.sh config_sys sys_user sys_pwd
where
sys_userspecifies the username.sys_pwdspecifies the user password.
Here is an example:
sh run.sh config_sys sys passwd
Run oblogproxy
Go to the oblogproxy directory.
cd /usr/local/oblogproxy
Run the following command to start the service:
./run.sh start
By default, the 2983 port is listened to. You can set the service_port field in the conf.json file to change the port. The service logs of oblogproxy are stored in the logs/ directory. The service logs of the LogReader thread are stored in the run/{client-id}/logs/ directory.
Note
You can then use oblogclient for OceanBase data subscription. For more information, see oblogclient documentation.
Use oblogclient for data subscription
You can use oblogclient to subscribe to data from OceanBase Database. Make sure that you have installed Maven dependencies before use.
<dependency>
<groupId>com.oceanbase.logclient</groupId>
<artifactId>logproxy-client</artifactId>
<version>1.0.7</version>
</dependency>
After that, you can configure the oblogclient by referencing the following sample code:
ObReaderConfig config = new ObReaderConfig();
// Specify the IP addresses of OceanBase root servers and separate multiple IP addresses with semicolons (;) in the following format: ip1:rpc_port1:sql_port1;ip2:rpc_port2:sql_port2
config.setRsList("xxx.xxx.xxx.1:2882:2881;xxx.xxx.xxx.2:2882:2881");
// Specify the username and password (user tenant).
config.setUsername("r***");
config.setPassword("****");
// Specify the UNIX start timestamp in seconds. A value of 0 specifies to start the client from the current time.
config.setStartTimestamp(0L);
// Specify the subscription allowlist in the tenant.db.table format. Use asterisks (*) as wildcards.
config.setTableWhiteList("sys.*.*");
// Specify the IP address of the server where oblogproxy is deployed to create the client instance.
LogProxyClient client = new LogProxyClient("xxx.xxx.xxx.1", 2983, config);
// Add the RecordListener.
client.addListener(new RecordListener() {
@Override
public void notify(LogMessage message){
// Process the message.
}
@Override
public void onException(LogProxyClientException e) {
// Handle the error.
if (e.needStop()) {
// Stop the client when an unrecoverable exception occurs.
client.stop();
}
}
});
// Start the client.
client.start();
client.join();
More information
For more information about oblogclient, see oblogclient.