forked from carlosabalde/libvmod-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
137 lines (121 loc) · 4.34 KB
/
Vagrantfile
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
# -*- mode: ruby -*-
# vi: set ft=ruby :
$script = <<SCRIPT
# Configuration.
REDIS_PORTS="6380 6381 6382 6390 6391 6392 6400 6401 6402"
REDIS_CLUSTER_PORTS="7000 7001 7002 7003 7004 7005 7006 7007 7008"
# General packages.
apt-get update -q
apt-get install -qq unzip apt-transport-https \
autotools-dev automake libtool python-docutils pkg-config libpcre3-dev \
libeditline-dev libedit-dev make dpkg-dev git libjemalloc-dev \
libev-dev libncurses-dev python-sphinx graphviz
gem install redis -v 3.3.3
# Varnish Cache.
sudo -u vagrant bash -c '\
git clone https://github.com/varnishcache/varnish-cache.git /tmp/varnish; \
cd /tmp/varnish; \
./autogen.sh; \
./configure; \
make; \
sudo make PREFIX="/usr/local" install; \
sudo ldconfig'
# hiredis.
sudo -u vagrant bash -c '\
cd /home/vagrant; \
wget --no-check-certificate https://github.com/redis/hiredis/archive/v0.13.3.zip -O hiredis-0.13.3.zip; \
unzip hiredis-0.13.3.zip; \
rm -f hiredis-0.13.3.zip; \
cd hiredis*; \
make; \
sudo make PREFIX="/usr/local" install; \
sudo ldconfig'
# Redis.
sudo -u vagrant bash -c '\
cd /home/vagrant; \
wget http://download.redis.io/releases/redis-4.0.1.tar.gz; \
tar zxvf redis-*.tar.gz; \
rm -f redis-*.tar.gz; \
cd redis-*; \
make; \
sudo make PREFIX="/usr/local" install; \
sudo ldconfig; \
sudo cp src/redis-trib.rb /usr/local/bin'
# General Redis setup.
mkdir -p /etc/redis /var/lib/redis
for PORT in $REDIS_PORTS $REDIS_CLUSTER_PORTS; do
cp /home/vagrant/redis*/utils/redis_init_script /etc/init.d/redis-server-$PORT
sed /etc/init.d/redis-server-$PORT -i \
-e "s%^REDISPORT=.*%REDISPORT=$PORT%" \
-e "s%^PIDFILE=/var/run/redis_%PIDFILE=/var/run/redis-%"
chmod +x /etc/init.d/redis-server-$PORT
update-rc.d -f redis-server-$PORT defaults
cp /home/vagrant/redis*/redis.conf /etc/redis/$PORT.conf
sed /etc/redis/$PORT.conf -i \
-e "s%^port .*%port $PORT%" \
-e "s%^dir .*%dir /var/lib/redis%" \
-e "s%^daemonize .*%daemonize yes%" \
-e "s%^pidfile .*%pidfile /var/run/redis-$PORT.pid%" \
-e "s%^# unixsocket .*%unixsocket /tmp/redis-$PORT.sock%" \
-e "s%^# unixsocketperm .*%unixsocketperm 777%" \
-e "s%^dbfilename .*%dbfilename dump-$PORT.rdb%" \
-e "s%^appendfilename .*%appendfilename appendonly-$PORT.aod%"
done
# Classic Redis setup.
for PORT in $REDIS_PORTS; do
if [ `expr $PORT % 10` -ne "0" ]; then
MASTER_PORT=`expr $PORT - $PORT % 10`
sed /etc/redis/$PORT.conf -i \
-e "s%^logfile .*%logfile /var/log/redis-$PORT.log%" \
-e "s%^# slaveof .*%slaveof 127.0.0.1 $MASTER_PORT%"
fi
service redis-server-$PORT start
done
# Redis Cluster setup.
REDIS_CLUSTER_NODES=""
for PORT in $REDIS_CLUSTER_PORTS; do
REDIS_CLUSTER_NODES="$REDIS_CLUSTER_NODES 127.0.0.1:$PORT"
sed /etc/redis/$PORT.conf -i \
-e "s%^logfile .*%logfile /var/log/redis-$PORT.log%" \
-e "s%^# cluster-enabled .*%cluster-enabled yes%" \
-e "s%^# cluster-config-file .*%cluster-config-file nodes-$PORT.conf%" \
-e "s%^# cluster-node-timeout .*%cluster-node-timeout 5000%" \
-e "s%^appendonly .*%appendonly yes%"
service redis-server-$PORT start
done
sudo -u vagrant bash -c "\
echo '/home/vagrant/redis*/src/redis-trib.rb create --replicas 2 $REDIS_CLUSTER_NODES' \
> /home/vagrant/create-redis-cluster.sh; \
chmod +x /home/vagrant/create-redis-cluster.sh"
# VMOD.
sudo -u vagrant bash -c '\
cd /vagrant; \
./autogen.sh; \
./configure; \
make'
SCRIPT
Vagrant.configure('2') do |config|
config.vm.hostname = 'dev'
config.vm.network :public_network
config.vm.synced_folder '.', '/vagrant', :nfs => false
config.vm.provider :virtualbox do |vb|
vb.customize [
'modifyvm', :id,
'--memory', '1024',
'--natdnshostresolver1', 'on',
'--accelerate3d', 'off',
]
end
config.vm.define :master do |machine|
machine.vm.box = 'ubuntu/trusty64'
machine.vm.box_version = '=14.04'
machine.vm.box_check_update = true
machine.vm.provision :shell, :privileged => true, :keep_color => false, :inline => $script
machine.vm.provider :virtualbox do |vb|
vb.customize [
'modifyvm', :id,
'--name', 'libvmod-redis (Varnish master)',
]
end
end
end