Open8

ゆるゆる自宅minecraftサーバー

プレミ社員プレミ社員

構成

  • 自宅のmac mini (minecraft鯖)
  • ConoHa VPS x 2
    • 監視用とプロキシ鯖

身内向けだけど家のIP教えたくない人やホワイトリスト管理めんどくさい人向け

プレミ社員プレミ社員

mac mini

#  minecraft-prometheus-exporter config.yml
host: 0.0.0.0
port: xxxx
enable_metrics:
  entities_total: true
  villagers_total: true
  loaded_chunks_total: true
  jvm_memory: true
  players_online_total: true
  players_total: true
  whitelisted_players: false
  tps: true
  world_size: true
  jvm_threads: true
  jvm_gc: true
  tick_duration_median: true
  tick_duration_average: true
  tick_duration_min: false
  tick_duration_max: true
  player_online: true
  player_statistic: true

デーモン管理はlaunchedを使っている(むずい、発狂した)
pfでプロキシからのアクセス以外を遮断
v6プラス環境なのでポートは適当に使えるものを使う
他にもDiscordSRVなど色々入れているが割愛

プレミ社員プレミ社員

VPS1 (nginx proxy)

  • 実はもともとここでminecraftが動いていた
  • minecraftユーザーにはここのIPを教える
  • iptables
  • niginx
    • 特定のポートでアクセスされた場合自宅のminecraftサーバーに接続させる
worker_processes 1;

pid /var/run/nginx.pid;

events {
  worker_connections 1024;
}

http {
  access_log /var/logs/nginx/access.log;
  error_log /var/logs/nginx/error.log;
}

stream {
  upstream mcserver {
    server x.x.x.x:xxxx;
  }
  server {
    listen 25565;
    proxy_pass mcserver;
  }
}

プレミ社員プレミ社員

VPS2

  • prometheusとgrafanaをdocker-composeで動かしている
# prometheus.yml
global:
  scrape_interval: 5s

scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets:
          - "xxx.xx.xxx.xxx:xxxx" # node_exporterのメトリクス出力先
          - "xxx.xx.xxx.xxx:xxxx" # minecraft-prometheus-exporterのメトリクス出力先
    relabel_configs:
      - replacement: "minecraft_monitor"
        target_label: instance
        action: replace
# docker-compose.yml
services:
  prometheus:
    image: prom/prometheus
    container_name: prometheus
    volumes:
      - "./prometheus.yml:/etc/prometheus/prometheus.yml"
      - "prometheus-data:/prometheus"
    restart: unless-stopped
  grafana:
    image: grafana/grafana-enterprise
    container_name: grafana
    restart: unless-stopped
    environment:
      GF_AUTH_ANONYMOUS_ENABLED: "true"
      GF_AUTH_ANONYMOUS_ORG_NAME: "まいくらさば"
      GF_AUTH_ANONYMOUS_ORG_ROLE: "Viewer"
      GF_SERVER_ROOT_URL: "https://hogehoge.com"
    volumes:
      - "grafana_storage:/var/lib/grafana"
    depends_on:
      - prometheus
  nginx:
    image: nginx:latest
    container_name: nginx
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx/conf.d:/etc/nginx/conf.d
      - nginx-certs-etc:/etc/letsencrypt/
      - nginx-certs-acme:/usr/share/nginx/html/.well-known/acme-challenge/
    depends_on:
      - grafana
volumes:
  prometheus-data: {}
  grafana_storage: {}
  nginx-certs-acme:
    external: true
  nginx-certs-etc:
    external: true

# grafana公開用nginx.conf
server {
  listen 80;
  listen [::]:80;
  server_name grafana.hogehoge.com;
  return 301  https://$host$request_uri;
}

server {
  listen 443 ssl;
  listen [::]:443 ssl;
  server_name grafana.hogehoge.com;

  location / {
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Connection '';
    proxy_http_version 1.1;

    proxy_pass http://grafana:3000;
  }

  location /.well-known/acme-challenge/ {
    root /usr/share/nginx/html/.well-known/acme-challenge/;
  }

  ssl_certificate     /etc/letsencrypt/live/grafana.hogehoge.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/grafana.hogehoge.com/privkey.pem;

  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
    root   /usr/share/nginx/html;
  }
}