CentOS7 citus9.5 集羣安裝及管理

 

1 全部節點配置 
#------服務安裝 服務
yum update -yhtml

#------擴展依賴安裝
yum install -y epel-release && yum update -ynode

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

# install PostgreSQL with Citus extension
sudo yum install -y citus_95
sudo yum install -y postgis2_95.x86_64github

# initialize system database (using RHEL 6 vs 7 method as necessary)
sudo service postgresql-9.5 initdb || sudo /usr/pgsql-9.5/bin/postgresql95-setup initdbsql

# preload citus extension
echo "shared_preload_libraries = 'citus'" | sudo tee -a /var/lib/pgsql/9.5/data/postgresql.conf
#------配置數據庫

sudo echo "listen_addresses = '*'" | sudo tee -a /var/lib/pgsql/9.5/data/postgresql.conf
sudo echo "host all all 0.0.0.0/0 trust" | sudo tee -a /var/lib/pgsql/9.5/data/pg_hba.confjson


#-------------------------啓動服務及開機自啓--------------api

# start the db server
sudo service postgresql-9.5 restart
# and make it start automatically when computer does
sudo chkconfig postgresql-9.5 onbash

#------------------------擴展---------------curl

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

2 主節點配置

#-----配置work節點
sudo echo "worker-101 5432" | sudo -u postgres tee -a /var/lib/pgsql/9.5/data/pg_worker_list.conf
#-----從新加載配置
sudo service postgresql-9.5 reload
#-----查看work節點
sudo -i -u postgres psql -c "SELECT * FROM master_get_active_worker_nodes();"

3 表測試

#-----建立表
CREATE TABLE github_events
(
event_id bigint,
event_type text,
event_public boolean,
repo_id bigint,
payload jsonb,
repo jsonb,
actor jsonb,
org jsonb,
created_at timestamp
);
#-----表分片
SELECT master_create_distributed_table('github_events', 'repo_id', 'hash');
#-----設定分片個數(16)及每一個分片副本數(3)
SELECT master_create_worker_shards('github_events', 16, 3);

#----插入數據
INSERT INTO github_events VALUES (2489373118,'PublicEvent','t',24509048,'{}','{"id": 24509048, "url": "https://api.github.com/repos/SabinaS/csee6868", "name": "SabinaS/csee6868"}','{"id": 2955009, "url": "https://api.github.com/users/SabinaS", "login": "SabinaS", "avatar_url": "https://avatars.githubusercontent.com/u/2955009?", "gravatar_id": ""}',NULL,'2015-01-01 00:09:13');

#---刪除或修改
SELECT master_modify_multiple_shards(
'DELETE FROM github_events);

4 集羣管理
#-----查看work節點
SELECT * from master_get_active_worker_nodes();
#-----元數據查看
SELECT * from master_get_table_metadata('github_events');
#-----分區查看
SELECT * from pg_dist_partition;
#-----分片查看
SELECT * from pg_dist_shard;
#-----分片分佈查看
SELECT * from pg_dist_shard_placement;
#-----移動分片
SELECT master_copy_shard_placement(shardid, 'good_host', 5432, 'bad_host', 5432);


5 加節點及移動分片 v1->v4

5.1 加節點
a 修改pg_worker_list.conf
b 從新載入配置 select pg_reload_conf(); 或 sudo service postgresql-9.5 reload
c 查看work節點 SELECT * from master_get_active_worker_nodes();

5.2 移動分片

a 查看分片元數據
SELECT * from master_get_table_metadata('github_events');
SELECT * from pg_dist_shard;
SELECT * from pg_dist_shard_placement;
shardid | shardstate | shardlength | nodename | nodeport
---------+------------+-------------+----------+----------
102013 | 1 | 0 | v1 | 5432


shardstate 1(正常) , 3(待修復) , 4(將刪除)
b 元數據中加入新分片
INSERT INTO pg_dist_shard_placement(shardid , shardstate , shardlength , nodename , nodeport) VALUES (102021,3,0,v4,5432)
c 移動數據到新分片
SELECT master_copy_shard_placement(102021, 'v1', 5432, 'v4', 5432);
d 標記刪除分片,改數據分片此時已經脫離集羣,待刪除
UPDATE pg_dist_shard_placement SET shardstate = 4 WHERE shardid = 102021 AND nodename = 'v1' AND nodeport = 5432
e 刪除原分片數據及元數據
DROP TABLE github_events_shard_id (在對應節點上進行操做)
DELETE FROM pg_dist_shard_placement shardstate = 4

6 主節點的HA 配置參看http://www.cnblogs.com/zhangeamon/p/5465501.html 問題: 應用程序鏈接從庫對數據分片移動後不生效 總結,程序只能鏈接主數據庫,可作讀寫分離

相關文章
相關標籤/搜索