ホーム > computer, Games > マインクラフト統合版セットアップ覚え書き

マインクラフト統合版セットアップ覚え書き

2024 年 1 月 16 日
  • server.properties
/opt/app/mincraft-be/server.properties
server-name=Dedicated Server
gamemode=survival
force-gamemode=false
difficulty=easy
allow-cheats=false
max-players=10
online-mode=true
allow-list=false
server-port=19132
server-portv6=19133
enable-lan-visibility=false
view-distance=12
tick-distance=8
player-idle-timeout=0
max-threads=8
level-name=dmC2YpSuAgA_
level-seed=
default-player-permission-level=member
texturepack-required=false
content-log-file-enabled=true
compression-threshold=1
compression-algorithm=zlib
server-authoritative-movement=server-auth
player-movement-score-threshold=20
player-movement-action-direction-threshold=0.85
player-movement-distance-threshold=0.3
player-movement-duration-threshold-in-ms=500
correct-player-movement=false
server-authoritative-block-breaking=false
chat-restriction=None
disable-player-interaction=false
client-side-chunk-generation-enabled=true
block-network-ids-are-hashes=true
disable-persona=false
disable-custom-skins=false
server-build-radius-ratio=Disabled
allow-outbound-script-debugging=false
allow-inbound-script-debugging=false
script-debugger-auto-attach=disabled
  • script一覧
/opt/scripts/bedrock-start.sh
#!/usr/bin/bash

SERVICE_NAME=bedrock.service
SCREEN_NAME=minecraft

f_service_start(){
  screen -S ${SCREEN_NAME} -D -m /opt/app/mincraft-be/bedrock_server
}

f_service_start
sleep 10
/opt/scripts/bedrock-set-options.sh
/opt/scripts/bedrock-set-options.sh
#!/usr/bin/bash

SCREEN_NAME=minecraft
RULES_LIST=/opt/scripts/gamerule-be.list

f_set-options(){

  sed -e /"^\s*\t*\s*#\|^\s*\t*\s*$"/d ${RULES_LIST} > setruleslist
  while read RULES ; do
    screen -S ${SCREEN_NAME} -X eval "stuff \"gamerule ${RULES}\015\""
  done < setruleslist
  rm setruleslist
}

f_set-options
/opt/scripts/gamerule-be.list
pvp                       FALSE
showCoordinates           TRUE
#doFireTick                TRUE
#recipesunlock             TRUE
#dolimitedcrafting         FALSE
#tntExplodes               TRUE
#respawnBlocksExplode      TRUE
#doMobLoot                 TRUE
#naturalRegeneration       TRUE
#doTileDrops               TRUE
#doImmediateRespawn        FALSE
#spawnRadius               5

#drowningDamage            TRUE
#fallDamage                TRUE
#fireDamage                TRUE
#freezeDamage              TRUE

#doDaylightCycle           TRUE
#keepInventory             FALSE
#doMobSpawning             TRUE
#doInsomnia                TRUE
#mobGriefing               TRUE
#doEntityDrops             TRUE
#doWeatherCycle            TRUE
#randomTickSpeed           2

#commandBlocksEnabled      TRUE
#commandBlockOutput        TRUE
#sendCommandFeedback       TRUE
#maxCommandChainLength     65536

#functionCommandLimit      10000
#showDeathMessages         TRUE
#showTags                  TRUE

#showbordereffect          TRUE
#showrecipemessages        TRUE
#playerssleepingpercentage 100
#projectilescanbreakblocks TRUE
/opt/scripts/minecraft_backup.sh
#!/usr/bin/bash


MINECRAFT_DIR=/opt/app/mincraft-be
BACKUP_DIR=/home/shuhei/bedrock-backup
BACKUP_age=8
ANNOUNCE_TIME=30

SERVICE_NAME=bedrock.service
SCREEN_NAME=minecraft

LOG_DIR=/home/shuhei/logs/minecraft


DATETIME=$(date +%Y%m%d-%H%M%S)

WORLDNAME=$(cat ${MINECRAFT_DIR}/server.properties | egrep -v "^#" | egrep "level-name" | cut -d= -f 2)
WORLD_DIR=${MINECRAFT_DIR}/worlds/${WORLDNAME}/
ARCHIVE_NAME=${WORLDNAME}_${DATETIME}.tar


#SCREEN_NAME=$(screen -ls | grep minecraft | awk -F\  '{print $1}')

f_stopService(){
  sudo systemctl stop $SERVICE_NAME
}

f_startService(){
  sudo systemctl start $SERVICE_NAME

  sleep 10

  screen -S ${SCREEN_NAME} -X eval "stuff \"gamerule showcoordinates true\015\""
  screen -S ${SCREEN_NAME} -X eval "stuff \"gamerule pvp false\015\""
}

f_compressLog(){
  if [ ! -d ${LOG_DIR} ] ; then
    mkdir -p ${LOG_DIR}
  fi

  FILECOUNT=$(ls ${LOG_DIR} | wc -l)
  TARGET_FILE=$(ls -tr ${LOG_DIR} | tail -n +${FILECOUNT})
  gzip ${LOG_DIR}/${TARGET_FILE}
}

f_backup_be(){
  if [ ! -d ${BACKUP_DIR} ] ; then
    mkdir -p ${BACKUP_DIR}
  fi

  sudo tar -cf ${BACKUP_DIR}/${ARCHIVE_NAME} ${WORLD_DIR}
  gzip ${BACKUP_DIR}/${ARCHIVE_NAME}

  BACKUP_age=$((BACKUP_age+1))
  for REMOVE_FILE in $(ls -t ${BACKUP_DIR} | tail -n +${BACKUP_age}) ; do
    rm ${BACKUP_DIR}/${REMOVE_FILE}
  done
}

f_countdown(){
  while [ $ANNOUNCE_TIME -gt 1 ] ; do

    FLAG=$((ANNOUNCE_TIME%10))

    if   [ $ANNOUNCE_TIME -le 5 ] ; then
      screen -S ${SCREEN_NAME} -X eval "stuff \"say このサーバーはメンテナンスのため約 ${ANNOUNCE_TIME} 分後に再 起動します\015\""
      sleep 2
      screen -S ${SCREEN_NAME} -X eval "stuff \"say 作業を中断しサーバーからログアウトしてください\015\""
      sleep 2
      screen -S ${SCREEN_NAME} -X eval "stuff \"say メンテナンスは 5分 程度を見込んでいます\015\""
    elif [ $FLAG -eq 0 ] ; then
      screen -S ${SCREEN_NAME} -X eval "stuff \"say このサーバーはメンテナンスのため約 ${ANNOUNCE_TIME} 分後に再 起動します\015\""
    fi

    sleep 1m
    ANNOUNCE_TIME=$((ANNOUNCE_TIME-1))
  done

  ANNOUNCE_TIME=60
  while [ $ANNOUNCE_TIME -gt 0 ] ; do
    screen -S ${SCREEN_NAME} -X eval "stuff \"say このサーバーはメンテナンスのため ${ANNOUNCE_TIME} 秒後に再起動 します\015\""
    sleep 1
    ANNOUNCE_TIME=$((ANNOUNCE_TIME-1))
  done

}

f_countdown

f_stopService

f_backup_be
f_compressLog

f_startService

ネットワークインターフェイス

sudo cat /etc/netplan/51-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
    eth0:
      dhcp4: false
      dhcp6: false
      addresses:
        - 172.16.1.51/24
      routes:
        - {to: default, via: 172.16.1.2}
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4
    eth1:
      dhcp4: false
    eth2:
      dhcp4: false
    eth3:
      dhcp4: false
      dhcp6: false
      addresses:
        - 192.168.1.151/24
  version: 2

ファイアウォール ルール

sudo ufw status
状態: アクティブ

To                         Action      From
--                         ------      ----
22                         ALLOW       192.168.0.0/16
Apache Full                ALLOW       Anywhere
19132                      ALLOW       Anywhere
19133                      ALLOW       Anywhere
161/udp                    ALLOW       Anywhere
Apache Full (v6)           ALLOW       Anywhere (v6)
19132 (v6)                 ALLOW       Anywhere (v6)
19133 (v6)                 ALLOW       Anywhere (v6)
161/udp (v6)               ALLOW       Anywhere (v6)
  • Systemd登録
/etc/systemd/system/bedrock.service
[Unit]
Description=Minecraft Bedrock Server
After=network.target local-fs.target

[Service]
Type=simple
User=shuhei
Group=shuhei
WorkingDirectory=/opt/app/mincraft-be/
Environment=LD_LIBRARY_PATH=.
ExecStart=screen -S minecraft -D -m /opt/app/mincraft-be/bedrock_server
ExecStop=screen -S minecraft -X eval "stuff \"stop\015\""
Restart=always

[Install]
WantedBy=multi-user.target

ユニットを作成したら systemctl をリロードして登録、開始する

$ sudo systemctl daemon-reload
$ sudo systemctl enable bedrock
$ sudo systemctl start bedrock
カテゴリー: computer, Games タグ:
コメントは受け付けていません。