安装步骤
安装包下载地址: https://repo.yandex.ru/clickhouse/rpm/stable/x86_64/
常规安装需要如下4个软件包
clickhouse-common-static — ClickHouse编译的二进制文件。
clickhouse-server — 创建clickhouse-server软连接,并安装默认配置服务
clickhouse-client — 创建clickhouse-client客户端工具软连接,并安装客户端配置文件。
clickhouse-common-static-dbg — 带有调试信息的ClickHouse二进制文件
最小化安装需要其中3个
clickhouse-common-static
clickhouse-server
clickhouse-client
服务器新建一个目录,上传rpm安装包到该目录
安装命令: rpm -ivh *.rpm
查看命令: rpm -qa|grep clickhouse
//卸载命令: rpm -e xxx.rpm
修改配置文件,把如下标签打开,允许远程连接
vim /etc/clickhouse-server/config.xml
<listen_host>::</listen_host>
启动并查看状态
systemctl start clickhouse-server
systemctl status clickhouse-server
启动客户端
无密码连接: clickhouse-client
有密码连接: clickhouse-client --user=default --password
>show databases;
>show tables;
防火墙打开相关端口
firewall-cmd --zone=public --add-port=8123/tcp --permanent
firewall-cmd --zone=public --add-port=9000/tcp --permanent
firewall-cmd --reload
相关目录
/usr/bin
/etc/clickhouse-server
/etc/clickhouse-client
/var/lib/clickhouse
/var/log/clickhouse-server
常见问题
1.远程无法连接解决方案
vim /etc/clickhouse-server/config.xml(放开<listen_host>::</listen_host>)
2.root无法启动解决方案
chown -R root:root /var/lib/clickhouse /var/log/clickhouse-server /etc/clickhouse-server /etc/clickhouse-client
/usr/bin/clickhouse-server --config-file /etc/clickhouse-server/config.xml
导入示例数据
示例数据集下载
https://clickhouse.com/docs/zh/getting-started/example-datasets
执行建表语句
--示例数据集由四个表组成:
--Menu - 有关菜单的信息,其中包含:餐厅名称,看到菜单的日期等
--Dish - 有关菜肴的信息,其中包含:菜肴名称以及一些特征。
--MenuPage - 有关菜单中页面的信息,每个页面都属于某个 Menu。
--MenuItem - 菜单项。某个菜单页面上的菜肴及其价格:指向 Dish 和 MenuPage的链接。
CREATE TABLE dish
(
id UInt32,
name String,
description String,
menus_appeared UInt32,
times_appeared Int32,
first_appeared UInt16,
last_appeared UInt16,
lowest_price Decimal64(3),
highest_price Decimal64(3)
) ENGINE = MergeTree ORDER BY id;
CREATE TABLE menu
(
id UInt32,
name String,
sponsor String,
event String,
venue String,
place String,
physical_description String,
occasion String,
notes String,
call_number String,
keywords String,
language String,
date String,
location String,
location_type String,
currency String,
currency_symbol String,
status String,
page_count UInt16,
dish_count UInt16
) ENGINE = MergeTree ORDER BY id;
CREATE TABLE menu_page
(
id UInt32,
menu_id UInt32,
page_number UInt16,
image_id String,
full_height UInt16,
full_width UInt16,
uuid UUID
) ENGINE = MergeTree ORDER BY id;
CREATE TABLE menu_item
(
id UInt32,
menu_page_id UInt32,
price Decimal64(3),
high_price Decimal64(3),
dish_id UInt32,
created_at DateTime,
updated_at DateTime,
xpos Float64,
ypos Float64
) ENGINE = MergeTree ORDER BY id;
解压示例数据
tar xvf 2021_08_01_07_01_17_data.tgz
导入示例数据
clickhouse-client --format_csv_allow_single_quotes 0 --input_format_null_as_default 0 --query "INSERT INTO dish FORMAT CSVWithNames" < Dish.csv
clickhouse-client --format_csv_allow_single_quotes 0 --input_format_null_as_default 0 --query "INSERT INTO menu FORMAT CSVWithNames" < Menu.csv
clickhouse-client --format_csv_allow_single_quotes 0 --input_format_null_as_default 0 --query "INSERT INTO menu_page FORMAT CSVWithNames" < MenuPage.csv
clickhouse-client --format_csv_allow_single_quotes 0 --input_format_null_as_default 0 --date_time_input_format best_effort --query "INSERT INTO menu_item FORMAT CSVWithNames" < MenuItem.csv
防火墙管理
Centos7 使用 firewall-cmd 命令 开放及查看端口开放情况
1、开放端口
firewall-cmd --zone=public --add-port=8888/tcp --permanent # 开放5672端口
firewall-cmd --zone=public --remove-port=8888/tcp --permanent #关闭5672端口
firewall-cmd --reload # 配置立即生效
2、查看防火墙所有开放的端口
firewall-cmd --zone=public --list-ports
3.、防火墙启动/关闭/重启/状态
systemctl start firewalld.service
systemctl stop firewalld.service
systemctl restart firewalld.service
systemctl status firewalld.service
4、查看防火墙状态
firewall-cmd --state
5、查看监听的端口
netstat -lnpt
PS:centos7默认没有 netstat 命令,需要安装 net-tools 工具,yum install -y net-tools
6、检查端口被哪个进程占用
netstat -lnpt |grep 8888