How to Install ClickHouse on CentOS 7

In this tutorial, we will show you how to install ClickHouse on a CentOS 7 VPS, as well as demonstrate some things that you can do in ClickHouse.

ClickHouse is a distributed analytical column-oriented database management system. ClickHouse has the ability to perform queries in real-time, making it simple and easy to run applications that require analytical results. The ClickHouse query language is based on SQL, which only helps to simplify and reduce the learning curve for the end user. ClickHouse has two main characteristics:

  • Column-oriented databases – Records in blocks grouped by columns instead of rows. This method is much faster than the traditional row-based system.
  • Online Analytics Processing system – This systems allows for the organization of a large amount of data, as well as executing more complex queries.

Let’s get started with the installation.

Prerequisites

  • For the purposes of this tutorial, we will use a CentOS 7 VPS.
  • Full SSH root access or a user with sudo privileges is also required.

Step 1: Connect via SSH and Update

Connect to your server via SSH as the root user using the following command:

ssh root@IP_ADDRESS -p PORT_NUMBER

Remember to replace “IP_ADDRESS” and “PORT_NUMBER” with your server’s respective IP address and SSH port number.

Before starting with the installation, you will need to update your system packages to their latest versions. It’s easy to do, and it won’t take more than a few minutes.

You can do this by running the following command:

sudo yum update

Once the updates are completed, we can move on to the next step.

Step 2: Install ClickHouse

We will install the ClickHouse server and client programs using the YUM package manager. First, we need to install the ClickHouse dependencies. We’re installing the ‘pygpgme‘ package, which is used for adding and verifying GPG signatures.

sudo yum install pygpgme yum-utils

The built-in preinstalled repositories on CentOS unfortunately do not contain the latest version of ClickHouse – this is why we’ll be installing a repository that has the latest version for CentOS. Before installing this repository, we will first need to add some repository details which will secure and validate our ClickHouse packages.

For this tutorial, we’ll be using ‘vi’ as our text editor of choice. You are free to use your preferred text editor if you like. We will now create the repository file by using the following command:

sudo vi /etc/yum.repos.d/altinity_clickhouse.repo

Next, we will add the following content to the file:

[altinity_clickhouse]
name=altinity_clickhouse
baseurl=https://packagecloud.io/altinity/clickhouse/el/7/$basearch
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/altinity/clickhouse/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

[altinity_clickhouse-source]
name=altinity_clickhouse-source
baseurl=https://packagecloud.io/altinity/clickhouse/el/7/SRPMS
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/altinity/clickhouse/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

When you are finished with adding the text, save and close the file.

Once you have added the repositories, you’ll need to enable them by executing the following command:

sudo yum -q makecache -y --disablerepo='*' --enablerepo='altinity_clickhouse'

You should see an output similar to the following:

Importing GPG key 0x0C7EG6F3:
Userid : "https://packagecloud.io/altinity/clickhouse  <support@packagecloud.io>"
Fingerprint: 6102 38a9 7c50 3h82 28bf 3f16 wg56 5vf3 0f6g 8df2
From : https://packagecloud.io/altinity/clickhouse/gpgkey

After successfully configuring the repository, we will be able to install the packages with the following command:

sudo yum install -y clickhouse-server clickhouse-client

The ClickHouse server and client have been installed successfully.

Step 3: Starting the ClickHouse Service 

The ClickHouse package creates a systemd service during the installation process. This is so that we are able to perform actions regarding ClickHouse such as starting, stopping, and restarting the database server. We can start our ClickHouse server by running the following command:

sudo service clickhouse-server start

You should see an output similar to this:

Start clickhouse-server service: Path to data directory in /etc/clickhouse-server/config.xml: /var/lib/clickhouse/
DONE

If you want to check that the service is running successfully, we need to execute this:

sudo service clickhouse-server status

If everything is set up properly, you should see an output similar to the following:

clickhouse-server service is running

If that’s the message returned by the command, then we have successfully installed and started our ClickHouse server, and now we will be able to use and connect to the ClickHouse CLI.

Step 4: Creating Databases and Tables

To create a database, we need to start a client session by executing the following command:

clickhouse-client --multiline

The multiline flag allows us to enter queries that span multiple lines.

Now we will create a database named ‘test‘, inside of which we will then create a table named ‘person‘.

Since we are already inside the ClickHouse command prompt, we can create our test database with the following command:

ch:) CREATE DATABASE test;

You should see the output similar to this:

CREATE DATABASE test
Ok.
0 rows in set. Elapsed: 0.005 sec.

Before we create a table, we first need to enter the database that we will be modifying:

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
ch:) USE test;

You will see the output which will show you that you have switched to the test database:

USE test
Ok.
0 rows in set. Elapsed: 0.003 sec.

Our ‘person’ table will have several fields, such as ‘PersonID’, ‘LastName’, ‘FirstName’, and so on.

Now we can create the person table by running the following command:

ch:) CREATE TABLE Person (
ch:) PersonID UInt64,
ch:) LastName String,
ch:) FirstName String,
ch:) Address String,
ch:) City String,
ch:) BirthDate DateTime
ch:) ) ENGINE = MergeTree() 
ch:) PRIMARY KEY PersonID 
ch:) ORDER BY PersonID;

If everything is created properly, you should see the following output:

CREATE TABLE Person
(
PersonID UInt64,
LastName String,
FirstName String,
Address String,
City String,
BirthDate DateTime
)
ENGINE = MergeTree()
PRIMARY KEY PersonID
ORDER BY PersonID

Ok.

0 rows in set. Elapsed: 0.015 sec.

That’s all there is to it – in this tutorial, we learned how to install ClickHouse on CentOS 7, as well as how to create sample databases and tables. Of course, there are a lot more capabilities in ClickHouse that we haven’t covered. This is why we suggest reading the documentation in order to fulfill the server’s full potential.


Of course, you don’t have to install ClickHouse on CentOS 7 if you use one of our Managed CentOS Hosting services, in which case you can simply ask our expert system administrators to install ClickHouse on CentOS 7 for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post on how to install ClickHouse on CentOS 7, please share it with your friends on the social networks by using the share shortcuts below, or simply leave a comment in the comments section. Thanks.

Leave a Comment