-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add khatru pyramid guide and update nostr-rs-relay pages (#3)
- Loading branch information
1 parent
56d5576
commit 585c940
Showing
17 changed files
with
562 additions
and
15 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
# Build | ||
|
||
We're now going to discuss how to build [Khatru Pyramid](https://github.com/github-tijlxyz/khatru-pyramid "Khatru Pyramid"). | ||
|
||
## Dependencies | ||
|
||
Before building the binary, we need to install Go and Git. | ||
|
||
We need to install Git to be able to clone the Khatru Pyramid repository: | ||
|
||
```bash | ||
apt install git | ||
``` | ||
|
||
We're now going to discuss how to install Go on your relay. | ||
|
||
First, you need to determine which version of Go you want to install which you can do by going to the [All releases](https://go.dev/dl "All releases") page on the Go website. | ||
|
||
Make sure to choose the appropriate download file for your relay's operating system (OS) and architecture. Since we're using Debian with an AMD processor, we're going to download the `linux-amd64` file. | ||
|
||
At the time of writing the current version of Go is `1.23.2`, so we'll be downloading the `go1.23.2.linux-amd64.tar.gz` file. | ||
|
||
We'll be downloading the file to the `/tmp` directory which is cleared when the system reboots. We’ll be downloading the file here because we won’t need this file after the installation process is completed. | ||
|
||
Since we're using a headless server, we can use the `wget` command to download Go: | ||
|
||
```bash | ||
wget -P /tmp https://go.dev/dl/go1.23.2.linux-amd64.tar.gz | ||
``` | ||
|
||
Be sure to replace `go1.23.2.linux-amd64.tar.gz` with whatever version of Go you're downloading and with whatever architecture you're using. | ||
|
||
Before extracting the contents of the file, be sure to first remove any previously installed version of Go: | ||
|
||
```bash | ||
rm -rf /usr/local/go | ||
``` | ||
|
||
You can now extract the contents of the file into the `/usr/local` directory: | ||
|
||
```bash | ||
tar -C /usr/local -xzf /tmp/go1.23.2.linux-amd64.tar.gz | ||
``` | ||
|
||
Be sure to not extract the contents into an already existing `/usr/local/go` directory since this can break the Go installation. | ||
|
||
After successfully extracting the contents, you should see a `go` directory in the `/usr/local` directory: | ||
|
||
```bash | ||
ls /usr/local | ||
``` | ||
|
||
You can now add `/usr/local/go/bin` to the `PATH` environment variable by adding `export PATH=$PATH:/usr/local/go/bin` to your `$HOME/.bashrc` file. | ||
|
||
First open the file with a text editor of your choice, e.g., `nano`: | ||
|
||
```bash | ||
nano $HOME/.bashrc | ||
``` | ||
|
||
Then add the following to the end of the file: | ||
|
||
```bash | ||
export PATH=$PATH:/usr/local/go/bin | ||
``` | ||
|
||
Save the changes made to the `.bashrc` file and exit the editor. | ||
|
||
The changes may not take effect until after you log back into the server. | ||
|
||
To apply the changes immediately run: | ||
|
||
```bash | ||
source $HOME/.bashrc | ||
``` | ||
|
||
Verify the installation was successful by running: | ||
|
||
```bash | ||
go version | ||
``` | ||
|
||
The command should output: | ||
|
||
```bash | ||
go version go1.23.2 linux/amd64 | ||
``` | ||
|
||
## Clone the Repository | ||
|
||
We'll be downloading the repository to the `/tmp` directory since it's cleared when the system reboots, and we don't need the files associated with the installation of Khatru Pyramid after the installation process is completed. | ||
|
||
Navigate to the `/tmp` directory: | ||
|
||
```bash | ||
cd /tmp | ||
``` | ||
|
||
If you want to keep the Khatru Pyramid repository on your relay, then you can download the repository in a persistent directory, e.g., your `$HOME` directory. | ||
|
||
We're now ready to clone the Khatru Pyramid repository: | ||
|
||
```bash | ||
git clone https://github.com/github-tijlxyz/khatru-pyramid.git | ||
``` | ||
|
||
After cloning the repository, navigate to the `khatru-pyramid` directory: | ||
|
||
```bash | ||
cd khatru-pyramid | ||
``` | ||
|
||
## Build Khatru Pyramid | ||
|
||
We're now ready to build Khatru Pyramid: | ||
|
||
```bash | ||
go build | ||
``` | ||
|
||
The compilation could take a while depending on your server's specs, so be patient while the binary is being built. | ||
|
||
When the compilation is finished the binary will be located in the `khatru-pyramid` directory. | ||
|
||
You can list out the contents of that directory to see the binary: | ||
|
||
```bash | ||
ls | ||
``` | ||
|
||
You should see the binary file which should be named `khatru-pyramid`. | ||
|
||
## Version | ||
|
||
At the time of writing, the latest version of Khatru Pyramid is `v0.1.0` which is what the rest of the guide is currently based on. | ||
|
||
## Run Binary | ||
|
||
You can now run the binary: | ||
|
||
```bash | ||
DOMAIN="relay.relayrunner.xyz" RELAY_NAME="Relay Runner's Khatru Pyramid Relay" RELAY_PUBKEY="3bcbb0f7dea9da9f5b2659ca5da89d5e576215de3885e51bd2474dd1b0c44b16" ./khatru-pyramid | ||
``` | ||
|
||
Khatru Pyramid should now be listening on `0.0.0.0:3334`. A relay database will be created in your current directory called `db` along with a file for storing user data called `users.json`. | ||
|
||
To stop the relay press `Ctrl+C`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,76 @@ | ||
# Configuration | ||
|
||
We're now going to discuss how to configure the Khatru Pyramid environment file which allows us to set various relay settings. We're also going to discuss how to create the data directory which will be owned by the `nostr` user. | ||
|
||
## Environment File | ||
|
||
We're going to create the Khatru Pyramid environment file in the `/etc/systemd/system` directory: | ||
|
||
```bash | ||
touch /etc/systemd/system/khatru-pyramid.env | ||
``` | ||
|
||
## Data Directory | ||
|
||
We're going to create a data directory for Khatru Pyramid in the `/var/lib` directory: | ||
|
||
```bash | ||
mkdir -p /var/lib/khatru-pyramid | ||
``` | ||
|
||
We can change the permissions of the data directory and all of its content, i.e., the files and subdirectories inside of it: | ||
|
||
```bash | ||
chmod 0755 -R /var/lib/khatru-pyramid | ||
``` | ||
|
||
We can then change the ownership of the data directory to use the `nostr` user: | ||
|
||
```bash | ||
chown -R nostr:nostr /var/lib/khatru-pyramid | ||
``` | ||
|
||
## Edit Environment File | ||
|
||
To change the relay settings you can open the `khatru-pyramid.env` file: | ||
|
||
```bash | ||
nano /etc/systemd/system/khatru-pyramid.env | ||
``` | ||
|
||
We're now going to add the following lines to the environment file: | ||
|
||
```ini | ||
DOMAIN="relay.relayrunner.xyz" | ||
PORT="3335" | ||
DATABASE_PATH="/var/lib/khatru-pyramid/db" | ||
USERDATA_PATH="/var/lib/khatru-pyramid/users.json" | ||
MAX_INVITES_PER_PERSON="3" | ||
RELAY_NAME="Relay Runner's Khatru Pyramid Relay" | ||
RELAY_PUBKEY="3bcbb0f7dea9da9f5b2659ca5da89d5e576215de3885e51bd2474dd1b0c44b16" | ||
RELAY_DESCRIPTION="Khatru Pyramid Nostr Relay" | ||
RELAY_CONTACT="[email protected]" | ||
RELAY_ICON="https://example.com/your-relay-icon.png" | ||
``` | ||
|
||
Here's a description of the relay settings: | ||
|
||
- `DOMAIN` - The domain name of your server, e.g., `relay.relayrunner.xyz`. | ||
|
||
- `PORT` - The port your relay will run on. This setting is optional and the default value is `3334`. We'll set this to `3335`. | ||
|
||
- `DATABASE_PATH` - The directory where your relay will store data. This setting is optional and the default value is set to `./db`. We'll set this to `/var/lib/khatru-pyramid/db`. | ||
|
||
- `USERDATA_PATH` - The file where your relay will store user data. This setting is optional and the default value is set to `./users.json`. We'll set this to `/var/lib/khatru-pyramid/users.json`. | ||
|
||
- `MAX_INVITES_PER_PERSON` - The maximum number of invites each person can make for the relay. This setting is optional and the default value is set to `3`. | ||
|
||
- `RELAY_NAME` - The name of your relay, e.g., `Relay Runner's Khatru Pyramid Relay`. | ||
|
||
- `RELAY_PUBKEY` - Your Nostr public key (32-byte hex, not npub), e.g., `3bcbb0f7dea9da9f5b2659ca5da89d5e576215de3885e51bd2474dd1b0c44b16`. | ||
|
||
- `RELAY_DESCRIPTION` - A description of your relay. This setting is optional and the default value is set to `""`. We'll set this to `Khatru Pyramid Nostr Relay`. | ||
|
||
- `RELAY_CONTACT` - Your email address used for administrative requests, e.g., `[email protected]`. This setting is optional and the default value is `""`. | ||
|
||
- `RELAY_ICON` - URL to your relay's icon, e.g., `https://example.com/your-relay-icon.png`. This setting is optional and the default value is `""`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,35 @@ | ||
# Install | ||
|
||
After building the binary, we're now going to "install" Khatru Pyramid by using the `install` command. | ||
|
||
We’re actually not installing Khatru Pyramid though since the `install` command isn’t used to install software packages despite its name. | ||
|
||
The `install` command is a way to copy files to a target location similar to the copy command, i.e., `cp`, but it gives us more control by allowing us to use advanced features when copying the files. | ||
|
||
Some of these advanced features include the abilities to adjust permission modes like when using the `chmod` command, adjust ownership permissions like when using the `chown` command, to make backups of the files, and to preserve the metadata of the files, e.g., the access and modifications times of the files. | ||
|
||
We're going to be "installing" the `khatru-pyramid` binary to the `/usr/local/bin` directory which allows us to run the binary from any directory. This makes running the binary easier since we don't have to navigate to or specify the path to the `khatru-pyramid` binary every time we want to run it. | ||
|
||
First, navigate to the directory where you installed the binary, e.g., | ||
|
||
```bash | ||
cd /tmp/khatru-pyramid | ||
``` | ||
|
||
To "install" Khatru Pyramid we can run: | ||
|
||
```bash | ||
install -v -m 0755 -o root -g root -t /usr/local/bin khatru-pyramid | ||
``` | ||
|
||
Here’s an explanation of the options we passed to the `install` command: | ||
|
||
`-v`: This option specifies that we would like to see the verbose output which means we’ll be displayed with the details of the process. | ||
|
||
`-m`: This option specifies the file permissions in octal notation for the files we’re copying, i.e., `0755`. | ||
|
||
`-o`: This option allows us to set the owner for the files we’re copying, i.e., `root`. | ||
|
||
`-g`: This option allows us to set the group for the files we’re copying, i.e., `root`. | ||
|
||
`-t`: This option specifies the target directory that we want to copy the specified files into, i.e., `/usr/local/bin`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Intro | ||
|
||
[Khatru Pyramid](https://github.com/github-tijlxyz/khatru-pyramid "Khatru Pyramid") is a relay implementation written in Go with an invite hierarchy feature. The relay is based on [Khatru](https://github.com/fiatjaf/khatru "Khatru") which is a framework for making custom relays. | ||
|
||
The repository is available on [GitHub](https://github.com/github-tijlxyz/khatru-pyramid "GitHub"). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,83 @@ | ||
# Service | ||
|
||
A service is a long-running process that can be started and stopped manually as well as set to automatically start when the system boots. It can be used to run background tasks, handle network requests, and interact with the system. | ||
|
||
## Create Unit File | ||
|
||
We're going to create a [systemd](https://systemd.io "systemd") service for Khatru Pyramid which will allow us to automatically start the relay on boot. | ||
|
||
To do this we're going to create and open the following systemd unit file: | ||
|
||
```bash | ||
nano /etc/systemd/system/khatru-pyramid.service | ||
``` | ||
|
||
## Edit Unit File | ||
|
||
We're now going to add the following lines to the `khatru-pyramid.service` unit file: | ||
|
||
```ini | ||
[Unit] | ||
Description=Khatru Pyramid Service | ||
After=network.target | ||
|
||
[Service] | ||
Type=simple | ||
User=nostr | ||
Group=nostr | ||
WorkingDirectory=/home/nostr | ||
EnvironmentFile=/etc/systemd/system/khatru-pyramid.env | ||
ExecStart=/usr/local/bin/khatru-pyramid | ||
Restart=on-failure | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
``` | ||
|
||
This service tells systemd to start Khatru Pyramid as the `nostr` user after the network has been properly configured using our specified environment file and to attempt to restart the service if it fails. | ||
|
||
## Reload systemd | ||
|
||
To apply the newly created Khatru Pyramid service we're going to reload systemd: | ||
|
||
```bash | ||
systemctl daemon-reload | ||
``` | ||
|
||
## Enable Service | ||
|
||
We can enable the Khatru Pyramid service to automatically start on boot: | ||
|
||
```bash | ||
systemctl enable khatru-pyramid.service | ||
``` | ||
|
||
## Start Service | ||
|
||
To start the Khatru Pyramid service: | ||
|
||
```bash | ||
systemctl start khatru-pyramid.service | ||
``` | ||
|
||
## Check Status | ||
|
||
The relay service should now be running and set to automatically start on boot. | ||
|
||
You can check the status of the service using: | ||
|
||
```bash | ||
systemctl status khatru-pyramid.service | ||
``` | ||
|
||
If the service is running, you should see the following in the output: | ||
|
||
```bash | ||
Active: active (running) | ||
``` | ||
|
||
If the service is enabled to automatically start on boot, you should see the following in the output: | ||
|
||
```bash | ||
Loaded: loaded (/etc/systemd/system/khatru-pyramid.service; enabled; preset: enabled) | ||
``` |
Oops, something went wrong.