Time series database: installation and use of clickhouse and clickhouse-client

background

Clickhouse is used in the company's project. After the time series database is installed, the relevant tables used by the business need to be initialized. The development provides a sql file for table building, here I need to execute the sql file to initialize it. Here I use Clickhouse's native command line client: Clickhouse-client, for quick import. 

Install clickhouse

1) Verify whether sse4.2 is supported

#clickhouse's server already client only supports x86_64, AArch64 or PowerPC64LE CPU architecture on Linux, FreeBSD or Mac OS X
grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"

2) Install clickhouse and clickhouse-client

If it is Ubuntu:

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.tech/deb/stable/ main/" | sudo tee \
    /etc/apt/sources.list.d/clickhouse.list

#Update deb source
sudo apt-get update

#Install clickhouse-server and clickhouse-client
sudo apt-get install -y clickhouse-server clickhouse-client
#Start clickhouse-server
sudo service clickhouse-server start

如果是Centos:

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/stable/x86_64
#Install clickhouse-server and clickhouse-client
sudo yum install clickhouse-server clickhouse-client
#Start clickhouse-serversudo /etc/init.d/clickhouse-server start

3) Clickhouse configuration

Clickhouse-server/etc/clickhouse-server/config.xml,根据自己的实际情况修改。

Clickhouse-client: Search down in order of priority

  • ./clickhouse-client.xml
  • ~/.clickhouse-client/config.xml
  • /etc/clickhouse-client/config.xml

We modify /etc/clickhouse-client/config.xml to add user, password, and secure three xml elements.

<config>  <user>defaultuser>
  <password>xxxpassword>
  <secure>Falsesecure>  <openSSL>
    <client> 
      <loadDefaultCAFile>trueloadDefaultCAFile>
      <cacheSessions>truecacheSessions>
      <disableProtocols>sslv2,sslv3disableProtocols>
      <preferServerCiphers>truepreferServerCiphers>
      
      <invalidCertificateHandler>
        
        <name>RejectCertificateHandlername>
      invalidCertificateHandler>
    client>
  openSSL>

  <prompt_by_server_display_name>
    <default>{display_name} :) default>
    <test>{display_name} \x01\e[1;32m\x02:)\x01\e[0m\x02 test> 
    <production>{display_name} \x01\e[1;31m\x02:)\x01\e[0m\x02 production> 
  prompt_by_server_display_name>
config>

After Clickhouse is installed, we use Clickhouse-client to simply operate Clickhouse:

Command line parameters:

  • --host, -h -– The host name of the server, the default is localhost. You can choose to use the host name or IPv4 or IPv6 address, which is commonly used .
  • --port-the connected port, default value: 9000. Note that HTTP interface and TCP native interface use different ports, which are commonly used .
  • --user, -u-username. Default value: default, commonly used .
  • --password-password. Default value: empty string, commonly used .
  • --query, -q-Use non-interactive mode query, commonly used .
  • --database, -d-Default current operating database. Default value: The default configuration of the server (default is default), commonly used .
  • --multiline, -m-If specified, multi-line query is allowed (Enter only represents a new line, not the end of the query), commonly used .
  • --multiquery, -n-If specified, multiple queries separated by; are allowed to be processed, which only take effect in non-interactive mode and are commonly used .
  • --format, -f-Use the specified default format to output the result.
  • --vertical, -E-If specified, the results are output in vertical format by default. This is the same as –format=Vertical. In this format, each value is printed on a separate line, which is very helpful for displaying wide tables.
  • --time, -t-If specified, the query execution time will be printed to stderr in non-interactive mode.
  • --stacktrace-If specified, if an exception occurs, stack trace information will be printed.
  • --config-file-The name of the configuration file, commonly used .
  • --secure-If specified, will connect to the server via a secure connection.
  • --history_file — The path of the file storing the command history.
  • --param_-Query parameter configuration query parameter .

example

1) Use Clickhouse-client to connect to Clickhouse's default database.

Format : clickhouse-client  --host Clickhouse host address  --user login name --password password --port Clickhouse port number

clickhouse-client --host 172.30.0.252 --user default --password xxx --port 9090

2) Import the sql file to the specified clickhouse

Format: clickhouse-client  --host Clickhouse host address  --user login name --password password   --port Clickhouse port number  --multiquery <xxx.sql 

clickhouse-client --host 172.30.0.252 --user default --password qingcloud2019 --port 9090 --multiquery < ck.sql

The above is the construction and simple instructions for Clickhouse, friends are welcome to leave a message~


Blogger: test to make money (a test open code farmer who is not 996 but 996)

Motto: Focus on test development and automated operation and maintenance, work hard to read, think and write, and lay the financial freedom for the life of the scroll.

Content categories: technology improvement, workplace miscellaneous talk, career development, reading and writing, investment and financial management, healthy life.

csdn:https://blog.csdn.net/ccgshigao

Blog Park: https://www.cnblogs.com/qa-freeroad/

51cto :https://blog.51cto.com/14900374

In the depressing years of programmers, we look forward to growing together, welcome to pay attention, thank you for making bricks!


Guess you like

Origin blog.51cto.com/14900374/2626182