【AntDB Installation and Deployment Documentation】ETCD+patroni for High Availability (1)
ETCD+patroni for high availability
etcd is responsible for the storage of cluster status information, which is used to contact each node, and patroni is responsible for providing high availability service for the cluster, the collection of both provides failover high availability service for AntDB standalone cluster.
IP | Component | Remarks |
10.20.16.227 | AntDB, ETCD, Patroni | Master Node |
10.20.16.228 | AntDB, ETCD, Patroni | Backup Nodes |
10.20.16.214 | AntDB, ETCD, Patroni | Backup Nodes |
**Note:** The following steps are all required to be executed on all hosts where the primary and backup are located. Therefore, the following steps need to be performed here on all 3 servers.
Install python3
1. Download the installation package, the recommended version is greater than or equal to 3.7, or get the installation package from AntDB operation and maintenance staff.
https://www.python.org/downloads/source/
To solve the problem that the '_ctypes' module of python cannot be found, you need to install this package additionally
# root user to execute it, or use antdb sudo to execute it
yum install -y libffi-devel
2. decompress it.
tar -zxvf Python-3.7.0.tgz
or
unzip Python-3.7.0.tgz
3, compile and install, here executed under the root user.
cd Python-3.7.0
./configure --prefix=/usr/local/
make
make install
4, create hyperlink
ln -s /usr/local/bin/pip3 /usr/bin/pip3
ln -s /usr/local/bin/python3 /bin/python3
5、Check python3 version
python3 -V
Install psycopg2
Install dependencies.
yum install -y postgresql-devel
Use the pip command to install psycopg2 or psycopg2-binary.
pip3 install psycopg2
If the pip command fails to install, you can download the psycopg2 installation package and install it manually.
tar -xzvf psycopg2-2.9.3.tar.gz
cd psycopg2-2.9.3
python3 setup.py build
python3 setpy.py install
Check if the installation is successful
python3 -c "import psycopg2; print(psycopg2.__version__)"
Normal result: No error is reported and the version number is output.
Install patroni
Install using the pip command under the root user.
pip3 install patroni
If the installation package is available, you can also install it by following, --find-links is the file path.
tar -xzvf patroni-2.1.2.tar.gz
pip3 install --no-index --find-links=file:/data1/adbpuq/patroni_offline_pg13/patroni-2.1.2 patroni
pip3 install --no-index --find-links=file:/data1/adbpuq/patroni_offline_pg13/patroni-2.1.2 python-etcd
Check Patroni
which patroni
patroni -h
Install etcd
Executed by root user
yum -y install etcd
Or install via the installation package at
tar -xzvf etcd-v3.3.18-linux-amd64.tar.gz
cd etcd-v3.3.18-linux-amd64
cp etcd /usr/bin
cp etcdctl /usr/bin
Check etcd
which etcd
which etcdctl
Build ETCD cluster
Configure etcd
Execute under the root user
1. Create etcd configuration directory and data directory
mkdir /etc/etcd
mkdir -p /var/lib/etcd/data
2. Configure etcd
Write the configuration of etcd to the yaml file, for example, on the host with IP 10.20.16.227, the configuration is as follows.
cat > /etc/etcd/conf.yaml <<EOF
name: etcd-1
data-dir: /var/lib/etcd/data
listen-client-urls: http://10.20.16.227:12379,http://127.0.0.1:12379
advertise-client-urls: http://10.20.16.227:12379
listen-peer-urls: http://10.20.16.227:12380
initial-advertise-peer-urls: http://10.20.16.227:12380
initial-cluster: etcd-1=http://10.20.16.227:12380,etcd-2=http://10.20.16.228:12380,etcd-3=http://10.20.16.214:12380
initial-cluster-token: etcd-cluster-token
initial-cluster-state: new
EOF
Parameter descriptions.
• name: Each node is different, and each member must have a unique name.
• data-dir: The directory of the etcd data file created above, where the data is saved when the service is running.
• listen-client-urls: listen address, the address of the external service.
• advertise-client-urls: the listening address used to notify other ETCD nodes that clients are accessing this node.
• listen-peer-urls: the listening address for this node to exchange data with other nodes (election, data synchronization), used to listen to other members.
• initial-advertise-peer-urls: address to notify other nodes to exchange data (election, synchronization) with this node
• initial-cluster: used to bootstrap the initial cluster configuration, information about all nodes in the cluster. The format is: name specified by name=address specified by initial-advertise-peer-urls.
• initial-cluster-token: Unique cluster identifier, nodes with the same identifier will be considered as being in a cluster
Here the structure of the cluster is one master and two standby, distributed on three hosts, the IP addresses of the three hosts are 10.20.16.227, 10.20.16.228, 10.20.16.214.
# Note that the names of the three machines cannot be the same
Host 10.20.16.228 etcd is configured as follows
cat > /etc/etcd/conf.yaml <<EOF
name: etcd-2
data-dir: /var/lib/etcd/data
listen-client-urls: http://10.20.16.228:12379,http://127.0.0.1:12379
advertise-client-urls: http://10.20.16.228:12379
listen-peer-urls: http://10.20.16.228:12380
initial-advertise-peer-urls: http://10.20.16.228:12380
initial-cluster: etcd-1=http://10.20.16.227:12380,etcd-2=http://10.20.16.228:12380,etcd-3=http://10.20.16.214:12380
initial-cluster-token: etcd-cluster-token
initial-cluster-state: new
EOF
Host 10.20.16.214 etcd is configured as follows
cat > /etc/etcd/conf.yaml <<EOF
name: etcd-3
data-dir: /var/lib/etcd/data
listen-client-urls: http://10.20.16.214:12379,http://127.0.0.1:12379
advertise-client-urls: http://10.20.16.214:12379
listen-peer-urls: http://10.20.16.214:12380
initial-advertise-peer-urls: http://10.20.16.214:12380
initial-cluster: etcd-1=http://10.20.16.227:12380,etcd-2=http://10.20.16.228:12380,etcd-3=http://10.20.16.214:12380
initial-cluster-token: etcd-cluster-token
initial-cluster-state: new
EOF