GeoServer稳定版centeros单机部署

GeoServer稳定版centeros单机部署

下载安装包

稳定版下载地址 http://geoserver.org/release/stable/
Packages 第一个链接就是了
下载完上传到centeros服务器上,找个位置
tar -zxvf ./文件名 解压

环境变量

需要提前安装java环境
记得GEOSERVER_HOME一定要导出
# export java environment
export JAVA_HOME=/usr/local/jdk1.8.0_161
export CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
export GEOSERVER_HOME=/lh3s/geoserver2.17

环境变量不建议放在root用户中,习惯不好
且建议修改~/.bashrc文件,而不建议修改 ~/.profile文件
修改后 source ~/.bashrc生效

启动方式

手动启动

解压、环境变量配置好后就可以使用
/lh3s/geoserver2.17/bin/startup.sh 启动服务
/lh3s/geoserver2.17/bin/shutdown.sh 关闭服务
手动启动在命令后面追加 & ,以保证后台执行

开机启动配置

创建开启启动文件,位置建议放在 /etc/systemd/system 中,不建议放在/lib/systemd目录中
配置文件内容
Environment环境变量很重要,记得配置
[Unit]
Description=GeoServer2.17
After=network.target
[Service]
Type=forking
User=arcgis
Environment="JAVA_HOME=/usr/local/jdk1.8.0_161" "JRE_HOME=/usr/local/jdk1.8.0_161/jre" "GEOSERVER_HOME=/lh3s/geoserver2.17"
ExecStart=/lh3s/geoserver2.17/bin/startup.sh
ExecStop=/lh3s/geoserver2.17/bin/shutdown.sh
[Install]
WantedBy=multi-user.target
**记得chmod 700给文件一个可执行权限
chmod 700 geoserver.service文件可执行权限
如果启动报错,还要给bin/startup.sh、bin/shutdown.sh 执行权限。**
然后systemctl命令就可以用了,使用之前记得reload一下服务。
systemctl daemon-reload 刷新uint服务
systemctl enable geoserver 设置开机启动
systemctl start geoserver 启动服务

然而现在如果直接启动服务会发现命令无法结束,命令行会一致卡在这里
这当时是不可以的,也不是我们想要的
于是打开启动脚本看了一眼
#!/bin/sh
# -----------------------------------------------------------------------------
# Start Script for GEOSERVER
#
# $Id$
# -----------------------------------------------------------------------------

# Guard against misconfigured JAVA_HOME
if [ ! -z "$JAVA_HOME" -a ! -x "$JAVA_HOME"/bin/java ]; then
  echo "The JAVA_HOME environment variable is set but JAVA_HOME/bin/java"
  echo "is missing or not executable:"
  echo "    JAVA_HOME=$JAVA_HOME"
  echo "Please either set JAVA_HOME so that the Java runtime is JAVA_HOME/bin/java"
  echo "or unset JAVA_HOME to use the Java runtime on the PATH."
  exit 1
fi

# Find java from JAVA_HOME or PATH
if [ ! -z "$JAVA_HOME" ]; then
  _RUNJAVA="$JAVA_HOME"/bin/java
elif [ ! -z "$(which java)" ]; then
  _RUNJAVA=java
else
  echo "A Java runtime (java) was not found in JAVA_HOME/bin or on the PATH."
  echo "Please either set the JAVA_HOME environment variable so that the Java runtime"
  echo "is JAVA_HOME/bin/java or add the Java runtime to the PATH."
  exit 1
fi

if [ -z $GEOSERVER_HOME ]; then
  #If GEOSERVER_HOME not set then guess a few locations before giving
  # up and demanding user set it.
  if [ -r start.jar ]; then
     echo "GEOSERVER_HOME environment variable not found, using current "
     echo "directory.  If not set then running this script from other "
     echo "directories will not work in the future."
     export GEOSERVER_HOME=`pwd`
  else 
    if [ -r ../start.jar ]; then
      echo "GEOSERVER_HOME environment variable not found, using current "
      echo "location.  If not set then running this script from other "
      echo "directories will not work in the future."
      export GEOSERVER_HOME=`pwd`/..
    fi
  fi 

  if [ -z "$GEOSERVER_HOME" ]; then
    echo "The GEOSERVER_HOME environment variable is not defined"
    echo "This environment variable is needed to run this program"
    echo "Please set it to the directory where geoserver was installed"
    exit 1
  fi

fi

if [ ! -r "$GEOSERVER_HOME"/bin/startup.sh ]; then
  echo "The GEOSERVER_HOME environment variable is not defined correctly"
  echo "This environment variable is needed to run this program"
  exit 1
fi

#Find the configuration directory: GEOSERVER_DATA_DIR
if [ -z $GEOSERVER_DATA_DIR ]; then
    if [ -r "$GEOSERVER_HOME"/data_dir ]; then
        export GEOSERVER_DATA_DIR="$GEOSERVER_HOME"/data_dir
    else
        echo "No GEOSERVER_DATA_DIR found, using application defaults"
              GEOSERVER_DATA_DIR=""
    fi
fi

cd "$GEOSERVER_HOME"

if [ -z $MARLIN_JAR]; then
    export MARLIN_JAR=`find \`pwd\`/webapps -name "marlin*.jar" | head -1`
    export MARLIN_ENABLER="-Xbootclasspath/a:$MARLIN_JAR -Dsun.java2d.renderer=org.marlin.pisces.MarlinRenderingEngine"
fi

echo "GEOSERVER DATA DIR is $GEOSERVER_DATA_DIR"
#added headless to true by default, if this messes anyone up let the list
#know and we can change it back, but it seems like it won't hurt -ch
exec "$_RUNJAVA" $JAVA_OPTS $MARLIN_ENABLER -DGEOSERVER_DATA_DIR="$GEOSERVER_DATA_DIR" -Djava.awt.headless=true -DSTOP.PORT=8079 -DSTOP.KEY=geoserver -jar start.jar
还是有几行代码的
看到最后一行发现使用了exec命令执行的,那就好办了
卡的原因是因为输出没有重定向,导致命令行一致输出卡着服务了,简单修改一下即可
使用nohup重定向一下数据流,修改一下最后一行代码
这是修改后的最后一行,前面加了nohup,后面加了 > /dev/null 2>&1 & 很少
exec nohup "$_RUNJAVA" $JAVA_OPTS $MARLIN_ENABLER -DGEOSERVER_DATA_DIR="$GEOSERVER_DATA_DIR" -Djava.awt.headless=true -DSTOP.PORT=8079 -DSTOP.KEY=geoserver -jar start.jar > /dev/null 2>&1 &
然后保存一下,重新启动服务就会发现一切正常了
最后,在启动的输出消息中发现geoserver换成spring boot项目了,舒服的很。
默认的用户名密码 	admin/geoserver
good luck!!!

GeoServer稳定版centeros单机部署_第1张图片

你可能感兴趣的:(开源GIS大杂烩,geoserver)