基于devops利用微服务引入三方服务---部署Arcgis Server、Postgresql、Postgis、WebAdapter、Portal for Arcgis

1、准备工作

1.1.软件准备

所有软件全部部署在同一台服务器上

软件 版本 系统 ip
Arcgis Server Linux 10.4 Centos7.5 192.168.0.153
Portal for Arcgis Linux 10.4 Centos7.5 192.168.0.153
Web Adaptor Linux 10.4 CentOS7.5 192.168.0.150
Postgis 2.3 Centos7.5 192.168.0.150
docker-ce 19.03 Centos7.5 1192.168.0.150
docker-compose 1.26.2 Centos7.5 192.168.0.150

08api76

08api78

1.2.docker/docker-compose安装

脚本安装
cat docker-install.sh

# 更换yum源并安装docker、docker-compose
yum -y install wget
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
mv CentOS7-Base-163.repo /etc/yum.repos.d/CentOS-Base.repo
yum clean all && yum makecache && yum -y update
# 安装docker18.03与docker-compose  
installdocker1()
{
        yum -y install yum-utils device-mapper-persistent-data lvm2
        yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
        yum-config-manager --enable docker-ce-edge
        yum-config-manager --enable docker-ce-test
        yum -y install docker-ce
}
installdocker2()
{
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager  --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum -y install docker-ce
}
docker version
if [ $? -eq 127 ];then
        echo "we can install docker-ce"
        sleep 5
        installdocker1
        if [ $? -ne 0 ];then
            echo "you should use aliyun image."
            installdocker2
        fi
        docker version
        if [ $? -lt 127 ];then
                echo "the installation of docker-ce is ok."
                rpm -qa | grep docker | xargs rpm -e --nodeps 
                yum -y install docker-ce-19.03*
        else
                echo "the installation of docker-ce failed ,please reinstall"
                exit -1
        fi
else
        echo "docker have installed,pleae uninstall old version"
        sleep 5
        rpm -qa | grep docker | xargs rpm -e --nodeps
        docker version
        if [ $? -eq 127 ];then
                echo "old docker have been uninstalled and you can install docker-ce"
                sleep 5
                installdocker1
                if [ $? -ne 0 ];then
                    echo "you should use aliyun image."
                    installdocker2
                fi
                docker version
                if [ $? -lt 127 ];then
                        echo "the installation of docker-ce is ok."
                        rpm -qa | grep docker | xargs rpm -e --nodeps
                        yum -y install docker-ce-19.03*
                else
                        echo "the installation of docker-ce failed anad please reinstall."
                        exit -1
                fi
        else
                echo "the old docker uninstalled conpletely and please uninstall again."
                exit -1
        fi
fi
systemctl start docker && systemctl enable docker && systemctl daemon-reload 
docker_version=$(docker version | grep "Version" | awk '{print $2}' | head -n 2 | sed -n '2p')
if [ $? -eq 0 ];then
        echo "docker start successfully and the version is ${docker_version}"
fi
# 安装docker-compose并检查版本
yum -y install epel-release  && yum -y install python-pip  && pip install docker-compose  && pip install --upgrade pip 
docker-compose_version=$(docker-compose version | grep 'docker-compose' | awk '{print $3}')
if [ $? -eq 0 ];then
        echo "the docker-compose version is ${docker-compose_version}"
fi
# 配置docker加速拉取
echo {\"registry-mirrors\":[\"https://nr630v1c.mirror.aliyuncs.com\"]} > /etc/docker/daemon.json

# 安装常用工具
yum -y install lrzsz && yum -y install openssh-clients && yum -y install telnet && yum -y install rsync 

# 防火墙配置
setenforce 0
sed -i 's/enforcing/disabled/g' /etc/selinux/config
sed -i 's/enforcing/disabled/g' /etc/sysconfig/selinux
systemctl stop firewalld
systemctl disable firewalld
systemctl daemon-reload

2、部署web adaptor

获取webadaptor的war包

tar zvxf Web_Adaptor_Java_Linux_104_149448.tar.gz    
cd WebAdaptor   
./Setup -m silent -l yes -d /home/ags   
cp /home/ags/arcgis/webadaptor10.4/java/arcgis.war  ./   

构建webadaptor的镜像
构建需要的相关文件
09api93

cat Dockerfile

FROM mcr.microsoft.com/java/jre:8u252-zulu-alpine

ADD apache-tomcat-8.5.53.tar.gz /usr/local
RUN mv /usr/local/apache-tomcat-8.5.53 /usr/local/tomcat && touch /usr/local/tomcat/catalina.out
ADD arcgis.war /usr/local/tomcat/webapps
EXPOSE 58080/tcp
EXPOSE 8000/tcp
RUN mkdir -p /service/config
RUN mkdir -p /service/monolith
WORKDIR /service
ADD wrapper /service
ADD launcher.sh /service
ADD config/ /service/config
ADD monolith /service/monolith
RUN chmod +x wrapper
RUN chmod +x monolith/tomcat
RUN chmod +x launcher.sh
CMD /service/wrapper

修改文件config/config.yml里的相关参数

...
check_url: "http://127.0.0.1:8080"
service_name: "wrapper-webadaptor"
query_name: ["wrapper-webadaptor"]
name: "wrapper-webadaptor-tracer"
...

在monolith中新建tomcat启动脚本
vi tomcat

/usr/local/tomcat/bin/startup.sh

修改脚本launcher.sh

...
app="tomcat"

        sh tomcat
...

ps:上述修改的文件省去了其他无需修改的地方

构建镜像
docker build -t waka2020/wrapper-webadaptor .

构建compose文件
cat docker-compose.yml

version: "3.4"
services:
  webadaptor:
    image: 192.168.0.152:8082/waka2020/wrapper-webadaptor:latest
    networks:
      - service_overlay
      - monitor_overlay
    ports:
      - "58080:58080"
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
    environment:
      - CENTER_HOSTNAME=nacos
      - SERVICE_ETHERNET_NAME=eth2
    deploy:
      placement:
        constraints: [node.hostname==node150]
      resources:
        limits:
          cpus: '1'
          memory: '1G'
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 3
networks:
  service_overlay:
    external: true
  monitor_overlay:
    external: true

类似发布hello和provider,发布后会注册到nacos
09api94

因为webadaptor禁止使用非80端口访问,但是包装器这里默认代理的是tomcat的8080端口,所以nginx做反向代理即可
cat nginx.conf

...
 location / {
          root html;
          index index.html; 
          proxy_set_header  Host  $host;
          proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header  X-Real-IP $remote_addr;
          proxy_pass http://webadaptor:58080;
        }
...

重载nginx配置,访问webadaptor
http://192.168.0.150/arcgis/webadaptor
09api95

3、部署Arcgis Server

修改宿主机hostname
hostnamectl set-hostname server.cmdi.com

添加主机名映射
echo "127.0.0.1 server.cmdi.com" >> /etc/hosts

防火墙配置
如果要开启防火墙需要打开一下端口

firewall-cmd --zone=public --add-port=6080/tcp --permanent   
firewall-cmd --zone=public --add-port=4000/tcp --permanent
firewall-cmd --zone=public --add-port=4001/tcp --permanent
firewall-cmd --zone=public --add-port=4002/tcp --permanent
firewall-cmd --zone=public --add-port=4003/tcp --permanent   
firewall-cmd --zone=public --add-port=6443/tcp --permanent 

文件数配置

cat <<EOF>> /etc/security/limits.conf   
ags soft nofile 65535
ags hard nofile 65535
ags soft nproc 25059
ags hard nproc 25059
EOF   

使文件数配置生效

ulimit -Hn -Hu
ulimit -Sn -Su

创建运行Arcgis的用户
groupadd arcgis
useradd -g arcgis ags
将所有安装包放置到/home/ags
mv /root/* /home/ags
切换至root
chown -R ags:arcgis ArcGISServer/
chmod 755 -R ArcGISServer/
下面的授权文件也需要赋予相同的权限

安装启动Arcgis Server启动可能需要用到的库

yum -y install fontconfig mesa-libGL mesa-libGLU libXtst libXext \
libX11 libXi libXdmcp libXrender libXau xorg-x11-server-Xvfb \
libXfont

静默安装Arcgis Server

tar zvxf  ArcGIS_for_Server_Linux_104_149446.tar.gz   
cd ArcGISServer   
./Setup -m silent -l yes -a /home/ags/ArcGISServer/ArcGIS\ Server\ 10.4.ecp   

当提示
08api79
表示安装完成

启动Arcgis Server

cd /home/ags/arcgis/server   
./startserver.sh   

查看端口是否起来
netstat -ntlp|grep 6080

将Agcgis Server添加至系统服务
cat arcgis.sh

#!/bin/bash

# chkconfig: 2345 55 25
# description: arcgis server is a map software

#切换至arcgis server专属用户
#[ $UID -ne 1002 ] &&  su ags

ArcgisServer_Dir="/home/ags/arcgis/server"

#切换至Arcgis启动脚本所在目录
[ $PWD != "$ArcgisServer_Dir" ] && cd $ArcgisServer_Dir 

start () 
{
  [[ $(netstat -ntlp  |  grep 6080 |  wc -l) -eq 0 && $(netstat -ntlp|grep 6443| wc  -l) -eq 0 ]] && su ags -c "./startserver.sh" || { echo "Arcgis Server is running"; exit -1; }
  sleep 5
  [[ $(netstat -ntlp|grep 6080  |  wc  -l) -eq 1 && $(netstat -ntlp|grep 6443  |  wc  -l) -eq 1 ]] && echo "Arcgis Server start successfully." 
} 

stop ()
{
  [[ $(netstat -ntlp|grep 6080  |  wc  -l) -eq 1 && $(netstat -ntlp|grep 6443  |  wc  -l) -eq 1 ]] && su ags -c "./stopserver.sh" || { echo "Arcgis Server is not running"; exit -1; }
  sleep 5
  [[ $(netstat -ntlp|grep 6080  |  wc  -l) -eq 0 && $(netstat -ntlp|grep 6443  |  wc  -l) -eq 0 ]] && echo "Arcgis Server stop successfully."
}

case $1 in

start) start;;

stop) stop;;

restart) stop && start ;;

*) echo "invalid entry."
   exit 1
   ;;
esac

加入自启动服务

cp arcgis.sh /etc/rc.d/init.d/arcgis
chkconfig --add arcgis   
chkconfig arcgis on

08api84

08api85

08api86

08api87

08api88

在部署过程中遇到一个问题:启动后自动停止,查看服务日志

[ags@node150 etc]$ tail -f /home/ags/arcgis/server/framework/etc/service_error.log
at com.esri.arcgis.discovery.nodeagent.impl.NodeAgent.startJMXServer(NodeAgent.java:412)
at com.esri.arcgis.discovery.nodeagent.impl.NodeAgent.start(NodeAgent.java:131)
... 2 more
Caused by: java.lang.IllegalArgumentException: Port value out of range: 65536
at java.net.ServerSocket.(ServerSocket.java:232)
at java.net.ServerSocket.(ServerSocket.java:181)
at com.esri.arcgis.discovery.util.IPUtil.isPortAvailable(IPUtil.java:588)
at com.esri.arcgis.discovery.util.JMXServerController.c(JMXServerController.java:178)
at com.esri.arcgis.discovery.util.JMXServerController.start(JMXServerController.java:35)
... 4 more

4、部署postgresql和postgis

构建postgresql的Dockerfile
cat Dockerfile

FROM postgres:9.4

RUN mkdir -p /var/lib/postgresql/plugin   
RUN echo "deb http://ftp.cn.debian.org/debian/ stretch main" > /etc/apt/sources.list \
    && echo "deb http://ftp.cn.debian.org/debian/ stretch-updates main" >> /etc/apt/sources.list \
    && echo "deb http://ftp.cn.debian.org/debian-security stretch/updates main" >> /etc/apt/sources.list \
    && apt-get -y  update \
    && apt-get -y upgrade  \
    && apt-get -y install postgresql-9.4-postgis-2.3

docker build -t postgresql-9.4-postgis-2.3:v1 .

构建compose文件
cat docker-compose.yml

version: "3"
services:
  postgis:
    image: postgresql-9.4-postgis-2.3:v1 
    networks:
      - database_overlay
    ports:
      - "5432:5432"
    volumes:
      - ./data:/var/lib/postgresql/data
      - ./lib:/usr/lib/postgresql/9.4/lib
    environment:
      - POSTGRES_PASSWORD=123456
    deploy:
      placement:
        constraints: [node.hostname==node150]
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 3
networks:
  database_overlay:
    external: true

启动服务
docker stack deplpy -c docker-compose.yml 150

添加postgis相关扩展

docker exec -it postgres bash   
su postgres   
createdb arcgis   
psql -d arcgis   
arcgis=# CREATE EXTENSION postgis;
arcgis=# CREATE EXTENSION postgis_topology;
arcgis=# CREATE EXTENSION fuzzystrmatch;
arcgis=# CREATE EXTENSION postgis_tiger_geocoder;       
\dx   

09api92
这样就添加了对数据库arcgis的postgis支持

ps:上面compose文件挂载了一个lib目录,该目录下放置的是来自arcgis server安装目录中DatabaseSupport\PostgreSQL下对应版本的st_geometry库,改库是针对arcMap连接postgresql数据库使用的