commit 2a8da27767f30ed2e6b92623ebadfd24f6174e73 Author: narawat Date: Tue Sep 22 06:16:30 2026 +0700 1st commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..698f842 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +data/ +nats_ui_db/ \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0c925ea --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,87 @@ +services: + nats-server1: + image: nats:latest + container_name: nats-server1 + command: ["-c", "/etc/nats/nats-server.conf", "--server_name", "nats-server1"] + ports: + - "4222:4222" # Client Traffic + - "9222:9222" # Websockets (Julia/Web UI) + - "6222:6222" # Cluster Routing Mesh + volumes: + - ./nats-server.conf:/etc/nats/nats-server.conf:ro + - ./data/nats-jetstream:/data/nats-jetstream + restart: unless-stopped + + + # ========================================== + # NATS UI Management + # ========================================== + # You only need the UI running on one of your machines + nats-ui: + image: ghcr.io/nats-nui/nui:latest + volumes: + - ./nats_ui_db:/db + ports: + - "31311:31311" + restart: unless-stopped + + + +# to make 3-node nats. copy docker-compose.yml and nats-server.conf to PC2 and PC3 + + +# Important Architectural Notes for Scaling Later +# When you eventually uncomment nats-server2 and nats-server3, keep these structural behaviors in mind: + +# The Quorum Rule (Raft): JetStream requires a strict majority to achieve quorum and allow stream writes. + +# With 1 node running, your cluster size is effectively 1, so quorum is met. + +# If you bring up a second node, your cluster size becomes 2, meaning you need both nodes online to function. Never run a 2-node JetStream cluster in production. + +# When you decide to scale up, uncomment both nats-server2 and nats-server3 at the same time to establish a stable 3-node cluster (where 2 out of 3 nodes must be alive). + +# Stream Replicas: When you create a Stream using the CLI or code in a 3-node cluster, you can specify --replicas 3. This instructs NATS to automatically mirror that stream’s data chunks across all 3 underlying storage engines over the internal 6222 mesh network. + + +# How Your Applications Connect Now +# When your application workers (like your Julia or Rust processes) connect to a multi-node cluster, you should provide all three host IPs in the client connection string: +# nats://192.168.1.101:4222,nats://192.168.1.102:4222,nats://192.168.1.103:4222 +# If PC 1 goes down completely, your application client will automatically reconnect to PC 2 or PC 3 within milliseconds, and JetStream data processing will continue without losing a single message. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nats-server.conf b/nats-server.conf new file mode 100644 index 0000000..74eeeaa --- /dev/null +++ b/nats-server.conf @@ -0,0 +1,32 @@ +port: 4222 + +websocket { + port: 9222 + no_tls: true +} + +# --- JETSTREAM CONFIGURATION --- +jetstream { + store_dir: "/data/nats-jetstream" +} + +# --- CLUSTERING CONFIGURATION --- +cluster { + # Add this line to give the cluster an explicit identity + name: "my_nats_cluster" + + port: 6222 + + routes = [ + "nats-route://192.168.88.21:6222" # PC1 IP + # "nats-route://nats-server2:6222" # replace nats-server2 with PC2 IP + # "nats-route://nats-server3:6222" # replace nats-server2 with PC3 IP + ] +} + +debug: true +trace: false + + + +