在線直播網(wǎng)站怎么做人民網(wǎng)輿情數(shù)據(jù)中心官網(wǎng)
文章目錄
- 0. 前言
- ClickHouse的安裝
- 1. 添加 ClickHouse 的倉庫
- 2. 安裝 ClickHouse
- 3. 啟動(dòng) ClickHouse 服務(wù)器
- 4. 使用 ClickHouse 客戶端
- ClickHouse的配置
- 1. 詳細(xì)安裝教程
- 1.1. 系統(tǒng)要求
- 1.1. 可用安裝包 {#install-from-deb-packages}
- 1.1.1. `DEB`安裝包
- 1.1.1. `RPM`安裝包 {#from-rpm-packages}
- 1.1.1.`Tgz`安裝包 {#from-tgz-archives}
- 1.1.1.`Docker`安裝包 {#from-docker-image}
- 1.1.1. 其他環(huán)境安裝包 {#from-other}
- 1.1.1. 使用源碼安裝 {#from-sources}
- 1.1. 啟動(dòng) {#qi-dong}

ClickHouse是一個(gè)用于聯(lián)機(jī)分析(OLAP)的列式數(shù)據(jù)庫管理系統(tǒng)(DBMS)。
0. 前言
安裝ClickHouse:首先,你需要選擇適合你操作系統(tǒng)的安裝方式。ClickHouse提供了各種安裝方法,包括二進(jìn)制包安裝、Docker容器安裝和源代碼編譯安裝。你可以根據(jù)自己的需求選擇其中一種方式進(jìn)行安裝。
ClickHouse的安裝
在 Unix-like 系統(tǒng)(包括 Linux 和 Mac OS)上安裝 ClickHouse 的推薦方式是使用預(yù)編譯的二進(jìn)制包。以下是在 Ubuntu 上安裝 ClickHouse 的步驟:
1. 添加 ClickHouse 的倉庫
sudo apt-get install apt-transport-https ca-certificates dirmngr
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E0C56BD4echo "deb https://repo.clickhouse.tech/deb/stable/ main/" | sudo tee \/etc/apt/sources.list.d/clickhouse.list
sudo apt-get update
2. 安裝 ClickHouse
sudo apt-get install -y clickhouse-server clickhouse-client
3. 啟動(dòng) ClickHouse 服務(wù)器
sudo service clickhouse-server start
4. 使用 ClickHouse 客戶端
clickhouse-client
如果你在 Windows 上,可以使用 Docker。首先安裝 Docker,然后運(yùn)行以下命令獲取 ClickHouse 鏡像并運(yùn)行:
docker run -d --name some-clickhouse-server --ulimit nofile=262144:262144 yandex/clickhouse-server
然后你可以使用 ClickHouse 客戶端連接服務(wù)器:
docker run -it --rm --link some-clickhouse-server:clickhouse-server yandex/clickhouse-client --host clickhouse-server
ClickHouse的配置
ClickHouse 的配置文件通常在 /etc/clickhouse-server/
目錄下。
主要的配置文件是 config.xml
,這里可以設(shè)置服務(wù)器的各種行為,比如內(nèi)存限制、連接限制、認(rèn)證、日志記錄等。
你也可以在 users.xml
文件中設(shè)置用戶級(jí)別的配置,比如訪問權(quán)限、查詢限制等。
使用 clickhouse-client
可以直接連接到服務(wù)器,如果需要遠(yuǎn)程連接,你可能需要在 users.xml
中添加相應(yīng)的網(wǎng)絡(luò)訪問權(quán)限。
1. 詳細(xì)安裝教程
1.1. 系統(tǒng)要求
ClickHouse可以在任何具有x86_64,AArch64或PowerPC64LE CPU架構(gòu)的Linux,FreeBSD或Mac OS X上運(yùn)行。
官方預(yù)構(gòu)建的二進(jìn)制文件通常針對(duì)x86_64進(jìn)行編譯,并利用SSE 4.2
指令集,因此,除非另有說明,支持它的CPU使用將成為額外的系統(tǒng)需求。下面是檢查當(dāng)前CPU是否支持SSE 4.2的命令:
$ grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"
要在不支持SSE 4.2
或AArch64
,PowerPC64LE
架構(gòu)的處理器上運(yùn)行ClickHouse,您應(yīng)該通過適當(dāng)?shù)呐渲谜{(diào)整從源代碼構(gòu)建ClickHouse。
1.1. 可用安裝包 {#install-from-deb-packages}
1.1.1. DEB
安裝包
建議使用Debian或Ubuntu的官方預(yù)編譯deb
軟件包。運(yùn)行以下命令來安裝包:
sudo apt-get install -y apt-transport-https ca-certificates dirmngr
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 8919F6BD2B48D754echo "deb https://packages.clickhouse.com/deb stable main" | sudo tee \/etc/apt/sources.list.d/clickhouse.list
sudo apt-get updatesudo apt-get install -y clickhouse-server clickhouse-clientsudo service clickhouse-server start
clickhouse-client # or "clickhouse-client --password" if you've set up a password.
Deprecated Method for installing deb-packages
sudo apt-get install apt-transport-https ca-certificates dirmngr
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E0C56BD4echo "deb https://repo.clickhouse.com/deb/stable/ main/" | sudo tee \/etc/apt/sources.list.d/clickhouse.list
sudo apt-get updatesudo apt-get install -y clickhouse-server clickhouse-clientsudo service clickhouse-server start
clickhouse-client # or "clickhouse-client --password" if you set up a password.
如果您想使用最新的版本,請(qǐng)用testing
替代stable
(我們只推薦您用于測(cè)試環(huán)境)。
你也可以從這里手動(dòng)下載安裝包:下載。
安裝包列表:
clickhouse-common-static
— ClickHouse編譯的二進(jìn)制文件。clickhouse-server
— 創(chuàng)建clickhouse-server
軟連接,并安裝默認(rèn)配置服務(wù)clickhouse-client
— 創(chuàng)建clickhouse-client
客戶端工具軟連接,并安裝客戶端配置文件。clickhouse-common-static-dbg
— 帶有調(diào)試信息的ClickHouse二進(jìn)制文件。
1.1.1. RPM
安裝包 {#from-rpm-packages}
推薦使用CentOS、RedHat和所有其他基于rpm的Linux發(fā)行版的官方預(yù)編譯rpm
包。
首先,您需要添加官方存儲(chǔ)庫:
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://packages.clickhouse.com/rpm/clickhouse.repo
sudo yum install -y clickhouse-server clickhouse-clientsudo /etc/init.d/clickhouse-server start
clickhouse-client # or "clickhouse-client --password" if you set up a password.
For systems with zypper
package manager (openSUSE, SLES):
sudo zypper addrepo -r https://packages.clickhouse.com/rpm/clickhouse.repo -g
sudo zypper --gpg-auto-import-keys refresh clickhouse-stable
sudo zypper install -y clickhouse-server clickhouse-clientsudo /etc/init.d/clickhouse-server start
clickhouse-client # or "clickhouse-client --password" if you set up a password.
Deprecated Method for installing rpm-packages
sudo yum install yum-utils
sudo rpm --import https://repo.clickhouse.com/CLICKHOUSE-KEY.GPG
sudo yum-config-manager --add-repo https://repo.clickhouse.com/rpm/clickhouse.repo
sudo yum install clickhouse-server clickhouse-clientsudo /etc/init.d/clickhouse-server start
clickhouse-client # or "clickhouse-client --password" if you set up a password.
如果您想使用最新的版本,請(qǐng)用testing
替代stable
(我們只推薦您用于測(cè)試環(huán)境)。prestable
有時(shí)也可用。
然后運(yùn)行命令安裝:
sudo yum install clickhouse-server clickhouse-client
你也可以從這里手動(dòng)下載安裝包:下載。
1.1.1.Tgz
安裝包 {#from-tgz-archives}
如果您的操作系統(tǒng)不支持安裝deb
或rpm
包,建議使用官方預(yù)編譯的tgz
軟件包。
所需的版本可以通過curl
或wget
從存儲(chǔ)庫https://packages.clickhouse.com/tgz/
下載。
下載后解壓縮下載資源文件并使用安裝腳本進(jìn)行安裝。以下是一個(gè)最新穩(wěn)定版本的安裝示例:
LATEST_VERSION=$(curl -s https://packages.clickhouse.com/tgz/stable/ | \grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | sort -V -r | head -n 1)
export LATEST_VERSIONcase $(uname -m) inx86_64) ARCH=amd64 ;;aarch64) ARCH=arm64 ;;*) echo "Unknown architecture $(uname -m)"; exit 1 ;;
esacfor PKG in clickhouse-common-static clickhouse-common-static-dbg clickhouse-server clickhouse-client
docurl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION-${ARCH}.tgz" \|| curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION.tgz"
donetar -xzvf "clickhouse-common-static-$LATEST_VERSION-${ARCH}.tgz" \|| tar -xzvf "clickhouse-common-static-$LATEST_VERSION.tgz"
sudo "clickhouse-common-static-$LATEST_VERSION/install/doinst.sh"tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION-${ARCH}.tgz" \|| tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION.tgz"
sudo "clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh"tar -xzvf "clickhouse-server-$LATEST_VERSION-${ARCH}.tgz" \|| tar -xzvf "clickhouse-server-$LATEST_VERSION.tgz"
sudo "clickhouse-server-$LATEST_VERSION/install/doinst.sh" configure
sudo /etc/init.d/clickhouse-server starttar -xzvf "clickhouse-client-$LATEST_VERSION-${ARCH}.tgz" \|| tar -xzvf "clickhouse-client-$LATEST_VERSION.tgz"
sudo "clickhouse-client-$LATEST_VERSION/install/doinst.sh"
Deprecated Method for installing tgz archives
export LATEST_VERSION=$(curl -s https://repo.clickhouse.com/tgz/stable/ | \grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | sort -V -r | head -n 1)
curl -O https://repo.clickhouse.com/tgz/stable/clickhouse-common-static-$LATEST_VERSION.tgz
curl -O https://repo.clickhouse.com/tgz/stable/clickhouse-common-static-dbg-$LATEST_VERSION.tgz
curl -O https://repo.clickhouse.com/tgz/stable/clickhouse-server-$LATEST_VERSION.tgz
curl -O https://repo.clickhouse.com/tgz/stable/clickhouse-client-$LATEST_VERSION.tgztar -xzvf clickhouse-common-static-$LATEST_VERSION.tgz
sudo clickhouse-common-static-$LATEST_VERSION/install/doinst.shtar -xzvf clickhouse-common-static-dbg-$LATEST_VERSION.tgz
sudo clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.shtar -xzvf clickhouse-server-$LATEST_VERSION.tgz
sudo clickhouse-server-$LATEST_VERSION/install/doinst.sh
sudo /etc/init.d/clickhouse-server starttar -xzvf clickhouse-client-$LATEST_VERSION.tgz
sudo clickhouse-client-$LATEST_VERSION/install/doinst.sh
對(duì)于生產(chǎn)環(huán)境,建議使用最新的stable
版本。你可以在GitHub頁面https://github.com/ClickHouse/ClickHouse/tags找到它,它以后綴-stable
標(biāo)志。
1.1.1.Docker
安裝包 {#from-docker-image}
要在Docker中運(yùn)行ClickHouse,請(qǐng)遵循Docker Hub上的指南。它是官方的deb
安裝包。
1.1.1. 其他環(huán)境安裝包 {#from-other}
對(duì)于非linux操作系統(tǒng)和Arch64 CPU架構(gòu),ClickHouse將會(huì)以master
分支的最新提交的進(jìn)行編譯提供(它將會(huì)有幾小時(shí)的延遲)。
- macOS —
curl -O 'https://builds.clickhouse.com/master/macos/clickhouse' && chmod a+x ./clickhouse
- FreeBSD —
curl -O 'https://builds.clickhouse.com/master/freebsd/clickhouse' && chmod a+x ./clickhouse
- AArch64 —
curl -O 'https://builds.clickhouse.com/master/aarch64/clickhouse' && chmod a+x ./clickhouse
下載后,您可以使用clickhouse client
連接服務(wù),或者使用clickhouse local
模式處理數(shù)據(jù),不過您必須要額外在GitHub下載server和users配置文件。
不建議在生產(chǎn)環(huán)境中使用這些構(gòu)建版本,因?yàn)樗鼈儧]有經(jīng)過充分的測(cè)試,但是您可以自行承擔(dān)這樣做的風(fēng)險(xiǎn)。它們只是ClickHouse功能的一個(gè)部分。
1.1.1. 使用源碼安裝 {#from-sources}
要手動(dòng)編譯ClickHouse, 請(qǐng)遵循Linux或Mac OS X說明。
您可以編譯并安裝它們,也可以使用不安裝包的程序。通過手動(dòng)構(gòu)建,您可以禁用SSE 4.2
或AArch64 cpu
。
Client: programs/clickhouse-clientServer: programs/clickhouse-server
您需要?jiǎng)?chuàng)建一個(gè)數(shù)據(jù)和元數(shù)據(jù)文件夾,并為所需的用戶chown
授權(quán)。它們的路徑可以在服務(wù)器配置(src/programs/server/config.xml
)中改變,默認(rèn)情況下它們是:
/opt/clickhouse/data/default//opt/clickhouse/metadata/default/
在Gentoo上,你可以使用emerge clickhouse
從源代碼安裝ClickHouse。
1.1. 啟動(dòng) {#qi-dong}
如果沒有service
,可以運(yùn)行如下命令在后臺(tái)啟動(dòng)服務(wù):
$ sudo /etc/init.d/clickhouse-server start
日志文件將輸出在/var/log/clickhouse-server/
文件夾。
如果服務(wù)器沒有啟動(dòng),檢查/etc/clickhouse-server/config.xml
中的配置。
您也可以手動(dòng)從控制臺(tái)啟動(dòng)服務(wù)器:
$ clickhouse-server --config-file=/etc/clickhouse-server/config.xml
在這種情況下,日志將被打印到控制臺(tái),這在開發(fā)過程中很方便。
如果配置文件在當(dāng)前目錄中,則不需要指定——config-file
參數(shù)。默認(rèn)情況下,它的路徑為./config.xml
。
ClickHouse支持訪問限制設(shè)置。它們位于users.xml
文件(與config.xml
同級(jí)目錄)。
默認(rèn)情況下,允許default
用戶從任何地方訪問,不需要密碼??刹榭?code>user/default/networks。
更多信息,請(qǐng)參見Configuration Files。
啟動(dòng)服務(wù)后,您可以使用命令行客戶端連接到它:
$ clickhouse-client
默認(rèn)情況下,使用default
用戶并不攜帶密碼連接到localhost:9000
。還可以使用--host
參數(shù)連接到指定服務(wù)器。
終端必須使用UTF-8編碼。
更多信息,請(qǐng)參閱Command-line client。
示例:
$ ./clickhouse-client
ClickHouse client version 0.0.18749.
Connecting to localhost:9000.
Connected to ClickHouse server version 0.0.18749.:) SELECT 1SELECT 1┌─1─┐
│ 1 │
└───┘1 rows in set. Elapsed: 0.003 sec.:)
恭喜,系統(tǒng)已經(jīng)工作了!
為了繼續(xù)進(jìn)行實(shí)驗(yàn),你可以嘗試下載測(cè)試數(shù)據(jù)集或查看教程。