一:安裝clickhouse
官網地址:https://clickhouse.tech/#quick-start
按照官網提供的方法快速安裝:(依次執行)
sudo yum install yum-utils sudo rpm --import https://repo.clickhouse.tech/CLICKHOUSE-KEY.GPG sudo yum-config-manager --add-repo https://repo.clickhouse.tech/rpm/clickhouse.repo sudo yum install clickhouse-server clickhouse-client
啟動服務並登陸:
# 啟動服務 sudo /etc/init.d/clickhouse-server start # 客戶端登錄 clickhouse-client
官方文檔:https://clickhouse.tech/docs/en/
服務各種操作:
# 查看狀態 service clickhouse-server status # 啟動服務 service clickhouse-server start # 停止服務 service clickhouse-server stop # 停止服務 service clickhouse-server restart
二:目錄配置
修改data目錄,安裝好后默認目錄是/var/lib/clickhouse/目錄下。要把這個目錄放在空間容量大的目錄下,比如我這里是:/data/clickhouse/ 。
修改的配置文件目錄在/etc/clickhouse-server/config.xml
官方說明:
Server config files are located in /etc/clickhouse-server/
. Before going further, please notice the <path>
element in config.xml
. Path determines the location for data storage, so it should be located on volume with large disk capacity; the default value is /var/lib/clickhouse/.If you want to adjust the configuration, it’s not handy to directly edit
config.xml
file, considering it might get rewritten on future package updates. The recommended way to override the config elements is to create files in config.d directory which serve as “patches” to config.xml.
The default location for server logs is /var/log/clickhouse-server/
. The server is ready to handle client connections once it logs the Ready for connections
message.
把數據存放目錄都配置到 /data/clickhouse/ 目錄下面。
vim /etc/clickhouse-server/config.xml
<!-- Path to data directory, with trailing slash. --> <path>/data/clickhouse/</path> <!-- Path to temporary data for processing hard queries. --> <tmp_path>/data/clickhouse/tmp/</tmp_path> <!-- Directory with user provided files that are accessible by 'file' table function. --> <user_files_path>/data/clickhouse/user_files/</user_files_path> <!-- Path to folder where users and roles created by SQL commands are stored. --> <access_control_path>/data/clickhouse/access/</access_control_path> <!-- Directory in <clickhouse-path> containing schema files for various input formats. The directory will be created if it doesn't exist. --> <format_schema_path>/data/clickhouse/format_schemas/</format_schema_path>
修改完之后重啟服務:
service clickhouse-server restart
三:登錄數據庫
登錄查看數據庫(默認用戶是default,密碼為空)
clickhouse-client 或者 clickhouse-client -h127.0.0.1 都可以。
[root@centf8120 ~]# clickhouse-client -h127.0.0.1 ClickHouse client version 20.6.4.44 (official build). Connecting to 127.0.0.1:9000 as user default. Connected to ClickHouse server version 20.6.4 revision 54436. centf8120.sharding3.db :) show databases; SHOW DATABASES ┌─name───────────────────────────┐ │ _temporary_and_external_tables │ │ default │ │ system │ └────────────────────────────────┘ 3 rows in set. Elapsed: 0.003 sec. centf8120.sharding3.db :)