forked from Kong/kong-vagrant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovision.sh
218 lines (176 loc) · 7.05 KB
/
provision.sh
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/bash
set -o errexit
KONG_VERSION=$1
CASSANDRA_VERSION=$2
KONG_UTILITIES=$3
ANREPORTS=$4
LOGLEVEL=$5
if [ "$CASSANDRA_VERSION" = "2" ]; then
CASSANDRA_VERSION=2.2.8
else
CASSANDRA_VERSION=3.0.9
fi
if [ -n "$HTTP_PROXY" -o -n "$HTTPS_PROXY" ]; then
touch /etc/profile.d/proxy.sh
touch /etc/apt/apt.conf.d/50proxy
fi
if [ -n "$HTTP_PROXY" ]; then
printf "using http proxy: %s\n" $HTTP_PROXY
echo "http_proxy=$HTTP_PROXY" >> /etc/profile.d/proxy.sh
echo "HTTP_PROXY=$HTTP_PROXY" >> /etc/profile.d/proxy.sh
echo "Acquire::http::proxy \"$HTTP_PROXY\";" >> /etc/apt/apt.conf.d/50proxy
echo "http_proxy=$HTTP_PROXY" >> /etc/wgetrc
fi
if [ -n "$HTTPS_PROXY" ]; then
printf "using https proxy: %s\n" $HTTPS_PROXY
echo "https_proxy=$HTTPS_PROXY" >> /etc/profile.d/proxy.sh
echo "HTTPS_PROXY=$HTTPS_PROXY" >> /etc/profile.d/proxy.sh
echo "Acquire::https::proxy \"$HTTP_PROXY\";" >> /etc/apt/apt.conf.d/50proxy
echo "https_proxy=$HTTPS_PROXY" >> /etc/wgetrc
fi
echo "Installing Kong version: $KONG_VERSION"
# Installing other dependencies
sudo apt-get update
sudo apt-get install -y git curl make pkg-config unzip libpcre3-dev apt-transport-https language-pack-en libssl-dev
# Assign permissions to "vagrant" user
sudo chown -R vagrant /usr/local
####################
# Install Postgres #
####################
# Install Postgres
sudo apt-get update
sudo apt-get install -y software-properties-common python-software-properties
sudo add-apt-repository "deb https://apt.postgresql.org/pub/repos/apt/ precise-pgdg main"
wget --quiet -O - https://postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y postgresql-9.5
# Configure Postgres
sudo bash -c "cat > /etc/postgresql/9.5/main/pg_hba.conf" << EOL
local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
EOL
sudo /etc/init.d/postgresql restart
# Create PG user and database
psql -U postgres <<EOF
\x
CREATE USER kong;
CREATE DATABASE kong OWNER kong;
CREATE DATABASE kong_tests OWNER kong;
EOF
#################
# install redis #
#################
sudo apt-get update
sudo apt-get install -y redis-server
sudo chown vagrant /var/log/redis/redis-server.log
#####################
# install Cassandra #
######################
# Install java runtime (Cassandra dependency)
echo Fetching and installing java...
sudo mkdir -p /usr/lib/jvm
sudo wget -q -O /tmp/jre-linux-x64.tar.gz --no-cookies --no-check-certificate --header 'Cookie: oraclelicense=accept-securebackup-cookie' http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jre-8u131-linux-x64.tar.gz
sudo tar zxvf /tmp/jre-linux-x64.tar.gz -C /usr/lib/jvm
sudo update-alternatives --install '/usr/bin/java' 'java' '/usr/lib/jvm/jre1.8.0_131/bin/java' 1
sudo update-alternatives --set java /usr/lib/jvm/jre1.8.0_131/bin/java
# install cassandra
echo Fetching and installing Cassandra...
echo 'deb http://debian.datastax.com/community stable main' | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
wget -q -O - '$@' http://debian.datastax.com/debian/repo_key | sudo apt-key add -
sudo apt-get update
sudo apt-get install cassandra=$CASSANDRA_VERSION -y --force-yes
sudo /etc/init.d/cassandra restart
################
# Install Kong #
################
echo Fetching and installing Kong...
set +o errexit
wget -q -O kong.deb "https://bintray.com/kong/kong-community-edition-deb/download_file?file_path=dists%2Fkong-community-edition-${KONG_VERSION}.trusty.all.deb"
if [ ! $? -eq 0 ]
then
# 0.10.3 and earlier are on Github
echo "failed downloading from BinTray, trying Github..."
set -o errexit
wget -q -O kong.deb https://github.com/Kong/kong/releases/download/$KONG_VERSION/kong-$KONG_VERSION.precise_all.deb
fi
set -o errexit
sudo apt-get update
sudo apt-get install -y netcat openssl libpcre3 dnsmasq procps perl
sudo dpkg -i kong.deb
rm kong.deb
###########################
# Install profiling tools #
###########################
if [ -n "$KONG_UTILITIES" ]; then
# install tools
sudo apt-get install -y httpie jq
# install systemtap
# https://openresty.org/en/build-systemtap.html
sudo apt-get install -y build-essential zlib1g-dev elfutils libdw-dev gettext
wget -q http://sourceware.org/systemtap/ftp/releases/systemtap-3.0.tar.gz
tar -xf systemtap-3.0.tar.gz
cd systemtap-3.0/
./configure --prefix=/opt/stap --disable-docs \
--disable-publican --disable-refdocs CFLAGS="-g -O2"
make
sudo make install
rm -rf ./systemtap-3.0 systemtap-3.0.tar.gz
# install stapxx and openresty-systemtap-toolkit
pushd /usr/local
git clone https://github.com/openresty/stapxx.git
git clone https://github.com/openresty/openresty-systemtap-toolkit.git
# install flamegraph
git clone https://github.com/brendangregg/FlameGraph.git
# install wrk and copy the binary to a location in PATH
git clone https://github.com/wg/wrk.git
cd wrk && make && sudo cp ./wrk /usr/local/bin/ && cd ..
popd
fi
# Adjust PATH
export PATH=$PATH:/usr/local/bin:/usr/local/openresty/bin:/opt/stap/bin:/usr/local/stapxx
# Prepare path to lua libraries
ln -sfn /usr/local /home/vagrant/.luarocks
# Set higher ulimit
sudo bash -c 'echo "fs.file-max = 65536" >> /etc/sysctl.conf'
sudo sysctl -p
sudo bash -c "cat >> /etc/security/limits.conf" << EOL
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
EOL
#############
# Finish... #
#############
# Adjust PATH for future ssh
echo "export PATH=\$PATH:/usr/local/bin:/usr/local/openresty/bin:/opt/stap/bin:/usr/local/stapxx:/usr/local/openresty/nginx/sbin" >> /home/vagrant/.bashrc
# do the same for root so we access to profiling tools
echo "export PATH=\$PATH:/usr/local/bin:/usr/local/openresty/bin:/opt/stap/bin:/usr/local/stapxx:/usr/local/openresty/nginx/sbin" >> /root/.bashrc
# copy host settings
if [ -n "$LOGLEVEL" ]; then
echo "export KONG_LOG_LEVEL=$LOGLEVEL" >> /home/vagrant/.bashrc
fi
if [ -n "$ANREPORTS" ]; then
echo "export KONG_ANONYMOUS_REPORTS=$ANREPORTS" >> /home/vagrant/.bashrc
fi
# create prefix (working directory) to the same location as source tree if available
if [ ! -d "/kong" ]; then
sudo mkdir /kong
sudo chown -R vagrant /kong
fi
echo "export KONG_PREFIX=/kong/servroot" >> /home/vagrant/.bashrc
# set admin listen addresses
echo "export KONG_ADMIN_LISTEN=0.0.0.0:8001" >> /home/vagrant/.bashrc
echo "export KONG_ADMIN_LISTEN_SSL=0.0.0.0:8444" >> /home/vagrant/.bashrc
# Adjust LUA_PATH to find the plugin dev setup
echo "export LUA_PATH=\"/kong-plugin/?.lua;/kong-plugin/?/init.lua;;\"" >> /home/vagrant/.bashrc
# Set locale
echo "export LC_ALL=en_US.UTF-8" >> /home/vagrant/.bashrc
echo "export LC_CTYPE=en_US.UTF-8" >> /home/vagrant/.bashrc
# fix locale warning
sudo echo "LC_CTYPE=\"en_US.UTF-8\"" >> /etc/default/locale
sudo echo "LC_ALL=\"en_US.UTF-8\"" >> /etc/default/locale
# Assign permissions to "vagrant" user
sudo chown -R vagrant /usr/local
echo "Successfully Installed Kong version: $KONG_VERSION"