GeoServer cluster deployment (implemented with nginx on liunx platform)

What is a server cluster?   
Server clustering refers to bringing many servers together to perform the same service. From the client's perspective, it looks like there is only one server. The cluster can use multiple computers to perform parallel calculations to obtain high computing speed, or multiple computers. Make a backup so that if any one machine is broken, the whole system can still operate normally. Once the cluster service is installed and running on the server, the server can join the cluster. Clustering operations can reduce the number of single points of failure and achieve high availability of clustered resources.
Why implement server clusters?  
Server clusters are implemented mainly for load balancing (there are more than two servers or sites providing services). Server services will send requests from clients based on some algorithm, and try to divide the requests among the machines in the cluster as much as possible to avoid A server fails due to too high load or causes slow calculation. The cluster deployment of GEOSERVER can improve the response speed of request tiles and the request speed of WFS data.
Insert picture description here
Software preparation
1.apache-tomcat8
2.geoserver.war
3.nginx software
Description: tomcat needs to download the linux version, download address
https://tomcat.apache.org/download-80.cgi
Insert picture description here
geoserver download implementation package
http: // geoserver .org / release / stable /
Insert picture description here
3. The nginx software can be downloaded and uploaded to the server, or it can be downloaded directly using the linux command. It is recommended to use the linux command to download, which will be introduced later.
Deployment instructions
In the production environment, the deployment of the geoserver cluster should be a node and a machine, such as nginx server, geoserver node1 server, geoserver node2 server, geoserver node2 server, file server, database server, etc. to form a Linux cluster. But in this explanation, because there is only one liunx server node, so I deployed them on the same machine, using different port numbers to distinguish, if you have multiple machines, you can not modify the port number.
In this deployment, the ports I assigned to each node are:
1. nginx load balancing server ------------- 9090 port
2.geoserver node1 ----------- ------- 9091 port
3.geoserver node2 ------------------ 9092 port
4.geoserver node3 ------------- ----- 9093 port
deployment process
1. preparation tomcat, change the service port
to create a place on the linux server directory "geoserver", three tomcat8 download server software and extract to the directory, as shown
Insert picture description here
here I have The names of the three tomcat servers have been renamed to occupy the port names.
If you are not familiar with the deployment of tomcat8 on liunx, please refer to the blog:
Linux system (Centos) install tomcat and deploy Web projects
https://blog.csdn.net/qq_21077715/article/ details / 85541685
Change the service port of each tomcat server.
Take tomcat-9091 as an example

Insert picture description here
Insert picture description here
Modify these three ports in server.xml .
Why is it +1? This is to distinguish different ports used by several tomcat servers. Similarly, node2 is +2 and node3 is +3.
2. Set tomcat to allow cross-domain
Add the following paragraph to each tomcat installation directory under conf> web.xml (I added it on line 589 or so).

<filter>
  <filter-name>CorsFilter</filter-name>
  <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
  <init-param>
    <param-name>cors.allowed.origins</param-name>
    <param-value>*</param-value>
  </init-param>
</filter>
<filter-mapping>
  <filter-name>CorsFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

This is done to allow normal access when using servers from different sources to access the service. No 'Access-Control-Allow-Origin' will not appear. Whether to set it or not depends on the specific situation.
3. Embed geoserver and
upload geoserver.war to the webapps directory under each node.
Insert picture description here
When the tomcat server is started, the war package will be automatically decompressed into a web project. Here, I have decompressed it before, so the "geoserver" already exists.
4. Start three tomcat servers
and execute them under bin /

sh startup.sh

After starting, the geoserver.war package will be automatically decompressed into the web project geoserver
Insert picture description here
5. Test whether each node of the geoserver has been started
. Enter ip: 9091 / geoserver / in the browser, and enter the following page to represent success: the
Insert picture description here
same reason to test the other two geoserver Child node.
6. Configure data synchronization for three geoserver subnodes.
Although we have started three geoserver services, the services are not synchronized. If you want three subnodes to provide a service at the same time, you need to go to the three geoserver web management page to configure Three identical services, if there are many nodes, this is very troublesome and inconvenient.
Therefore, we need to set the data directory of the three geoserver nodes to a unified directory, and no longer use the default separate directory of each node. The best way is to set the directory to an NFS file server, but because we only have one machine here, we create a unified data directory, named GEOSERVER_DATA_DIR.
Insert picture description here
We also need to re-specify the data directory of each geoserver:

geoserver/tomcat-9091/webapps/geoserver/WEB-INF/web.xml

Edit web.xml to
set a unified data directory

<--
<context-param>
       <param-name>GEOSERVER_DATA_DIR</param-name>
        <param-value>C:\eclipse\workspace\geoserver_trunk\cite\confCiteWFSPostGIS</param-value>
    </context-param> 
   -->
    <context-param>
       <param-name>GEOSERVER_DATA_DIR</param-name>
        <param-value>\GEOSERVER_DATA_DIR</param-value>
    </context-param> 

save.
Restart the three tomcat servers.
At this time, the service is published in one of the nodes, and the other nodes will also synchronize the service because their data directories are consistent.
For example, I published the layer aerial on the 9091 node, and it will be synchronized on 9092 and 9093.
Insert picture description here
Insert picture description here
Insert picture description here
At this point, the configuration of the three geoserver nodes is complete.
7. Configure nginx cluster
7.1 to install dependent packages

//一键安装上面四个依赖
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

7.2. Download and unzip the installation package

//创建一个文件夹
cd /usr/local
mkdir nginx
cd nginx
//下载tar包
wget http://nginx.org/download/nginx-1.13.7.tar.gz
tar -xvf nginx-1.13.7.tar.gz

7.3. Install nginx

//进入nginx目录
cd /usr/local/nginx
//进入目录
cd nginx-1.13.7
//执行命令
./configure
//执行make命令
make
//执行make install命令
make install

7.4. Configure nginx.conf

# 打开配置文件
vi /usr/local/nginx/conf/nginx.conf

Change the port number to 9090

Change localhost to your server ip address.
As shown below, where the server node points to the real GeoServer address

upstream mygeoserver {

		ip_hash;
		server 服务器ip:9091;
		server 服务器ip:9092;
		server 服务器ip:9093;

	}

    server {
        listen       9090;
        server_name  服务器ip;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            #root   html;
            #index  index.html index.htm;
            proxy_pass http://mygeoserver;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

The role of "ip_hash" is to support the session so that it can access the same address. If the cluster service you deploy has multiple GeoServers, but it always jumps around the login pages of each GeoServer, and you cannot enter the management page, then it is missing "Ip_hash".

Then add the location configuration to the http server node, as shown below, where proxy_pass configures path forwarding:

location / {

	proxy_pass http://mygeoserver;

}
7.5. Start nginx

/usr/local/nginx/sbin/nginx -s reload

or

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

Check whether the nginx process is started:

ps -ef | grep nginx

Insert picture description here
General common commands after installation

Enter the installation directory,

命令: cd /usr/local/nginx/sbin

Start, close, restart, command:

./nginx start

./nginx -s stop close

./nginx -s reload Restart
7.6 to check whether nginx normally occupies port 9090

lsof -i:9090


Insert picture description here
If the following content appears, it means normal startup. If nothing appears, it means that the configuration file has not taken effect. Nginx occupies port 80 by default. Check the nginx.conf file.
7.7 Use nginx to access the geoserver web management page
Browser enter
http: // serverip: 9090 / geoserver to
enter the geoserver web management page, refresh a few times without problems, you can verify that the geoserver cluster configuration using nginx reverse proxy is successful.
Insert picture description here
8. Publish the wms service and provide the service with the address of the nginx reverse proxy server.
Randomly enter a node, or enter the web management page through nginx, and publish a wms service.
Write the following code in the front-end page (cesium calls wms service)

var aerial = new Cesium.WebMapServiceImageryProvider({
                    url: 'http://服务器ip:9090/geoserver/cluster_test/wms',//使用nginx代理
                    layers: 'cluster_test:aerial',
                    parameters: {
                        service: 'WMS',
                        format: 'image/png',
                        transparent: true
                    }
       });
viewer.imageryLayers.addImageryProvider(aerial);

The normal access service of the front-end page
Insert picture description here
is pending.
Database nodes and file servers have not been said.
It hasn't been said to use geoserver to publish various services.

Published 54 original articles · praised 17 · 40,000+ views

Guess you like

Origin blog.csdn.net/weixin_43311389/article/details/105499512