Last year we published an article on installing the open-source version of Scalr:
http://blogs.reliablepenguin.com/2013/08/29/scalr-install-notes
Now there’s a new 4.5 release of Scalr available so it’s time for an update.
We’re installing on Cento 6.4 hosted on a RackSpace Performance 1 Cloud Server.
The installation instructions have improved since the last time around but Scalr is till a complex install:
https://scalr-wiki.atlassian.net/wiki/display/docs/Installing+Scalr+4.5
Follow these instructions one section at a time and make sure you’ve got the section complete and working before moving to the next section. We’ve provided notes below about each section.
Before you start, select a hostname for the server and add a DNS A record. For this article we’ll use:
1 |
scalr.domain.com |
You’ll have problems later on if you don’t get the hostname setup in advance.
Also I like to add some swap to the server:
1 2 3 4 |
dd if=/dev/zero of=/1GB.swap bs=1M count=1024 mkswap /1GB.swap swapon /1GB.swap echo "/1GB.swap none swap sw 0 0" >>/etc/fstab |
Create UNIX Users and Group for Scalr
I setup a script at /root/env.sh with the environment variable as follows:
1 2 3 4 5 6 |
#!/bin/bash export SERVICE_USER=root export WEB_USER=apache export SCALR_GROUP=scalr export SCALR_INSTALL=/opt/scalr |
This makes it easy to get the environment right.
1 2 3 |
/usr/sbin/useradd www-data /usr/sbin/groupadd scalr /usr/sbin/groupmems -g scalr -a root -a apache |
Notice that we’re using user “apache” instead of “www-data” since this is CentOS instead of Ubuntu.
Configure your firewall
Edit /etc/sysconfig/iptables and add lines shown:
1 2 3 4 5 |
-A INPUT -m conntrack --ctstate NEW -m tcp -p tcp --dport 22 -j ACCEPT -A INPUT -m conntrack --ctstate NEW -m tcp -p tcp --dport 80 -j ACCEPT -A INPUT -m conntrack --ctstate NEW -m tcp -p tcp --dport 443 -j ACCEPT -A INPUT -m conntrack --ctstate NEW -m tcp -p tcp --dport 8080 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited |
And restart the service:
1 |
/sbin/service iptables restart |
Install Scalr’s PHP Dependencies
The PHP dependencies are tricky. Tried using the IUS repository but kept having problems with errors like this:
1 |
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/http.so' - /usr/lib64/php/modules/http.so: undefined symbol: php_iconv_string in Unknown on line 0 |
So I started over with the Remi repository:
1 2 |
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm yum install remi-release-6.rpm |
Now edit /etc/yum.repos.d/remi.repo and enable the “remi” and “remi-php55” repositories.
1 |
yum install php php-mcrypt php-soap php-snmp php-mysqlnd php-ldap php-pecl-http1 php-pecl-yaml php-pecl-ssh2 |
The instructions say to install the php-pecl-rrd extension now but it’s better to wait due to dependency issues that we’ll see later.
Also notice that we’re installing php-pecl-http1 instead of php-pecl-http. This is critical.
Install Scalr’s Python Dependencies
Python is installed by default so just a couple of additional packages to install:
1 |
yum install python-devel libevent-devel python-crypto m2crypto net-snmp-python |
As with PHP, we’ll defer installing the python-rrdtool package until a later step.
Configure PHP for Scalr
Edit /etc/php.ini and (a) enable “short_open_tags” and (b) set the “date.timezone” setting.
Update System SNMP MIBs
For CentOS there is no “snmp-mibs-downloader”. I ended up doing nothing for this step.
Download and Install Scalr 4.5
I choose to install Scalr in /opt/scalr with the following steps:
1 2 3 4 |
cd /opt wget https://github.com/Scalr/scalr/archive/v4.5.1.tar.gz tar -xvzf v4.5.1 mv scalr-4.5.1 scalr |
Notice that back in the first step, I set the SCALR_INSTALL environment variable. No run the installer:
1 2 |
cd /opt/scalr/app/python python setup.py install |
Install and Configure MySQL
Install MySQL server and set to start on boot:
1 2 3 |
yum install mysql-server /sbin/chkconfig --level 345 mysqld on /sbin/service mysqld start |
Set the mysql root login and secure:
http://blogs.reliablepenguin.com/2012/10/09/secure-mysql-installation
I like to add a .my.cnf file:
http://blogs.reliablepenguin.com/2012/10/09/create-my-cnf-file-for-mysql-authentication
Edit the /etc/my.cnf file and add this line to the “[mysqld]” section:
1 |
max_connections = 300 |
Now create the database and user for Scalr:
1 2 3 4 |
mysql mysql> create database scalr_db; mysql> grant all privileges on scalr_db.* to 'scalr_user'@'localhost' identified by 'xxxxxxxxxx'; mysql>flush privileges; |
And load the database structure and data:
1 2 |
mysql scalr_db < /opt/scalr/sql/structure.sql mysql scalr_db < /opt/scalr/sql/data.sql |
Create the Scalr Cache folder
1 2 3 4 |
cd /opt/scalr mkdir app/cache chown root.apache app/cache chmod 770 app/cache/ |
Install and Configure rrdtool and rrdcached
The default version of rrdtool is too old …. we need at least 1.4:
1 2 3 4 5 6 |
cd /root yum erase rrdtool rrdtool-devel yum install gettext ruby perl-Time-HiRes wget http://packages.express.org/rrdtool/rrdtool-perl-1.4.7-1.el6.wrl.x86_64.rpm wget http://packages.express.org/rrdtool/rrdtool-1.4.7-1.el6.wrl.x86_64.rpm rpm -i rrdtool-1.4.7-1.el6.wrl.x86_64.rpm rrdtool-perl-1.4.7-1.el6.wrl.x86_64.rpm |
And now we can get the PHP and Python dependencies that we skipped earlier:
1 2 3 |
yum install php-pecl-rrd wget http://packages.express.org/rrdtool/rrdtool-python-1.4.7-1.el6.wrl.x86_64.rpm rpm -i rrdtool-python-1.4.7-1.el6.wrl.x86_64.rpm |
Set rrdcached to start on boot:
1 |
/sbin/chkconfig --level 345 rrdcached on |
Edit /etc/sysconfig/rrdcached and change the “RRDCACHED_USER” to “root” and add the following line:
1 |
OPTIONS="$OPTIONS -s scalr -j /var/lib/rrdcached/journal/ -F -b /var/lib/rrdcached/db/ -B -l unix:/var/run/rrdcached.sock "; |
Now create the graphics and data directories:
1 2 3 4 5 6 7 |
mkdir -p /opt/scalr/app/www/graphics chmod 755 /opt/scalr/app/www/graphics chown root.www-data /opt/scalr/app/www/graphics mkdir /var/lib/rrdcached/journal/ mkdir /var/lib/rrdcached/db/ mkdir --mode=775 /var/lib/rrdcached/db/{x1x6,x2x7,x3x8,x4x9,x5x0} chown root:apache /var/lib/rrdcached/db/{x1x6,x2x7,x3x8,x4x9,x5x0} |
And start the service:
1 |
/sbin/service rrdcached start |
Install and Configure Apache
Install Apache “httpd” package and SSL support:
1 |
yum install httpd mod_ssl |
Edit /etc/httpd/conf.d/vhosts.conf and add:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<VirtualHost *:80> ServerAdmin webmaster@reliablepenguin.com ServerName scalr.domain.com DocumentRoot /opt/scalr/app/www ErrorLog logs/scalr.domain.com-error_log CustomLog logs/scalr.domain.com-access_log combined <Directory /opt/scalr/app/www> Options -Indexes +FollowSymLinks +MultiViews AllowOverride All Order allow,deny allow from all </Directory> </VirtualHost> |
Set Apache to start on boot and start it now:
1 2 |
/sbin/chkconfig --level 345 httpd on /sbin/service httpd start |
Configure Scalr
Copy the sample config file:
1 |
cp /opt/scalr/app/etc/config.yml-sample /opt/scalr/app/etc/config.yml |
Now edit the config file at /opt/scalr/app/etc/config.yml and set the following parameters:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
scalr: connections: mysql: &connections_mysql host: 'localhost' port: ~ name: scalr_db user: scalr_user pass: 'XXXXXXXXXXXXX' email: address: 'scalr@domain.com' name: 'RP Scalr' endpoint: host: 'scalr2.domain.com' load_statistics: connections: plotter: host: http://scalr2.domain.com port: 8080 rrd_dir: /var/lib/rrdcached/db img_dir: /opt/scalr/app/www/graphics img_url: /graphics |
Leave the other parameters at default settings.
Configure the Scalr Cronjobs
Edit “apache” cronjobs:
1 |
crontab -e -u apache |
and add the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
* * * * * /usr/bin/php -q /opt/scalr/app/cron/cron.php --Scheduler */5 * * * * /usr/bin/php -q /opt/scalr/app/cron/cron.php --UsageStatsPoller */2 * * * * /usr/bin/php -q /opt/scalr/app/cron-ng/cron.php --Scaling */2 * * * * /usr/bin/php -q /opt/scalr/app/cron/cron.php --SzrMessaging */2 * * * * /usr/bin/php -q /opt/scalr/app/cron/cron.php --BundleTasksManager */15 * * * * /usr/bin/php -q /opt/scalr/app/cron-ng/cron.php --MetricCheck */2 * * * * /usr/bin/php -q /opt/scalr/app/cron-ng/cron.php --Poller * * * * * /usr/bin/php -q /opt/scalr/app/cron/cron.php --DNSManagerPoll 17 5 * * * /usr/bin/php -q /opt/scalr/app/cron/cron.php --RotateLogs */2 * * * * /usr/bin/php -q /opt/scalr/app/cron/cron.php --EBSManager */20 * * * * /usr/bin/php -q /opt/scalr/app/cron/cron.php --RolesQueue */5 * * * * /usr/bin/php -q /opt/scalr/app/cron-ng/cron.php --DbMsrMaintenance */20 * * * * /usr/bin/php -q /opt/scalr/app/cron-ng/cron.php --LeaseManager */1 * * * * /usr/bin/php -q /opt/scalr/app/cron-ng/cron.php --ServerTerminate |
Configure the Scalr Daemons
Edit /etc/init.d/scalr and copy/paste the following contents:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
#!/bin/bash # scalr daemon # chkconfig: 345 20 80 # description: scalr daemons # processname: scalr PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME case "$1" in start) printf "%-50s" "Starting message sender..." PID=`python -m scalrpy.msg_sender -p /var/run/msg_sender.pid -l /var/log/scalr.msg_sender.log -c /opt/scalr/app/etc/config.yml --start > /dev/null 2>&1 & echo $!` if [ -z $PID ]; then printf "%s\n" "Fail" else echo $PID > $PIDFILE printf "%s\n" "Ok" fi printf "%-50s" "Starting queue processor..." PID=`python -m scalrpy.dbqueue_event -p /var/run/dbqueue_event.pid -l /var/log/scalr.dbqueue_event.log -c /opt/scalr/app/etc/config.yml --start > /dev/null 2>&1 & echo $!` if [ -z $PID ]; then printf "%s\n" "Fail" else echo $PID > $PIDFILE printf "%s\n" "Ok" fi printf "%-50s" "Starting stats plotter..." PID=`python -m scalrpy.load_statistics -p /var/run/load_statistics.plotter.pid -l /var/log/scalr.load_statistics.plotter.log -c /opt/scalr/app/etc/config.yml --plotter --start > /dev/null 2>&1 & echo $!` if [ -z $PID ]; then printf "%s\n" "Fail" else echo $PID > $PIDFILE printf "%s\n" "Ok" fi printf "%-50s" "Starting stats poller..." PID=`python -m scalrpy.load_statistics -p /var/run/load_statistics.poller.pid -l /var/log/scalr.load_statistics.poller.log -c /opt/scalr/app/etc/config.yml --poller --start > /dev/null 2>&1 & echo $!` if [ -z $PID ]; then printf "%s\n" "Fail" else echo $PID > $PIDFILE printf "%s\n" "Ok" fi ;; status) printf "%-50s" "Checking message sender..." PIDFILE=/var/run/msg_sender.pid if [ -f $PIDFILE ]; then PID=`cat $PIDFILE` if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then printf "%s\n" "Process dead but pidfile exists" else echo "Running" fi else printf "%s\n" "Service not running" fi printf "%-50s" "Checking queue processor..." PIDFILE=/var/run/dbqueue_event.pid if [ -f $PIDFILE ]; then PID=`cat $PIDFILE` if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then printf "%s\n" "Process dead but pidfile exists" else echo "Running" fi else printf "%s\n" "Service not running" fi printf "%-50s" "Checking stats plotter..." PIDFILE=/var/run/load_statistics.plotter.pid if [ -f $PIDFILE ]; then PID=`cat $PIDFILE` if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then printf "%s\n" "Process dead but pidfile exists" else echo "Running" fi else printf "%s\n" "Service not running" fi printf "%-50s" "Checking stats poller..." PIDFILE=/var/run/load_statistics.poller.pid if [ -f $PIDFILE ]; then PID=`cat $PIDFILE` if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then printf "%s\n" "Process dead but pidfile exists" else echo "Running" fi else printf "%s\n" "Service not running" fi ;; stop) printf "%-50s" "Stopping message sender..." PIDFILE=/var/run/msg_sender.pid PID=`cat $PIDFILE` cd $DAEMON_PATH if [ -f $PIDFILE ]; then kill -HUP $PID printf "%s\n" "Ok" rm -f $PIDFILE else printf "%s\n" "pidfile not found" fi printf "%-50s" "Stopping queue processor..." PIDFILE=/var/run/dbqueue_event.pid PID=`cat $PIDFILE` cd $DAEMON_PATH if [ -f $PIDFILE ]; then kill -HUP $PID printf "%s\n" "Ok" rm -f $PIDFILE else printf "%s\n" "pidfile not found" fi printf "%-50s" "Stopping stats plotter..." PIDFILE=/var/run/load_statistics.plotter.pid PID=`cat $PIDFILE` cd $DAEMON_PATH if [ -f $PIDFILE ]; then kill -HUP $PID printf "%s\n" "Ok" rm -f $PIDFILE else printf "%s\n" "pidfile not found" fi printf "%-50s" "Stopping stats poller..." PIDFILE=/var/run/load_statistics.poller.pid PID=`cat $PIDFILE` cd $DAEMON_PATH if [ -f $PIDFILE ]; then kill -HUP $PID printf "%s\n" "Ok" rm -f $PIDFILE else printf "%s\n" "pidfile not found" fi ;; restart) $0 stop $0 start ;; *) echo "Usage: $0 {status|start|stop|restart}" exit 1 esac |
Now set the service to start on boot and start it for the first time:
1 2 |
/sbin/chkconfig --level 345 scalr on /sbin/service scalr start |
Validate your Scalr installation
Now run the validation script:
1 2 |
cd /opt/scalr/app/www/ php testenvironment.php |
Log in to Scalr
Open a browser and go to:
http://scalr.domain.com
Login with user “admin” and password “admin”.
Go to the Admin -> admin -> edit and change the admin password.
All Done!
Scalr install is now complete. You can get started using Scalr by adding a user and building an environment.