CMDBuild 3.1.1 on Centos 7

This is not so different from the previous article: https://blog.giuseppeurso.net/cmdbuild-3-1-installation-on-centos7/

Only real difference is that this is not going to work if you deploy the webapp as webaps/ROOT.war. You have instead, to deploy it as /webapps/cmdbuild.

Install Postgresql first.

The following is the installation script for postgresql and it has to be installed before running the tomcat/cmdbuild install script.

As you can see, at the beginnning of the script there are some variables to set. Just keep in mind that usernames and password used in this first script, must then match the ones in the second script: basically the postgresql accounts that are used by cmdbuild.
The user cmdbuild_super_user will be used during the installation to create the database and perform other operations on it, while the other user (cmdbuild_user_name) is used by tomcat and the webapp for regular db usage.

#!/usr/bin/env bash

##################################
install_folder="/usr/share/"       #  C
cmdbuild_user_name="cmdbuild"      #  O
cmdbuild_user_pass="cmdbuild"      #  N
cmdbuild_super_user="scmdbuild"    #  F
cmdbuild_super_pass="scmdbuild"    #  I
sql_queries_path="/var/tmp/"       #  G
cmdbuild_sql_file="cmdbuild.sql"   #  !
scmdbuild_sql_file="scmdbuild.sql" #  @
cmdbuild_db_name="cmdbuild"        #  @
postgresql_version="96"            #
################################

#cd ${sql_queries_path}

yum -y install centos-release-scl
yum -y install rh-postgresql${postgresql_version}-postgresql-server rh-postgresql${postgresql_version}-postgresql
#yum -y install rh-postgresql${postgresql_version}-syspaths.x86_64

su - postgres --command ". /opt/rh/rh-postgresql96/enable;  postgresql-setup --initdb"
systemctl enable rh-postgresql${postgresql_version}-postgresql.service
systemctl start rh-postgresql${postgresql_version}-postgresql.service

firewall-cmd --permanent --add-port=5432/tcp
firewall-cmd --reload

echo -e "CREATE DATABASE ${cmdbuild_db_name};" > ${sql_queries_path}/${cmdbuild_sql_file}
echo -e "CREATE USER ${cmdbuild_user_name} WITH encrypted password '"${cmdbuild_user_pass}"';" >> ${sql_queries_path}/${cmdbuild_sql_file}
echo -e "GRANT ALL PRIVILEGES ON DATABASE ${cmdbuild_db_name} TO ${cmdbuild_user_name};" >> ${sql_queries_path}/${cmdbuild_sql_file}
echo -e "DROP DATABASE ${cmdbuild_db_name};" >> ${sql_queries_path}/${cmdbuild_sql_file}
echo -e "CREATE USER ${cmdbuild_super_user} WITH encrypted password '"${cmdbuild_super_pass}"';" > ${sql_queries_path}/${scmdbuild_sql_file}
echo -e "ALTER USER ${cmdbuild_super_user} WITH SUPERUSER;" >> ${sql_queries_path}/${scmdbuild_sql_file}

su - postgres --command ". /opt/rh/rh-postgresql96/enable; psql --file=${sql_queries_path}/${cmdbuild_sql_file}"
su - postgres --command ". /opt/rh/rh-postgresql96/enable; psql --file=${sql_queries_path}/${scmdbuild_sql_file}"

#rm -rf ${sql_queries_path}/${cmdbuild_sql_file}
#rm -rf ${sql_queries_path}/${scmdbuild_sql_file}

# Backup original config files
cp -pr /var/opt/rh/rh-postgresql${postgresql_version}/lib/pgsql/data/pg_hba.conf /var/opt/rh/rh-postgresql${postgresql_version}/lib/pgsql/data/pg_hba.conf.orig
cp -pr /var/opt/rh/rh-postgresql${postgresql_version}/lib/pgsql/data/postgresql.conf /var/opt/rh/rh-postgresql${postgresql_version}/lib/pgsql/data/postgresql.conf.orig

sed -i 's/# IPv4 local connections:/# IPv4 local connections:\n host         all         all    0.0.0.0\/0       md5/g' /var/opt/rh/rh-postgresql${postgresql_version}/lib/pgsql/data/pg_hba.conf
sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '0.0.0.0'/g" /var/opt/rh/rh-postgresql${postgresql_version}/lib/pgsql/data/postgresql.conf

#ln -s /opt/rh/rh-postgresql${postgresql_version}/root/usr/lib64/libpq.so.rh-postgresql${postgresql_version}-5.9 /opt/rh/rh-postgresql${postgresql_version}/root/usr/lib64/libpq.so.5
#ln -s /opt/rh/rh-postgresql${postgresql_version}/root/usr/lib64/libpq.so.5 /usr/lib64/libpq.so.5

systemctl restart rh-postgresql${postgresql_version}-postgresql.service

Here it goes the latest version of the install script, both for postgres and for cmdbuild/tomcat.

Script for tomcat/cmdbuild.

Please remember to check that the version of tomcat is available. For example try to open in your browser: https://www-eu.apache.org/dist/tomcat/tomcat-8/ and check the version available matches tha one in the configuration of this script: look for variable called: “tomcat_version”. This said you only need to chmod +x the script and run it.

#!/usr/bin/env bash
set -x
install_folder="/opt"
postgresql_server="10.5.60.51"
database_name="cmdbuild"
cmdbuild_user_name="cmdbuild"
cmdbuild_user_pass="cmdbuild"
cmdbuild_super_user="scmdbuild"
cmdbuild_super_pass="scmdbuild"
tomcat_version="8.5.46"
java_version="1.8.0"
postgres_version="96"
cmdbuild_version="3.1.1"
tomcat_user="tomcat"
tomcat_group="tomcat"

yum -y update
yum -y install nc wget centos-release-scl java-${java_version}-openjdk.x86_64 rh-postgresql${postgres_version}-postgresql rh-postgresql${postgres_version}-syspaths.x86_64

firewall-cmd --permanent --add-port=22/tcp
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --permanent --add-port=7800/tcp # <-- For Jgroup
firewall-cmd --permanent --add-port=8009/tcp # <-- For AJP
firewall-cmd --reload


# I think the following is a fix for some of the consequences of using software colection. IMHO you should use centos8 if you need centos8
# First remove crap from other versions (true story)
#rm -rfv /opt/rh/rh-postgresql${postgres_version}/root/usr/lib64/libpq.so*
#rm -rfv /usr/lib64/libpq.so*
ln -s /opt/rh/rh-postgresql${postgres_version}/root/usr/lib64/libpq.so.rh-postgresql96-5.9 /opt/rh/rh-postgresql${postgres_version}/root/usr/lib64/libpq.so.5
ln -s /opt/rh/rh-postgresql${postgres_version}/root/usr/lib64/libpq.so.5 /usr/lib64/libpq.so.5

nc -z ${postgresql_server} 5432 > /dev/null
if [ $? -eq 0 ]; then
    echo -e "Test tcp connection to the db suceeded"
else
    echo -e "The connection to the database ${database_name} to the server ${postgresql_server} didn't work, please check the config."
    exit 1
fi

groupadd ${tomcat_group}
useradd -M -s /sbin/nologin -g ${tomcat_group} -d ${install_folder}/tomcat ${tomcat_user}

#tomcat
cd ~
wget -O /var/tmp/apache-tomcat-${tomcat_version}.tar.gz https://www-eu.apache.org/dist/tomcat/tomcat-8/v${tomcat_version}/bin/apache-tomcat-${tomcat_version}.tar.gz
mkdir -p ${install_folder}/tomcat
tar -xzf /var/tmp/apache-tomcat-${tomcat_version}.tar.gz -C ${install_folder}/tomcat --strip-components=1
chgrp -R ${tomcat_user} ${install_folder}/tomcat
chmod -R g+r ${install_folder}/tomcat/conf/*
chmod g+rx ${install_folder}/tomcat/conf
chown -R ${tomcat_user} ${install_folder}/tomcat/logs/
chmod -R g+w ${install_folder}/tomcat/work
chmod -R g+w ${install_folder}/tomcat/temp
chmod -R g+w ${install_folder}/tomcat/logs
chmod -R g+r ${install_folder}/tomcat/conf
chmod -R g+w ${install_folder}/tomcat/webapps

# Systemd
cat > /etc/systemd/system/tomcat.service <<EOF
# Systemd unit file for tomcat
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/jre
Environment=CATALINA_PID=${install_folder}/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=${install_folder}/tomcat
Environment=CATALINA_BASE=${install_folder}/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1536M -XX:MaxPermSize=256M -server -XX:+UseParallelGC -Dfile.encoding=UTF8'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
ExecStart=${install_folder}/tomcat/bin/startup.sh
ExecStop=/bin/kill -15 \$MAINPID
User=${tomcat_user}
Group=${tomcat_group}
UMask=0007
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl start tomcat
systemctl enable tomcat
systemctl stop tomcat

rm -rf ${install_folder}/tomcat/webapps/*


#Download cmdbuild
mkdir -p /var/tmp/f
mkdir -p ${install_folder}/tomcat/webapps
chmod g+w ${install_folder}/tomcat/webapps
cd /var/tmp/f
if ! [[ -f /var/tmp/cmdbuild-${cmdbuild_version}.war ]]; then
    wget -O /var/tmp/cmdbuild-${cmdbuild_version}.war https://sourceforge.net/projects/cmdbuild/files/${cmdbuild_version}/cmdbuild-${cmdbuild_version}.war/download?use_mirror=netcologne#
fi
if ! [[ -f /var/tmp/f/cmdbuild-${cmdbuild_version}-resources.tar.gz ]]; then
  wget -O /var/tmp/f/cmdbuild-${cmdbuild_version}-resources.tar.gz https://sourceforge.net/projects/cmdbuild/files/${cmdbuild_version}/cmdbuild-${cmdbuild_version}-resources.tar.gz/download#
fi
cp /var/tmp/cmdbuild-${cmdbuild_version}.war ${install_folder}/tomcat/webapps/cmdbuild.war
systemctl start tomcat
sleep 20
systemctl stop tomcat

mkdir -p ${install_folder}/tomcat/conf/cmdbuild


cat <<EOF > "${install_folder}"/tomcat/conf/cmdbuild/database.conf
db.url=jdbc:postgresql://${postgresql_server}:5432/${database_name}
db.username=${cmdbuild_user_name}
db.password=${cmdbuild_user_pass}
db.admin.username=${cmdbuild_super_user}
db.admin.password=${cmdbuild_super_pass}
EOF

chown ${tomcat_user}. ${install_folder}/tomcat/conf/cmdbuild/database.conf

cd /var/tmp/f
tar -xzf /var/tmp/f/cmdbuild-${cmdbuild_version}-resources.tar.gz
cp /var/tmp/f/tomcat-libs/postgresql-*.jar ${install_folder}/tomcat/lib/
chown ${tomcat_user}. ${install_folder}/tomcat/lib/postgresql-*.jar

systemctl stop tomcat
chmod +x ${install_folder}/tomcat/webapps/cmdbuild/cmdbuild.sh
bash ${install_folder}/tomcat/webapps/cmdbuild/cmdbuild.sh dbconfig create empty -configfile ${install_folder}/tomcat/conf/cmdbuild/database.conf
systemctl start tomcat

Let me know how it goes.

 
(Visited 51 times, 1 visits today)

Author: Giuseppe Urso

Giuseppe lives in Haarlem now with his shiny dog, Filippa In 1982 received his first home computer, a Commodore 64, followed by Datasette and a 1541 Floppy Disk Drive. In 1999 he installed his first Linux distro (LRH6). In 2006 he switched to Debian as favourite OS. Giuseppe Urso actively sustains the Free Software Fundation and his founder Richard Mattew Stallman, he speaks to people trying to convince them to join the fight now, and about how important is to use Free Software only. He has a job as Infra Specialist at Hippo Enterprise Java Cms an Open Source Enterprise class Content Management System, one of the coolest company ever, in Amsterdam. He's always ready to install Debian on other people computers for free.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.