Tuesday, May 17, 2022

Install DSpace 7 on Debian 11/Ubuntu 20.04/22.04 LTS

We use Xubuntu 22.04 LTS for the installation of DSpace 7. ISO file of the operating system can be downloaded from the Xubuntu website, https://xubuntu.org/release/22-04. No problem using other Ubuntu flavours (e.g. Ubuntu with GNOME, KDE, Lubuntu) for the installation. Either burn the ISO file to a pen drive or DVD. Install the Xubuntu on the machine. Create a user account during the installation (e.g. mgu). Create the user with the name dspace after the installation of Linux based operating system. If you have already run on a Ubuntu/Debian (e.g. for Koha), create a dspace user.

Prepare the system for Dspace installation

DSpace consists of both a Java-based backend and an Angular-based frontend. Both backend and frontend need to be installed separately. Install the prerequisites for the Dspace software. Dspace builds on the Java platform and it requires a set of software packages like Tomcat, Solr, Maven, Ant, etc.

Update Xubuntu

Apply the following commands one by one to receive new Xubuntu updates. It makes the Xubuntu new.

sudo apt update && sudo apt upgrade -y

Create a DSpace user from the terminal after the installation. Here are the commands to create the DSpace user;

sudo useradd -m dspace
sudo passwd dspace

[enter a password for the new user dspace]

Install Open JDK

The JDK is a development environment for building applications, applets, and components using the Java programming language. JDK prepares an environment to run Java-based applications on the machine.

sudo apt install default-jdk build-essential -y

Set the JAVA_HOME Environment Variable

DSpace requires the Java installation location. Open the following file to add the java environment variable,

sudo mousepad /etc/environment

Add the following two lines to the file,

JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
JAVA_OPTS="-Xmx512M -Xms64M -Dfile.encoding=UTF-8"

Save and close the file.

Apply the following commands one by one to check Java Home is successfully saved,

source /etc/environment
echo $JAVA_HOME
echo $JAVA_OPTS

Install a few more tools to support the Dspace installation.

sudo apt install curl git -y

Install Maven and Ant

Apache Maven requires for the build process during the Dspace installation. Maven helps to download the dependencies.

sudo apt install maven -y

Maven is used to build the installer. Ant used to install/deploy DSpace to the installation directory

sudo apt install  ant -y

Install PostgreSQL

PostgreSQL, also known as Postgres, is a free and open-source relational database management system. Dspace makes use of PostgreSQL as a Relational Database System. Apply the following command to install PostreSQL and related packages;

sudo apt-get install postgresql postgresql-client postgresql-contrib libpostgresql-jdbc-java -y

Apply the following command to check the PostgreSQL version number. 

psql -V psql

Version numbers vary in Ubuntu 20.04, 22.04 and Debian 11. Note down it. PostgreSQL 14 is available with Ubuntu 22.04. Check whether the installation of PostgreSQL is successful or not,

sudo pg_ctlcluster 14 main start
sudo systemctl status postgresql

Apply the key, Ctrol+C to exit from the screen.

Create a password for PostgreSQL.

sudo passwd postgres

Try to login into PostgreSQL using the password created.

su postgres

The command prompt looks like this postgres@user: if you could log in successfully. apply the following command to exit from there,

exit

Open the following file,

sudo mousepad /etc/postgresql/14/main/postgresql.conf

Change the version number (Ubuntu 20.04 and Debian 11 users) in the above-mentioned command and apply the command on the terminal.

Uncomment the line (remove #) listen_addresses = 'localhost' under connection settings option.

Save and exit

We need to tighten the security of PostgreSQL. Here also change the PostgreSQL number. Open the following file,

sudo mousepad /etc/postgresql/14/main/pg_hba.conf

Add the following above the line, # Database administrative login by Unix domain socket.

#DSpace configuration
host dspace dspace 127.0.0.1 255.255.255.255 md5

Restart Postresql

sudo systemctl restart postgresql

Solr Installation

Solr is an open-source search platform, written in Java. Its major features include full-text search, hit highlighting, faceted search, real-time indexing, dynamic clustering, database integration, NoSQL features, and rich document handling.

Download the Solr software package from the website and save it to the opt folder in the operating system. 

Enter into the /opt folder.

cd /opt

Download the Solr (version 8) package using the following command line,

sudo wget https://www.apache.org/dyn/closer.lua/lucene/solr/8.11.1/solr-8.11.1.zip?action=download

Rename the Zip file,

sudo mv solr-8.11.1.zip\?action\=download solr-8.11.1.zip

Unzip the package,

sudo unzip solr-8.11.1.zip

Rename Solr directory

sudo mv solr-8.11.1 solr

Downloaded Solr ZIP files not required, delete it,

sudo rm solr-8.11.1.zip

Apply the following command to check Solr directory available at /opt

ls

Change the folder permission to Dspace user,

sudo chown -R dspace:dspace solr

Check whether the folder permission changed or not.

ls -la

Login to the dspace user account to start Solr.

su dspace

Start Solr by applying the command,

/opt/solr/bin/solr start

Wait until Solr Starts.

Apply the following command to exit from the dspace user account.

exit

Add the URL on a browser to open the Solr interface,

http://localhost:8983/solr

Download the DSpace package

Apply the following two commands one by one to download the DSpace package in the dspace user home.

Return to the home folder.

cd 

Download the DSpace package.

wget https://github.com/DSpace/DSpace/archive/refs/tags/dspace-7.2.1.zip

Extract the package,

sudo unzip dspace-7.2.1.zip

Rename the package to dspace,

sudo mv DSpace-dspace-7.2.1 dspace

Move the package to the root folder of the operating system,

sudo mv dspace /

Change the dspace folder permission to dspace user.

sudo chown -R dspace:dspace /dspace

Install Tomcat

Tomcat provides a "pure Java" HTTP web server environment in which Java code can run. 

sudo apt install tomcat9 -y
sudo systemctl restart cron.service

Specify the DSpace installation path to Tomcat. Open the following file,

sudo mousepad /lib/systemd/system/tomcat9.service

Add the following line under #Security,

ReadWritePaths=/dspace

Save and close the file.

Alter Tomcat's default configuration to support searching and browsing of multi-byte UTF-8.

Open the following file,

sudo mousepad /etc/tomcat9/server.xml

Find the below mentioned lines in the file, and comment out. Add  <!-- in the first line and --> in the last line,

<Connector port="8080" protocol="HTTP/1.1"
            connectionTimeout="20000"
            redirectPort="8443" />

It will looks like after commented out,

<!-- <Connector port="8080" protocol="HTTP/1.1"
            connectionTimeout="20000"
            redirectPort="8443" /> -->

Add following lines below the commented out lines,

<Connector port="8080" protocol="HTTP/1.1"
minSpareThreads="25"
enableLookups="false"
redirectPort="8443"
connectionTimeout="20000"
disableUploadTimeout="true"
URIEncoding="UTF-8"/>
Save and close the file.
Restart Tomcat,

sudo systemctl restart tomcat9.service

If it shows the following message,

Warning: The unit file, source configuration file or drop-ins of tomcat9.service changed on disk. Run 'systemctl daemon-reload' to reload units.

Apply the following command,

sudo systemctl daemon-reload

Again try to restart the Tomcat,

sudo systemctl restart tomcat9.service

Database setup

Create a DSpace user. Apply the following commands one by one,
Login into the Postgres terminal,

sudo su postgres

Enter into the following directory. If any changes in the version number, add it.

cd /etc/postgresql/14/main

Create the user named dspace. Enter the password when it asks. This is the connection password for the DSpace database, note down it. 

createuser --username=postgres --no-superuser --pwprompt dspace

This command will create the database with the name dspace. The owner of the database is dspace, the same user created in the previous command.

createdb --username=postgres --owner=dspace --encoding=UNICODE dspace

Enable pgcrypto extension. 

The pgcrypto module provides cryptographic functions for PostgreSQL. It secures data from the security breach.

psql --username=postgres dspace -c "CREATE EXTENSION pgcrypto;"

Exit from the Postgres terminal,

exit

Create a new DSpace configuration file. Apply the following commands one by one,

cd /dspace/dspace/config/
sudo cp local.cfg.EXAMPLE local.cfg
sudo mousepad local.cfg

See the important lines in the file and their purpose, 

DSpace server URL
dspace.server.url = http://localhost:8080/server

DSpace frontend URL
dspace.ui.url = http://localhost:4000

# Name of the site
dspace.name = DSpace at My University

If any changes in the DSpace database username / password, mention here.

# Database username and password
db.username = dspace
db.password = dspace

Uncomment following line in the local.cfg file,

solr.server = http://localhost:8983/solr

Save and close the file.

Installation of DSpace backend

Apply the following commands,

source /etc/environment
echo $JAVA_HOME
echo $JAVA_OPTS

Build the Installation Package

su dspace
cd /dspace
mvn package

The package building process depends on the Internet speed and server responses and it may take 10 to 30 minutes to finish. 

Install DSpace Backend

Apply the following commands one bye one,
cd dspace/target/dspace-installer
ant fresh_install

Initialize your Database

cd /dspace/bin/
./dspace database migrate
exit

Copy the DSpace web apps folder to the Tomcat server

sudo cp -R /dspace/webapps/* /var/lib/tomcat9/webapps*

Copy Solr folders and change permission

sudo cp -R /dspace/solr/* /opt/solr/server/solr/configsets/
sudo chown -R dspace:dspace /opt/solr/server/solr/configsets/

Create DSpace Administrator Account

sudo /dspace/bin/dspace create-administrator

This process will ask questions,

Email Address: [Enter an email address to login Dspace, e.g., dspace@dspace]
First Name: [Enter the name of the user, e.g. Dspace]
Last Name: [e.g. Admin]
Password: [Enter the password to log in to DSpace].
Again to confirm:  [Once again enter the same password]
Is the above data correct? (y or n): [y] 

Change permission of DSpace to Tomcat user

sudo chown -R tomcat:tomcat /dspace/
sudo systemctl restart tomcat9.service

Now Open a Browser and test whether the below pages are displaying correctly or not.
Open the REST API Interface at,

Try to open OAI-PMH Interface,

http://localhost:8080/server/oai/request?verb=Identify 

Install the Front End

To install the front required to install Node.js, Yarn, and DSpace-Angular packages.

Install Node.js

Node.js is an open-source, cross-platform, back-end JavaScript runtime environment.

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt install nodejs -y

Install NVM

Node Version Manager (NVM) is a tool used to manage multiple active Node. js versions. Apply the commands one by one.

sudo su

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.39.1/install.sh | bash

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

Close the current terminal and open a new one and the following commands,

sudo su
nvm list-remote

Find the latest LTS version from the list and install it.

nvm install --lts

Install Yarn

Yarn is a software packaging system.

npm install --global yarn
npm install --global pm2

Front end installation

DSpace user interface build on Angular. Angular is a TypeScript-based free and open-source web application framework. Follow the steps to install Dspace-Angular.

We are going to place the dspace-angular package into /opt folder and enter it into the folder;

cd /home/dspace

Download the dspace-angular package,

wget https://github.com/DSpace/dspace-angular/archive/refs/tags/dspace-7.2.zip

Extract the package,

unzip dspace-7.2.zip
rm dspace-7.2.zip

Enter into the dspace-angular folder,

cd /home/dspace/dspace-angular-dspace-7.2

Install all dependencies,

yarn install

Enter into the /dspace-angular/config folder,

cd config

Copy and rename the following file,

cp config.example.yml config.prod.yml

Open the config file

mousepad config.prod.yml

Find the block of information in listed in the file and make changes like this,

# The REST API server settings
# NOTE: these must be 'synced' with the 'dspace.server.url' setting in your backend's local.cfg.
rest:
ssl: false
host: localhost
port: 8080

Save and close the file.

Run the command,

yarn run build:prod
exit

Startup the User Interface

Create a PM2 JSON configuration file. 
Create the file,

sudo mousepad /home/dspace/dspace-angular-dspace-7.2/dspace-ui.json

Copy the following content into the dspace-ui.jason file,

{
    "apps": [
        {
           "name": "dspace-ui",
           "cwd": "/home/dspace/dspace-angular-dspace-7.2/",
           "script": "dist/server/main.js",
           "env": {
              "NODE_ENV": "production",
   "DSPACE_REST_SSL": "false",
   "DSPACE_REST_HOST": "localhost",
   "DSPACE_REST_PORT": "8080",
   "DSPACE_REST_NAMESPACE": "/server"
           }
        }
    ]
}


Start the application using PM2. Apply the following command to start the service,

pm2 start /home/dspace/dspace-angular-dspace-7.2/dspace-ui.json

Autostart the dspace-ui.json

Enable autostart of dspace-ui.json at Cronjob to start the service when booting the system,

sudo crontab -u dspace -e   

Add the following lines to the bottom of the editor.

#Solr autostart
@reboot /opt/solr/bin/solr start

Save and close the file. Press Ctrl + O to save the file, and Ctrl + X to exit from the crontab.

Create a cronjob to start dspace-ui.json

sudo su
crontab -e

Add the following line

#Auto start dspace-angular
@reboot bash -ci 'pm2 start /home/dspace/dspace-angular-dspace-7.2/dspace-ui.json'

To save the file, apply Ctrl + O key combination. Exit from the editor, and apply Ctrl + X.

Enter the below URL on the browser to start the DSpace frontend,

http://localhost:4000

You may also want to install/configure pm2-logrotate to ensure that PM2's log folder doesn't fill up over time.

pm2 install pm2-logrotate
pm2 set pm2-logrotate:max_size 1000K
pm2 set pm2-logrotate:compress true
pm2 set pm2-logrotate:rotateInterval 0 0 19 1 1 7

Restart the computer and check the Solr, Tomcat, and DSpace works.

Express my sincere thanks to the contributors; Jeremiah Kellogg (Library Faculty, Systems, Eastern Oregon University), Anoop P.A. (Technical Assistant, Kerala Institute Of Local Administration), and Mahesh Palamuttath (Librarian, East Campus, Sacred Heart College, Thevara, Ernakulam). 

References



No comments:

Post a Comment