Files
syno-scripts/Bash/RHEL/TESTING/RHEL_full_install_alfresco.sh
T

557 lines
17 KiB
Bash
Executable File

#!/bin/bash
set -e
# Variables
POSTGRES_USER=alfresco
POSTGRES_PASSWORD=alfresco
POSTGRES_DB=alfresco
JAVA_HOME=/usr/lib/jvm/java-17-openjdk
TOMCAT_VERSION=10.1.26
TOMCAT_USER=rheluser
TOMCAT_GROUP=rheluser
TOMCAT_HOME=/home/rheluser/tomcat
ACTIVEMQ_VERSION=5.18.5
ACTIVEMQ_USER=rheluser
ACTIVEMQ_GROUP=rheluser
ACTIVEMQ_HOME=/home/rheluser/activemq
SOLR_VERSION=2.0.9.1
SOLR_USER=rheluser
SOLR_GROUP=rheluser
SOLR_HOME=/home/rheluser/alfresco-search-services
TRANSFORM_JAR=alfresco-transform-core-aio-5.1.0.jar
TRANSFORM_USER=rheluser
TRANSFORM_GROUP=rheluser
TRANSFORM_HOME=/home/rheluser/transform
NODEJS_SETUP_URL="/root/RHEL_full_install_alfresco_addon.sh"
CONTENT_APP_REPO=https://github.com/Alfresco/alfresco-content-app.git
CONTENT_APP_VERSION=4.4.1
NGINX_CONF_PATH=/etc/nginx/conf.d/alfresco-content-app.conf
NGINX_ROOT=/var/www/alfresco-content-app
# Helper function to print and execute commands
execute() {
echo "$ $@"
"$@"
}
# Anlegen des Users und Gruppe
user_add_and_group(){
execute sudo groupadd rheluser
execute sudo useradd -m -g rheluser rheluser
}
# Update and upgrade the system
00_update_system() {
echo "Updating system..."
execute sudo dnf update -y
}
# Install PostgreSQL and configure database
01_install_postgresql() {
echo "Installing PostgreSQL..."
execute sudo dnf install -y postgresql-server postgresql-contrib
echo "Initializing PostgreSQL database..."
execute sudo postgresql-setup --initdb
echo "Configuring PostgreSQL..."
execute sudo sed -i 's/local\s\+all\s\+postgres\s\+peer/local all postgres trust/' /var/lib/pgsql/data/pg_hba.conf
execute sudo sed -i 's/local\s\+all\s\+all\s\+peer/local all all md5/' /var/lib/pgsql/data/pg_hba.conf
echo "Starting PostgreSQL service..."
execute sudo systemctl start postgresql
execute sudo systemctl enable postgresql
echo "Configuring Alfresco database..."
execute sudo -u postgres psql -c "CREATE USER ${POSTGRES_USER} WITH PASSWORD '$POSTGRES_PASSWORD';"
execute sudo -u postgres psql -c "CREATE DATABASE ${POSTGRES_DB} OWNER ${POSTGRES_USER} ENCODING 'UTF8';"
execute sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE ${POSTGRES_DB} TO ${POSTGRES_USER};"
}
# Install Java JDK 17
02_install_java() {
echo "Installing Java JDK 17..."
execute sudo dnf install -y java-17-openjdk
echo "Checking Java version..."
execute java -version
}
# Install Apache Tomcat
03_install_tomcat() {
echo "Downloading and installing Apache Tomcat..."
execute wget https://dlcdn.apache.org/tomcat/tomcat-10/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz -O /tmp/apache-tomcat-$TOMCAT_VERSION.tar.gz
execute sudo mkdir -p $TOMCAT_HOME
execute sudo tar xzvf /tmp/apache-tomcat-$TOMCAT_VERSION.tar.gz -C $TOMCAT_HOME --strip-components=1
echo "Setting permissions for Tomcat directories..."
execute sudo chown -R $TOMCAT_USER:$TOMCAT_GROUP $TOMCAT_HOME
execute sudo chmod -R u+x $TOMCAT_HOME/bin
echo "Creating Tomcat systemd service file..."
cat <<EOL | sudo tee /etc/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
[Service]
Type=forking
User=$TOMCAT_USER
Group=$TOMCAT_GROUP
Environment="JAVA_HOME=$JAVA_HOME"
Environment="CATALINA_PID=$TOMCAT_HOME/temp/tomcat.pid"
Environment="CATALINA_HOME=$TOMCAT_HOME"
Environment="CATALINA_BASE=$TOMCAT_HOME"
Environment="CATALINA_OPTS=-Xms2048M -Xmx3072M -server -XX:MinRAMPercentage=50 -XX:MaxRAMPercentage=80"
Environment="JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom"
Environment="JAVA_TOOL_OPTIONS=-Dencryption.keystore.type=JCEKS -Dencryption.cipherAlgorithm=DESede/CBC/PKCS5Padding -Dencryption.keyAlgorithm=DESede -Dencryption.keystore.location=/home/rheluser/keystore/metadata-keystore/keystore -Dmetadata-keystore.password=mp6yc0UD9e -Dmetadata-keystore.aliases=metadata -Dmetadata-keystore.metadata.password=oKIWzVdEdA -Dmetadata-keystore.metadata.algorithm=DESede"
ExecStart=$TOMCAT_HOME/bin/startup.sh
ExecStop=$TOMCAT_HOME/bin/shutdown.sh
[Install]
WantedBy=multi-user.target
EOL
echo "Reloading systemd daemon..."
execute sudo systemctl daemon-reload
echo "Starting Tomcat service..."
execute sudo systemctl start tomcat
echo "Stopping Tomcat service..."
execute sudo systemctl stop tomcat
echo "Enabling Tomcat service to start on boot..."
execute sudo systemctl enable tomcat
}
# Install Apache ActiveMQ
04_install_activemq() {
echo "Downloading and installing Apache ActiveMQ..."
execute wget https://dlcdn.apache.org/activemq/$ACTIVEMQ_VERSION/apache-activemq-$ACTIVEMQ_VERSION-bin.tar.gz -O /tmp/apache-activemq-$ACTIVEMQ_VERSION-bin.tar.gz
execute sudo mkdir -p $ACTIVEMQ_HOME
execute sudo tar xzvf /tmp/apache-activemq-$ACTIVEMQ_VERSION-bin.tar.gz -C $ACTIVEMQ_HOME --strip-components=1
echo "Setting permissions for ActiveMQ directories..."
execute sudo chown -R $ACTIVEMQ_USER:$ACTIVEMQ_GROUP $ACTIVEMQ_HOME
execute sudo chmod -R 755 $ACTIVEMQ_HOME
echo "Creating ActiveMQ systemd service file..."
cat <<EOL | sudo tee /etc/systemd/system/activemq.service
[Unit]
Description=Apache ActiveMQ
After=network.target
[Service]
Type=forking
User=$ACTIVEMQ_USER
Group=$ACTIVEMQ_GROUP
Environment="JAVA_HOME=$JAVA_HOME"
Environment="ACTIVEMQ_HOME=$ACTIVEMQ_HOME"
Environment="ACTIVEMQ_BASE=$ACTIVEMQ_HOME"
Environment="ACTIVEMQ_CONF=$ACTIVEMQ_HOME/conf"
Environment="ACTIVEMQ_DATA=$ACTIVEMQ_HOME/data"
ExecStart=$ACTIVEMQ_HOME/bin/activemq start
ExecStop=$ACTIVEMQ_HOME/bin/activemq stop
[Install]
WantedBy=multi-user.target
EOL
echo "Reloading systemd daemon..."
execute sudo systemctl daemon-reload
echo "Starting ActiveMQ service..."
execute sudo systemctl start activemq
echo "Stopping ActiveMQ service..."
execute sudo systemctl stop activemq
echo "Enabling ActiveMQ service to start on boot..."
execute sudo systemctl enable activemq
}
# Download Content
05_down_content(){
# Ensure system is updated and curl is installed
echo "Updating package list and installing curl..."
sudo dnf update -y
sudo dnf install -y curl
# URLs of the resources to be downloaded
URLS=(
"https://nexus.alfresco.com/nexus/repository/releases/org/alfresco/alfresco-content-services-community-distribution/23.2.1/alfresco-content-services-community-distribution-23.2.1.zip"
"https://nexus.alfresco.com/nexus/repository/releases/org/alfresco/alfresco-search-services/2.0.9.1/alfresco-search-services-2.0.9.1.zip"
"https://nexus.alfresco.com/nexus/repository/releases/org/alfresco/alfresco-transform-core-aio/5.1.0/alfresco-transform-core-aio-5.1.0.jar"
)
# Directory to save the downloaded files
DOWNLOAD_DIR="./downloads"
# Create the download directory if it does not exist
mkdir -p "$DOWNLOAD_DIR"
# Function to download a file
download_file() {
local url=$1
local dest_dir=$2
local filename=$(basename "$url")
echo "Downloading $filename..."
curl -L -o "$dest_dir/$filename" -w "\nHTTP Status: %{http_code}\n" "$url"
if [ $? -eq 0 ]; then
echo "Downloaded $filename successfully."
else
echo "Failed to download $filename."
fi
# Check if the file size is greater than 0 bytes
if [ ! -s "$dest_dir/$filename" ]; then
echo "Warning: Downloaded file $filename is empty."
fi
}
# Loop through each URL and download the file
for url in "${URLS[@]}"; do
download_file "$url" "$DOWNLOAD_DIR"
done
echo "All downloads are complete."
}
# Install Alfresco Community Edition
06_install_alfresco(){
set -e
echo "Install unzip command"
execute sudo dnf -y install unzip
echo "Create support folders and configuration in Tomcat"
mkdir -p /home/rheluser/tomcat/shared/classes && mkdir -p /home/rheluser/tomcat/shared/lib
sed -i 's|^shared.loader=$|shared.loader=${catalina.base}/shared/classes,${catalina.base}/shared/lib/*.jar|' /home/rheluser/tomcat/conf/catalina.properties
echo "Unzip Alfresco ZIP Distribution File"
mkdir /tmp/alfresco
unzip downloads/alfresco-content-services-community-distribution-23.2.1.zip -d /tmp/alfresco
echo "Copy JDBC driver"
cp /tmp/alfresco/web-server/lib/postgresql-42.6.0.jar /home/rheluser/tomcat/shared/lib/
echo "Configure JAR Addons deployment"
mkdir -p /home/rheluser/modules/platform && mkdir -p /home/rheluser/modules/share && mkdir -p /home/rheluser/tomcat/conf/Catalina/localhost
cp /tmp/alfresco/web-server/conf/Catalina/localhost/* /home/rheluser/tomcat/conf/Catalina/localhost/
echo "Install Web Applications"
cp /tmp/alfresco/web-server/webapps/* /home/rheluser/tomcat/webapps/
echo "Apply configuration"
cp -r /tmp/alfresco/web-server/shared/classes/* /home/rheluser/tomcat/shared/classes/
mkdir /home/rheluser/keystore && cp -r /tmp/alfresco/keystore/* /home/rheluser/keystore/
mkdir /home/rheluser/alf_data
cat <<EOL | tee /home/rheluser/tomcat/shared/classes/alfresco-global.properties
#
# Custom content and index data location
#
dir.root=/home/rheluser/alf_data
dir.keystore=/home/rheluser/keystore/
#
# Database connection properties
#
db.username=alfresco
db.password=alfresco
db.driver=org.postgresql.Driver
db.url=jdbc:postgresql://localhost:5432/alfresco
#
# Solr Configuration
#
solr.secureComms=secret
solr.sharedSecret=secret
solr.host=localhost
solr.port=8983
index.subsystem.name=solr6
#
# Transform Configuration
#
localTransform.core-aio.url=http://localhost:8090/
#
# Events Configuration
#
messaging.broker.url=failover:(nio://localhost:61616)?timeout=3000&jms.useCompression=true
#
# URL Generation Parameters
#-------------
alfresco.context=alfresco
alfresco.host=localhost
alfresco.port=8080
alfresco.protocol=http
share.context=share
share.host=localhost
share.port=8080
share.protocol=http
EOL
echo "Apply AMPs"
mkdir /home/rheluser/amps && cp -r /tmp/alfresco/amps/* /home/rheluser/amps/
mkdir /home/rheluser/bin && cp -r /tmp/alfresco/bin/* /home/rheluser/bin/
java -jar /home/rheluser/bin/alfresco-mmt.jar install /home/rheluser/amps /home/rheluser/tomcat/webapps/alfresco.war -directory
java -jar /home/rheluser/bin/alfresco-mmt.jar list /home/rheluser/tomcat/webapps/alfresco.war
echo "Modify alfresco and share logs directory"
mkdir /home/rheluser/tomcat/webapps/alfresco && unzip /home/rheluser/tomcat/webapps/alfresco.war -d /home/rheluser/tomcat/webapps/alfresco
mkdir /home/rheluser/tomcat/webapps/share && unzip /home/rheluser/tomcat/webapps/share.war -d /home/rheluser/tomcat/webapps/share
sed -i 's|^appender\.rolling\.fileName=alfresco\.log|appender.rolling.fileName=/home/rheluser/tomcat/logs/alfresco.log|' /home/rheluser/tomcat/webapps/alfresco/WEB-INF/classes/log4j2.properties
sed -i 's|^appender\.rolling\.fileName=share\.log|appender.rolling.fileName=/home/rheluser/tomcat/logs/share.log|' /home/rheluser/tomcat/webapps/share/WEB-INF/classes/log4j2.properties
echo "Alfresco has been configured"
}
# Install Apache Solr
07_install_solr() {
echo "Downloading and installing Apache Solr..."
execute mkdir /tmp/solr
execute unzip downloads/alfresco-search-services-$SOLR_VERSION.zip -d /tmp/solr
execute mv /tmp/solr/alfresco-search-services /home/rheluser
echo "Creating Solr systemd service file..."
cat <<EOL | sudo tee /etc/systemd/system/solr.service
[Unit]
Description=Apache SOLR Web Application Container
After=network.target
[Service]
Type=forking
User=$SOLR_USER
Group=$SOLR_GROUP
Environment="JAVA_HOME=$JAVA_HOME"
ExecStart=/home/rheluser/alfresco-search-services/solr/bin/solr start -a "-Dcreate.alfresco.defaults=alfresco,archive -Dalfresco.secureComms=secret -Dalfresco.secureComms.secret=secret"
ExecStop=/home/rheluser/alfresco-search-services/solr/bin/solr stop
[Install]
WantedBy=multi-user.target
EOL
echo "Reloading systemd daemon..."
execute sudo systemctl daemon-reload
echo "Starting Solr service..."
execute sudo systemctl start solr
echo "Stopping Solr service..."
execute sudo systemctl stop solr
echo "Enabling Solr service to start on boot..."
execute sudo systemctl enable solr
}
# Install Transform dependencies
08_install_transform() {
sudo subscription-manager repos --enable codeready-builder-for-rhel-8-$(arch)-rpms
sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
echo "Install Transform dependencies"
sudo dnf install -y GraphicsMagick libreoffice perl-Image-ExifTool
echo "Downloading and installing Alfresco PDF Renderer..."
execute curl -L -o /tmp/alfresco-pdf-renderer-1.2-linux.tgz https://nexus.alfresco.com/nexus/repository/releases/org/alfresco/alfresco-pdf-renderer/1.2/alfresco-pdf-renderer-1.2-linux.tgz
execute sudo tar xf /tmp/alfresco-pdf-renderer-1.2-linux.tgz -C /usr/bin
echo "Configuring Transform server..."
execute mkdir /home/rheluser/transform
execute cp downloads/alfresco-transform-core-aio-5.1.0.jar /home/rheluser/transform
echo "Creating Transform systemd service file..."
cat <<EOL | sudo tee /etc/systemd/system/transform.service
[Unit]
Description=Transform Application Container
After=network.target
[Service]
Type=simple
User=$TRANSFORM_USER
Group=$TRANSFORM_GROUP
Environment="JAVA_HOME=$JAVA_HOME"
Environment="LIBREOFFICE_HOME=/usr/lib/libreoffice"
ExecStart=java -jar /home/rheluser/transform/alfresco-transform-core-aio-5.1.0.jar
ExecStop=/bin/kill -15 $MAINPID
[Install]
WantedBy=multi-user.target
EOL
echo "Reloading systemd daemon..."
execute sudo systemctl daemon-reload
echo "Starting Transform service..."
execute sudo systemctl start transform
echo "Stopping Transform service..."
execute sudo systemctl stop transform
echo "Enabling Transform service to start on boot..."
execute sudo systemctl enable transform
}
# Install Node.js and build Alfresco Content App
09_install_nodejs() {
echo "Installing Node.js and npm..."
#execute curl -fsSL $NODEJS_SETUP_URL | sudo -E bash -
bash $NODEJS_SETUP_UR
execute sudo dnf install -y nodejs
echo "Verifying Node.js and npm installation..."
execute node -v
execute npm -v
echo "Cloning and building Alfresco Content App..."
execute git clone $CONTENT_APP_REPO
execute cd alfresco-content-app
execute git checkout tags/$CONTENT_APP_VERSION -b $CONTENT_APP_VERSION
execute npm install
execute npm run build
}
# Install and configure Nginx
10_install_nginx() {
echo "Installing Nginx..."
execute sudo dnf install -y nginx
echo "Creating directory for Alfresco Content App..."
execute sudo mkdir -p $NGINX_ROOT
execute sudo cp -r /home/rheluser/alfresco-content-app/dist/content-ce/* $NGINX_ROOT
echo "Creating Nginx systemd service file..."
cat <<EOL | sudo tee /etc/systemd/system/nginx.service
[Unit]
Description=A high performance web server and a reverse proxy server
Documentation=man:nginx(8)
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOL
echo "Reloading systemd daemon..."
execute sudo systemctl daemon-reload
echo "Enabling Nginx service to start on boot..."
execute sudo systemctl enable nginx
echo "Configuring Nginx..."
cat <<EOL | sudo tee $NGINX_CONF_PATH
server {
listen 80;
server_name localhost;
client_max_body_size 0;
set \$allowOriginSite *;
proxy_pass_request_headers on;
proxy_pass_header Set-Cookie;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host \$host:\$server_port;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_pass_header Set-Cookie;
root $NGINX_ROOT;
index index.html;
location / {
try_files \$uri \$uri/ /index.html;
}
location /alfresco/ {
proxy_pass http://localhost:8080;
}
location /share/ {
proxy_pass http://localhost:8080;
}
}
EOL
echo "Restarting Nginx..."
execute sudo systemctl restart nginx
}
11_service_restart(){
## RECOMMENDATION: run this sequence of commands manually, waiting between one command and the next one to ensure service dependencies are met.
echo "Starting postgresql"
sudo systemctl start postgresql
echo "Starting activemq"
sudo systemctl start activemq
echo "Starting transform"
sudo systemctl start transform
echo "Starting tomcat"
sudo systemctl start tomcat
echo "Starting solr"
sudo systemctl start solr
echo "Starting nginx"
sudo systemctl start nginx
echo "Services have been started successfully!"
}
# Main script execution
main() {
user_add_and_group
00_update_system
01_install_postgresql
02_install_java
03_install_tomcat
04_install_activemq
05_down_content
06_install_alfresco
07_install_solr
08_install_transform
09_install_nodejs
10_install_nginx
11_servie_restart
echo "Installation and configuration complete."
}
main