使用nakama
第一步 下载nakama
第二步 docker拉去cockroachDB
第三步 运行数据库迁移:nakama.exe migrate up
第四部 启动nakama
您可以通过将浏览器导航到127.0.0.1:7351来访问Nakama控制台。
提示登录时,默认凭据为admin:password
可以使用--config标志在运行时指定配置文件。
nakama --config my-special-config.yml
Nakama系统非常灵活。您可以通过gRPC, HTTP, Websockets和rUDP与服务器交换数据。由于这种灵活性,Nakama需要4个端口可用于绑定到:
在端口7350上绑定到HTTP API服务器可以在配置中更改端口。
在7351端口上绑定到HTTP API服务器,这个服务器启动嵌入式开发人员控制台。可以在配置中更改端口。
在端口7349上绑定到gRPC API服务器。根据API服务器端口选择端口。
在7348端口上绑定到gRPC API服务器,该服务器启动嵌入式控制台。根据API服务器端口选择端口。
dockerfile:
FROM heroiclabs/nakama-pluginbuilder:3.28.0 AS builder
ENV GO111MODULE on
ENV CGO_ENABLED 1
WORKDIR /go_nakama
COPY . .
RUN go build --trimpath --buildmode=plugin -o ./go_test.so
FROM heroiclabs/nakama:3.28.0
COPY --from=builder /go_nakama/go_test.so /nakama/modules-go/go_test.so
docker-compose:
services:
cockroachdb:
image: cockroachdb/cockroach:latest
command: start-single-node --insecure --store=attrs=ssd,path=/var/lib/cockroach/
restart: "no"
volumes:
- cockroachData:/var/lib/cockroach
expose:
- "8080"
- "26257"
ports:
- "26257:26257"
- "8080:8080"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health?ready=1"]
interval: 3s
timeout: 3s
retries: 5
nakama:
build: .
entrypoint:
- "/bin/sh"
- "-ecx"
- >
/nakama/nakama migrate up --database.address root@cockroachdb:26257 &&
exec /nakama/nakama --name nakama1 --config /nakama/data/nakama_config.yml
restart: "no"
depends_on:
cockroachdb:
condition: service_healthy
volumes:
- ./:/nakama/data
expose:
- "7349"
- "7350"
- "7351"
- "9100"
ports:
- "7349:7349"
- "7350:7350"
- "7351:7351"
healthcheck:
test: ["CMD", "/nakama/nakama", "healthcheck"]
interval: 30s
timeout: 5s
retries: 5
volumes:
cockroachData:
nakama的配置文件:
name: nakama-node-1
data_dir: "./data/"
logger:
level: DEBUG
metrics:
reporting_freq_sec: 60
namespace: ""
prometheus_port: 7354
database:
address:
- "root@cockroachdb:26257"
conn_max_lifetime_ms: 0
max_open_conns: 0
max_idle_conns: 100
runtime:
env:
- "example_apikey=example_apivalue"
- "encryptionkey=afefa==e332*u13=971mldq"
path: "/nakama/modules-go/"
http_key: "defaulthttpkey"
socket:
server_key: "defaultkey"
port: 7350
max_message_size_bytes: 4096 # bytes
read_timeout_ms: 10000
write_timeout_ms: 10000
idle_timeout_ms: 60000
write_wait_ms: 5000
pong_wait_ms: 10000
ping_period_ms: 8000 # Must be less than pong_wait_ms
outgoing_queue_size: 16
session:
encryption_key: "defaultencryptionkey"
token_expiry_sec: 7200
social:
steam:
publisher_key: ""
app_id: 0
console:
port: 7351
username: "admin"
password: "password"
cluster:
join:
- "10.0.0.2:7352"
- "10.0.0.3:7352"
gossip_bindaddr: "0.0.0.0"
gossip_bindport: 7352
rpc_port: 7353
local_priority: true
work_factor_interval_ms: 1000
tracker:
max_delta_sizes:
- 100
- 1000
- 10000
matchmaker:
max_tickets: 2
interval_sec: 15
max_intervals: 3
iap:
apple:
shared_password: "password"
google:
client_email: "email@google.com"
private_key: "pk"
huawei:
public_key: "pk"
client_id: "id"
client_secret: "secret"