{"id":257,"date":"2024-01-17T02:39:26","date_gmt":"2024-01-17T02:39:26","guid":{"rendered":"https:\/\/www.ccsgeo.com\/?p=257"},"modified":"2024-02-17T16:41:23","modified_gmt":"2024-02-17T16:41:23","slug":"deploying-an-open-source-gis-stack-part-3-installing-geoserver","status":"publish","type":"post","link":"https:\/\/www.ccsgeo.com\/index.php\/2024\/01\/17\/deploying-an-open-source-gis-stack-part-3-installing-geoserver\/","title":{"rendered":"Deploying an Open Source GIS Stack (Part 3: Installing Geoserver)"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Geoserver Layer Preview<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">In <a href=\"https:\/\/www.ccsgeo.com\/index.php\/2024\/01\/06\/deploying-an-open-source-gis-stack-part-2-installing-postgresql-with-postgis\/\" data-type=\"link\" data-id=\"https:\/\/www.ccsgeo.com\/index.php\/2024\/01\/06\/deploying-an-open-source-gis-stack-part-2-installing-postgresql-with-postgis\/\">Part 2<\/a> of our series on deploying an Open Source GIS Stack, we went through how to install PostgreSQL with PostGIS in order to create a repository for our geographic data. Now, we need a way to serve out that data to our (theoretical) clients. In this blog, I am going to walk through the process of installing Geoserver and configuring access from client machines. In Part 3.5, I will go through how to add our PostgreSQL database as a data source and how to access our published data from QGIS. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installation <\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">First, download the Linux binary from the Geoserver website: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/geoserver.org\/download\/\">https:\/\/geoserver.org\/download\/<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I chose to download the 2.24.1 version to my local machine and then use the scp command to copy the .zip file over to my \/home directory on my Linux machine. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next, we need to ensure that we have the correct Java Runtime Environment. I used the command from the following documentation to install JRE: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/cloudinfrastructureservices.co.uk\/how-to-install-geoserver-server-on-ubuntu-20-04-tutorial-step-by-step\/\">https:\/\/cloudinfrastructureservices.co.uk\/how-to-install-geoserver-server-on-ubuntu-20-04-tutorial-step-by-step\/<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>$apt install default-jdk -y<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When I check the Java version with <strong>java &#8211;version <\/strong>I get: <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"756\" height=\"93\" src=\"https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-12.png\" alt=\"Java version confirmation\" class=\"wp-image-261\" srcset=\"https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-12.png 756w, https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-12-300x37.png 300w\" sizes=\"auto, (max-width: 756px) 100vw, 756px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">As suggested in the <a href=\"https:\/\/docs.geoserver.org\/maintain\/en\/user\/installation\/linux.html\" data-type=\"link\" data-id=\"https:\/\/docs.geoserver.org\/maintain\/en\/user\/installation\/linux.html\">installation docs for Geoserver<\/a>, I used the mkdir command to create a new folder in the \/usr\/share directory: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\/usr\/share\/<strong>$ mkdir geoserver<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then, use the cp command to copy the .zip file to this directory and unzip it with: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$unzip geoserver-2.24.1-bin.zip<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Set an environment variable to point to the Geoserver installation folder: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>$echo &#8220;export GEOSERVER_HOME=\/usr\/share\/geoserver&#8221; &gt;&gt; ~\/.profile. ~\/.profile<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you need to, you can confirm that the environment variable is set correctly using the printenv command: <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"391\" height=\"58\" src=\"https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-13.png\" alt=\"Geoserver environment variable\" class=\"wp-image-263\" srcset=\"https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-13.png 391w, https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-13-300x45.png 300w\" sizes=\"auto, (max-width: 391px) 100vw, 391px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">*NOTE: If you do not set the environment variable correctly, at startup Geoserver will attempt to access the data directory in an incorrect location which will prevent it from starting properly: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Incorrect: <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"147\" src=\"https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-14-1024x147.png\" alt=\"Geoserver environment variable incorrect\" class=\"wp-image-264\" srcset=\"https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-14-1024x147.png 1024w, https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-14-300x43.png 300w, https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-14-768x110.png 768w, https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-14.png 1101w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Correct: <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"858\" height=\"93\" src=\"https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-15.png\" alt=\"Geoserver environment variable correct\" class=\"wp-image-265\" srcset=\"https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-15.png 858w, https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-15-300x33.png 300w, https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-15-768x83.png 768w\" sizes=\"auto, (max-width: 858px) 100vw, 858px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, ensure your user owns the directory structure you created: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>$sudo chown -R USER_NAME \/usr\/share\/geoserver\/<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configuration <\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now that we have everything installed, we still need to be able to access Geoserver from the client machine. In order to do this, we need to modify the web.xml file in \/usr\/share\/geoserver\/webapps\/geoserver\/WEB-INF  to enable cross origin requests (CORS). You can use cd to access the location above and access the file with nano: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\/usr\/share\/geoserver\/webapps\/geoserver\/WEB-INF<strong>$ sudo nano web.xml<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Scroll down to the CORS section and uncomment out the section for CORS in Jetty so that it looks like this: <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"984\" height=\"354\" src=\"https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-16.png\" alt=\"Uncomment CORS setting\" class=\"wp-image-268\" srcset=\"https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-16.png 984w, https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-16-300x108.png 300w, https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-16-768x276.png 768w\" sizes=\"auto, (max-width: 984px) 100vw, 984px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">As noted in the comment, there is another section further down that must also be uncommented: <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"980\" height=\"123\" src=\"https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-17.png\" alt=\"Additional CORS setting uncomment\" class=\"wp-image-269\" srcset=\"https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-17.png 980w, https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-17-300x38.png 300w, https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-17-768x96.png 768w\" sizes=\"auto, (max-width: 980px) 100vw, 980px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">*NOTE: Make sure you have your comment syntax right. If there is a problem with the syntax in this file, Geoserver will not start. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, we should be able to start up Geoserver. From the usr\/share\/geoserver\/bin directory, we can: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">usr\/share\/geoserver\/bin<strong>$ sh startup.sh<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You should now be able to reach Geoserver in a web browser from your client machine at: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&lt;ip address of server&gt;:8080\/geoserver <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As I configured the machine where I installed Geoserver with a <a href=\"https:\/\/www.ccsgeo.com\/index.php\/2023\/12\/23\/deploying-an-open-source-gis-stack-part-1-the-plan-and-deploying-the-name-server\/\" data-type=\"link\" data-id=\"https:\/\/www.ccsgeo.com\/index.php\/2023\/12\/23\/deploying-an-open-source-gis-stack-part-1-the-plan-and-deploying-the-name-server\/\">domain name<\/a>, I can reach Geoserver at gisgeoserver1.ccsgeo.local: <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"311\" src=\"https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-18-1024x311.png\" alt=\"\" class=\"wp-image-271\" srcset=\"https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-18-1024x311.png 1024w, https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-18-300x91.png 300w, https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-18-768x233.png 768w, https:\/\/www.ccsgeo.com\/wp-content\/uploads\/2024\/01\/image-18.png 1101w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">You can also login using the default credentials: admin\/geoserver. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Success! <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Startup Configuration <\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you are like me, you may be calling the startup.sh command from an ssh connection to the machine where Geoserver is installed. This means that once you close the command prompt where you called startup.sh, the program will stop. To get around this and ensure Geoserver is always running, we need to configure a Systemd service file. Use cd to navigate to \/usr\/lib\/systemd\/system and use nano to create a new file in this location: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\/usr\/lib\/systemd\/system<strong>$ nano geoserver.service<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Add the following lines: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>[Unit]<br>Description=GeoServer Service<br>After=network.target<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>[Service]<br>Type=simple<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>User=username<br>Group=username<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Environment=&#8221;GEOSERVER_HOME=\/usr\/share\/geoserver&#8221;<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>ExecStart=\/usr\/share\/geoserver\/bin\/startup.sh<br>ExecStop=\/usr\/share\/geoserver\/bin\/shutdown.sh<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>[Install]<br>WantedBy=multi-user.target<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Save and close the file. Now: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>$systemctl daemon-reload<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And set it up to always start at server reload: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>$systemctl enable &#8211;now geoserver<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can always check the status by running: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>$systemctl status geoserver<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Confirm that Geoserver is running and you should be good to go! <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion <\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this blog, we walked through how to install Geoserver and configure it for access from client machines. Stay tuned for Part 3.5 where I will walk through connecting our PostgreSQL database to Geoserver and publish layers that we can access from client applications.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Resources: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/medium.com\/random-gis-talks\/installing-geoserver-binary%EF%B8%8F-on-ubuntu-18-04-using-terminal-ff9429ab47fa\">https:\/\/medium.com\/random-gis-talks\/installing-geoserver-binary%EF%B8%8F-on-ubuntu-18-04-using-terminal-ff9429ab47fa<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/docs.geoserver.org\/maintain\/en\/user\/installation\/linux.html\">https:\/\/docs.geoserver.org\/maintain\/en\/user\/installation\/linux.html<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/cloudinfrastructureservices.co.uk\/how-to-install-geoserver-server-on-ubuntu-20-04-tutorial-step-by-step\/\">https:\/\/cloudinfrastructureservices.co.uk\/how-to-install-geoserver-server-on-ubuntu-20-04-tutorial-step-by-step\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Geoserver Layer Preview In Part 2 of our series on deploying an Open Source GIS Stack, we went through how to install PostgreSQL with PostGIS in order to create a repository for our geographic data. Now, we need a way to serve out that data to our (theoretical) clients. In this blog, I am going [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":278,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[13,7,6,12],"tags":[],"class_list":["post-257","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-foss","category-technology","category-web","category-workflow"],"_links":{"self":[{"href":"https:\/\/www.ccsgeo.com\/index.php\/wp-json\/wp\/v2\/posts\/257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ccsgeo.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ccsgeo.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ccsgeo.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ccsgeo.com\/index.php\/wp-json\/wp\/v2\/comments?post=257"}],"version-history":[{"count":15,"href":"https:\/\/www.ccsgeo.com\/index.php\/wp-json\/wp\/v2\/posts\/257\/revisions"}],"predecessor-version":[{"id":316,"href":"https:\/\/www.ccsgeo.com\/index.php\/wp-json\/wp\/v2\/posts\/257\/revisions\/316"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ccsgeo.com\/index.php\/wp-json\/wp\/v2\/media\/278"}],"wp:attachment":[{"href":"https:\/\/www.ccsgeo.com\/index.php\/wp-json\/wp\/v2\/media?parent=257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccsgeo.com\/index.php\/wp-json\/wp\/v2\/categories?post=257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccsgeo.com\/index.php\/wp-json\/wp\/v2\/tags?post=257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}