> If there is only **1 core 1G**? Please refer to my blog: [Linux small resource server experience summary](http://moonrailgun.com/posts/6769ba51/) expand memory space by swapping memory
>
> 可供参考的内存用量:
> Memory usage for reference:
> 
## 前置环境
## Pre-environment
### Docker / Docker Compose
首先需要确保有 `Docker / Docker Compose` 环境
First you need to make sure you have a `Docker / Docker Compose` environment
安装方式可参考: [安装 Docker 环境](./install-docker.md)
The installation method can refer to: [Install the docker environment](./install-docker.md)
## 拉取镜像
## Pull Image
你可以通过从**公共镜像拉取已经编译好的镜像**或者**通过源码手动编译**
You can pull the compiled image from **public image** or **manually compile from source code**
> Using the compiled image can compile without spending enough computer resources, which is very friendly to servers with small resource configurations. In addition, compared to source code compilation, the code of the public image is more stable.
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
<Tabs groupId="build">
<TabItem value="cli" label="使用cli一键安装" default>
<TabItem value="cli" label="One-command installation using cli" default>
> 使用 `cli` 请确保在你的服务器上已经拥有了node环境(建议node版本 16+)
> 如果对node不了解可以使用`从公共镜像中手动安装`方式
> Use `cli` Please make sure you already have a node environment on your server (node version 16+ is recommended)
> If you don't know about node, you can use `Manually install from public image`
使用 命令行工具 tailchat-cli 一键拉取/更新镜像:
Use the command line tool `tailchat-cli` to pull/update the image with one click:
docker tag moonrailgun/tailchat tailchat # 将下载的镜像改名为tailchat(和源码编译保持一致,如果不改的话会走源码编译流程)
docker pull moonrailgun/tailchat # Pull the tailchat image from the public image registry
docker tag moonrailgun/tailchat tailchat # Retag the downloaded image to tailchat (consistent with source code compilation, if not changed, it will follow the source code compilation process)
*This section is for advanced players to get the latest tailchat implementation, please make sure you have enough knowledge of `docker`, `nodejs`, `git`*
#### 编译环境 node 环境
#### Compilation environment
- 从 [官网下载](https://nodejs.org/en/download/)
- 或者使用 [nvm](https://github.com/nvm-sh/nvm)
- Download from [official website](https://nodejs.org/en/download/)
`pnpm` is a package management tool for `nodejs`, a substitute for `npm`, in order to ensure the same dependency environment as developers, it is strongly recommended that you use pnpm as a follow-up package management tool
git clone https://github.com/msgbyte/tailchat.git # Clone the project to local
```
#### 编译项目
#### Compile project
```bash
cd tailchat && docker compose build
```
*编译对服务器配置有一定要求,2核4G编译约10分钟,供参考*
*Compilation has certain requirements on server configuration, 2-core 4G compilation takes about 10 minutes, for reference*
编译完毕后可以通过 `docker images` 查看编译完毕的镜像。
After the compilation is complete, you can view the compiled image through `docker images`.
</TabItem>
</Tabs>
## 启动项目
## Startup project
<Tabs groupId="build">
<TabItem value="cli" label="使用cli一键安装" default>
<TabItem value="cli" label="One-command installation using cli" default>
```bash
npx tailchat-cli docker init
```
执行该命令会以交互式的方式向你询问一些配置相关的问题(如下图),填写完毕后即可自动生成配置文件
Executing this command will ask you some configuration-related questions in an interactive manner (as shown in the figure below), and the configuration file will be automatically generated after filling it out

</TabItem>
<TabItem value="public-image" label="从公共镜像中手动安装">
<TabItem value="public-image" label="Manually install from public image">
> 启动之前需要下载配置文件以告知 `docker-compose` 要如何启动镜像
> 从仓库下载配置文件与配置环境变量:
> A configuration file needs to be downloaded before starting to tell `docker-compose` how to start the image
> Download configuration files and configure environment variables from the repository:
Modify the configuration of the `docker-compose.env` file, the following fields are recommended to be modified:
- `API_URL` is an externally accessible url address, used for file service access, it can be a domain name or an ip **If the sent picture cannot be displayed normally, this variable is not set**
- `SECRET` server-side encryption key, used to generate Token. The default is `tailchat`
</TabItem>
<TabItem value="source-code" label="从源码中编译">
<TabItem value="source-code" label="Compile from source">
在启动之前需要修改一下配置
Need to modify the configuration before starting
修改 `docker-compose.env` 文件的配置,以下字段推荐修改:
Modify the configuration of the `docker-compose.env` file, the following fields are recommended to be modified:
- `API_URL` 对外可访问的url地址,用于文件服务访问, 可以是域名也可以是ip
- `SECRET` 服务端加密秘钥,用于生成Token. 默认为 `tailchat`
- `API_URL` is an externally accessible url address, used for file service access, it can be a domain name or an ip **If the sent picture cannot be displayed normally, this variable is not set**
- `SECRET` server-side encryption key, used to generate Token. The default is `tailchat`
- If it is started by `docker-compose`, you can directly edit `docker-compose.env`, and use `docker compose up -d` directly after the modification to take effect
In `Tailchat`, some services are strongly dependent on `https`, such as audio and video calls, embedding external `https` media resources and web pages, etc.
If you have no related experience, and only deploy `Tailchat` service on the same machine (without occupying **80**/**443** port), then we recommend `swag` from `Tailchat` Configuration begins.
Modify the content of `swag.env`, change the value of `URL` to the domain name, such as: `URL=tailchat.example.com`
:::info
`https`协议是依赖域名做证书校验的,因此需要提前分配一个域名指向目标服务器
The `https` protocol relies on the domain name for certificate verification, so it is necessary to assign a domain name in advance to point to the target server
:::
域名的地址需要在购买域名的管理后台创建一条A指向记录。
The address of the domain name needs to create an A pointing record in the management background of the purchased domain name.
在分配好域名后我们就可以启动服务了。
After assigning the domain name we can start the service.
If everything goes well, the `swag` service has automatically applied for a certificate for you and started the reverse proxy service. At this time, if you visit `https://tailchat.example.com` in the browser, you can see the familiar The interface is already there.
> Because the `Tailchat` environment is a bit complicated for beginners, it provides a `docker-based one-command` environment configuration. But for students who are not familiar with `docker`, `docker` itself may also be a kind of complexity.
> Therefore, in order to facilitate everyone to quickly build `Tailchat`, this article is provided as a guide. Students who have a certain understanding of `docker` can skip this article
> This article takes `linux centos` as an example, the goal is to facilitate the deployment directly on the server. For students who want to use it on other systems (`windows`, `mac`), you can refer to the official documentation to install `docker`
## 一键安装 docker
## One-command installation of docker
官方维护的一键安装 `Docker` 脚本, 适合不喜欢研究细节的同学
Officially maintained one-command installation `Docker` script, suitable for students who don’t like to study details
在服务器终端按照以下操作依次执行即可
Execute the following operations in sequence on the server terminal
*PS: `docker-compose-plugin` provides the `docker compose` command, the usage is the same as `docker-compose`*
> 如果`docker ps`显示守护进程没有启动(Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?)的话可以执行以下命令启动: `sudo systemctl start docker`
> If `docker ps` shows that the daemon process is not started (Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?), you can execute the following command to start it: `sudo systemctl start docker`
For historical reasons, `docker compose` has a `docker` plugin version and a `docker compose` standalone version. Generally speaking, `docker compose xxx` is equivalent to `docker-compose xxx`
You can start a simple http service to see if it is a problem with the docker-proxy layer. *This problem may occur on the docker-ce image machine of Tencent lighthouse, you can choose to use the centos7 image to reinstall*
```bash
docker run --rm --name nginx-test -p 8080:80 nginx
If the open platform is deployed behind a proxy, if the endpoint in the JSON of the access `/open/.well-known/openid-configuration` result is incorrect, please try to modify the configuration of the proxy to forward real ip.