← Back to NetEase/pomelo

How to Deploy & Use NetEase/pomelo

Pomelo Game Server Framework Deployment Guide

Prerequisites

  • Node.js: Version 8.0 or higher
  • npm: Version 5.0 or higher (comes with Node.js)
  • Git: For cloning the repository
  • Operating System: Linux, macOS, or Windows (with appropriate build tools)

Installation

  1. Clone the repository:

    git clone https://github.com/NetEase/pomelo.git
    cd pomelo
    
  2. Install dependencies:

    npm install
    
  3. Install Pomelo CLI globally (optional but recommended for development):

    npm install -g pomelo
    

Configuration

Environment Variables

Pomelo uses the following environment variables:

  • NODE_ENV: Set to development or production
  • PORT: Port for the server (default: 3005)

Configuration Files

Pomelo uses a config directory with the following structure:

config/
├── master.json
├── servers.json
└── development/
    ├── server.json
    └── ...

Key Configuration Files:

  1. master.json: Master server configuration
  2. servers.json: Server list and configuration
  3. server.json: Individual server configuration

Example Configuration

// config/servers.json
{
  "development": {
    "connector": [
      {"id": "connector-server-1", "host": "127.0.0.1", "port": 3001, "clientPort": 3010}
    ],
    "chat": [
      {"id": "chat-server-1", "host": "127.0.0.1", "port": 3002}
    ]
  }
}

Build & Run

Development

  1. Start the master server:

    pomelo start master
    
  2. Start all servers:

    pomelo start
    
  3. Start specific server type:

    pomelo start connector
    
  4. Stop all servers:

    pomelo stop
    

Production

  1. Build for production (if needed):

    npm run build
    
  2. Start in production mode:

    NODE_ENV=production pomelo start
    

Deployment

Recommended Platforms

Pomelo is suitable for deployment on:

  1. Docker: Container-based deployment
  2. AWS EC2: Virtual machine instances
  3. Google Cloud Platform: Compute Engine instances
  4. DigitalOcean: Droplets
  5. Heroku: For smaller scale deployments

Docker Deployment

  1. Create Dockerfile:

    FROM node:14
    WORKDIR /app
    COPY package*.json ./
    RUN npm install
    COPY . .
    EXPOSE 3005
    CMD ["pomelo", "start"]
    
  2. Build and run:

    docker build -t pomelo-app .
    docker run -p 3005:3005 pomelo-app
    

Cloud Deployment (AWS Example)

  1. Create EC2 instance with Node.js installed
  2. Clone repository and install dependencies
  3. Configure environment variables
  4. Start Pomelo:
    NODE_ENV=production pm2 start app.js --name pomelo
    

Troubleshooting

Common Issues

  1. Port Already in Use:

    • Solution: Change port in configuration or kill the process using the port
    lsof -i :3005
    kill -9 <PID>
    
  2. Module Not Found:

    • Solution: Ensure all dependencies are installed
    npm install
    
  3. Connection Refused:

    • Check if servers are running
    • Verify firewall settings
    • Check configuration files for correct host and port
  4. Memory Issues:

    • Increase Node.js memory limit
    node --max-old-space-size=4096 app.js
    
  5. Session Issues:

    • Verify session service configuration
    • Check Redis connection if using external session store

Debug Mode

Enable debug logging:

DEBUG=pomelo:* pomelo start

Performance Monitoring

Use built-in monitoring tools:

pomelo list
pomelo monitor

Configuration Validation

Validate configuration before starting:

pomelo check

This guide provides a comprehensive overview of deploying and using Pomelo, covering all essential aspects from installation to troubleshooting. The framework's distributed architecture and modular design make it suitable for various deployment scenarios, from development to production environments.