AntDB Installation and Deployment Documentation - P3
Tags: database
Published: 2023-07-28 02:03:00

## Centralized master node installation

**_Installation with RPM package (not recommended)_**

**Dependency package installationdependence**

For offline environment, it is recommended to build a local yum source on the host computer through the image file of the operating system to facilitate the installation of dependencies. Under cento or redhat operating system, execute the following command to install the dependencies.

```
sudo yum install -y perl-ExtUtils-Embed 
sudo yum install -y flex 
sudo yum install -y bison 
sudo yum install -y readline-devel 
sudo yum install -y zlib-devel 
sudo yum install -y openssl-devel 
sudo yum install -y pam-devel 
sudo yum install -y libxml2-devel 
sudo yum install -y libxslt-devel 
sudo yum install -y openldap-devel 
sudo yum install -y python-devel 
sudo yum install -y gcc-c++  
```
For other operating systems, please just change the installation command, and the dependency package names will remain the same. Some dependencies do not provide libssh2 package, you can install it by compiling the source code.

• Download at: https://www.libssh2.org/download/

• Source code compilation and installation (executed by root).

```
wget https://www.libssh2.org/download/libssh2-1.9.0.tar.gz 
tar xzvf libssh2-1.9.0.tar.gz 
cd libssh2-1.9.0 
./configure 
make 
make install 
```
**Installing RPM packages**

Upload the RPM package provided by the deliverer to the server and install it under root or a user with sudo privileges. Install to the default path /opt/app/antdb.

```
sudo rpm -ivh antdb-xxx.rpm 
```
If you want to install to other paths, you can do so as follows:

```
sudo rpm -ivh antdb-xxx.rpm --relocate=/opt/app/antdb=$ADBHOME 
$ADBHOME as a custom directory, the name is best to be known by its name, e.g.: 
/home/antdb/app/antdb 
```
After the RPM package is installed, the value of the variable ADB_HOME will either be /opt/app/antdb, or a directory of your choice. Next, you need to modify the directory permissions.

```
sudo chown -R antdb:antdb $ADBHOME 
sudo chmod -R 755 $ADBHOME  
```
**Configure Environment Variables**

After installing the RPM package, executable files such as initdb and pg_ctl will be created in the bin directory of the specified directory (i.e. $ADBHOME directory). To initialize the database you also need to configure the PATH variable in order to do so. Append the following to the hidden file .bashrc under the current user (execute vim ~/.bashrc to open the file).

```
export ADBHOME=/opt/app/antdb 
export PATH=$ADBHOME/bin:$PATH 
export LD_LIBRARY_PATH=$ADBHOME/lib:$LD_LIBRARY_PATH 
export PGDATABASE=postgres 
```
Note: ADBHOME needs to be set according to the installation path of the RPM package. Then just execute the following command to make it effective.

source ~/.bashrc 
**_Install with tar package_**

Copy the installation package (ADB-Community.tar.gz) to the directory of AntDB user (e.g. uatadb), and modify the permissions of the package.

```
chown -R uatadb:uatadb ADB-Community.tar.gz #Change the user permissions of the installer to uatadb 
```
Log in to the new user to install AntDB.

```
su - uatadb  #Login to the newly created AntDB user 
tar -xzvf ADB-Community.tar.gz  #Unzip the installation package 
cd ADB-Community  #Enter the unzipped directory ADB-Community with the cd command. 
```
Use the tarball installation, and execute the AntDB_install.sh script to achieve interactive installation and silent installation.

**Interactive installation**

Execute sh AntDB_install.sh under ADB-Community for interactive installation of AntDB.

```
sh AntDB_install.sh 
```
The interactive installation can be customized in three places, as shown below. You can choose the default value or customize it. In the second place, choose the default value or "c", which means the installation is centralized database.

```
# Step one: 
# Select whether to agree to the user agreement, only if you agree(Y) can you continue to install, if not (N), it will exit the installation. 
Do you agree?(Y/N)[Default:Y] 
You input: 
OK, you agree to the agreement. continue... 
check_agreement...success. 
# Step two: 
# Select the mode in which you want to install, centralized (c), distributed (d). The default selection is c, for a centralized installation. Enter Q to abort this installation. 
# Here, we choose c for a centralized database installation 
Please enter the deployment mode "(c)entralized" or "(d)istributed" or "Q" to exit the installation.[Default:centralized]c 
You input : c 
# Step three: 
# Fill in the installation path. Note: You need to fill in the absolute path. 
# If the user does not fill in the absolute path, just enter, it will be installed to the default path. Enter Q to abort this installation. 
Please enter a valid empty directory to install antdb. Or enter "Q/q" to exit the installation.[Default:/data/adb01/app/antdb] 
You input : 
Use default install path:[/data/adb01/app/antdb]. continue... 
check install path... 
check install path ...success. 
decompress_package... 
decompress_package...success. 
copy files... 
copy files...success. 
set bash environment... 
please excute cmd 'source /data/adb01/.bashrc' to make the environment variables take effect. 
set bash environment...success. 
set kernel config... 
Please refer to the following files in the installation directory to manually set the recommended kernel config. 
/data/adb01/app/antdb/setup/common/kernel_limits.conf 
/data/adb01/app/antdb/setup/common/kernel_sysctl.conf 
antdb install ...success. 
```
After the above execution, according to the prompt, you need to source the environment variables, and after the source is done, the installation of the binaries is finished.

```
source /data/adb01/.bashrc 
```
**Silent form installation**

Execute sh AntDB_install.sh -s under ADB-Community for non-interactive installation of AntDB.

```
sh AntDB_install.sh -s 
```
By default, the silent installation selects the centralized version and installs in the default path. After execution, you need to source the environment variable, and after source, the binary is installed.

```
source /data/adb01/.bashrc 
```
**_Initialize the data directory_**

Before initializing, you need to determine the data storage directory of AntDB, which in this document is assumed to be: /data/antdb/data. The initialization is done via the initdb command as follows.

```
initdb -D /data/uat/data --wal-segsize=1024 
```
The data directory is not required to exist, if it already exists, make sure the directory is empty. The antdb operating system user needs to have read and write access to the data directory. After the initialization is complete, a series of files and directories will be created in the /data/antdb/data directory.

_**Modify database parameters**_

In the data directory, the file with the file name postgresql.conf is the configuration file for the database parameters, and the user can modify this file to change the database parameters. The configuration can be appended at the end of the file.

```
cat >> /data/uat/data/postgresql.conf <<EOF 
listen_addresses='*' 
superuser_reserved_connections=13 
tcp_keepalives_idle=60 
tcp_keepalives_interval=5 
tcp_keepalives_count=10 
work_mem=16MB 
min_wal_size=2GB 
maintenance_work_mem=1GB 
max_stack_depth=7000 
wal_sync_method=open_datasync 
wal_compression=on 
wal_log_hints=on 
checkpoint_timeout=15min 
checkpoint_completion_target=0.9 
archive_mode=on 
archive_command='/bin/date' 
wal_keep_segments=64 
log_destination='csvlog' 
logging_collector=on 
log_directory='pg_log' 
log_rotation_size=100MB 
log_min_messages=error 
log_statement=ddl 
track_activity_query_size=2048 
autovacuum_max_workers=5 
autovacuum_vacuum_threshold=500 
autovacuum_analyze_threshold=500 
max_locks_per_transaction=256 
```
The following parameters, which need to be determined according to the actual requirements, are replaced by the bolded and italicized parts.

• port=custom database port number, recommended to be set to 15432 if not required.

• max_connections=custom maximum number of connections.

• max_prepared_transactions=equal to the maximum number of connections.

• max_worker_processes=cpu * 2.

• shared_buffers=physical_memory * 25%GB.

• effective_cache_size=physical_memory * 75%GB.

• max_wal_size=2 * shared_buffersGB.

• random_page_cost= set to 1 if SSD disks; keep the default value of 4 if SATA disks.

_**Configure AntDB whitelist**_

There is a file named pg_hba.conf in the data directory of AntDB, this file is the file to configure the access whitelist, the configuration format is as follows.

```
# TYPE DATABASE USER ADDRESS METHOD 
```
ADDRESS consists of IP network segment/subnet mask, please configure it by yourself according to the actual situation. For example, add a configuration in hba that allows IP segments connected to the database to access all databases through md5 authentication.

```
cat >> /data/uat/data/pg_hba.conf << EOF 
host  all  all  10.0.0.0/8  md5 
EOF 
```
Note: IPV4 or IPV6 addresses can be specified in host, but the specification needs to be unified. That is: either specify the IPV4 address uniformly, or the IPV6 address uniformly. The details can be found at: https://www.postgresql.org/docs/13/auth-pg-hba-conf.html

**_Start the database_**

After initialization, you can start the database with the pg_ctl command, -D refers to the data directory specified during initialization.

```
pg_ctl start -D /data/antdb/data 
```
After the initialization is completed, you can use the psql command to log in to the database.

```
psql -d postgres -p 5432 
```
At this point, the AntDB database installation and startup is complete.

If you need to build a standby machine, please refer to the chapter of building a single cluster with one master and two standby machines.