【教程】安装 MCSManager 面板


安装脚本

#!/bin/bash

# Check if running as root
if [ "$(id -u)" != "0" ]; then 
    echo "Please run as root (use sudo)"
    exit 1
fi

# Function to check if a port is available
check_port() {
    local port=$1
    if netstat -tuln | grep -q ":${port} "; then
        return 1    # Port is in use
    else
        return 0    # Port is available
    fi
}

# Function to get a random available port in a range
get_random_port() {
    local min_port=$1
    local max_port=$2
    local port

    while true; do
        port=$(( ($RANDOM % ($max_port - $min_port + 1)) + $min_port ))
        if check_port $port; then
            echo $port
            break
        fi
    done
}

# Set installation path (default: current directory)
CURRENT_DIR=$(pwd)
read -p "Enter installation path (default: current directory ${CURRENT_DIR}): " INSTALL_PATH
INSTALL_PATH=${INSTALL_PATH:-$CURRENT_DIR}

# Ask about port configuration
echo "Port configuration:"
echo "1. Use random ports"
echo "2. Set custom ports"
echo "3. Use default ports (23333/24444)"
read -p "Choose an option (1-3): " PORT_OPTION

case $PORT_OPTION in
    1)
        # Generate random ports
        WEB_PORT=$(get_random_port 20000 25000)
        DAEMON_PORT=$(get_random_port 25001 30000)
        echo "Generated random ports:"
        echo "Web panel port: $WEB_PORT"
        echo "Daemon port: $DAEMON_PORT"
        ;;
    2)
        # Custom ports
        read -p "Enter web panel port (default: 23333): " WEB_PORT
        read -p "Enter daemon port (default: 24444): " DAEMON_PORT
        WEB_PORT=${WEB_PORT:-23333}
        DAEMON_PORT=${DAEMON_PORT:-24444}
        ;;
    *)
        # Default ports
        WEB_PORT=23333
        DAEMON_PORT=24444
        DAEMON_RCON_PORT=25575
        DAEMON_SERVER_PORT=25565
        ;;
esac

# Create docker-compose.yml
cat > "${INSTALL_PATH}/docker-compose.yml" << EOF
services:
  web:
    image: githubyumao/mcsmanager-web:latest
    restart: unless-stopped
    ports:
      - "${WEB_PORT}:23333"
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ${INSTALL_PATH}/web/data:/opt/mcsmanager/web/data
      - ${INSTALL_PATH}/web/logs:/opt/mcsmanager/web/logs

  daemon:
    image: githubyumao/mcsmanager-daemon:latest
    restart: unless-stopped
    ports:
      - "${DAEMON_PORT}:${DAEMON_PORT}"
      - "${DAEMON_RCON_PORT}:${DAEMON_RCON_PORT}"
      - "${DAEMON_SERVER_PORT}:${DAEMON_SERVER_PORT}"
    environment:
      - MCSM_DOCKER_WORKSPACE_PATH=${INSTALL_PATH}/daemon/data/InstanceData
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ${INSTALL_PATH}/daemon/data:/opt/mcsmanager/daemon/data
      - ${INSTALL_PATH}/daemon/logs:/opt/mcsmanager/daemon/logs
      - /var/run/docker.sock:/var/run/docker.sock
EOF

# Save port configuration
cat > "${INSTALL_PATH}/ports.conf" << EOF
WEB_PORT=${WEB_PORT}
DAEMON_PORT=${DAEMON_PORT}
INSTALL_PATH=${INSTALL_PATH}
EOF

echo "================================================================"
echo "Docker Compose configuration has been created at: ${INSTALL_PATH}/docker-compose.yml"
echo "Port configuration saved to: ${INSTALL_PATH}/ports.conf"
echo
echo "To start the service, run:"
echo "cd ${INSTALL_PATH} && docker compose up -d"
echo
echo "The panel will be accessible at: http://YOUR_IP:${WEB_PORT}"
echo "Daemon port: ${DAEMON_PORT}"
echo "----------------------------------------------------------------"
echo "Important: When configuring the daemon connection in the web panel,"
echo "make sure to use port ${DAEMON_PORT}"
echo "================================================================"

添加远程管理节点

查看 global.json ,根据将 port 端口填到下面的远程端口中,将 key 填到下面的远程节点密钥中。

cat ./daemon/data/Config/global.json

转发内网端口

sudo iptables -t nat -F PREROUTING
sudo iptables -t nat -A POSTROUTING -j MASQUERADE
sudo iptables -t nat -L PREROUTING -n -v
sudo iptables -t nat -A PREROUTING -p tcp -m tcp --dport 25565 -j DNAT --to-destination 100.102.127.58:25565

sudo iptables -t nat -A PREROUTING -p udp -m udp --dport 25565 -j DNAT --to-destination 100.102.127.58:25565

如果本文帮助到了你,帮我点个广告可以咩(o′┏▽┓`o)


评论
  目录