|
| 1 | +# Self Deployment |
| 2 | + |
| 3 | +### Prerequisites |
| 4 | +ForNet is a client-server model program, you need to deploy server firstly, |
| 5 | +and ForNet now needs relay node to let devices connect each other. You need have a linux server to deploy the relay instance. |
| 6 | +We are in hard work to build SaaS backend server and implement p2p connection feature. You would only need to install client then. |
| 7 | + |
| 8 | +If you like to build ForNet from the source code, please refer [Develop Guide](./develop) for more information. |
| 9 | + |
| 10 | +### Client |
| 11 | +you can download client binary app at Github <a :href="`${$sourceUrl}/releases`">release page</a>, it now supports macOS、Linux and Windows 11. **Client needs root/administrator permission to run**, unix is to create tun, Windows is to install driver. |
| 12 | + |
| 13 | + |
| 14 | +### Server |
| 15 | +The manager server is written by Scala 3, you can deploy the jar or docker image. It uses Postgres to store data. and uses [rmqtt](https://github.com/rmqtt/rmqtt) to interact with client. |
| 16 | + |
| 17 | +There is <a :href="`${$sourceUrl}/tree/main/command/docker-compose/simple/docker-compose.yml`">docker-compose.yml</a> for quick start, you can ship it with: |
| 18 | +```shell |
| 19 | +# must be in the directory |
| 20 | +# it needs config files of backend and rmqtt |
| 21 | +cd /command/docker-compose/simple |
| 22 | +docker-compose up |
| 23 | +``` |
| 24 | +If you would like to deploy with docker step by step, you can follow this: |
| 25 | +#### Postgres |
| 26 | +```shell |
| 27 | +# If platform is Mac/Windows, change --network=host to -p 5432:5432 |
| 28 | +docker run -d --name postgres --network=host \ |
| 29 | +-e POSTGRES_PASSWORD=tnet_db_password \ |
| 30 | +-e POSTGRES_DB=tnet_db \ |
| 31 | +-e POSTGRES_USER=postgres \ |
| 32 | +-v $(pwd):/var/lib/postgresql/data \ |
| 33 | +postgres:15 |
| 34 | +``` |
| 35 | + |
| 36 | +#### Deploy RMQTT Docker |
| 37 | +Here is an example of rmqtt <a :href="$sourceUrl + '/tree/main/command/docker/mqtt'">config</a>, you can run it after changed backend server url in `config/plugin/rmqtt-auth-http.toml`. |
| 38 | + |
| 39 | +More details about RMQTT can be found [here](https://github.com/rmqtt/rmqtt). |
| 40 | +```shell |
| 41 | +cd /command/docker/mqtt |
| 42 | +# RMQTT will use port: |
| 43 | +# 1883(mqtt) 6060(http api) 5363(grpc) |
| 44 | +docker run -d --name mqtt --network=host \ |
| 45 | + -v $(pwd)/log:/var/log/rmqtt \ |
| 46 | + -v $(pwd)/config/rmqtt.toml:/app/rmqtt/rmqtt.toml \ |
| 47 | + -v $(pwd)/config/plugin:/app/rmqtt/plugin \ |
| 48 | + rmqtt/rmqtt:latest |
| 49 | +``` |
| 50 | + |
| 51 | +#### Deploy Server Docker |
| 52 | +There is two config file: `application.conf` and `logback.xml`, you can get the example <a :href="$sourceUrl + '/tree/main/command/docker/backend/config'">here</a>. |
| 53 | +More details about config can be found [here](config.md). |
| 54 | + |
| 55 | +```shell |
| 56 | +# run server with database init, 8080 is for http api, 9000 is for grpc. |
| 57 | +docker run -it -d \ |
| 58 | +-p 8080:8080 -p 9000:9000 \ |
| 59 | +-v ${local_machine/applcation.conf+logback.xml/path}:/config \ |
| 60 | +--name=fornet-backend \ |
| 61 | +fornetcode/fornet-backend:latest |
| 62 | + |
| 63 | +``` |
| 64 | + |
| 65 | +## Up and Running |
| 66 | + |
| 67 | +### Create Network |
| 68 | +After the backend server up, visit the backend website: http://127.0.0.1:8080, If you use simple auth, just type the config value of `auth.simple.token` to login in. |
| 69 | +Then you could create network, and get invite code to let client node join in. |
| 70 | + |
| 71 | +### Client Join Network |
| 72 | +There's `fornet` and `fornet-cli`, `fornet` is the background service, `fornet-cli` is used to interact with `fornet`. |
| 73 | +```shell |
| 74 | +# run fornet in background |
| 75 | +sudo fornet & |
| 76 | +# you could get the invite cod from the admin web. |
| 77 | +sudo fornet-cli join ${invite code} |
| 78 | +``` |
| 79 | +You can also use docker in Linux(thisdoes not support macOS, indows). |
| 80 | +```shell |
| 81 | +# export config to host, otherwise private.key will miss if image delete |
| 82 | +docker run -it --name=fornet \ |
| 83 | +--cap-add=NET_ADMIN \ |
| 84 | +--network=host \ |
| 85 | +--device=/dev/net/tun \ |
| 86 | +-v ${config_path}:/config \ |
| 87 | +fornet:latest |
| 88 | +# join network |
| 89 | +docker exec -it fornet fornet-cli join ${invite code} |
| 90 | +``` |
| 91 | + |
| 92 | +### Auto Launch |
| 93 | +#### Linux |
| 94 | +ForNet now don't support automatically start after host reboot in Linux, you can get it with Systemd. |
| 95 | +``` |
| 96 | +cp fornet /usr/local/bin/ |
| 97 | +``` |
| 98 | +create the Systemd configuration file at `/etc/systemd/system/fornet.service` |
| 99 | +``` |
| 100 | +[Unit] |
| 101 | +Description=ForNet client daemon |
| 102 | +After=network.target |
| 103 | +
|
| 104 | +[Service] |
| 105 | +Type=simple |
| 106 | +User=root |
| 107 | +Restart=always |
| 108 | +ExecStart=/usr/local/bin/fornet |
| 109 | +
|
| 110 | +[Install] |
| 111 | +WantedBy=multi-user.target |
| 112 | +
|
| 113 | +``` |
| 114 | + |
| 115 | +After that you're supposed to reload systemd: |
| 116 | +``` |
| 117 | +systemctl daemon-reload |
| 118 | +``` |
| 119 | + |
| 120 | +Launch fornet on system startup with: |
| 121 | +``` |
| 122 | +systemctl enable fornet |
| 123 | +``` |
| 124 | +Launch fornet immediately with: |
| 125 | +``` |
| 126 | +systemctl start fornet |
| 127 | +``` |
| 128 | + |
| 129 | +#### macOS |
| 130 | +```shell |
| 131 | +sudo fornet-cli launch enable |
| 132 | +``` |
| 133 | +## What's More |
| 134 | +If you are interested with this project, you can go [roadmap](../plan) to get more information. |
0 commit comments