ClickHouse的安装和使用

      最近因为要做实时大屏监控指标,为此整理一下这写天的调研结果。

      官方文档:https://clickhouse.yandex/

 

安装:

执行命令: 

grep -q sse4_2 /proc/cpuinfo && echo “SSE 4.2 supported” || echo “SSE 4.2 not supported”


下载地址:http://repo.red-soft.biz/repos/clickhouse/stable/el7/

wget http://repo.red-soft.biz/repos/clickhouse/stable/el7/clickhouse-client-1.1.54236-4.el7.x86_64.rpm
wget http://repo.red-soft.biz/repos/clickhouse/stable/el7/clickhouse-compressor-1.1.54236-4.el7.x86_64.rpm
wget http://repo.red-soft.biz/repos/clickhouse/stable/el7/clickhouse-debuginfo-1.1.54236-4.el7.x86_64.rpm
wget http://repo.red-soft.biz/repos/clickhouse/stable/el7/clickhouse-server-1.1.54236-4.el7.x86_64.rpm
wget http://repo.red-soft.biz/repos/clickhouse/stable/el7/clickhouse-server-common-1.1.54236-4.el7.x86_64.rpm

 

rpm -ivh clickhouse-server-common-1.1.54236-4.el7.x86_64.rpm
rpm -ivh clickhouse-server-1.1.54236-4.el7.x86_64.rpm


  报错:错误:依赖检测失败:libodbc.so.2()(64bit) 被 clickhouse-server-1.1.54236-4.el7.x86_64 需要
  解决办法:yum install *ODBC*

rpm -ivh clickhouse-debuginfo-1.1.54236-4.el7.x86_64.rpm
rpm -ivh clickhouse-compressor-1.1.54236-4.el7.x86_64.rpm
rpm -ivh clickhouse-client-1.1.54236-4.el7.x86_64.rpm


关闭防火墙 

systemctl stop firewalld.service #停止firewall 
systemctl disable firewalld.service #禁止firewall开机启动


启动clickhouse服务端 

service clickhouse-server start

通过客户端连接 

clickhouse-client –m 

 

参数配置 
3.2.1 放开远程访问 

vi /etc/clickhouse-server/config.xml 


修改服务器的配置文件/etc/clickhouse-server/config.xml,第65行,放开注释即可,修改之后的内容如下:

 
    :: 
    ::1
    127.0.0.1


 
 
3.2.2 内存限制设置 
 

vi /etc/clickhouse-server/users.xml 
 10000000000


 
3.2.3 设置数据目录 
 

vi /etc/clickhouse-server/config.xml 
  84     
     88     5368709120
     89 
     90 
     91     
     92     /server/install/clickhouse/data/

 
修改之后,重启服务: 

service clickhouse-server stop 
service clickhouse-server start


使用:

 (1)进入 cd /etc/clickhouse-server/
 (2)
clickhouse-client:

远程登录:

clickhouse-client --host 192.168.100.128 --port 8123 -u root --password 123456 -m 
create table default.person (id UInt16,name String) ENGINE = Memory;
insert into default.person (id,name) values (1,'张三01');
insert into default.person (id,name) values (2,'张三02');
insert into default.person (id,name) values (3,'张三03');
create table IF NOT EXISTS  default.hblfyla AS select * from mysql('localhost:3306', 'clickhouse', 'person', 'root', '123456') ENGINE MergeTree() PARTITION BY toYYYYMM(EventDate) ORDER BY (CounterID, EventDate, intHash32(UserID)) SAMPLE BY intHash32(UserID) SETTINGS index_granularity=8192
CREATE TABLE rt_anls.ck_test_info (
	dp_event String,
	dp_event_time DateTime,
	loan_id Int32, 
	loan_no String,
	user_id Int32, 
	real_name String,
	id_card String,
	loan_day Int16,
	loan_unit String,
	interest_rate Decimal(16, 2),
	apply_amount Decimal(16, 2), 
	loan_amount Decimal(16, 2), 
	data_from String,  
	due_interest Decimal(16, 2), 
	due_amount Decimal(16, 2), 
	act_interest Decimal(16, 2), 
	act_amount Decimal(16, 2), 
	stage_sum Int16,  
	repay_type String, 
	begin_date DateTime, 
	end_date DateTime, 
	loan_status String, 
	audit_status String,  
	apply_time DateTime,
	loan_time DateTime, 
	settle_time DateTime,
	credit_id Int32, 
	anti_fraud String, 
	anti_decision String,
	anti_score Int16, 
	audit_time DateTime, 
	create_time DateTime, 
	update_time DateTime, 
	rate_id Int32,  curop_id Int32,  
	curop_name String,  
	curop_time DateTime,  
	curop_memo String, 
	mobile String, 
	user_notify Int16,
	carrier_id Int16,  
	approval_type String, 
	is_auto_approval Int16,
	rejection_days Int16, 
	sub_source String,  
	is_unique Int16, 
	lending_tag String, 
	repay_part_flag Int16,
	channel String, 
	type_code String,
	scene String, 
	repay_service_type String, 
	generate_type String,  
	dp_table_name String
)ENGINE = MergeTree() PARTITION BY toYYYYMMDD(dp_event_time) ORDER BY (dp_event_time, dp_event, loan_id) SETTINGS index_granularity = 8192

 

ClickHouse的安装和使用_第1张图片


增加字段:

ADD COLUMN [IF NOT EXISTS] name [type] [default_expr] [AFTER name_after]

 

你可能感兴趣的:(clickhouse)