Skip to content
Permalink
master
Go to file
@deniszh
Latest commit 80254f4 Mar 29, 2020 History
9 contributors

Users who have contributed to this file

@obfuscurity @deniszh @Dispader @mathyourlife @colini @CMihalcik @CarlFK @b @arska
executable file 146 lines (121 sloc) 5.11 KB
#!/bin/bash -ex
# Graphite installation script for Ubuntu 18.04
# Jason Dixon <jason@dixongroup.net>
SYNTHESIZE_HOME=$( cd "$( dirname "$0" )" && pwd )
UBUNTU_RELEASE=`lsb_release -a 2>/dev/null | grep '^Descrip' | cut -s -f 2`
GRAPHITE_HOME='/opt/graphite'
GRAPHITE_CONF="${GRAPHITE_HOME}/conf"
GRAPHITE_STORAGE="${GRAPHITE_HOME}/storage"
if [ -z $GRAPHITE_RELEASE ]; then
GRAPHITE_RELEASE='1.1.7'
fi
if [ -z $STATSITE_RELEASE ]; then
STATSITE_RELEASE='master'
fi
if [[ ! $UBUNTU_RELEASE =~ 'Ubuntu 18.04' ]]; then
echo "Sorry, this is only supported for Ubuntu Linux 18.04."
exit 1
fi
if [[ -d $GRAPHITE_HOME ]]; then
echo "Looks like you already have a Graphite installation in ${GRAPHITE_HOME}, aborting."
exit 1
fi
# Update apt since the vagrant image might be old
apt-get update -y
# Install package dependencies from apt
RUNLEVEL=1 apt-get install -y git wget curl netbase collectd memcached \
build-essential automake libtool libffi-dev libcairo2-dev libcairo2 libffi6 \
python3-dev python3-pip fontconfig apache2 libapache2-mod-wsgi-py3
# Download source repositories for Graphite/Carbon/Whisper and Statsite
cd /usr/local/src
git clone https://github.com/graphite-project/graphite-web.git
git clone https://github.com/graphite-project/carbon.git
git clone https://github.com/graphite-project/whisper.git
git clone https://github.com/armon/statsite.git
# Build and install Graphite/Carbon/Whisper and Statsite
mkdir -p /opt/graphite
cd whisper; \
git checkout ${GRAPHITE_RELEASE}; \
python3 setup.py install
cd ../carbon; \
git checkout ${GRAPHITE_RELEASE}; \
pip3 install -r requirements.txt; \
python3 setup.py install
cd ../graphite-web; \
pip3 install django==2.2.9; \
git checkout ${GRAPHITE_RELEASE}; \
pip3 install -r requirements.txt; \
python3 check-dependencies.py; \
python3 setup.py install
cd ../statsite; \
git checkout ${STATSITE_RELEASE}; \
./autogen.sh; \
./configure; make; \
cp statsite /usr/local/sbin/; \
cp sinks/graphite.py /usr/local/sbin/statsite-sink-graphite.py
# Update txamqp to support RabbitMQ 2.4+
# also install service_identity to remove TLS error
pip3 install txamqp service_identity --upgrade
# Install configuration files for Graphite/Carbon and Apache
cp ${SYNTHESIZE_HOME}/templates/statsite/statsite.conf /etc/statsite.conf
mkdir ${GRAPHITE_CONF}/examples
mv ${GRAPHITE_CONF}/*.example ${GRAPHITE_CONF}/examples/
cp ${SYNTHESIZE_HOME}/templates/graphite/conf/* ${GRAPHITE_CONF}/
cp ${SYNTHESIZE_HOME}/templates/collectd/collectd.conf /etc/collectd/
cp ${SYNTHESIZE_HOME}/templates/apache/graphite.conf /etc/apache2/sites-available/
# using systemd units instead of init and upstart files
cp ${SYNTHESIZE_HOME}/templates/systemd/* /etc/systemd/system/
# installing scripts for carbon-cache instances control script
cp ${SYNTHESIZE_HOME}/templates/scripts/* /usr/local/bin/
# Setup the correct Apache site and modules
a2dissite 000-default
a2ensite graphite
a2enmod ssl
a2enmod socache_shmcb
a2enmod rewrite
# Install configuration files for Django
cd ${GRAPHITE_HOME}/webapp/graphite
cp ${SYNTHESIZE_HOME}/templates/graphite/webapp/* .
sed -i -e "s/UNSAFE_DEFAULT/`date | md5sum | cut -d ' ' -f 1`/" local_settings.py
# Setup the Django database
PYTHONPATH=${GRAPHITE_HOME}/webapp django-admin.py migrate --noinput --settings=graphite.settings --run-syncdb
PYTHONPATH=${GRAPHITE_HOME}/webapp django-admin.py collectstatic --noinput --settings=graphite.settings
# Add carbon system user and set permissions
groupadd -g 998 carbon
useradd -c "carbon user" -g 998 -u 998 -s /bin/false carbon
chmod 775 ${GRAPHITE_STORAGE}
chown www-data:carbon ${GRAPHITE_STORAGE}
chown www-data:www-data ${GRAPHITE_STORAGE}/graphite.db
chown -R carbon ${GRAPHITE_STORAGE}/whisper
mkdir -p ${GRAPHITE_STORAGE}/log/carbon-cache/
chown -R carbon ${GRAPHITE_STORAGE}/log
mkdir ${GRAPHITE_STORAGE}/log/apache2
chown -R www-data ${GRAPHITE_STORAGE}/log/webapp
# Setup hourly systemd timer to rebuild Graphite index
cp ${SYNTHESIZE_HOME}/templates/scripts/graphite-build-index /usr/local/bin/graphite-build-index
systemctl daemon-reload
systemctl enable graphite-build-index.timer
systemctl start graphite-build-index.timer
systemctl start graphite-build-index
# Install Grafana
apt-get install -y apt-transport-https
apt-get install -y software-properties-common wget
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
apt-get install grafana
# Bootstrap Grafana datasources and dashboards
mkdir -p /etc/grafana/provisioning/datasources/
mkdir -p /etc/grafana/provisioning/dashboards/
cp ${SYNTHESIZE_HOME}/templates/grafana/provisioning/datasources/* /etc/grafana/provisioning/datasources/
cp ${SYNTHESIZE_HOME}/templates/grafana/provisioning/dashboards/* /etc/grafana/provisioning/dashboards/
systemctl restart grafana-server
# Enabling processes start
/usr/local/bin/carbon-cache enable
systemctl enable statsite
systemctl enable grafana-server
# Start our processes
/usr/local/bin/carbon-cache start
service memcached restart
service collectd restart
service apache2 restart
service statsite restart
You can’t perform that action at this time.