mirror of
https://github.com/ditatompel/insights.git
synced 2025-04-10 05:16:23 +07:00
Added new article about Self-hosted HiSHtory
This commit is contained in:
parent
93050f18ac
commit
43ed832ec4
4 changed files with 406 additions and 0 deletions
Binary file not shown.
After Width: | Height: | Size: 71 KiB |
Binary file not shown.
After Width: | Height: | Size: 82 KiB |
203
content/tutorials/self-hosted-hishtory/index.id.md
Normal file
203
content/tutorials/self-hosted-hishtory/index.id.md
Normal file
|
@ -0,0 +1,203 @@
|
||||||
|
---
|
||||||
|
title: Langkah-langkah Menginstall Self-hosted HiSHtory
|
||||||
|
description: Cara menginstall self-hosted HiSHtory, sebuah program yang menyimpan konteks riwayat terminal. Ikuti panduan yang mudah diikuti ini untuk proses penyiapan yang lancar
|
||||||
|
summary: HiSHtory adalah alat yang menyimpan konteks riwayat terminal, termasuk tanggal dieksekusinya perintah, direktori, dan durasi perintah tersebut berjalan. Artikel ini menunjukkan cara menginstal self-hosted HiSHtory, yang memungkinkan Anda mengelola riwayat terminal dengan mudah.
|
||||||
|
date: 2025-03-20T19:08:00+07:00
|
||||||
|
lastmod:
|
||||||
|
draft: false
|
||||||
|
noindex: false
|
||||||
|
nav_weight: 1000
|
||||||
|
categories:
|
||||||
|
- Self-Hosted
|
||||||
|
tags:
|
||||||
|
- Bash
|
||||||
|
- Zsh
|
||||||
|
- HiSHtory
|
||||||
|
- Linux
|
||||||
|
images:
|
||||||
|
authors:
|
||||||
|
- ditatompel
|
||||||
|
---
|
||||||
|
|
||||||
|
Jika Anda sering bekerja menggunakan Linux Terminal, fitur _history_ pada
|
||||||
|
_shell_ yang kita gunakan bisa sangat membantu meningkatkan produktifitas kita.
|
||||||
|
Namun, **secara _default_**, fitur _shell history_ seperti `bash` atau `zsh`
|
||||||
|
memikili keterbatasan. Beberapa diantaranya adalah:
|
||||||
|
|
||||||
|
- Tidak menyimpan informasi dari direktori mana perintah yang kita jalankan.
|
||||||
|
- Tidak adanya informasi apakah perintah tersebut sukses dieksekusi atau tidak.
|
||||||
|
- Tidak adanya informasi seberapa lama komputer kita membutuhkan waktu untuk
|
||||||
|
menyelesaikan perintah tersebut.
|
||||||
|
|
||||||
|
Bagi sebagian besar pengguna Linux, fitur-fitur diatas memang sedikit
|
||||||
|
_overkill_ dan bukan sebuah fitur yang krusial. Dan menyimpan informasi ekstra
|
||||||
|
tersebut sedikit banyak dapat meningkatkan disk I/O dan mempengaruhi performa
|
||||||
|
mesin. Tetapi, bagi sebagian penguna Linux lainnya, fitur tersebut dapat sangat
|
||||||
|
membantu melakukan investigasi ataupun troubleshooting pada sebuah sistem.
|
||||||
|
|
||||||
|
Jika informasi-informasi tersebut dapat disimpan secara terpusat dan dapat
|
||||||
|
dilakukan pencarian berdasarkan kata kunci tertentu, tentu akan sangat membantu
|
||||||
|
meringankan tugas para Linux System Administrstrator yang seringkali banyak
|
||||||
|
menggunakan perintah dengan _pipeline_ yang kompleks. Untungnya ada sebuah
|
||||||
|
program yang bernama **HiSHtory**.
|
||||||
|
|
||||||
|
## Pengenalan HiSHtory
|
||||||
|
|
||||||
|
[HiSHtory][hishtory-gh] merupakan program yang menyimpan konteks history
|
||||||
|
terminal dari jam dan tanggal kapan perintah tersebut dieksekusi, lokasi
|
||||||
|
direktori yang aktif saat perintah dijalankan, dan seberapa lama perintah
|
||||||
|
tersebut dieksekusi. Informasi tersebut dapat disimpan secara lokal (per mesin)
|
||||||
|
ataupun terpusat (_clint-server architecture_).
|
||||||
|
|
||||||
|
Dengan kata lain, Anda dapat melakukan pencarian _shell pipeline_ yang
|
||||||
|
kompleks dari server atau mesin lain dengan mudah dari laptop atau salah satu
|
||||||
|
komputer Anda.
|
||||||
|
|
||||||
|
## Menggunakan HiSHtory secara Terpusat (self-hosted)
|
||||||
|
|
||||||
|
Di artikel ini, saya akan menggunakan 2 buah laptop dengan sistem opersai
|
||||||
|
Linux dengan detail sebagai berikut:
|
||||||
|
|
||||||
|
- hostname T420 dengan IP `192.168.2.22` akan bertugas sebagai server sekaligus
|
||||||
|
client
|
||||||
|
- hostname P50 sebagai client
|
||||||
|
|
||||||
|
Perlu diperhatikan bahwa saya akan mengunakan HiSHtory server versi Docker,
|
||||||
|
sehingga pastikan komputer server sudah terinstall Docker dan dapat berjalan
|
||||||
|
dengan baik.
|
||||||
|
|
||||||
|
### Mengkonfigurasi HiSHtory Server
|
||||||
|
|
||||||
|
1. Login ke komputer server dan `clone` repositori
|
||||||
|
[ddworken/hishtory][hishtory-gh] dan masuk ke direktori tersebut:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
git clone https://github.com/ddworken/hishtory.git
|
||||||
|
cd hishtory
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Edit `backend/server/docker-compose.yml` dan sesuaikan konfigurasi sesuai
|
||||||
|
kebutuhan. Karena saya menggunakan PostgreSQL sebagai database backend-nya,
|
||||||
|
saya mengubah `POSTGRES_PASSWORD` dari `TODO_YOUR_POSTGRES_PASSWORD_HERE`
|
||||||
|
ke `MyStrongPassword`. Karena saya mengubah konfigurasi default password
|
||||||
|
Posgres, saya perlu menyesuaikan juga nilai dari environment variable
|
||||||
|
`HISHTORY_POSTGRES_DB` sesuai dengan password yang sudah saya tentukan.
|
||||||
|
Selain itu, karena port 80 pada server sudah saya gunakan untuk proses
|
||||||
|
lain, saya mengubah listen port HiSHtory server di host machine dari
|
||||||
|
port `80` ke port `45680`.
|
||||||
|

|
||||||
|
Kurang lebih konfigurasi `backend/server/docker-compose.yml` saya
|
||||||
|
sebagai berikut:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
version: "3.8"
|
||||||
|
networks:
|
||||||
|
hishtory:
|
||||||
|
driver: bridge
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres
|
||||||
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- hishtory
|
||||||
|
environment:
|
||||||
|
POSTGRES_PASSWORD: MyStrongPass
|
||||||
|
POSTGRES_DB: hishtory
|
||||||
|
PGDATA: /var/lib/postgresql/data/pgdata
|
||||||
|
volumes:
|
||||||
|
- postgres-data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: pg_isready -U postgres
|
||||||
|
interval: 10s
|
||||||
|
timeout: 3s
|
||||||
|
hishtory:
|
||||||
|
depends_on:
|
||||||
|
postgres:
|
||||||
|
condition: service_healthy
|
||||||
|
networks:
|
||||||
|
- hishtory
|
||||||
|
build:
|
||||||
|
context: ../../
|
||||||
|
dockerfile: ./backend/server/Dockerfile
|
||||||
|
restart: unless-stopped
|
||||||
|
deploy:
|
||||||
|
restart_policy:
|
||||||
|
condition: on-failure
|
||||||
|
delay: 3s
|
||||||
|
environment:
|
||||||
|
HISHTORY_POSTGRES_DB: postgresql://postgres:MyStrongPass@postgres:5432/hishtory?sslmode=disable
|
||||||
|
HISHTORY_COMPOSE_TEST: $HISHTORY_COMPOSE_TEST
|
||||||
|
ports:
|
||||||
|
- 45680:8080
|
||||||
|
volumes:
|
||||||
|
postgres-data:
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Kemudian _build_ docker image dengan menjalankan perintah:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
docker compose -f backend/server/docker-compose.yml build
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Setelah proses build selesai, coba jalankan HiSHtory server menggunakan
|
||||||
|
perintah:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
docker compose -f backend/server/docker-compose.yml up
|
||||||
|
```
|
||||||
|
|
||||||
|
Tunggu beberapa saat dan pastikan HiSHtory server berjalan dengan baik. Hal
|
||||||
|
ini bisa di cek dengan menggunakan perintah `docker ps` atau melakukan
|
||||||
|
pengecekan langsung ke HiSHtory HTTP server: `curl -sIL http://127.0.0.1:45680`
|
||||||
|
(ubah dan sesuaikan IP:port dengan konfigurasi milik Anda).
|
||||||
|
|
||||||
|
### Mengkonfigurasi HiSHtory Client
|
||||||
|
|
||||||
|
Satu hal yang penting, karena kita akan menggunakan _self-hosted_, Anda
|
||||||
|
**perlu** menambahkan juga environment variable
|
||||||
|
`HISHTORY_SERVER=http://<ip>:<port>` ke `.bashrc` atau `.zshrc` Anda
|
||||||
|
(sesuaikan alamat IP dan port yang digunakan).
|
||||||
|
|
||||||
|
Selain itu, secara _default_, HiSHtory client akan terinstall di `~/.hishtory`.
|
||||||
|
Namun, supaya `$HOME` direktori saya lebih rapi, di artikel kali ini saya akan
|
||||||
|
menggunakan direktori `~/.config/hishtory`. Hal ini bisa dilakukan dengan
|
||||||
|
menambahkan `HISHTORY_PATH=.config/hishtory` ke `.bashrc` atau `.zshrc` Anda.
|
||||||
|
|
||||||
|
Sehingga kurang lebih `.bashrc` atau `.zshrc` saya ada tambahan konfigureasi
|
||||||
|
sebagai berikut:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
export HISHTORY_PATH=.config/hishtory
|
||||||
|
# sesuaikan IP dan port di bawah ini dengan environment Anda
|
||||||
|
export HISHTORY_SERVER="http://192.168.2.22:45680"
|
||||||
|
```
|
||||||
|
|
||||||
|
Setelah envoronment variable diatas ditambahkan, reload sesi shell Anda,
|
||||||
|
kemudian download dan jalankan install script yang sudah tersedia:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
curl https://hishtory.dev/install.py | python3 -
|
||||||
|
```
|
||||||
|
|
||||||
|
Script tersebut akan secara otomatis mengenerate device ID dan secret key Anda
|
||||||
|
serta berbagai konfigurasi dasar lainnya. Simpan secret key yang tampil
|
||||||
|
sehingga dapat Anda gunakan untuk sinkronisasi di komputer lain.
|
||||||
|
|
||||||
|
Untuk mengkonfigurasi pada komputer atau server kedua dan seterusnya, ulangi
|
||||||
|
proses diatas di masing-masing komputer atau server. Setelah proses installasi
|
||||||
|
hishtory menggunakan install script terakhir diatas selesai, jalankan perintah
|
||||||
|
berikut:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
hishtory init $YOUR_HISHTORY_SECRET_FROM_FIRST_DEVICE
|
||||||
|
```
|
||||||
|
|
||||||
|
Ubah `$YOUR_HISHTORY_SECRET_FROM_FIRST_DEVICE` dengan secret key dari device
|
||||||
|
pertama.
|
||||||
|
|
||||||
|
> **Catatan**: Secret key juga bisa ditampilan dengan menjalankan perintah
|
||||||
|
> `hishtory status` dari device pertama.
|
||||||
|
|
||||||
|
Semoga membantu.
|
||||||
|
|
||||||
|
[hishtory-gh]: ttps://github.com/ddworken/hishtory "Repositori Official HiSHtory"
|
203
content/tutorials/self-hosted-hishtory/index.md
Normal file
203
content/tutorials/self-hosted-hishtory/index.md
Normal file
|
@ -0,0 +1,203 @@
|
||||||
|
---
|
||||||
|
title: "Installing Self-Hosted HiSHtory: A Step-by-Step Guide"
|
||||||
|
description: Learn how to install the self-hosted version of HiSHtory, a program that stores terminal history context. Follow this easy-to-follow guide for a smooth setup process.
|
||||||
|
summary: HiSHtory is a powerful tool that stores terminal history context, including command execution dates, directories, and duration. This article shows you how to install the self-hosted version of HiSHtory, allowing you to manage your terminal history with ease.
|
||||||
|
date: 2025-03-20T22:00:00+07:00
|
||||||
|
lastmod:
|
||||||
|
draft: false
|
||||||
|
noindex: false
|
||||||
|
nav_weight: 1000
|
||||||
|
categories:
|
||||||
|
- Self-Hosted
|
||||||
|
tags:
|
||||||
|
- Bash
|
||||||
|
- Zsh
|
||||||
|
- HiSHtory
|
||||||
|
- Linux
|
||||||
|
images:
|
||||||
|
authors:
|
||||||
|
- ditatompel
|
||||||
|
---
|
||||||
|
|
||||||
|
If you frequently work using the Linux Terminal, the _history_ feature on the
|
||||||
|
shell we use can greatly help increase our productivity. However, by default,
|
||||||
|
shells such as `bash` or `zsh` have some limited command history features,
|
||||||
|
for example:
|
||||||
|
|
||||||
|
- The information from which directory a command was run is not saved.
|
||||||
|
- There is no information about whether a command was successfully executed
|
||||||
|
or not.
|
||||||
|
- There is no information on how long it takes for your computer to complete
|
||||||
|
a command.
|
||||||
|
|
||||||
|
For most Linux users, these features are indeed more than sufficient and not
|
||||||
|
essential. Storing extra information can, in effect, increase disk I/O and
|
||||||
|
affect machine performance too. However, for some other Linux users, this
|
||||||
|
feature can be very helpful when conducting investigations or troubleshooting
|
||||||
|
on a system.
|
||||||
|
|
||||||
|
If this information can be stored centrally and searched based on specific
|
||||||
|
keywords, it will certainly help alleviate the task of Linux System
|
||||||
|
Administrators who often use many complex commands with pipelines. Fortunately,
|
||||||
|
there is a program called **HiSHtory**.
|
||||||
|
|
||||||
|
## Introduction to HiSHtory
|
||||||
|
|
||||||
|
[HiSHtory][hishtory-gh] is a program that stores terminal history context,
|
||||||
|
including the date and time when the command was executed, the location of the
|
||||||
|
active directory when the command was executed, and the duration of command
|
||||||
|
execution. This information can be stored locally (on a per-machine basis) or
|
||||||
|
centrally through a client-server architecture.
|
||||||
|
|
||||||
|
In other words, you can easily perform complex shell pipeline searches from
|
||||||
|
a server or another machine, even if you're accessing them from your laptop or
|
||||||
|
one of your computers, without having to physically or remotly switch between
|
||||||
|
machines.
|
||||||
|
|
||||||
|
## Using Self-hosted HiSHtory
|
||||||
|
|
||||||
|
In this article, I will demonstrate self-hosted HiSHtory setup using 2 laptops
|
||||||
|
with Linux operating systems. The details of the laptops are as follows:
|
||||||
|
|
||||||
|
- The laptop with hostname T420, having IP address 192.168.2.22, will serve as
|
||||||
|
both the server and client.
|
||||||
|
- The laptop with hostname P50 will act as the client.
|
||||||
|
|
||||||
|
Please note that I will be utilizing the Docker version of the HiSHtory server,
|
||||||
|
so ensure that the server computer has Docker installed and configured to
|
||||||
|
run properly.
|
||||||
|
|
||||||
|
### Configuring HiSHtory Server
|
||||||
|
|
||||||
|
1. Log in to the server computer and clone the repository
|
||||||
|
[ddworken/hishtory][hishtory-gh] and enter the directory:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
git clone https://github.com/ddworken/hishtory.git
|
||||||
|
cd hishtory
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Edit the `backend/server/docker-compose.yml` file and adjust the
|
||||||
|
configuration as needed. Since I'm using PostgreSQL as my backend database,
|
||||||
|
I updated the `POSTGRES_PASSWORD` environment variable from
|
||||||
|
`TODO_YOUR_POSTGRES_PASSWORD_HERE` to `MyStrongPassword`. Additionally,
|
||||||
|
because the default PostgreSQL password configuration has changed, I also
|
||||||
|
need to update the value of the `HISTORY_POSTGRES_DB` environment variable
|
||||||
|
to match the new password. Furthermore, since port 80 on the server is
|
||||||
|
already in use by another process, I've updated the HiSHtory server listen
|
||||||
|
port on the host machine from port 80 to port 45680.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Here's an overview of my `backend/server/docker-compose.yml` configuration:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
version: "3.8"
|
||||||
|
networks:
|
||||||
|
hishtory:
|
||||||
|
driver: bridge
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres
|
||||||
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- hishtory
|
||||||
|
environment:
|
||||||
|
POSTGRES_PASSWORD: MyStrongPass
|
||||||
|
POSTGRES_DB: hishtory
|
||||||
|
PGDATA: /var/lib/postgresql/data/pgdata
|
||||||
|
volumes:
|
||||||
|
- postgres-data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: pg_isready -U postgres
|
||||||
|
interval: 10s
|
||||||
|
timeout: 3s
|
||||||
|
hishtory:
|
||||||
|
depends_on:
|
||||||
|
postgres:
|
||||||
|
condition: service_healthy
|
||||||
|
networks:
|
||||||
|
- hishtory
|
||||||
|
build:
|
||||||
|
context: ../../
|
||||||
|
dockerfile: ./backend/server/Dockerfile
|
||||||
|
restart: unless-stopped
|
||||||
|
deploy:
|
||||||
|
restart_policy:
|
||||||
|
condition: on-failure
|
||||||
|
delay: 3s
|
||||||
|
environment:
|
||||||
|
HISHTORY_POSTGRES_DB: postgresql://postgres:MyStrongPass@postgres:5432/hishtory?sslmode=disable
|
||||||
|
HISHTORY_COMPOSE_TEST: $HISHTORY_COMPOSE_TEST
|
||||||
|
ports:
|
||||||
|
- 45680:8080
|
||||||
|
volumes:
|
||||||
|
postgres-data:
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Next, build the Docker image by running this command:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
docker compose -f backend/server/docker-compose.yml build
|
||||||
|
```
|
||||||
|
|
||||||
|
4. After the build process is complete, try running the HiSHtory server using
|
||||||
|
this command:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
docker compose -f backend/server/docker-compose.yml up
|
||||||
|
```
|
||||||
|
|
||||||
|
Wait a few moments and ensure that the HiSHtory server is running properly.
|
||||||
|
This can be verified by using the `docker ps` command or checking directly with
|
||||||
|
the HiSHtory HTTP server: `curl -sIL http://127.0.0.1:45680` (adjust the
|
||||||
|
IP:port according to your configuration).
|
||||||
|
|
||||||
|
### Configuring HiSHtory Clients
|
||||||
|
|
||||||
|
One important consideration is that, since we will be using a self-hosted
|
||||||
|
setup, you **must** add the environment variable
|
||||||
|
`HISHTORY_SERVER=http://<ip>:<port>` to your `.bashrc` or `.zshrc`
|
||||||
|
file (adjust the IP address and port used).
|
||||||
|
|
||||||
|
Additionally, by default, HiSHtory client is installed in `~/.hishtory`.
|
||||||
|
However, to keep my `$HOME` directory organized, I will use the
|
||||||
|
`~/.config/hishtory` directory. This can be achieved by adding
|
||||||
|
`HISHTORY_PATH=.config/hishtory` to your `.bashrc` or `.zshrc`.
|
||||||
|
|
||||||
|
So, my `.bashrc` or `.zshrc` has the following additional configuration:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
export HISHTORY_PATH=.config/hishtory
|
||||||
|
# adjust IP and port below with your environment settings
|
||||||
|
export HISHTORY_SERVER="http://192.168.2.22:45680"
|
||||||
|
```
|
||||||
|
|
||||||
|
After adding these environment variables, reload your shell session,
|
||||||
|
then download and run the available install script:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
curl https://hishtory.dev/install.py | python3 -
|
||||||
|
```
|
||||||
|
|
||||||
|
The script will automatically generate your device ID and secret key as well
|
||||||
|
as various other basic configurations. Save the secret key that appears so you
|
||||||
|
can use it for synchronization on other computers.
|
||||||
|
|
||||||
|
To configure on a second computer or server, repeat this process on each
|
||||||
|
computer or server. After completing the HiSHtory installation using the last
|
||||||
|
install script above, run the following command:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
hishtory init $YOUR_HISHTORY_SECRET_FROM_FIRST_DEVICE
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace `$YOUR_HISHTORY_SECRET_FROM_FIRST_DEVICE` with the secret key from
|
||||||
|
the first device.
|
||||||
|
|
||||||
|
> **Note**: The secret key can also be displayed by running the
|
||||||
|
> `hishtory status` command on the first device.
|
||||||
|
|
||||||
|
I hope this helps!
|
||||||
|
|
||||||
|
[hishtory-gh]: ttps://github.com/ddworken/hishtory "Official HiSHtory Repository"
|
Loading…
Reference in a new issue