|
| 1 | +## 快速開始 |
| 2 | + |
| 3 | +使用壹句命令開啓 Syncplay 服務,是的,就這麽簡單。 |
| 4 | + |
| 5 | +```bash |
| 6 | +> docker run --rm --net=host dnomd343/syncplay |
| 7 | +Welcome to Syncplay server, ver. 1.7.1 |
| 8 | +``` |
| 9 | + |
| 10 | +> 按下 `Ctrl+C` 將退出服務。 |
| 11 | +
|
| 12 | +如果沒有意外,您可以在客戶端填入服務器 IP 或域名進行驗證,默認端口是 `tcp/8999` 。若無法連上,請檢查您的防火牆設置。 |
| 13 | + |
| 14 | +爲了更好地運行服務,我們應當使用以下命令讓 Syncplay 在後台運行,並保持啓動。 |
| 15 | + |
| 16 | +```bash |
| 17 | +docker run -d --net=host --restart=always --name=syncplay dnomd343/syncplay |
| 18 | +``` |
| 19 | + |
| 20 | +> 您可以使用 `docker ps -a` 看到正在運行的服務,還可以使用 `docker rm -f syncplay` 停止服務。 |
| 21 | +
|
| 22 | +您可以加入更多的參數來實現定制化,例如我們讓服務器連接時需要輸入密碼、禁止聊天、並在進入房間後顯示壹句歡迎語,使用以下命令。 |
| 23 | + |
| 24 | +> 注意在按下回車前,您必須執行 `docker rm -f syncplay` 移除掉原有的服務,否則它們會發生沖突。 |
| 25 | +
|
| 26 | +```bash |
| 27 | +docker run -d --net=host --restart=always --name=syncplay dnomd343/syncplay \ |
| 28 | + --disable-chat --password=PASSWD --motd='HELLO WORLD' |
| 29 | +``` |
| 30 | + |
| 31 | +服務器在必要的時候會被重啓,也可能是 Docker 服務需要更新,無論是不是預期中的,這個時候將 Syncplay 持久化是很有必要的,這意味著房間數據將會被保存到磁盤上。您需要選擇壹個工作目錄來保存他們,例如 `/etc/syncplay/` ,執行以下命令,數據會被保存到 `rooms.db` 文件中。 |
| 32 | + |
| 33 | +```bash |
| 34 | +docker run -d --net=host \ |
| 35 | + --restart=always --name=syncplay \ |
| 36 | + --volume /etc/syncplay/:/data/ \ |
| 37 | + dnomd343/syncplay --persistent |
| 38 | +``` |
| 39 | + |
| 40 | +這個目錄還有更多的用途,例如添加 `--enable-stats` 選項將開啓統計功能,數據將被保存到目錄下 `stats.db` 這個文件中。您還可以在目錄下創建 `config.yml` 文件,將配置參數寫在裏面,Syncplay 啓動時將會自動讀取,避免在命令行中鍵入大量參數。 |
| 41 | + |
| 42 | +```yaml |
| 43 | +# /etc/syncplay/config.yml |
| 44 | +password: 'My Password' |
| 45 | +persistent: true |
| 46 | +enable-stats: true |
| 47 | +disable-chat: false |
| 48 | +motd: | |
| 49 | + Hello, here is a syncplay server. |
| 50 | + More information... |
| 51 | +``` |
| 52 | +
|
| 53 | +在實際部署時,開啓 TLS 總會是壹個好主意(當然它不是必要的,這壹步可以跳過),幸運的是,Syncplay 可以很簡單地做到這壹點。在開始前,您需要准備壹個域名,並把它的 DNS 解析到當前服務器上,同時,我們必須擁有它的證書文件。 |
| 54 | +
|
| 55 | +證書的申請可以通過 [`acme.sh`](https://acme.sh/) 、[`certbot`](https://certbot.eff.org/) 或者其他合理的方式進行。總之,您最終會得到壹把私鑰和壹張證書,Syncplay 需要您提供以下三個文件。 |
| 56 | + |
| 57 | ++ `cert.pem` :CA 機構簽發的證書 |
| 58 | ++ `chain.pem` :CA 機構的證書鏈 |
| 59 | ++ `privkey.pem` :證書的私鑰文件 |
| 60 | + |
| 61 | +例如在 `acme.sh` 中,可以這樣子執行命令,將 `343.re` 這個域名的證書配置保存到 `/etc/ssl/certs/343.re/` 目錄下。 |
| 62 | + |
| 63 | +```bash |
| 64 | +acme.sh --install-cert -d 343.re \ |
| 65 | + --cert-file /etc/ssl/certs/343.re/cert.pem \ |
| 66 | + --ca-file /etc/ssl/certs/343.re/chain.pem \ |
| 67 | + --key-file /etc/ssl/certs/343.re/privkey.pem |
| 68 | +``` |
| 69 | + |
| 70 | +現在我們已經准備好了,只需要執行下面的命令,壹個更安全更隱私的 Syncplay 服務將會啓動。 |
| 71 | + |
| 72 | +```bash |
| 73 | +docker run -d --net=host \ |
| 74 | + --restart=always --name=syncplay \ |
| 75 | + --volume /etc/syncplay/:/data/ \ |
| 76 | + --volume /etc/ssl/certs/343.re/:/certs/ \ |
| 77 | + dnomd343/syncplay --persistent --enable-tls |
| 78 | +``` |
| 79 | + |
| 80 | +> 注意客戶端的服務器地址必須與證書匹配,否則連接將會失敗。 |
| 81 | + |
| 82 | +需要說明的是,與有些服務不同,Syncplay 在證書發生更新時不需要手動重啓,它會自動檢測證書的變化,並使用最新的版本。此外,Syncplay 服務端的 TLS 是自適應的,這意味著,即使是不支持 TLS 的舊版本客戶端,它們仍然可以正常通訊,但是注意此時安全加密將不再生效。 |
| 83 | + |
| 84 | +## 命令行參數 |
| 85 | + |
| 86 | +您可以通過指定以下命令行參數來定制 Syncplay 服務器。 |
| 87 | + |
| 88 | +> 以下參數是針對 docker 調整過的,與[官方文檔](https://man.archlinux.org/man/extra/syncplay/syncplay-server.1)不完全相同,使用時請以此爲准。 |
| 89 | + |
| 90 | ++ `--port [PORT]` :Syncplay 服務器監聽端口, 默認爲 `8999` |
| 91 | + |
| 92 | ++ `--password [PASSWD]` :用戶登錄服務器的密碼,默認不啓用 |
| 93 | + |
| 94 | ++ `--motd [MESSAGE]` :用戶進入房間的歡迎內容,默認不啓用 |
| 95 | + |
| 96 | ++ `--salt [TEXT]` :密碼加鹽,指定隨機字符串,用于抵抗哈希攻擊(例如彩虹表),默認爲空字符串 |
| 97 | + |
| 98 | ++ `--random-salt` :使用隨機生成的鹽,僅當 `--salt` 未指定時生效,默認不啓用 |
| 99 | + |
| 100 | ++ `--isolate-rooms` :開啓獨立房間,用戶將看不到其他房間的用戶信息,默認不啓用 |
| 101 | + |
| 102 | ++ `--disable-chat` :禁止聊天功能,默認不啓用 |
| 103 | + |
| 104 | ++ `--disable-ready` :禁止就緒指示器功能,默認不啓用 |
| 105 | + |
| 106 | ++ `--enable-stats` :開啓服務器統計功能,數據將被保存到 `stats.db` 文件中,默認不啓用 |
| 107 | + |
| 108 | ++ `--enable-tls` :開啓 TLS 支持, 證書文件需要挂載到 `/certs/` 目錄下,包括 `cert.pem` 、`chain.pem` 、`privkey.pem` 三個文件,默認不啓用 |
| 109 | + |
| 110 | ++ `--persistent` :開啓房間數據持久化,信息將被保存到 `rooms.db` 文件中,僅當 `--isolate-rooms` 未指定時有效,默認不啓用 |
| 111 | + |
| 112 | ++ `--max-username [NUM]` :用戶名最大長度,默認爲 `150` |
| 113 | + |
| 114 | ++ `--max-chat-message [NUM]` :聊天消息最大長度,默認爲 `150` |
| 115 | + |
| 116 | ++ `--permanent-rooms [ROOM ...]` :即使播放列表爲空時仍會列出的房間,僅當 `--persistent` 指定時有效,默認爲空 |
| 117 | + |
| 118 | ++ `--listen-ipv4` :自定義 Syncplay 服務在 IPv4 網絡上的監聽地址,默認不啓用 |
| 119 | + |
| 120 | ++ `--listen-ipv6` :自定義 Syncplay 服務在 IPv6 網絡上的監聽地址,默認不啓用 |
| 121 | + |
| 122 | +> 當您僅指定 `--listen-ipv4` 時,Syncplay 將不會在 IPv6 上監聽,反之同理。當兩者均指定時,Syncplay 將工作在雙棧網絡下。 |
| 123 | + |
| 124 | +您也可以使用以下命令輸出幫助信息。 |
| 125 | + |
| 126 | +```bash |
| 127 | +> docker run --rm syncplay --help |
| 128 | +usage: syncplay [-h] [-p PORT] [--password PASSWD] [--motd MESSAGE] |
| 129 | + [--salt TEXT] [--random-salt] [--isolate-rooms] |
| 130 | + [--disable-chat] [--disable-ready] [--enable-stats] |
| 131 | + [--enable-tls] [--persistent] [--max-username NUM] |
| 132 | + [--max-chat-message NUM] [--permanent-rooms [ROOM ...]] |
| 133 | + [--listen-ipv4 INTERFACE] [--listen-ipv6 INTERFACE] |
| 134 | +
|
| 135 | +Syncplay Docker Bootstrap |
| 136 | +
|
| 137 | +options: |
| 138 | + -h, --help show this help message and exit |
| 139 | + -p PORT, --port PORT listen port of syncplay server |
| 140 | + --password PASSWD authentication of syncplay server |
| 141 | + --motd MESSAGE welcome text after the user enters the room |
| 142 | + --salt TEXT string used to secure passwords |
| 143 | + --random-salt use a randomly generated salt value |
| 144 | + --isolate-rooms room isolation enabled |
| 145 | + --disable-chat disables the chat feature |
| 146 | + --disable-ready disables the readiness indicator feature |
| 147 | + --enable-stats enable syncplay server statistics |
| 148 | + --enable-tls enable tls support of syncplay server |
| 149 | + --persistent enables room persistence |
| 150 | + --max-username NUM maximum length of usernames |
| 151 | + --max-chat-message NUM |
| 152 | + maximum length of chat messages |
| 153 | + --permanent-rooms [ROOM ...] |
| 154 | + permanent rooms of syncplay server |
| 155 | + --listen-ipv4 INTERFACE |
| 156 | + listening address of ipv4 |
| 157 | + --listen-ipv6 INTERFACE |
| 158 | + listening address of ipv6 |
| 159 | +``` |
| 160 | + |
| 161 | +## 配置文件 |
| 162 | + |
| 163 | +如果您配置了較多的選項,每次啓動時輸入大量命令行參數會是相當麻煩且易出錯的事情,這個時候可以將它們寫到配置文件中。在工作目錄中創建 `config.yml` 文件,它使用 YAML 格式,支持命令行中的所有參數,Syncplay 在啓動時會自動讀取並加載,但需要注意的是,如果命令行指定了同樣的參數,將會覆蓋配置文件的選項。 |
| 164 | + |
| 165 | +```yaml |
| 166 | +port: 7999 |
| 167 | +salt: 'SALT' |
| 168 | +random-salt: true |
| 169 | +password: 'My Password' |
| 170 | +persistent: true |
| 171 | +enable-tls: true |
| 172 | +enable-stats: true |
| 173 | +isolate-rooms: true |
| 174 | +disable-chat: true |
| 175 | +disable-ready: true |
| 176 | +max-username: 256 |
| 177 | +max-chat-message: 2048 |
| 178 | +listen-ipv4: 127.0.0.1 |
| 179 | +listen-ipv6: ::1 |
| 180 | +permanent-rooms: |
| 181 | + - ROOM_1 |
| 182 | + - ROOM_2 |
| 183 | + - ROOM_3 |
| 184 | +motd: | |
| 185 | + Hello, here is a syncplay server. |
| 186 | + More information... |
| 187 | +``` |
| 188 | + |
| 189 | +## 環境變量 |
| 190 | + |
| 191 | +Syncplay 容器還支持通過環境變量來配置,它支持數字、字符串以及布爾三種類型的字段,這裏意味著 `permanent-rooms` 不被支持。環境變量全部使用大寫命名,並將 `-` 替換爲 `_` ,布爾值使用 `ON` 或者 `TRUE` 表示,下面是壹個使用環境變量的例子。 |
| 192 | + |
| 193 | +```bash |
| 194 | +docker run -d --net=host --restart=always --name=syncplay \ |
| 195 | + --env PORT=7999 --env MOTD=Hello --env DISABLE_READY=ON \ |
| 196 | + dnomd343/syncplay |
| 197 | +``` |
| 198 | + |
| 199 | +您或許已經注意到了,我們支持三種配置方式:命令行參數、配置文件和環境變量,它們的優先級由高到低,也就是命令行參數將覆蓋配置文件的選項,配置文件將覆蓋環境變量的值,您可以搭配使用它們。 |
| 200 | + |
| 201 | +## Docker Compose |
| 202 | + |
| 203 | +使用 `docker-compose` 來部署 Syncplay 是壹種更優雅的方式,妳需要創建壹個 `docker-compose.yml` 配置文件,寫入以下的示例。 |
| 204 | + |
| 205 | +```yaml |
| 206 | +# /etc/syncplay/docker-compose.yml |
| 207 | +version: '3' |
| 208 | +services: |
| 209 | + syncplay: |
| 210 | + container_name: syncplay |
| 211 | + image: dnomd343/syncplay |
| 212 | + network_mode: host |
| 213 | + restart: always |
| 214 | + volumes: |
| 215 | + - ./:/data/ |
| 216 | +``` |
| 217 | + |
| 218 | +我們將這個文件保存在 `/etc/syncplay/` 目錄下,由于使用了相對路徑,因此它也同樣處于工作目錄中,在該目錄下執行命令啓動 Syncplay 服務。 |
| 219 | + |
| 220 | +```bash |
| 221 | +> docker-compose up |
| 222 | +Recreating syncplay ... done |
| 223 | +Attaching to syncplay |
| 224 | +syncplay | Welcome to Syncplay server, ver. 1.7.1 |
| 225 | +``` |
| 226 | + |
| 227 | +> 添加 `-d` 選項可以讓服務在後台運行。 |
| 228 | + |
| 229 | +類似的,您可以映射證書目錄來開啓 TLS 功能,以及編輯 `config.yml` 文件來配置更多選項。 |
| 230 | + |
| 231 | +## 錯誤排查 |
| 232 | + |
| 233 | +如果您遇到了任何錯誤,請先使用 `docker logs syncplay` 命令打印進程輸出內容,它可能包含有用的錯誤信息,您還可以通過指定環境變量 `DEBUG=ON` 來輸出更詳細的日志。 |
| 234 | + |
| 235 | +```bash |
| 236 | +> docker run --rm --env DEBUG=ON dnomd343/syncplay |
| 237 | +Bootstrap options -> [('port', <class 'int'>, False), ('password', <class 'str'>, False), ('motd', <class 'str'>, False), ('salt', <class 'str'>, False), ('random_salt', <class 'bool'>, False), ('isolate_rooms', <class 'bool'>, False), ('disable_chat', <class 'bool'>, False), ('disable_ready', <class 'bool'>, False), ('enable_stats', <class 'bool'>, False), ('enable_tls', <class 'bool'>, False), ('persistent', <class 'bool'>, False), ('max_username', <class 'int'>, False), ('max_chat_message', <class 'int'>, False), ('permanent_rooms', <class 'str'>, True), ('listen_ipv4', <class 'str'>, False), ('listen_ipv6', <class 'str'>, False)] |
| 238 | +Environment variables -> environ({'PATH': '/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'HOSTNAME': '0a28a2e2ea50', 'DEBUG': 'ON', 'LANG': 'C.UTF-8', 'GPG_KEY': 'A035C8C19219BA821ECEA86B64E628F8D684696D', 'PYTHON_VERSION': '3.10.13', 'PYTHON_PIP_VERSION': '23.0.1', 'PYTHON_SETUPTOOLS_VERSION': '65.5.1', 'PYTHON_GET_PIP_URL': 'https://github.com/pypa/get-pip/raw/4cfa4081d27285bda1220a62a5ebf5b4bd749cdb/public/get-pip.py', 'PYTHON_GET_PIP_SHA256': '9cc01665956d22b3bf057ae8287b035827bfd895da235bcea200ab3b811790b6', 'PYTHONUNBUFFERED': '1', 'HOME': '/root'}) |
| 239 | +Environment options -> {} |
| 240 | +Configure file -> {} |
| 241 | +Configure file options -> {} |
| 242 | +Command line arguments -> Namespace(port=None, password=None, motd=None, salt=None, random_salt=False, isolate_rooms=False, disable_chat=False, disable_ready=False, enable_stats=False, enable_tls=False, persistent=False, max_username=None, max_chat_message=None, permanent_rooms=None, listen_ipv4=None, listen_ipv6=None) |
| 243 | +Command line options -> {} |
| 244 | +Bootstrap final options -> {} |
| 245 | +Syncplay startup arguments -> ['--port', '8999', '--salt', ''] |
| 246 | +Welcome to Syncplay server, ver. 1.7.1 |
| 247 | +``` |
| 248 | + |
| 249 | +## 高級選項 |
| 250 | + |
| 251 | +出于壹些原因,您可能需要更改配置文件或工作目錄的位置,這在 Syncplay 容器中是可行的,它需要您使用環境變量來指定。 |
| 252 | + |
| 253 | ++ `TEMP_DIR` :臨時目錄,它不需要被持久化,默認爲 `/tmp/` |
| 254 | + |
| 255 | ++ `WORK_DIR` :工作目錄,它存儲和 Syncplay 相關的數據,默認爲 `/data/` |
| 256 | + |
| 257 | ++ `CERT_DIR` :證書目錄,它用于存放 TLS 相關的證書和私鑰文件,默認爲 `/certs/` |
| 258 | + |
| 259 | ++ `CONFIG` :配置文件,它定義引導腳本讀取的 YAML 配置,默認爲 `config.yml` |
| 260 | + |
| 261 | +## 容器構建 |
| 262 | + |
| 263 | +您可以直接從源碼中構架出鏡像,使用以下命令。 |
| 264 | + |
| 265 | +```bash |
| 266 | +docker build -t syncplay https://github.com/dnomd343/syncplay-docker.git |
| 267 | +``` |
| 268 | + |
| 269 | +您也可以更改源代碼來實現自己的定制。 |
| 270 | + |
| 271 | +```bash |
| 272 | +> git clone https://github.com/dnomd343/syncplay-docker.git |
| 273 | +> cd syncplay-docker/ |
| 274 | +# some edit... |
| 275 | +> docker build -t syncplay . |
| 276 | +``` |
| 277 | + |
| 278 | +如果您需要多種架構的鏡像,請使用 `buildx` 命令構建。 |
| 279 | + |
| 280 | +```bash |
| 281 | +docker buildx build -t dnomd343/syncplay \ |
| 282 | + --platform=linux/amd64,linux/386,linux/arm64,linux/arm/v7 \ |
| 283 | + https://github.com/dnomd343/syncplay-docker.git --push |
| 284 | +``` |
| 285 | + |
| 286 | +## 許可證 |
| 287 | + |
| 288 | +MIT ©2023 [@dnomd343](https://github.com/dnomd343) |
0 commit comments