在上一章節中,我們介紹了ClickHouse定義,以及深入的了解其使用到的儲存特性,還有其他有關於就此資料庫的用途、目的、儲存方式的效能來進行討論。在本章節中,會帶領讀者來開始安裝ClickHouse。
ClickHouse可以運行在任何的Linux發行版本、FreeBSD、Mac OS X系統且是x86_64的架構、AArch64(ARM之64位元架構)或是PowerPC64LE等CPU架構。
ClickHouse官方已經有提供預先編譯好的二進位元執行檔,這個執行檔是在x86_64位元的架構並有SSE 4.2指令集下編譯完成的。
下面的指令可以用來幫助我們要安裝的標的的作業系統上的CPU架構是否有支援SSE 4.2指令集:
grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"
如果我們為了要讓ClickHouse運行在沒有支援SSE 4.2指令集的CPU架構上,或是要運行在AArch64與PowerPC64LE等架構上的話,若出現SSE 4.2 not supported
,則需要自行下載ClickHouse的原始碼譯並使用適當的設定與參數進行編譯。
如果讀者們使用的是Debian系列的Linux發行版本的作業系統,如Debian或Ubuntu等,就可以使用這個方法將ClickHouse安裝到目的的作業系統上,同時這也是ClickHouse官方建議地安裝方法,執行下列的這些指令來安裝套件:
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates dirmngr
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 8919F6BD2B48D754
echo "deb https://packages.clickhouse.com/deb stable main" | sudo tee /etc/apt/sources.list.d/clickhouse.list
sudo apt-get update
sudo apt-get install -y clickhouse-server clickhouse-client
sudo service clickhouse-server start
clickhouse-client # 如果在安裝過程中有設定密碼,則執行"clickhouse-client --password"指令
接著我們使用一個乾淨的Ubuntu 18.04的作業系統來示範上述的安裝方法:
一開始我們需要先更新鏡像來源,所以先執行sudo apt-get update
的指令,相關指令執行的結果與過程如下:
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$ sudo apt-get update
[sudo] password for peter:
Get:1 http://mirrors.digitalocean.com/ubuntu bionic InRelease [242 kB]
Hit:2 https://repos-droplet.digitalocean.com/apt/droplet-agent main InRelease
Get:3 http://mirrors.digitalocean.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 http://mirrors.digitalocean.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:5 http://mirrors.digitalocean.com/ubuntu bionic-updates/main amd64 Packages [2729 kB]
Get:6 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:7 http://mirrors.digitalocean.com/ubuntu bionic-updates/main Translation-en [503 kB]
Get:8 http://mirrors.digitalocean.com/ubuntu bionic-updates/restricted amd64 Packages [913 kB]
Get:9 http://mirrors.digitalocean.com/ubuntu bionic-updates/restricted Translation-en [126 kB]
Get:10 http://mirrors.digitalocean.com/ubuntu bionic-updates/universe amd64 Packages [1842 kB]
Get:11 http://mirrors.digitalocean.com/ubuntu bionic-updates/universe Translation-en [399 kB]
Get:12 http://mirrors.digitalocean.com/ubuntu bionic-updates/multiverse amd64 Packages [24.9 kB]
Get:13 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [2389 kB]
Get:14 http://security.ubuntu.com/ubuntu bionic-security/main Translation-en [414 kB]
Get:15 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [884 kB]
Get:16 http://security.ubuntu.com/ubuntu bionic-security/restricted Translation-en [122 kB]
Get:17 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [1228 kB]
Get:18 http://security.ubuntu.com/ubuntu bionic-security/universe Translation-en [282 kB]
Get:19 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [19.0 kB]
Fetched 12.4 MB in 3s (4368 kB/s)
Reading package lists... Done
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~
接著要安裝一些必要的套件,其中apt-transport-https
、ca-certificates
以及dirmngr
之套件是用來管理外部鏡像時使用,相關執行的指令與過程如下:
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$ sudo apt-get install -y apt-transport-https ca-certificates dirmngr
Reading package lists... Done
Building dependency tree
Reading state information... Done
ca-certificates is already the newest version (20211016~18.04.1).
dirmngr is already the newest version (2.2.4-1ubuntu1.6).
dirmngr set to manually installed.
apt-transport-https is already the newest version (1.6.14).
0 upgraded, 0 newly installed, 0 to remove and 25 not upgraded.
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$
從上面得知,這台機器已經安裝好這些套件了,如果沒有安裝的話,則會向下列這樣安裝沒有安裝到的套件:
sudo apt-get install -y apt-transport-https ca-certificates dirmngr
Reading package lists... Done
Building dependency tree
Reading state information... Done
ca-certificates is already the newest version (20211016~20.04.1).
ca-certificates set to manually installed.
dirmngr is already the newest version (2.2.19-3ubuntu2.2).
dirmngr set to manually installed.
The following NEW packages will be installed:
apt-transport-https
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 1704 B of archives.
After this operation, 162 kB of additional disk space will be used.
Get:1 http://ports.ubuntu.com/ubuntu-ports focal-updates/universe arm64 apt-transport-https all 2.0.9 [1704 B]
Fetched 1704 B in 0s (3649 B/s)
Selecting previously unselected package apt-transport-https.
(Reading database ... 106859 files and directories currently installed.)
Preparing to unpack .../apt-transport-https_2.0.9_all.deb ...
Unpacking apt-transport-https (2.0.9) ...
Setting up apt-transport-https (2.0.9) ...
接著將ClickHouse之鏡像的GPG金鑰匯入到目的的作業系統,相關的執行指令與過程如下:
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 8919F6BD2B48D754
Executing: /tmp/apt-key-gpghome.EfkLJrUrHF/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv 8919F6BD2B48D754
gpg: key 8919F6BD2B48D754: public key "ClickHouse Inc. Repositories Key <packages@clickhouse.com>" imported
gpg: Total number processed: 1
gpg: imported: 1
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$
接著將ClickHouse鏡像位址寫入到/etc/apt/sources.list.d/clickhouse.list
之檔案中,同時可以使用cat
指令來確定該檔案已經正確寫入並有指定的鏡像網址的內容,相關的指令執行過程與輸出內容如下:
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$ echo "deb https://packages.clickhouse.com/deb stable main" | sudo tee /etc/apt/sources.list.d/clickhouse.list
deb https://packages.clickhouse.com/deb stable main
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$ cat /etc/apt/sources.list.d/clickhouse.list
deb https://packages.clickhouse.com/deb stable main
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$
接著使用下列的指令來更新上述加入的ClickHouse鏡像來源的資訊,相關的執行指令的過程與輸出的內容如下:
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$ sudo apt-get update
Get:1 http://mirrors.digitalocean.com/ubuntu bionic InRelease [242 kB]
Hit:2 http://mirrors.digitalocean.com/ubuntu bionic-updates InRelease
Hit:3 https://repos-droplet.digitalocean.com/apt/droplet-agent main InRelease
Hit:4 http://mirrors.digitalocean.com/ubuntu bionic-backports InRelease
Get:5 https://packages.clickhouse.com/deb stable InRelease [5536 B]
Hit:6 http://security.ubuntu.com/ubuntu bionic-security InRelease
Get:7 https://packages.clickhouse.com/deb stable/main amd64 Packages [18.1 kB]
Fetched 266 kB in 1s (342 kB/s)
Reading package lists... Done
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$
從上面的執行指令輸出的內容可以發現,Get:7 https://packages.clickhouse.com/deb stable/main amd64 Packages
有正確的取得到鏡像的資訊。
接著可以進行ClickHouse資料庫的安裝了,相關執行指令的過程與輸出的內容如下:
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$ sudo apt-get install -y clickhouse-server clickhouse-client
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
clickhouse-common-static
Suggested packages:
clickhouse-common-static-dbg
The following NEW packages will be installed:
clickhouse-client clickhouse-common-static clickhouse-server
0 upgraded, 3 newly installed, 0 to remove and 25 not upgraded.
Need to get 265 MB of archives.
After this operation, 773 MB of additional disk space will be used.
Get:1 https://packages.clickhouse.com/deb stable/main amd64 clickhouse-common-static amd64 22.8.4.7 [265 MB]
Get:2 https://packages.clickhouse.com/deb stable/main amd64 clickhouse-client amd64 22.8.4.7 [75.3 kB]
Get:3 https://packages.clickhouse.com/deb stable/main amd64 clickhouse-server amd64 22.8.4.7 [99.2 kB]
Fetched 265 MB in 4s (63.3 MB/s)
Selecting previously unselected package clickhouse-common-static.
(Reading database ... 60519 files and directories currently installed.)
Preparing to unpack .../clickhouse-common-static_22.8.4.7_amd64.deb ...
Unpacking clickhouse-common-static (22.8.4.7) ...
Selecting previously unselected package clickhouse-client.
Preparing to unpack .../clickhouse-client_22.8.4.7_amd64.deb ...
Unpacking clickhouse-client (22.8.4.7) ...
Selecting previously unselected package clickhouse-server.
Preparing to unpack .../clickhouse-server_22.8.4.7_amd64.deb ...
Unpacking clickhouse-server (22.8.4.7) ...
Setting up clickhouse-common-static (22.8.4.7) ...
Setting up clickhouse-server (22.8.4.7) ...
ClickHouse binary is already located at /usr/bin/clickhouse
Symlink /usr/bin/clickhouse-server already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-server to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-client already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-client to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-local already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-local to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-benchmark already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-benchmark to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-copier already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-copier to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-obfuscator already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-obfuscator to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-git-import to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-compressor already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-compressor to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-format already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-format to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-extract-from-config already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-extract-from-config to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-keeper already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-keeper to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-keeper-converter to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-disks to /usr/bin/clickhouse.
Creating clickhouse group if it does not exist.
groupadd -r clickhouse
Creating clickhouse user if it does not exist.
useradd -r --shell /bin/false --home-dir /nonexistent -g clickhouse clickhouse
Will set ulimits for clickhouse user in /etc/security/limits.d/clickhouse.conf.
Creating config directory /etc/clickhouse-server/config.d that is used for tweaks of main server configuration.
Creating config directory /etc/clickhouse-server/users.d that is used for tweaks of users configuration.
Config file /etc/clickhouse-server/config.xml already exists, will keep it and extract path info from it.
/etc/clickhouse-server/config.xml has /var/lib/clickhouse/ as data path.
/etc/clickhouse-server/config.xml has /var/log/clickhouse-server/ as log path.
Users config file /etc/clickhouse-server/users.xml already exists, will keep it and extract users info from it.
Creating log directory /var/log/clickhouse-server/.
Creating data directory /var/lib/clickhouse/.
Creating pid directory /var/run/clickhouse-server.
chown -R clickhouse:clickhouse '/var/log/clickhouse-server/'
chown -R clickhouse:clickhouse '/var/run/clickhouse-server'
chown clickhouse:clickhouse '/var/lib/clickhouse/'
groupadd -r clickhouse-bridge
useradd -r --shell /bin/false --home-dir /nonexistent -g clickhouse-bridge clickhouse-bridge
chown -R clickhouse-bridge:clickhouse-bridge '/usr/bin/clickhouse-odbc-bridge'
chown -R clickhouse-bridge:clickhouse-bridge '/usr/bin/clickhouse-library-bridge'
Enter password for default user:
從上面的安裝過程來看,安裝到一半的時候,會有一個Enter password for default user:
的互動的使用者輸入的訊息,這邊是要給預設使用者default
一個密碼,在這邊我們輸入clickhouse
當作default
使用者的密碼,輸入完密碼之後,接著就會執行下面的輸出的訊息:
.......
Enter password for default user:
Password for default user is saved in file /etc/clickhouse-server/users.d/default-password.xml.
Setting capabilities for clickhouse binary. This is optional.
Cannot set 'net_admin' or 'ipc_lock' or 'sys_nice' or 'net_bind_service' capability for clickhouse binary. This is optional. Taskstats accounting will be disabled. To enable taskstats accounting you may add the required capability later manually.
chown -R clickhouse:clickhouse '/etc/clickhouse-server'
ClickHouse has been successfully installed.
Start clickhouse-server with:
sudo clickhouse start
Start clickhouse-client with:
clickhouse-client --password
Synchronizing state of clickhouse-server.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable clickhouse-server
Setting up clickhouse-client (22.8.4.7) ...
Processing triggers for systemd (237-3ubuntu10.53) ...
Processing triggers for ureadahead (0.100.0-21) ...
接著可以透過下面的指令來啟動ClickHouse資料庫,相關的執行指令與輸出的內容如下:
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$ sudo service clickhouse-server start
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$
同時我們可以透過下列的指令來確定目前ClickHouse server的執行狀態,相關的執行指令輸出的內容如下:
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$ sudo service clickhouse-server status
● clickhouse-server.service - ClickHouse Server (analytic DBMS for big data)
Loaded: loaded (/lib/systemd/system/clickhouse-server.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-09-07 03:48:07 UTC; 9s ago
Main PID: 3451 (clckhouse-watch)
Tasks: 206 (limit: 4915)
CGroup: /system.slice/clickhouse-server.service
├─3451 clickhouse-watchdog --config=/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse-server/click
└─3461 /usr/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse-serve
如果systemctl
指令存在在目的的作業系統的話,我們也可以透過使用下列的指令來操作ClickHouse資料庫server,相關指令執行的方式與輸出內容如下:
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$ sudo systemctl start clickhouse-server.service
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$ sudo systemctl status clickhouse-server.service
● clickhouse-server.service - ClickHouse Server (analytic DBMS for big data)
Loaded: loaded (/lib/systemd/system/clickhouse-server.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-09-07 03:48:07 UTC; 4min 35s ago
Main PID: 3451 (clckhouse-watch)
Tasks: 206 (limit: 4915)
CGroup: /system.slice/clickhouse-server.service
├─3451 clickhouse-watchdog --config=/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse-server/click
└─3461 /usr/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse-serve
同時也可以使用下列的指令來確認是否ClickHouse資料庫伺服器服務會在自動開機的時候自己啟動,相關執行指令與輸出的內容如下:
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$ sudo systemctl is-enabled clickhouse-server.service
enabled
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$
接著使用下列的指令就可以執行ClickHouse的客戶端指令來連線到當前的ClickHouse資料庫了,相關的執行指令與輸出的結果如下:
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$ clickhouse-client --password
ClickHouse client version 22.8.4.7 (official build).
Password for user (default):
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 22.8.4 revision 54460.
Warnings:
* Linux is not using a fast TSC clock source. Performance can be degraded. Check /sys/devices/system/clocksource/clocksource0/current_clocksource
ubuntu-s-4vcpu-8gb-amd-sgp1-01 :)
根據從上面的輸出內容,會看到一個警告,這個警告是因為這個目的作業系統是在虛擬機器的環境中,可能會影響到ClickHouse資料庫的效能,若是在實體機器上的話,則是會使用TSC Clock Source,則不會有上述這則警告出現,可以使用下列的指令來確認Clock Source,相關執行指令的輸出結果如下:
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource
kvm-clock
localadmin@clickhouse01:~$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource
tsc
localadmin@clickhouse02:~$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource
hpet
從上述的內容來看,也有可能在實體機器的情形下,會出現hpet
的情況,這是因為當前實體機器的Linux Kernel不支援新的Intel CPU架構,因此需要更新Kernel到較新的版本來解決這個問題。
若要離開ClickHouse客戶端的shell介面,則可以輸入exit
或是同時按下「ctrl」與「d」的組合鍵來離開,相關的指令與輸出訊息如下:
......
ubuntu-s-4vcpu-8gb-amd-sgp1-01 :)
ubuntu-s-4vcpu-8gb-amd-sgp1-01 :) exit
Bye.
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$
下列的相關指令是已經被官方棄用的安裝方法:
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates dirmngr
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E0C56BD4
echo "deb https://repo.clickhouse.com/deb/stable/ main/" | sudo tee \
/etc/apt/sources.list.d/clickhouse.list
sudo apt-get update
sudo apt-get install -y clickhouse-server clickhouse-client
sudo service clickhouse-server start
clickhouse-client # 如果在安裝過程中有設定密碼,則執行"clickhouse-client --password"指令
舊的安裝方法目前已經停止更新新的ClickHouse資料庫版本,若之前已經使用上述被官方棄用的方法來進行安裝ClickHouse資料庫,則可以使用下列的方法來遷移到新的安裝方法:
localadmin@clickhouse01:~$ sudo apt-key del E0C56BD4
[sudo] password for localadmin:
OK
localadmin@clickhouse01:~$
localadmin@clickhouse01:~$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 8919F6BD2B48D754
Executing: /tmp/apt-key-gpghome.EfkLJrUrHF/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv 8919F6BD2B48D754
gpg: key 8919F6BD2B48D754: public key "ClickHouse Inc. Repositories Key <packages@clickhouse.com>" imported
gpg: Total number processed: 1
gpg: imported: 1
localadmin@clickhouse01:~$
localadmin@clickhouse01:~$ echo "deb https://packages.clickhouse.com/deb stable main" | sudo tee /etc/apt/sources.list.d/clickhouse.list
deb https://packages.clickhouse.com/deb stable main
localadmin@clickhouse01:~$ sudo apt-get update
Get:1 http://mirrors.digitalocean.com/ubuntu bionic InRelease [242 kB]
Hit:2 https://repos-droplet.digitalocean.com/apt/droplet-agent main InRelease
Get:3 http://mirrors.digitalocean.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 http://mirrors.digitalocean.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:5 http://mirrors.digitalocean.com/ubuntu bionic-updates/main amd64 Packages [2729 kB]
Get:6 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:7 http://mirrors.digitalocean.com/ubuntu bionic-updates/main Translation-en [503 kB]
Get:8 http://mirrors.digitalocean.com/ubuntu bionic-updates/restricted amd64 Packages [913 kB]
Get:9 http://mirrors.digitalocean.com/ubuntu bionic-updates/restricted Translation-en [126 kB]
Get:10 http://mirrors.digitalocean.com/ubuntu bionic-updates/universe amd64 Packages [1842 kB]
Get:11 http://mirrors.digitalocean.com/ubuntu bionic-updates/universe Translation-en [399 kB]
Get:12 http://mirrors.digitalocean.com/ubuntu bionic-updates/multiverse amd64 Packages [24.9 kB]
Get:13 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [2389 kB]
Get:14 http://security.ubuntu.com/ubuntu bionic-security/main Translation-en [414 kB]
Get:15 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [884 kB]
Get:16 http://security.ubuntu.com/ubuntu bionic-security/restricted Translation-en [122 kB]
Get:17 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [1228 kB]
Get:18 http://security.ubuntu.com/ubuntu bionic-security/universe Translation-en [282 kB]
Get:19 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [19.0 kB]
Fetched 12.4 MB in 3s (4368 kB/s)
Reading package lists... Done
localadmin@clickhouse01:~$ sudo apt-get install -y clickhouse-server clickhouse-client
從上面的遷移鏡像的方法可以得知,首先先使用apt-key
的指令將舊的GPG金鑰進行移除,接著匯入新的GPG金鑰,接著再把新的鏡像網址更新到/etc/apt/sources.list.d/clickhouse.list
檔案中,接著再執行sudo apt-get update
的指令來更新鏡像的來源,這樣一來就完成了ClickHouse的鏡像遷移了。
在設定鏡像來源的時候,我們若要安裝其他版本的ClickHouse資料庫,則可以把stable
換成lts
版本,相關鏡像的網址設定,改成下列所示:
localadmin@clickhouse01:~$ echo "deb https://packages.clickhouse.com/deb lts main" | sudo tee /etc/apt/sources.list.d/clickhouse.list
deb https://packages.clickhouse.com/deb lts main
從上面可以得知,ClickHouse的DEB鏡像來源有下列這幾種套件:
在使用sudo apt-get install -y clickhouse-server clickhouse-client
指令安裝ClickHouse伺服器與客戶端時,並不會安裝clickhouse-common-static-dbg
,會歸類在建議的套件,相關的輸出指令如下:
peter@ubuntu-s-4vcpu-8gb-amd-sgp1-01:~$ sudo apt-get install -y clickhouse-server clickhouse-client
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
clickhouse-common-static
Suggested packages:
clickhouse-common-static-dbg
The following NEW packages will be installed:
clickhouse-client clickhouse-common-static clickhouse-server
......
如果要在安裝ClickHouse資料庫的時候,來指定要安裝的資料庫版本,則可以使用下列的指令來達成:
sudo apt-get install clickhouse-server=21.8.5.7 clickhouse-client=21.8.5.7 clickhouse-common-static=21.8.5.7
若是透過RPM套件來進行安裝,則是目標的Linux發行版本是以RPM為基礎的套件管理的作業系統,以下是幾種常見的發行的版本:
以下相關安裝的執行指令如下:
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-client
sudo /etc/init.d/clickhouse-server start
clickhouse-client # 如果default使用者有設定密碼的話,則使用"clickhouse-client --password"的指令
接著我們使用一個乾淨的Rocky Linux 8.6的版本作業系統來示範上述的安裝方法:
一開始我們需要先安裝yum的鏡像管理工具,所以先執行sudo yum install -y yum-utils
的指令來確保yum-utils
套件已經有安裝了,相關指令執行的結果與過程如下:
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$ sudo yum install -y yum-utils
[sudo] password for peter:
Last metadata expiration check: 0:00:40 ago on Wed 07 Sep 2022 06:15:55 AM UTC.
Package yum-utils-4.0.21-11.el8.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$
從上述的指令輸出可以知道,yum-utils
的套件已經安裝好了,接著再使用sudo yum-config-manager --add-repo https://packages.clickhouse.com/rpm/clickhouse.repo
將ClickHouse的鏡像進行匯入,相關執行指令的輸出內容如下:
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$ sudo yum-config-manager --add-repo https://packages.clickhouse.com/rpm/clickhouse.repo
[sudo] password for peter:
Adding repo from: https://packages.clickhouse.com/rpm/clickhouse.repo
接著就可以使用``指令來安裝ClickHouse伺服器與客戶端的版本了,相關的執行指令與輸出的結果如下:
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$ sudo yum install -y clickhouse-server clickhouse-client
ClickHouse - Stable Repository 1.2 kB/s | 821 B 00:00
ClickHouse - Stable Repository 10 kB/s | 4.0 kB 00:00
Importing GPG key 0x2B48D754:
Userid : "ClickHouse Inc. Repositories Key <packages@clickhouse.com>"
Fingerprint: 3A9E A119 3A97 B548 BE14 57D4 8919 F6BD 2B48 D754
From : https://packages.clickhouse.com/rpm/stable/repodata/repomd.xml.key
ClickHouse - Stable Repository 73 kB/s | 53 kB 00:00
DigitalOcean Droplet Agent 14 kB/s | 3.3 kB 00:00
Dependencies resolved.
============================================================================================================
Package Architecture Version Repository Size
============================================================================================================
Installing:
clickhouse-client x86_64 22.8.4.7-1 clickhouse-stable 75 k
clickhouse-server x86_64 22.8.4.7-1 clickhouse-stable 100 k
Installing dependencies:
clickhouse-common-static x86_64 22.8.4.7-1 clickhouse-stable 252 M
Transaction Summary
============================================================================================================
Install 3 Packages
Total download size: 253 M
Installed size: 737 M
Downloading Packages:
(1/3): clickhouse-server-22.8.4.7.x86_64.rpm 1.0 MB/s | 100 kB 00:00
(2/3): clickhouse-client-22.8.4.7.x86_64.rpm 582 kB/s | 75 kB 00:00
(3/3): clickhouse-common-static-22.8.4.7.x86_64.rpm 12 MB/s | 252 MB 00:20
------------------------------------------------------------------------------------------------------------
Total 12 MB/s | 253 MB 00:20
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : clickhouse-common-static-22.8.4.7-1.x86_64 1/3
Installing : clickhouse-server-22.8.4.7-1.x86_64 2/3
Running scriptlet: clickhouse-server-22.8.4.7-1.x86_64 2/3
ClickHouse binary is already located at /usr/bin/clickhouse
Symlink /usr/bin/clickhouse-server already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-server to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-client to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-local to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-benchmark to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-copier already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-copier to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-obfuscator to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-git-import to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-compressor to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-format to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-extract-from-config already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-extract-from-config to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-keeper already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-keeper to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-keeper-converter to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-disks to /usr/bin/clickhouse.
Creating clickhouse group if it does not exist.
groupadd -r clickhouse
Creating clickhouse user if it does not exist.
useradd -r --shell /bin/false --home-dir /nonexistent -g clickhouse clickhouse
Will set ulimits for clickhouse user in /etc/security/limits.d/clickhouse.conf.
Creating config directory /etc/clickhouse-server/config.d that is used for tweaks of main server configuration.
Creating config directory /etc/clickhouse-server/users.d that is used for tweaks of users configuration.
Config file /etc/clickhouse-server/config.xml already exists, will keep it and extract path info from it.
/etc/clickhouse-server/config.xml has /var/lib/clickhouse/ as data path.
/etc/clickhouse-server/config.xml has /var/log/clickhouse-server/ as log path.
Users config file /etc/clickhouse-server/users.xml already exists, will keep it and extract users info from it.
Creating log directory /var/log/clickhouse-server/.
Creating data directory /var/lib/clickhouse/.
Creating pid directory /var/run/clickhouse-server.
chown -R clickhouse:clickhouse '/var/log/clickhouse-server/'
chown -R clickhouse:clickhouse '/var/run/clickhouse-server'
chown clickhouse:clickhouse '/var/lib/clickhouse/'
groupadd -r clickhouse-bridge
useradd -r --shell /bin/false --home-dir /nonexistent -g clickhouse-bridge clickhouse-bridge
chown -R clickhouse-bridge:clickhouse-bridge '/usr/bin/clickhouse-odbc-bridge'
chown -R clickhouse-bridge:clickhouse-bridge '/usr/bin/clickhouse-library-bridge'
Password for default user is empty string. See /etc/clickhouse-server/users.xml and /etc/clickhouse-server/users.d to change it.
Setting capabilities for clickhouse binary. This is optional.
chown -R clickhouse:clickhouse '/etc/clickhouse-server'
ClickHouse has been successfully installed.
Start clickhouse-server with:
sudo clickhouse start
Start clickhouse-client with:
clickhouse-client
Synchronizing state of clickhouse-server.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable clickhouse-server
Created symlink /etc/systemd/system/multi-user.target.wants/clickhouse-server.service → /usr/lib/systemd/system/clickhouse-server.service.
Installing : clickhouse-client-22.8.4.7-1.x86_64 3/3
Running scriptlet: clickhouse-client-22.8.4.7-1.x86_64 3/3
Verifying : clickhouse-server-22.8.4.7-1.x86_64 1/3
Verifying : clickhouse-common-static-22.8.4.7-1.x86_64 2/3
Verifying : clickhouse-client-22.8.4.7-1.x86_64 3/3
Installed:
clickhouse-client-22.8.4.7-1.x86_64 clickhouse-common-static-22.8.4.7-1.x86_64
clickhouse-server-22.8.4.7-1.x86_64
Complete!
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$
其中,RPM裡面可以取得的套件有clickhouse-client
、clickhouse-server
、clickhouse-common-static
以及clickhouse-common-static-dbg
,相關的套件描述和用途,與DEB套件的相符合的。
從上述的安裝ClickHouse資料庫相關的套件過程中可以得知,並沒有與DEB套件一樣有等待使用者輸入的密碼提示,取而代之的是出現Password for default user is empty string. See /etc/clickhouse-server/users.xml and /etc/clickhouse-server/users.d to change it.
訊息,這意思是ClickHouse的安裝程式偵測到在這個shell環境無法啟用互動模式來設定密碼,所以ClickHouse伺服器的default使用者預設就設定沒有密碼,後面的章節將會提到如何使用設定檔來設定default使用者的密碼。
接著使用下列的指令將ClickHouse資料庫伺服器啟動,相關的指令與執行後的輸出訊息如下:
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$ sudo /etc/init.d/clickhouse-server start
chown -R clickhouse: '/var/run/clickhouse-server/'
Will run clickhouse su 'clickhouse' /usr/bin/clickhouse-server --config-file /etc/clickhouse-server/config.xml --pid-file /var/run/clickhouse-server/clickhouse-server.pid --daemon
Waiting for server to start
Waiting for server to start
Server started
sed: can't read /etc/cron.d/clickhouse-server: No such file or directory
啟動完成ClickHouse資料庫伺服器之後,接著執行ClickHouse的客戶端指令,相關的指令執行如下:
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$ clickhouse-client
ClickHouse client version 22.8.4.7 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 22.8.4 revision 54460.
Warnings:
* Linux is not using a fast TSC clock source. Performance can be degraded. Check /sys/devices/system/clocksource/clocksource0/current_clocksource
* Linux transparent hugepages are set to "always". Check /sys/kernel/mm/transparent_hugepage/enabled
rockylinux-g-2vcpu-8gb-sgp1-01 :)
要離開ClickHouse客戶端則可以使用exit
命令或是使用「ctrl」與「d」的組合鍵,相關執行指令的輸出訊息如下:
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$ clickhouse-client
ClickHouse client version 22.8.4.7 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 22.8.4 revision 54460.
Warnings:
* Linux is not using a fast TSC clock source. Performance can be degraded. Check /sys/devices/system/clocksource/clocksource0/current_clocksource
* Linux transparent hugepages are set to "always". Check /sys/kernel/mm/transparent_hugepage/enabled
rockylinux-g-2vcpu-8gb-sgp1-01 :) exit
Bye.
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$
其中,在Rocky Linux上連上ClickHouse資料庫伺服器時候,多了Linux transparent hugepages are set to "always". Check /sys/kernel/mm/transparent_hugepage/enabled
警告訊息,原因是在Rocky Linux上使用的Kernel版本較舊,因此需要將Linux transparent hugepages之設定關閉或者將Kernel更新到更新的版本,相關的指令執行如下:
首先,先安裝vim
文字編輯器
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$ sudo yum install -y vim
接著使用vim /etc/default/grub
將GRUB開機檔打開,找到GRUB_CMDLINE_LINUX="console=ttyS0,115200n8 no_timer_check net.ifnames=0 crashkernel=auto"
這行,大概會是在第6行的地方,所以可以使用「:6」切換到該行並按下「i」鍵,接著將這行改成下列的設定:
GRUB_CMDLINE_LINUX="console=ttyS0,115200n8 no_timer_check net.ifnames=0 crashkernel=auto transparent_hugepage=madvise"
修改完成之後,按下ESC鍵並輸入「:wq」,接著再執行sudo grub2-mkconfig -o /boot/grub2/grub.cfg
指令來產生新的GRUB選單檔案並來使用客製化設定:
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
done
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$
接著再執行sudo reboot
指令將機器重新開機,開機完成之後,再執行sudo cat /sys/kernel/mm/transparent_hugepage/enabled
就會發現設定已經切換成madvise
了:
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$ sudo cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$ sudo reboot
Connection to 128.199.95.22 closed by remote host.
Connection to 128.199.95.22 closed.
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$ sudo cat /sys/kernel/mm/transparent_hugepage/enabled
[sudo] password for peter:
always [madvise] never
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$
接著再使用clickhouse-client
連到ClickHouse資料庫,就不會再出現上述的警告訊息了:
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$ clickhouse-client
ClickHouse client version 22.8.4.7 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 22.8.4 revision 54460.
Warnings:
* Linux is not using a fast TSC clock source. Performance can be degraded. Check /sys/devices/system/clocksource/clocksource0/current_clocksource
rockylinux-g-2vcpu-8gb-sgp1-01 :)
另外,在Linux Ubuntu發布版本的Transparent Huge Pages設定預設是madvise
,因此不需要再做額外的設定。
以下的安裝方法是已經被ClickHouse官方所棄用的:
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-client
sudo /etc/init.d/clickhouse-server start
clickhouse-client # 如果default使用者有設定密碼的話,則使用"clickhouse-client --password"的指令
若要從上述被棄用的安裝方法遷移到新的安裝方法,則可以使用下列的指令來完成:
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$ sudo rm /etc/yum.repos.d/clickhouse.repo
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$ sudo rpm -e "gpg-pubkey-e0c56bd4-574473a5"
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$ sudo yum-config-manager --add-repo https://packages.clickhouse.com/rpm/clickhouse.repo
[peter@rockylinux-g-2vcpu-8gb-sgp1-01 ~]$ sudo yum install -y clickhouse-server clickhouse-client
上面的遷移方法就是先將被棄用的GPG金鑰與設定的鏡像檔案進行刪除,接著再使用新的方法來進行鏡像的匯入與安裝。
在本次章節中,我們學到了如何在DEB與RPM為基礎的Linux發布版本的作業系統上安裝ClickHouse相關的套件與設定鏡像,在下一章節中,會接著介紹用其他的安裝ClickHouse套件的方法。