Citus For PostgreSQL 部署

#配置操作系统

1.配置/etc/hosts

2.关闭防火墙和 SElinux

3.配置网络

4.配置yum 

5.配置用户和相关目录

for ip in `tail -4 /etc/hosts | awk '{print $1}'`;

do

    ssh ${ip} "useradd postgres;mkdir -p /data/;chown postgres.postgres -R /data;echo postgres | passwd --stdin postgres";

done

for ip in `tail -4 /etc/hosts | awk '{print $1}'`;

do

    ssh ${ip} "mkdir pack";

done

6.配置互信

#部署PostgreSQL 

for ip in `tail -4 /etc/hosts | awk '{print $1}'`;

do

ssh ${ip} "yum install -y \

icu.x86_64  \

libicu-devel.x86_64 \

perl-ExtUtils-Embed.noarch \

readline-devel.x86_64 \

zlib-devel.x86_64 \

globus-gssapi-gsi.x86_64 \

globus-gssapi-gsi-devel.x86_64 \

pam-devel.x86_64 \

libxml++-devel.x86_64 \

libxslt-devel.x86_64 \

openldap-devel.x86_64 \

systemd-devel.x86_64 \

tcl-devel.x86_64   \

python-devel \

flex-devel.x86_64 flex.x86_64

";

done

for ip in `tail -4 /etc/hosts | awk '{print $1}'`;

do

ssh ${ip} "cd /home/postgres/pack/postgresql-12.4;./configure \

--prefix=/data/pg12 \

--bindir=/data/pg12/bin \

--sysconfdir=/data/pg12/etc \

--libdir=/data/pg12/lib \

--includedir=/data/pg12/include \

--datarootdir=/data/pg12/share \

--datadir=/data/pg12/share \

--localedir=/data/pg12/share/locale \

--mandir=/data/pg12/share/man \

--docdir=/data/pg12/share/doc/postgresql \

--htmldir=/data/pg12/share/html \

--enable-nls='zh_CN' \

--with-pgport=10001 \

--with-perl \

--with-python \

--with-tcl \

--with-gssapi 

--with-icu \

--with-openssl \

--with-pam \

--with-ldap \

--with-systemd \

--with-readline \

--with-libxml \

--with-libxslt \

--with-zlib \

--with-segsize=1 \

--with-blocksize=8 \

--with-wal-blocksize=8";

done

#配置 PostgreSQL 环境变量

for ip in `tail -8 /etc/hosts | awk '{print $1}'`;

do

ssh ${ip} "cat > /data/pg12/postgresql.env<<EOF

export PGHOME=/data/pg12 

export PGDATA=\${PGHOME}/pgdata

export PGDATABASE=postgres 

export PGUSER=postgres 

export PGPORT=10001

export PATH=\${PGHOME}/bin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin:/usr/local/sbin:\$PATH

export LD_LIBRARY_PATH=\${PGHOME}/lib:/usr/lib:/usr/lib64:/lib:/lib64:/usr/local/lib:/usr/local/lib64:\$LD_LIBRARY_PATH

export MANPATH=\${PGHOME}/share/man:\$MANPATH 

EOF"

ssh ${ip} "echo ". /data/pg12/postgresql.env" >> /home/postgres/.bashrc";

done

#启用监听和pg_hba.conf 

#部署Citus

上传 citus 包

https://github.com/citusdata/citus

解压

安装依赖

yum install -y libcurl-devel 

#执行 ./autogen.sh 

#执行./configure 

#编译安装 make -j24 && make install 

#启动 PostgreSQL 服务器

pg_ctl start -D $PGDATA -l /tmp/logfile 

#给每个数据都需要创建扩展

#可以给 template1 创建扩展即可

psql -U postgres -d template1 -c "create extension citus"

#添加 dn 节点

SELECT master_add_node('pgcmdn02',10001);

SELECT master_add_node('pgcmdn03',10001);

SELECT master_add_node('pgcmdn04',10001);

#查看节点添加是否成功

postgres=# SELECT * FROM master_get_active_worker_nodes();

 node_name | node_port 

-----------+-----------

 pgcmdn03  |     10001

 pgcmdn02  |     10001

 pgcmdn04  |     10001

#citus 分布表分两步走

1.创建符合 PostgreSQL 规则的普通表

2.对需要分布的表进行函数分布键进行分发

CREATE TABLE tab_dist(

    id integer primary key,

name varchar not null,

age integer,

    carrer varchar,

create_time timestamp default now() not null

);

postgres=# SELECT * FROM create_distributed_table('tab_dist','id');

 create_distributed_table 

--------------------------

 

(1 row)

#数据分布的列

SELECT a.*,b.*

FROM pg_dist_placement AS a,

     pg_dist_node b

WHERE a.groupid = b.groupid

  AND b.noderole = 'primary'

  AND a.sharedid = (

  SELECT get_shard_id_for_distribution_column('tab_dist','id'));



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章