Skip to content

Instantly share code, notes, and snippets.

@chicks
Last active December 8, 2018 13:04
Show Gist options
  • Save chicks/7903312 to your computer and use it in GitHub Desktop.
Save chicks/7903312 to your computer and use it in GitHub Desktop.
Sugar and DB2 on CentOS 6.4
# Disable SELinux
echo 0 > /selinux/enforce
perl -pi -e 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# Install required packages
yum install pdksh compat-libstdc++-33 compat-libstdc++-33.i686 libaio libaio.i686 \
pam-1.1.1-17.el6.x86_64 pam-1.1.1-17.el6.i686 nfs-utils openssh-clients \
numactl
# Update Kernel Parameters (http://ibm.co/1czEKb4)
#
# Install and License DB2
#
# Create DB2 Groups and Users
groupadd db2iadm1
groupadd db2fadm1
groupadd dasadm1
useradd -N -g db2iadm1 -m -d /home/db2inst1 db2inst1
useradd -N -g db2fadm1 -m -d /home/db2fenc1 db2fenc1
useradd -N -g dasadm1 -m -d /home/dasusr1 dasusr1
passwd db2inst1
passwd db2fenc1
passwd dasusr1
# Download and Unpack DB2 Server into /root/ibm/server
./db2prereqcheck
# Run the installer
./db2_install
# Install the license
/opt/ibm/db2/V10.5/adm/db2licm -a <path to license>
#
# Setup DB2 Administration Server, DB2 Instance, and Setup DB2 to start on boot
#
# Create a DAS Instance
/opt/ibm/db2/V10.5/instance/dascrt -u dasusr1
# Start up DAS
su - dasusr1 -c '/opt/ibm/db2/V10.5/das/bin/db2admin start'
# Configure DB2 AUTOSTART
su - dasusr1 -c '/opt/ibm/db2/V10.5/adm/db2set DB2AUTOSTART=YES'
# Setup DB2 Path for everyone
echo 'export PATH=${PATH}:/opt/ibm/db2/V10.5/bin' > /etc/profile.d/db2.sh
# Create a DB2 Instance
/opt/ibm/db2/V10.5/instance/db2icrt -a server -u db2fenc1 db2inst1
# Enable Auto-Start
/opt/ibm/db2/V10.5/instance/db2iauto -on db2inst1
# Confirm db2fm.conf is present, if not see http://ibm.co/1bVlxSE
ls -l /etc/init/db2fmcd.conf
# Enable Fault Manager Coordinator (So that DB2 Starts on boot!)
/opt/ibm/db2/V10.5/bin/db2fmcu -u -p /opt/ibm/db2/V10.5/bin/db2fmcd
# Start up the Fault Monitor Daemon
/opt/ibm/db2/V10.5/bin/db2fm -i db2inst1 -U
# Start up the Fault Monitor Service
/opt/ibm/db2/V10.5/bin/db2fm -i db2inst1 -u
# Turn on the Fault Monitor for the instance
/opt/ibm/db2/V10.5/bin/db2fm -i db2inst1 -f on
# Check instance state
su - db2inst1 -c 'db2fm -s -S'
# Enable TCP/IP for the instance
su - db2inst1 -c 'db2 update database manager configuration using svcename DB2_db2inst1'
su - db2inst1 -c 'db2set DB2COMM=tcpip'
# Confirm TCP/IP is enabled
su - db2inst1 -c 'db2 get database manager configuration'
# Enable MySQL Compatibility mode
su - db2inst1 -c 'db2set DB2_COMPATIBILITY_VECTOR=MYS'
# Start the database
su - db2inst1 -c 'db2ls'
su - db2inst1 -c 'db2start'
#
# Setup a Database for Sugar
#
# NOTE this creates a default 32k table space which is the maximum. Only a few tables in Sugar need 8k, others need only 4k
# However if you are using Studio the table needs enough extra space to add columns
# Also note that the specified collation is case insensitive US. By default DB2 is case sensitive.
su - db2inst1
db2 "CREATE DATABASE SUGARCRM USING CODESET UTF-8 TERRITORY US COLLATE USING UCA500R1_LEN_S2 PAGESIZE 32 K"
#
# Setup DB2 Text Search Service
#
# Increase ulimit for all users
echo '* hard nofile 1048576' >> /etc/security/limits.conf
# Print the current config
configTool printAll -configPath /opt/ibm/db2/V10.5/cfg/db2tss/config
# Create a new TSS configuration for db2inst1
configTool configureParams \
-configPath / home/db2inst1/sqllib/db2tss/config \
-logPath /home/db2inst1/sqllib/db2tss/logs \
-tempDirPath /home/db2inst1/sqllib/tmp \
-installPath /home/db2inst1/sqllib/db2tss
# Create a new TSS configuration token for db2inst1
configTool generateToken \
-configPath /home/db2inst1/sqllib/db2tss/config \
-seed db2inst1
# Create a new TSS Listener for db2inst1
configTool configureHTTPListener \
-configPath /home/db2inst1/sqllib/db2tss/config \
-adminHTTPPort 60606
# Update /etc/services (as root)
echo -e "DB2_db2inst1_tss\t60606/tcp" >> /etc/services
# Verify the configurationTool output contains an "authentication token"
configTool printAll -configPath /home/db2inst1/sqllib/db2tss/config
# Start DB2 TSS
db2ts "START FOR TEXT"
# Enable TSS
db2ts "enable database for text connect to SUGARCRM"
#
# Troubleshooting
#
# Ensure the SYSTOOLS table space is created (the GET_DBSIZE_INFO will create the tablespace if not created)
db2 "connect to SUGARCRM"
db2 "CALL GET_DBSIZE_INFO(?, ?, ?, -1)"
#
# Confirm you have SYSADM Privileges
#
# View current user
db2 "VALUES SYSPROC.AUTH_GET_INSTANCE_AUTHID()"
# View current user's authorities (Replace DB2ADMIN with the result of the previous command)
db2 "SELECT * FROM TABLE (SYSPROC.AUTH_LIST_AUTHORITIES_FOR_AUTHID ('DB2ADMIN', 'U'))AS T ORDER BY AUTHORITY"
# Grant DBADM to user
db2 "GRANT DBADM ON DATABASE TO USER DB2ADMIN"
<?php
// Use this to test connectivity to db2. Useful for checking IIS permissions
$database = 'DATABASE=SUGARCRM;HOSTNAME=localhost;PORT=60006;PROTOCOL=TCPIP;UID=db2inst1;PWD=Sugar123!;';
$conn = db2_connect($database, '', '');
if ($conn) {
echo "Connection succeeded.\n";
db2_close($conn);
}
else {
$stmt_err = db2_stmt_error();
$stmt_err_msg = db2_stmt_errormsg();
$conn_err = db2_conn_error();
$conn_err_msg = db2_conn_errormsg();
echo "Connection failed.\n";
echo "Statement Error : $stmt_err Statement Error Message : $stmt_err_msg\n";
echo "Connection Error : $conn_err Connection Error Message : $conn_err_msg\n";
}
?>
# Install packages
yum install httpd mod_ssl mod_php apc php php-devel php-gd php-pear php-mbstring \
php-imap php-bcmath java-1.7.0-openjdk
# Turn on Apache
chkconfig httpd on
service httpd start
# Install DB2 Driver
pecl install ibm_db2
echo 'extension=ibm_db2.so' >> /etc/php.ini
echo 'ibm_db2.instance_name=db2inst1' >> /etc/php.ini
# Update PHP.ini
perl -pi -e 's/memory_limit = 128M/memory_limit = 512M/g' /etc/php.ini
perl -pi -e 's/;error_log = syslog/error_log = \/var\/log\/httpd\/php_error\.log/g' /etc/php.ini
perl -pi -e 's/;date.timezone =/date.timezone = UTC/g' /etc/php.ini
perl -pi -e 's/upload_max_filesize = 2M/upload_max_filesize = 100M/g' /etc/php.ini
#
# Verify DB2 driver functionality
#
# Download or copy/paste the db2_test.php file below
# You may need to adjust your connection string depending on the port and user/pass you require
curl -o /var/www/html/db2_test.php https://gist.github.com/chicks/7903312/raw/ef1709df7cba512fb5261ae406d63e56cd101451/db2_test.php
# Set the execute bit
chmod 755 /var/www/html/db2_test.php
# Run
php -f /var/www/html/db2_test.php
#
# Install ElasticSearch
#
# Install Package
yum localinstall https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.7.noarch.rpm
# Enable on boot
chkconfig elasticsearch on
# Start the server
service elasticsearch start
# Check the server
curl -X GET http://localhost:9200/
# Mount the guest additions
mount -r /dev/cdrom /media
# Update to Latest Kernel
yum update kernel*
reboot
# Install EPEL Repo
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# Install required packages
yum install gcc kernel-devel kernel-headers dkms make bzip2 perl
# Current running kernel on Fedora, CentOS 6 and Red Hat (RHEL) 6
export KERN_DIR=/usr/src/kernels/`uname -r`
# Install Guest Additions
cd /media
./VBoxLinuxAdditions.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment