在CentOS7.2上部署基于PostgreSQL10的citus分布式数据库

前端之家收集整理的这篇文章主要介绍了在CentOS7.2上部署基于PostgreSQL10的citus分布式数据库前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

转自citusdata官网在线文档《Multi-node setup on Fedora,CentOS,or Red Hat
在其基础上进行了些微的改动。

This section describes the steps needed to set up a multi-node Citus cluster on your own Linux machines from RPM packages.

Steps to be executed on all nodes

1. Add repository

# Add Citus repository for package manager@H_403_11@
curl https://install.citusdata@H_403_11@.com@H_403_11@/community/rpm.sh@H_403_11@ | sudo bash

2. Install Postgresql + Citus and initialize a database

# install Postgresql with@H_403_11@ Citus extension@H_403_11@
sudo yum install -y citus72_10
# initialize system database (using@H_403_11@ RHEL 6@H_403_11@ vs 7@H_403_11@ method@H_403_11@ as@H_403_11@ necessary@H_403_11@) sudo@H_403_11@ service@H_403_11@ postgresql@H_403_11@-10 initdb@H_403_11@ || sudo@H_403_11@ /usr@H_403_11@/pgsql@H_403_11@-10/bin@H_403_11@/postgresql@H_403_11@-10-setup@H_403_11@ initdb@H_403_11@ # preload@H_403_11@ citus@H_403_11@ extension@H_403_11@ echo@H_403_11@ "shared_preload_libraries@H_403_11@ = 'citus@H_403_11@'" | sudo@H_403_11@ tee@H_403_11@ -a@H_403_11@ /var@H_403_11@/lib@H_403_11@/pgsql@H_403_11@/10/data@H_403_11@/postgresql@H_403_11@.conf@H_403_11@@H_403_11@

Postgresql adds version-specific binaries in /usr/pgsql-10/bin,but you’ll usually just need psql,whose latest version is added to your path,and managing the server itself can be done with the service command.

3. Configure connection and authentication

Before starting the database let’s change its access permissions. By default the database server listens only to clients on localhost. As a part of this step,we instruct it to listen on all IP interfaces,and then configure the client authentication file to allow all incoming connections from the local network.

sudo@H_403_11@ vi /var/lib/pgsql/10@H_403_11@/data@H_403_11@/postgresql.conf@H_403_11@
# Uncomment listen_addresses for@H_403_11@ the changes to@H_403_11@ take@H_403_11@ effect
listen_addresses = '*'@H_403_11@
sudo@H_403_11@ vi /var/lib/pgsql/10@H_403_11@/data@H_403_11@/pg_hba.conf@H_403_11@
# Allow unrestricted access@H_403_11@ to@H_403_11@ nodes in@H_403_11@ the local network. The following ranges
# correspond to@H_403_11@ 24@H_403_11@,20@H_403_11@,and@H_403_11@ 16@H_403_11@-bit@H_403_11@ blocks in@H_403_11@ Private IPv4 address spaces.
local   all@H_403_11@             all@H_403_11@                                     peer   
local   replication     all@H_403_11@                                     peer
host    all@H_403_11@             all@H_403_11@             192.168@H_403_11@.7@H_403_11@.0@H_403_11@/24@H_403_11@          trust
host    all@H_403_11@             all@H_403_11@             0.0@H_403_11@.0@H_403_11@.0@H_403_11@/0@H_403_11@               md5

# Also allow the host unrestricted access@H_403_11@ to@H_403_11@ connect to@H_403_11@ itself
host    all@H_403_11@             all@H_403_11@             127.0@H_403_11@.0@H_403_11@.1@H_403_11@/32@H_403_11@            trust
host    all@H_403_11@             all@H_403_11@             ::1@H_403_11@/128@H_403_11@                 trust

【Note】

Your DNS settings may differ. Also these settings are too permissive for some environments,see our notes about Worker Security. The Postgresql manual explains how to make them more restrictive.

4. 配置防火墙

#查看@H_403_11@
firewall-cmd --zone=public@H_403_11@ --query-port=5432@H_403_11@/tcp

#添加5432端口(--permanent永久生效,没有此参数重启后失效)@H_403_11@
firewall-cmd --zone=public@H_403_11@ --add-port=5432@H_403_11@/tcp --permanent

#重新载入@H_403_11@
firewall-cmd --reload

5. Start database servers,create Citus extension

# start@H_403_11@ the db server sudo service postgresql-10@H_403_11@ restart # and@H_403_11@ make it start@H_403_11@ automatically when@H_403_11@ computer does sudo chkconfig postgresql-10@H_403_11@ on@H_403_11@@H_403_11@

You must add the Citus extension to every database you would like to use in a cluster. The following example adds the extension to the default database which is named postgres.

sudo -i@H_403_11@ -u@H_403_11@ postgres psql -c@H_403_11@ "CREATE EXTENSION citus;"@H_403_11@

Steps to be executed on the coordinator node

The steps listed below must be executed only on the coordinator node after the prevIoUsly mentioned steps have been executed.

1. Add worker node information

We need to inform the coordinator about its workers. To add this information,we call a UDF which adds the node information to the pg_dist_node catalog table,which the coordinator uses to get the list of worker nodes. For our example,we assume that there are two workers (named worker-101,worker-102). Add the workers’ DNS names (or IP addresses) and server ports to the table.

sudo -i -u postgres psql -c "SELECT@H_403_11@ * from@H_403_11@ master_add_node('192.168.7.130'@H_403_11@,5432@H_403_11@);@H_403_11@"
sudo -i -u postgres psql -c "SELECT@H_403_11@ * from@H_403_11@ master_add_node('192.168.7.131'@H_403_11@,5432@H_403_11@);@H_403_11@"

2. Verify that installation has succeeded

To verify that the installation has succeeded,we check that the coordinator node has picked up the desired worker configuration. This command when run in the psql shell should output the worker nodes we added to the pg_dist_node table above.

sudo -i@H_403_11@ -u@H_403_11@ postgres psql -c@H_403_11@ "SELECT * FROM master_get_active_worker_nodes();"@H_403_11@

Ready to use Citus

At this step,you have completed the installation process and are ready to use your Citus cluster. The new Citus database is accessible in psql through the postgres user:

sudo -i@H_403_11@ -u@H_403_11@ postgres psql

【Note】

Please note that Citus reports anonymous information about your cluster to the Citus Data company servers. To learn more about what information is collected and how to opt out of it,see Checks For Updates and Cluster Statistics.

猜你在找的CentOS相关文章