chproxy说明
- chproxy 是clickhouse官方列出的开源代理服务(go语言开发), github地址(https://github.com/Vertamedia/chproxy)
Chproxy, is an http proxy and load balancer for ClickHouse database
环境
- centos7.4
- chproxy1.13
本文设为1台chproxy代理3台clickhouse
两个用户:只读用户(readonly),和读写用户(insert)。
下载安装
- 可以下载源码,编译安装,也提供编译好二进制包,直接下载编译好的二进制即可
#下载地址
https://github.com/Vertamedia/chproxy/releases
-
下载后解压,编写配置文件后,即可直接运行
- 编写配置文件 config.yaml
# 所有的chproxy配置参数参见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进程
- 编写配置文件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机器。