apt install curl
curl https://clickhouse.com/ | sh
this will download a clickhouse file, you need to run the following command to install
sudo ./clickhouse install
it will ask the following questions
Enter password for default user:
Allow server to accept connections from the network (default is localhost only), [y/N]:
and prompt with this
ClickHouse has been successfully installed. Start clickhouse-server with:
sudo clickhouse start
Start clickhouse-client with:
clickhouse-client --password
Now create a unit file
vim /etc/systemd/system/clickhouse-server.service
and add the following content
[Unit]
Description=ClickHouse Server (analytic DBMS for big data)
Requires=network-online.target
# NOTE: that After/Wants=time-sync.target is not enough, you need to ensure# that the time was adjusted already, if you use systemd-timesyncd you are# safe, but if you use ntp or some other daemon, you should configure it# additionaly.
After=time-sync.target network-online.target
Wants=time-sync.target
[Service]
Type=notify
# NOTE: we leave clickhouse watchdog process enabled to be able to see OOM/SIGKILL traces in clickhouse-server.log files.# If you wish to disable the watchdog and rely on systemd logs just add "Environment=CLICKHOUSE_WATCHDOG_ENABLE=0" line.
User=clickhouse
Group=clickhouse
Restart=always
RestartSec=30
# Since ClickHouse is systemd aware default 1m30sec may not be enough
TimeoutStartSec=0
# %p is resolved to the systemd unit name
RuntimeDirectory=%p
ExecStart=/usr/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml --pid-file=%t/%p/%p.pid
# Minus means that this file is optional.
EnvironmentFile=-/etc/default/%p
# Bring back /etc/default/clickhouse for backward compatibility
EnvironmentFile=-/etc/default/clickhouse
LimitCORE=infinity
LimitNOFILE=500000
CapabilityBoundingSet=CAP_NET_ADMIN CAP_IPC_LOCK CAP_SYS_NICE CAP_NET_BIND_SERVICE
[Install]
# ClickHouse should not start from the rescue shell (rescue.target).
WantedBy=multi-user.target
Start clickhouse server
systemctl restart clickhouse-server
Check Status
$ systemctl status clickhouse-server
● clickhouse-server.service - ClickHouse Server (analytic DBMS for big data)
Loaded: loaded (/etc/systemd/system/clickhouse-server.service; disabled; vendor preset: enabled)
Active: active (running) since Wed 2023-12-27 14:01:00 PKT; 11s ago
Main PID: 4548 (clickhouse-serv)
Tasks: 673 (limit: 2323)
Memory: 225.2M
CPU: 956ms
CGroup: /system.slice/clickhouse-server.service
├─4547 clickhouse-watchdog --config=/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse-server/clickho>
└─4548 /usr/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse-server/clickho>
Dec 27 14:00:59 qryn-server clickhouse-server[4548]: Merging configuration file '/etc/clickhouse-server/config.d/data-paths.xml'.
Dec 27 14:00:59 qryn-server clickhouse-server[4548]: Merging configuration file '/etc/clickhouse-server/config.d/listen.xml'.
Dec 27 14:00:59 qryn-server clickhouse-server[4548]: Merging configuration file '/etc/clickhouse-server/config.d/logger.xml'.
Dec 27 14:00:59 qryn-server clickhouse-server[4548]: Merging configuration file '/etc/clickhouse-server/config.d/openssl.xml'.
Dec 27 14:00:59 qryn-server clickhouse-server[4548]: Merging configuration file '/etc/clickhouse-server/config.d/user-directories.x>Dec 27 14:00:59 qryn-server clickhouse-server[4548]: Saved preprocessed configuration to '/var/lib/clickhouse/preprocessed_configs/>
Dec 27 14:00:59 qryn-server clickhouse-server[4548]: Processing configuration file '/etc/clickhouse-server/users.xml'.
Dec 27 14:00:59 qryn-server clickhouse-server[4548]: Merging configuration file '/etc/clickhouse-server/users.d/default-password.xm>Dec 27 14:00:59 qryn-server clickhouse-server[4548]: Saved preprocessed configuration to '/var/lib/clickhouse/preprocessed_configs/>
Dec 27 14:01:00 qryn-server systemd[1]: Started ClickHouse Server (analytic DBMS for big data).
Connect to clickhouse-server with the following command
$ clickhouse-client -u default --password
ClickHouse client version 23.12.1.1214 (official build).
Password for user (default):
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 23.12.1.
Warnings:
* Linux transparent hugepages are set to "always". Check /sys/kernel/mm/transparent_hugepage/enabled
* Linux threads max count is too low. Check /proc/sys/kernel/threads-max
* Available memory at server startup is too low (2GiB).
* Maximum number of threads is lower than 30000. There could be problems with handling a lot of simultaneous queries.
qryn-server :)
cd /usr/local/src/
wget https://go.dev/dl/go1.21.5.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.5.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
cd
go version
Start Writing API
mkdir /usr/local/hbapp/
cd /usr/local/hbapp/
vim main.go
copy the code
package main
import (
"database/sql""fmt""log""net/http"
_ "github.com/go-sql-driver/mysql"// Import MySQL driver"github.com/gorilla/mux"
)
vardb*sql.DBfuncinit() {
varerrerror// Connect to your databasedb, err=sql.Open("mysql", "username:password@tcp(localhost:3306)/your_database")
iferr!=nil {
log.Fatal(err)
}
// Check if the connection is successfulerr=db.Ping()
iferr!=nil {
log.Fatal(err)
}
}
funcmain() {
r:=mux.NewRouter()
// Define your API endpointr.HandleFunc("/check/{input}", CheckExistence).Methods("GET")
// Start the HTTP serverlog.Fatal(http.ListenAndServe(":8080", r))
}
// CheckExistence is the handler for the API endpointfuncCheckExistence(w http.ResponseWriter, r*http.Request) {
// Get the input parameter from the URLvars:=mux.Vars(r)
input:=vars["input"]
// Call a function to check if the input exists in the databaseexists, err:=checkDatabase(input)
iferr!=nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Return the result as JSONifexists {
fmt.Fprint(w, `{"exists": true}`)
} else {
fmt.Fprint(w, `{"exists": false}`)
}
}
// checkDatabase is a function to check if the input exists in the databasefunccheckDatabase(inputstring) (bool, error) {
// Perform a query to check existence in your database// Replace "your_table" and "your_column" with your actual table and column namesquery:="SELECT COUNT(*) FROM your_table WHERE your_column = ?"varcountinterr:=db.QueryRow(query, input).Scan(&count)
iferr!=nil {
returnfalse, err
}
// If count is greater than 0, the input exists in the databasereturncount>0, nil
}
Install go modules
go install github.com/gorilla/mux@latest
go install github.com/go-sql-driver/mysql@latest