Skip to content

Instantly share code, notes, and snippets.

@afbjorklund
Last active December 6, 2022 06:56
Show Gist options
  • Save afbjorklund/f026800977b6eb0aad79cf01fd7be136 to your computer and use it in GitHub Desktop.
Save afbjorklund/f026800977b6eb0aad79cf01fd7be136 to your computer and use it in GitHub Desktop.

MULTIPLE SERVERS

Distributed setup of:

  • ccache
  • redis
  • distcc/distccd
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.box = "ubuntu/focal64"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
if Vagrant.has_plugin?("vagrant-cachier")
config.cache.scope = :machine
end
# distccd
config.vm.define "distccd" do |distccd|
distccd.vm.hostname = 'distccd'
distccd.vm.network "private_network", ip: "192.168.61.10"
distccd.vm.provision :shell, :inline => <<-SHELL
apt-get update
apt-get install -y distcc gcc
sed -e 's/^STARTDISTCC.*/STARTDISTCC="true"/' -i.orig /etc/default/distcc
sed -e 's/^ALLOWEDNETS.*/ALLOWEDNETS="192.168.61.0\\/24"/' -i /etc/default/distcc
echo "192.168.61.0/24" >> /etc/distcc/clients.allow
ln -s ../../bin/distcc /usr/lib/distcc/cc
sed -e 's/^LISTENER.*/LISTENER="0.0.0.0"/' -i /etc/default/distcc
service distcc restart
SHELL
end
# redis
config.vm.define "redis" do |redis|
redis.vm.hostname = 'redis'
redis.vm.network "private_network", ip: "192.168.61.11"
redis.vm.provision :shell, :inline => <<-SHELL
apt-get update
apt-get install -y redis-server
# assume a default memory of 512M, lower from 0 (all)
sed -e '/^# maxmemory / amaxmemory 256mb' -i.orig /etc/redis/redis.conf
sed -e '/^# maxmemory-policy / amaxmemory-policy allkeys-lru' -i /etc/redis/redis.conf
sed -e 's/^bind 127.0.0.1 ::1/bind 0.0.0.0/' -i /etc/redis/redis.conf
sed -e 's/^protected-mode yes/protected-mode no/' -i /etc/redis/redis.conf
service redis-server restart
SHELL
end
# ccache
config.vm.define "ccache" do |ccache|
ccache.vm.hostname = 'ccache'
ccache.vm.network "private_network", ip: "192.168.61.12"
ccache.vm.provision :shell, :privileged => false, :inline => <<-SHELL
sudo apt-get update
sudo apt-get install -y build-essential git
git clone https://github.com/ccache/ccache.git
cd ccache
sudo apt-get install -y cmake libhiredis-dev
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo .
sudo apt-get install -y --no-install-recommends asciidoctor xsltproc docbook-xml docbook-xsl
make -j `nproc`
make unittest
sudo make install
sudo apt-get install -y distcc-pump redis-tools
sudo sed -e 's|/usr/lib/distcc-pump/include_server|/usr/lib/distcc-pump/lib/python3.8/site-packages/include_server|' -i /usr/bin/distcc-pump
sudo sed -e 's/time.clock/time.process_time/g' -i /usr/lib/distcc-pump/lib/python3.8/site-packages/include_server/statistics.py
sudo sed -e 's/time.clock/time.process_time/g' -i /usr/lib/distcc-pump/lib/python3.8/site-packages/include_server/parse_file.py
export DISTCC_HOSTS=192.168.61.10,lzo,cpp
export CCACHE_REMOTE_STORAGE=redis://192.168.61.11
export CCACHE_SECONDARY_STORAGE=$CCACHE_REMOTE_STORAGE
redis-cli -h 192.168.61.11 ping
sudo apt-get install -y nutcracker
sudo mkdir -p /etc/nutcracker
sudo tee /etc/nutcracker/nutcracker.yml <<EOF
pool:
listen: 127.0.0.1:16379
preconnect: true
redis: true
servers:
- 192.168.61.11:6379:1
EOF
sudo /etc/init.d/nutcracker stop
sudo /etc/init.d/nutcracker start
export CCACHE=ccache
export CCACHE_PREFIX=distcc
export CCACHE_PREFIX_CPP=distcc
export CCACHE_REMOTE_STORAGE=redis://127.0.0.1:16379
export CCACHE_SECONDARY_STORAGE=$CCACHE_REMOTE_STORAGE
export DISTCC=distcc-pump
export DISTCC_LOG=$PWD/distcc.log DISTCC_VERBOSE=1
export CCACHE_LOGFILE=$PWD/ccache.log
echo 'int main() {}' > test.c
$DISTCC $CCACHE cc -c test.c
cat ccache.log
cat distcc.log
export REDIS_HOST=192.168.61.11
export REDIS_PORT=6379
set -x
redis-cli -h $REDIS_HOST -p $REDIS_PORT ping
redis-cli -h $REDIS_HOST -p $REDIS_PORT --scan --pattern 'ccache:*'
set +x
$CCACHE -C
$CCACHE cc -c test.c
$CCACHE -s
set -x
redis-cli -h $REDIS_HOST -p $REDIS_PORT info
set +x
true
SHELL
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment