ccrice
@ccrice

前几天,尝试搭建pocketmine,官方文档里的脚本无法使用,查阅百度也做不到有用的信息。最后在不停的尝试之下,终于成功搭建。

搭建

方法一 快速搭建

由于官方的脚本无法使用,所以需要自己创建脚本。把下面的内容上传到要安装pocketmine的文件夹,并命名为install.sh

#!/bin/bash
CHANNEL="stable"
BRANCH="stable"
NAME="PocketMine-MP"
BUILD_URL=""
update=off
forcecompile=off
alldone=no
checkRoot=on
alternateurl=off
INSTALL_DIRECTORY="./"
IGNORE_CERT="no"
while getopts "rucid:v:t:" opt; do
    case $opt in
        a)
            alternateurl=on
            ;;
        r)
            checkRoot=off
            ;;
        u)
            update=on
            ;;
        c)
            forcecompile=on
            ;;
        d)
            INSTALL_DIRECTORY="$OPTARG"
            ;;
        i)
            IGNORE_CERT="yes"
            ;;
        v)
            CHANNEL="$OPTARG"
            ;;
        t)
            BUILD_URL="$OPTARG"
            ;;
        \?)
            echo "Invalid option: -$OPTARG" >&2
            exit 1
            ;;
    esac
done
if [ `getconf LONG_BIT` == "32" ]; then
    echo "[ERROR] PocketMine-MP is no longer supported on 32-bit systems."
    exit 1
fi
#Needed to use aliases
shopt -s expand_aliases
type wget > /dev/null 2>&1
if [ $? -eq 0 ]; then
    if [ "$IGNORE_CERT" == "yes" ]; then
        alias download_file="wget --no-check-certificate -q -O -"
    else
        alias download_file="wget -q -O -"
    fi
else
    type curl >> /dev/null 2>&1
    if [ $? -eq 0 ]; then
        if [ "$IGNORE_CERT" == "yes" ]; then
            alias download_file="curl --insecure --silent --show-error --location --globoff"
        else
            alias download_file="curl --silent --show-error --location --globoff"
        fi
    else
        echo "error, curl or wget not found"
        exit 1
    fi
fi
if [ "$checkRoot" == "on" ]; then
    if [ "$(id -u)" == "0" ]; then
        echo "This script is running as root, this is discouraged."
        echo "It is recommended to run it as a normal user as it doesn't need further permissions."
        echo "If you want to run it as root, add the -r flag."
        exit 1
    fi
fi
if [ "$CHANNEL" == "soft" ]; then
    NAME="PocketMine-Soft"
fi
ENABLE_GPG="no"
PUBLICKEY_URL="http://cdn.pocketmine.net/pocketmine.asc"
PUBLICKEY_FINGERPRINT="20D377AFC3F7535B3261AA4DCF48E7E52280B75B"
PUBLICKEY_LONGID="${PUBLICKEY_FINGERPRINT: -16}"
GPG_KEYSERVER="pgp.mit.edu"
function check_signature {
    echo "[*] Checking signature of $1"
    "$GPG_BIN" --keyserver "$GPG_KEYSERVER" --keyserver-options auto-key-retrieve=1 --trusted-key $PUBLICKEY_LONGID --verify "$1.sig" "$1"
    if [ $? -eq 0 ]; then
        echo "[+] Signature valid and checked!"
    else
        "$GPG_BIN" --refresh-keys > /dev/null 2>&1
        echo "[!] Invalid signature! Please check for file corruption or a wrongly imported public key (signed by $PUBLICKEY_FINGERPRINT)"
        exit 1
    fi
}
function parse_json {
    echo "$1" | grep "\"$2\"" | cut -d ':' -f2- | tr -d ' ",'
}
if [[ "$BUILD_URL" != "" && "$CHANNEL" == "custom" ]]; then
    BASE_VERSION="custom"
    BUILD="unknown"
    VERSION_DATE_STRING="unknown"
    ENABLE_GPG="no"
    VERSION_DOWNLOAD="$BUILD_URL"
    MCPE_VERSION="unknown"
    PHP_VERSION="unknown"
else
    echo "[*] Retrieving latest build data for channel \"$CHANNEL\""
    VERSION_DATA=$(download_file "https://update.pmmp.io/api?channel=$(tr '[:lower:]' '[:upper:]' <<< ${CHANNEL:0:1})${CHANNEL:1}")
    if [ "$VERSION_DATA" != "" ]; then
        error=$(parse_json "$VERSION_DATA" error)
        if [ "$error" != "" ]; then
            echo "[!] Failed to get download information: $error"
            exit 1
        fi
        FILENAME=$(parse_json "$VERSION_DATA" phar_name)
        BASE_VERSION=$(parse_json "$VERSION_DATA" base_version)
        BUILD=$(parse_json "$VERSION_DATA" build_number)
        MCPE_VERSION=$(parse_json "$VERSION_DATA" mcpe_version)
        PHP_VERSION=$(parse_json "$VERSION_DATA" php_version)
        VERSION_DATE=$(parse_json "$VERSION_DATA" date)
        BASE_URL=$(parse_json "$VERSION_DATA" url)
        VERSION_DOWNLOAD=$(parse_json "$VERSION_DATA" download_url)
        if [ "$(uname -s)" == "Darwin" ]; then
            VERSION_DATE_STRING=$(date -r $VERSION_DATE)
        else
            VERSION_DATE_STRING=$(date --date="@$VERSION_DATE")
        fi
        GPG_SIGNATURE=$(parse_json "$VERSION_DATA" signature_url)
        if [ "$GPG_SIGNATURE" != "" ]; then
            ENABLE_GPG="yes"
        fi
        if [ "$BASE_VERSION" == "" ]; then
            echo "[!] Couldn't get the latest $NAME version"
            exit 1
        fi
        GPG_BIN=""
        if [ "$ENABLE_GPG" == "yes" ]; then
            type gpg > /dev/null 2>&1
            if [ $? -eq 0 ]; then
                GPG_BIN="gpg"
            else
                type gpg2 > /dev/null 2>&1
                if [ $? -eq 0 ]; then
                    GPG_BIN="gpg2"
                fi
            fi
            if [ "$GPG_BIN" != "" ]; then
                gpg --fingerprint $PUBLICKEY_FINGERPRINT > /dev/null 2>&1
                if [ $? -ne 0 ]; then
                    download_file $PUBLICKEY_URL | gpg --trusted-key $PUBLICKEY_LONGID --import
                    gpg --fingerprint $PUBLICKEY_FINGERPRINT > /dev/null 2>&1
                    if [ $? -ne 0 ]; then
                        gpg --trusted-key $PUBLICKEY_LONGID --keyserver "$GPG_KEYSERVER" --recv-key $PUBLICKEY_FINGERPRINT
                    fi
                fi
            else
                ENABLE_GPG="no"
            fi
        fi
    else
        echo "[!] Failed to download version information: Empty response from API"
        exit 1
    fi
fi
echo "[*] Found $NAME $BASE_VERSION (build $BUILD) for Minecraft: PE v$MCPE_VERSION (PHP $PHP_VERSION)"
echo "[*] This $CHANNEL build was released on $VERSION_DATE_STRING"
if [ "$ENABLE_GPG" == "yes" ]; then
    echo "[+] The build was signed, will check signature"
elif [ "$GPG_SIGNATURE" == "" ]; then
    if [[ "$CHANNEL" == "beta" ]] || [[ "$CHANNEL" == "stable" ]]; then
        echo "[-] This channel should have a signature, none found"
    fi
fi
echo "[*] Installing/updating $NAME on directory $INSTALL_DIRECTORY"
mkdir -m 0777 "$INSTALL_DIRECTORY" 2> /dev/null
cd "$INSTALL_DIRECTORY"
echo "[1/3] Cleaning..."
rm -f "$NAME.phar"
rm -f README.md
rm -f CONTRIBUTING.md
rm -f LICENSE
rm -f start.sh
rm -f start.bat
#Old installations
rm -f PocketMine-MP.php
rm -r -f src/
echo -n "[2/3] Downloading $NAME phar..."
set +e
download_file "$VERSION_DOWNLOAD" > "$NAME.phar"
if ! [ -s "$NAME.phar" ] || [ "$(head -n 1 $NAME.phar)" == '<!DOCTYPE html>' ]; then
    rm "$NAME.phar" 2> /dev/null
    echo " failed!"
    echo "[!] Couldn't download $NAME automatically from $VERSION_DOWNLOAD"
    exit 1
else
    if [ "$CHANNEL" == "soft" ]; then
        download_file "https://raw.githubusercontent.com/PocketMine/PocketMine-Soft/${BRANCH}/resources/start.sh" > start.sh
    else
        download_file "https://raw.githubusercontent.com/pmmp/PocketMine-MP/${BRANCH}/start.sh" > start.sh
    fi
    download_file "https://raw.githubusercontent.com/pmmp/PocketMine-MP/${BRANCH}/LICENSE" > LICENSE
    download_file "https://raw.githubusercontent.com/pmmp/PocketMine-MP/${BRANCH}/README.md" > README.md
    download_file "https://raw.githubusercontent.com/pmmp/PocketMine-MP/${BRANCH}/CONTRIBUTING.md" > CONTRIBUTING.md
    download_file "https://raw.githubusercontent.com/pmmp/php-build-scripts/${BRANCH}/compile.sh" > compile.sh
fi
chmod +x compile.sh
chmod +x start.sh
echo " done!"
if [ "$ENABLE_GPG" == "yes" ]; then
    download_file "$GPG_SIGNATURE" > "$NAME.phar.sig"
    check_signature "$NAME.phar"
fi
if [ "$update" == "on" ]; then
    echo "[3/3] Skipping PHP recompilation due to user request"
else
    echo -n "[3/3] Obtaining PHP: detecting if build is available..."
    while [ "$forcecompile" == "off" ]
    do
        rm -r -f bin/ >> /dev/null 2>&1
        if [ "$(uname -s)" == "Darwin" ]; then
            PLATFORM="MacOS-x86_64"
            echo -n " MacOS PHP build available"
        elif [ "$(uname -s)" == "Linux" ]; then
            #if [[ "$(cat /etc/redhat-release 2>/dev/null)" == *CentOS* ]]; then
            #echo -n " CentOS PHP build available, downloading $CENTOS_BUILD.tar.gz..."
            #download_file "https://dl.bintray.com/pocketmine/PocketMine/$CENTOS_BUILD.tar.gz" | tar -zx > /dev/null 2>&1
            #else
            #TODO: check architecture (we might not be on an x86_64 system)
            PLATFORM="Linux-x86_64"
            echo -n " Linux PHP build available"
            #fi
        else
            echo " no prebuilt PHP download available"
            break
        fi
        echo -n "... downloading $PHP_VERSION ..."
        download_file "https://jenkins.pmmp.io/job/PHP-$PHP_VERSION-Aggregate/lastSuccessfulBuild/artifact/PHP-$PHP_VERSION-$PLATFORM.tar.gz" | tar -zx > /dev/null 2>&1
        chmod +x ./bin/php7/bin/*
        if [ -f ./bin/composer ]; then
            chmod +x ./bin/composer
        fi
        echo -n " updating php.ini..."
        sed -i'.bak' "s/date.timezone=.*/date.timezone=$(date +%Z)/" bin/php7/bin/php.ini
        EXTENSION_DIR=$(find "$(pwd)/bin" -name *debug-zts*) #make sure this only captures from `bin` in case the user renamed their old binary folder
        #Modify extension_dir directive if it exists, otherwise add it
        LF=

然后在命令行中cd到要安装的目录,输入

bash install.sh -r

进行安装。会自动下载所需依赖
安装完成后输入 bash start.sh -r就可以启动服务器啦

方法二 手动安装

有些时候,官方的脚本下载运行环境超慢,这个时候就可以手动安装。

安装PHP

由于pocketmine使用PHP,所以需要安装PHP。这里使用的系统是ubuntu
第一步安装依赖

sudo apt-get install libxml2-dev
sudo apt-get install libcurl3-openssl-dev
sudo apt-get install libcurl4-gnutls-dev
sudo apt-get install libbz2-dev
sudo apt-get install libjpeg-dev
sudo apt-get install libpng-dev
sudo apt-get install libxpm-dev
sudo apt-get install libfreetype6-dev
sudo apt-get install libmcrypt-dev
sudo apt-get install libmysql++-dev
sudo apt-get install libxslt1-dev

第二步下载PHP

cd /home/download

#导航到下载文件夹 可以改成其他的
wget http://php.net/get/php-7.3.0.tar.bz2/from/a/mirror
#下载PHP
tar xvf mirror
#解压
cd php-7.3.0/

修改configure参数

./configure  --prefix=/usr/local/php --enable-fpm --enable-sockets --enable-mbstring=all  -enable-mysqlnd  --with-config-file-path=/usr/local/php/etc --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-curl --with-gd
#编译安装
<pre><code>make -j2  
sudo make install 
sudo cp php.ini-development /usr/local/php/etc/php.ini
cd /usr/local/php/etc
sudo cp php-fpm.conf.default php-fpm.conf
cd /usr/local/php/etc/php-fpm.d
sudo cp www.conf.default www.conf
#修改profile文件。这里使用了Vim编辑器,如果不知道怎么使用Vim编辑器,请百度。
vim /etc/profile
#将下面的一句话加到末尾
export PATH=$PATH:/usr/local/php/bin
source /etc/profile
php -v 
#出现版本号说明安装成功
php -m
#查看你安装的依赖 

下载pocketmine

下载pocketmine,然后进入要安装的目录

wget https://jenkins.pmmp.io/job/PocketMine-MP/1790/artifact/PocketMine-MP.phar
#下载pocketmine

之后下载start.sh到安装pocketmine的目录,并输入bash start.sh -r就可以启动啦

附件

start.sh文件

有些时候安装完成之后start.sh文件会错误导致无法启动服务器。这个时候只需要替换start.sh为正确内容即可
#!/bin/bash
DIR="$(cd -P "$( dirname "${BASH_SOURCE[0]}" )" &amp;&amp; pwd)"
cd "$DIR"
while getopts "p:f:l" OPTION 2&gt; /dev/null; do
    case ${OPTION} in
        p)
            PHP_BINARY="$OPTARG"
            ;;
        f)
            POCKETMINE_FILE="$OPTARG"
            ;;
        l)
            DO_LOOP="yes"
            ;;
        \?)
            break
            ;;
    esac
done
if [ "$PHP_BINARY" == "" ]; then
    if [ -f ./bin/php7/bin/php ]; then
        export PHPRC=""
        PHP_BINARY="./bin/php7/bin/php"
    elif [[ ! -z $(type php) ]]; then
        PHP_BINARY=$(type -p php)
    else
        echo "Couldn't find a working PHP 7 binary, please use the installer."
        exit 1
    fi
fi
if [ "$POCKETMINE_FILE" == "" ]; then
    if [ -f ./PocketMine-MP.phar ]; then
        POCKETMINE_FILE="./PocketMine-MP.phar"
    else
        echo "PocketMine-MP.phar not found"
        echo "Downloads can be found at https://github.com/pmmp/PocketMine-MP/releases"
        exit 1
    fi
fi
LOOPS=0
set +e
if [ "$DO_LOOP" == "yes" ]; then
    while true; do
        if [ ${LOOPS} -gt 0 ]; then
            echo "Restarted $LOOPS times"
        fi
        "$PHP_BINARY" "$POCKETMINE_FILE" $@
        echo "To escape the loop, press CTRL+C now. Otherwise, wait 5 seconds for the server to restart."
        echo ""
        sleep 5
        ((LOOPS++))
    done
else
    exec "$PHP_BINARY" "$POCKETMINE_FILE" $@
fi</code></pre>
\n'
        grep -q '^extension_dir' bin/php7/bin/php.ini &amp;&amp; sed -i'bak' "s{^extension_dir=.*{extension_dir=\"$EXTENSION_DIR\"{" bin/php7/bin/php.ini || sed -i'bak' "1s{^{extension_dir=\"$EXTENSION_DIR\"\\$LF{" bin/php7/bin/php.ini
        echo -n " checking..."
        if [ "$(./bin/php7/bin/php -r 'echo 1;' 2&gt;/dev/null)" == "1" ]; then
            echo " done"
            alldone=yes
        else
            echo " downloaded PHP build doesn't work on this platform!"
        fi
        break
    done
    if [ "$alldone" == "no" ]; then
        set -e
        echo "[3/3] No prebuilt PHP found, compiling PHP automatically. This might take a while."
        echo
        exec "./compile.sh"
    fi
fi
rm compile.sh
echo "[*] Everything done! Run ./start.sh to start $NAME"
exit 0

然后在命令行中cd到要安装的目录,输入

进行安装。会自动下载所需依赖
安装完成后输入 bash start.sh -r就可以启动服务器啦

上午1:20 · 2020年03月11日
61
1
0
发表留言

    高贵的bread
    11个月前

    嗯。。。

技术
我搭建pocketmine服务器的过程
前几天,尝试搭建pocketmine,官方文档里的脚本无法使用,查阅百度也做不到有用的信息。最后在不停的尝试之下,终于成功搭建。搭建方法一 ...
扫描右侧二维码继续阅读
March 11, 2020
CC米饭
blogger
ccrice
而已米饭只是
最近回复
一个不知向何处的人
一个不知向何处的人 学长你好,我是今年刚上高一的学生,看完你这篇文章总觉得我们很像啊。从初中就觉得自己一直在颓废着,做什么事都不能坚持下去.........以为上了高中就能改变这种生活态度,真正到高中时才发现这不是与之前没什么两样嘛。。 还是同样的没有目标与方向,感觉我的人生就要完蛋了这样子。 突然发现我们的童年好像都是Minecraft,还记得当时用着家里的烂电脑玩着不知从哪里搞来的整合包,靠着仅仅只有十几帧和小窗的糟糕游戏体验玩得很开心;还记得第一次在服务器交到朋友时激动的整晚睡不着觉,并为他不上线了伤心了好长时间...... 那时的日子明明只过了几年为什么变得很模糊了呢? 过了一段时间到初中我渐渐感到家里的那老电脑越来越不行了,机缘巧合下我了解到了关于计算机硬件相关知识 之后我就想要台不错的电脑,想着只要能开着光影玩上Minecraft我就死而无憾了(笑。 初三毕业后我确实得到了一台还不错的笔记本——第一时间装好光影,在打开的那一刻,我的心情毫无起伏,“这不是我梦寐以求的吗?”然而内心平静地回应了我,这并不是我想要的,但我真的不知道还有什么是我想要追求的,我的梦想的一丝曙光也终于消散了。 一不小心写的有点多,在乱逛时突然发现这网络世界中有与我相同爱好与差不多烦恼的人,总觉得就像无垠大的世界中遇见知己一样,话说学长你选的BGM真是催泪啊 希望我们能解决各自烦恼吧,祝学长学业顺利,希望有缘能再见到你的。 by-Dlocy
白羊李志远
白羊李志远 好看
统计
文章:18 篇
分类:6 个
评论:65 条
by yoniu.
CC米饭