chproxy說明
- chproxy 是clickhouse官方列出的開源代理服務(wù)(go語言開發(fā)), github地址(https://github.com/Vertamedia/chproxy)
Chproxy, is an http proxy and load balancer for ClickHouse database
環(huán)境
- centos7.4
- chproxy1.13
本文設(shè)為1臺chproxy代理3臺clickhouse
兩個用戶:只讀用戶(readonly),和讀寫用戶(insert)油够。
下載安裝
- 可以下載源碼须眷,編譯安裝,也提供編譯好二進(jìn)制包鸣剪,直接下載編譯好的二進(jìn)制即可
#下載地址
https://github.com/Vertamedia/chproxy/releases
-
下載后解壓组底,編寫配置文件后,即可直接運(yùn)行
- 編寫配置文件 config.yaml
# 所有的chproxy配置參數(shù)參見https://github.com/Vertamedia/chproxy/blob/master/config/examples/combined.yml)
hack_me_please: false
log_debug: true
server:
http:
listen_addr: ":9090"
allowed_networks: ["172.0.0.0/8","192.0.0.0/8"]
read_timeout: 3m
param_groups:
- name: "pz"
params:
- key: "max_query_size"
value: "100000000"
- key: "max_ast_elements"
value: "10000000"
- key: "max_expanded_ast_elements"
value: "10000000"
users:
- name: "insert"
to_cluster: "writer-cluster"
to_user: "default"
params: "pz"
allow_cors: true
cache: "longterm"
- name: "readonly"
to_cluster: "readonly-cluster"
to_user: "readonly"
cache: "shotterm"
params: "pz"
allow_cors: true
max_concurrent_queries: 200
max_execution_time: 2m
clusters:
- name: "writer-cluster"
nodes: [
"host1:8123",
"host2:8123",
"host3:8123"
]
users:
- name: "default"
password: ""
- name: "readonly-cluster"
nodes: [
"host1:8123",
"host2:8123",
"host3:8123"
]
users:
- name: "readonly"
password: ""
caches:
- name: "longterm"
dir: "/mapbar/chproxy/cache/"
max_size: 9500Mb
expire: 130s
- name: "shotterm"
dir: "/mapbar/chproxy/cache-shot/"
max_size: 9500Mb
expire: 130s
Supervisor 管理chproxy進(jìn)程
- 編寫配置文件chproxy.ini ,放入 /etc/supervisord.d/
[program:chproxy]
redirect_stderr=true
stdout_logfile=/var/log/supervisor/chproxy.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=10
command= /opt/software/chproxy/chproxy --config /opt/software/chproxy/config.yaml
timeout = 60*60
user=root
autostart=true
autorestart=true
startsecs=10
startretries=1
stopasgroup=true
killasgroup=true
environment=LC_ALL='en_US.UTF-8',LANG='en_US.UTF-8',LC_LANG='en_US.UTF-8'
- 啟動chproxy
supervisorctl reread
supervisorctl update chproxy
- 端口測試
echo "SELECT 1;" | curl -u insert: --data-binary @- 192.168.9.45:9090
echo "SELECT 1;" | curl -u readonly: --data-binary @- 192.168.9.44:9090
說明
- 完成以上步驟筐骇,chproxy即安裝完畢债鸡,使用clickhouse jdbc 通過proxy即可寫入和讀取clickhouse機(jī)器。