major updates for v0.6.x release

This commit is contained in:
Dave Horton committed 2021-07-03 11:37:31 -04:00
1 parent 475c137798
commit 074fa88a69
80 files changed
+16732 -366

No files matched your search

@@ -2,13 +2,9 @@
VERSION=$1
cd /home/admin
mkdir apps credentials
cp /tmp/ecosystem.config.js apps
cd apps
git clone https://github.com/jambonz/jambonz-feature-server.git -b ${VERSION}
git clone https://github.com/jambonz/fsw-clear-old-calls.git
cd /home/admin/apps/jambonz-feature-server && sudo npm install --unsafe-perm
cd /home/admin/apps/fsw-clear-old-calls && npm install && sudo npm install -g .
+11 -5
View File
@@ -4,8 +4,8 @@
"ssh_username": "admin",
"ami_description": "jambonz feature server",
"instance_type": "t2.xlarge",
"drachtio_version": "main",
"jambonz_version": "master",
"drachtio_version": "v0.8.10",
"jambonz_version": "v0.6.3",
"install_telegraf": "yes",
"install_datadog": "no"
},
@@ -23,12 +23,12 @@
},
"instance_type": "{{user `instance_type`}}",
"ssh_username": "{{user `ssh_username`}}",
"ami_name": "jambonz-feature-server-{{user `drachtio_version`}}-{{isotime |clean_resource_name }}",
"ami_name": "jambonz-feature-server-{{user `jambonz_version`}}-{{isotime |clean_resource_name }}",
"ami_description": "{{user `ami_description`}}",
"launch_block_device_mappings": [
{
"device_name": "/dev/xvda",
"volume_size": 40,
"volume_size": 60,
"volume_type": "gp2",
"delete_on_termination": true
}
@@ -59,7 +59,13 @@
"gnupg2 wget pkg-config ca-certificates libjpeg-dev libsqlite3-dev libpcre3-dev libldns-dev \\",
"libspeex-dev libspeexdsp-dev libedit-dev libtiff-dev yasm valgrind libswscale-dev haveged \\",
"libopus-dev libsndfile-dev libshout3-dev libmpg123-dev libmp3lame-dev libopusfile-dev",
"sudo chmod a+w /usr/local/src"
"sudo chmod a+w /usr/local/src",
"ssh-keyscan github.com >> ~/.ssh/known_hosts",
"mkdir ~/apps",
"cd ~/apps",
"git clone git@github.com:jambonz/jambonz-feature-server.git -b {{user `jambonz_version`}}",
"git clone git@github.com:jambonz/fsw-clear-old-calls.git -b {{user `jambonz_version`}}",
"sudo find / -name authorized_keys | sudo xargs -0 -r rm -Rf"
]
},
{
+6 -4
View File
@@ -4,6 +4,7 @@
"ssh_username": "admin",
"ami_description": "jambonz monitoring server",
"instance_type": "t2.medium",
"jambonz_version": "v0.6.0",
"homer_user": "homer_user",
"homer_password": "XcapJTqy11LnsYRtxXGPTYQkAnI",
"install_influxdb": "yes",
@@ -26,12 +27,12 @@
},
"instance_type": "{{user `instance_type`}}",
"ssh_username": "{{user `ssh_username`}}",
"ami_name": "jambonz-monitoring-server-all-in-one-{{isotime |clean_resource_name }}",
"ami_name": "jambonz-monitoring-server-{{user `jambonz_version`}}-{{isotime |clean_resource_name }}",
"ami_description": "{{user `ami_description`}}",
"launch_block_device_mappings": [
{
"device_name": "/dev/xvda",
"volume_size": 40,
"volume_size": 100,
"volume_type": "gp2",
"delete_on_termination": true
}
@@ -45,7 +46,7 @@
"Name": "{{user `tag_name`}}"
},
"run_tags": {
"Name": "homer-ami-building"
"Name": "jambonz-monitoring-server-build"
}
}],
"provisioners": [
@@ -55,7 +56,8 @@
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done",
"sudo apt-get update",
"sudo apt-get -y install software-properties-common make cmake gcc g++ dirmngr sudo python3-dev \\",
"curl wget sed git"
"curl wget sed git",
"sudo find / -name authorized_keys | sudo xargs -0 -r rm -Rf"
]
},
{
@@ -0,0 +1,35 @@
<drachtio>
<!-- udp port to listen on for client connections and shared secret used to authenticate clients -->
<admin port="9022" secret="cymru">127.0.0.1</admin>
<request-handlers>
<request-handler sip-method="INVITE">http://127.0.0.1:4000</request-handler>
</request-handlers>
<sip>
<contacts>
</contacts>
<udp-mtu>4096</udp-mtu>
</sip>
<cdrs>false</cdrs>
<logging>
<file>
<name>/var/log/drachtio/drachtio.log</name>
<archive>/var/log/drachtio/archive</archive>
<size>100</size>
<maxSize>10000</maxSize>
<auto-flush>true</auto-flush>
</file>
<sofia-loglevel>3</sofia-loglevel>
<loglevel>info</loglevel>
</logging>
</drachtio>
@@ -0,0 +1,30 @@
[Unit]
Description=drachtio
After=syslog.target network.target local-fs.target
[Service]
; service
Type=forking
ExecStartPre=/bin/sh -c 'systemctl set-environment LOCAL_IP=`curl -s http://169.254.169.254/latest/meta-data/local-ipv4`'
ExecStart=/usr/local/bin/drachtio --daemon --contact sip:${LOCAL_IP};transport=udp \
--address 0.0.0.0 --port 9022
TimeoutSec=15s
Restart=always
; exec
User=root
Group=daemon
LimitCORE=infinity
LimitNOFILE=100000
LimitNPROC=60000
;LimitSTACK=240
LimitRTPRIO=infinity
LimitRTTIME=7000000
IOSchedulingClass=realtime
IOSchedulingPriority=2
CPUSchedulingPolicy=rr
CPUSchedulingPriority=89
UMask=0007
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,27 @@
module.exports = {
apps : [
{
name: 'sbc-rtpengine-sidecar',
cwd: '/home/admin/apps/sbc-rtpengine-sidecar',
script: 'app.js',
instance_var: 'INSTANCE_ID',
out_file: '/home/admin/.pm2/logs/jambonz-sbc-rtpengine-sidecar.log',
err_file: '/home/admin/.pm2/logs/jambonz-sbc-rtpengine-sidecar.log',
exec_mode: 'fork',
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '1G',
env: {
NODE_ENV: 'production',
LOGLEVEL: 'info',
JAMBONES_SBCS: '${JAMBONES_SBC_SIP_IPS}',
ENABLE_METRICS: 1,
STATS_HOST: '127.0.0.1',
STATS_PORT: 8125,
STATS_PROTOCOL: 'tcp',
STATS_TELEGRAF: 1
}
}
]
};
@@ -6,12 +6,14 @@ After=syslog.target network.target local-fs.target
[Service]
; service
Type=forking
Environment="LD_LIBRARY_PATH=/usr/local/lib/"
ExecStartPre=/bin/sh -c 'systemctl set-environment LOCAL_IP=`curl -s http://169.254.169.254/latest/meta-data/local-ipv4`'
ExecStartPre=/bin/sh -c 'systemctl set-environment PUBLIC_IP=`curl -s http://169.254.169.254/latest/meta-data/public-ipv4`'
ExecStart=/usr/local/bin/rtpengine \
--interface private/${LOCAL_IP} \
--interface public/${LOCAL_IP}!${PUBLIC_IP} \
--listen-ng=22222 \
--listen-http=8080 \
--listen-udp=12222 \
--listen-cli=127.0.0.1:9900 \
--pidfile /var/run/rtpengine.pid \
@@ -0,0 +1,13 @@
#!/bin/bash
cd /home/admin/apps
cp /tmp/ecosystem.config.js .
cd /home/admin/apps/sbc-rtpengine-sidecar && sudo npm install --unsafe-perm
sudo -u admin bash -c "pm2 install pm2-logrotate"
sudo -u admin bash -c "pm2 set pm2-logrotate:max_size 1G"
sudo -u admin bash -c "pm2 set pm2-logrotate:retain 5"
sudo -u admin bash -c "pm2 set pm2-logrotate:compress true"
sudo chown -R admin:admin /home/admin/apps
@@ -0,0 +1,16 @@
#!/bin/bash
VERSION=$1
echo "drachtio version to install is ${VERSION}"
chmod 0777 /usr/local/src
cd /usr/local/src
git clone https://github.com/drachtio/drachtio-server.git -b ${VERSION}
cd drachtio-server
git submodule update --init --recursive
./autogen.sh && mkdir -p build && cd $_ && ../configure CPPFLAGS='-DNDEBUG -g -O0' && make && sudo make install
sudo mv /tmp/drachtio.conf.xml /etc
sudo mv /tmp/drachtio.service /etc/systemd/system
sudo chmod 644 /etc/drachtio.conf.xml
sudo chmod 644 /etc/systemd/system/drachtio.service
sudo systemctl enable drachtio
@@ -0,0 +1,3 @@
#!/bin/bash
curl -sL https://deb.nodesource.com/setup_14.x | sudo bash - && sudo apt-get install -y nodejs
sudo npm install -g pino-pretty pm2 pm2-logrotate
@@ -7,6 +7,12 @@ cd /usr/local/src
git clone https://github.com/BelledonneCommunications/bcg729.git
cd bcg729
cmake . -DCMAKE_INSTALL_PREFIX=/usr && make && sudo make install chdir=/usr/local/src/bcg729
cd /usr/local/src
git clone https://github.com/warmcat/libwebsockets.git -b v3.2.3
cd /usr/local/src/libwebsockets
sudo mkdir -p build && cd build && sudo cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo && sudo make && sudo make install
cd /usr/local/src
git clone https://github.com/sipwise/rtpengine.git -b ${VERSION}
cd rtpengine/daemon
@@ -15,3 +21,4 @@ cp /usr/local/src/rtpengine/daemon/rtpengine /usr/local/bin
sudo mv /tmp/rtpengine.service /etc/systemd/system
sudo chmod 644 /etc/systemd/system/rtpengine.service
sudo systemctl enable rtpengine
sudo systemctl start rtpengine
+27 -6
View File
@@ -2,9 +2,11 @@
"variables": {
"region": "us-east-1",
"ssh_username": "admin",
"ami_description": "jambonz SBC RTP",
"ami_description": "jambonz SBC media server",
"drachtio_version": "main",
"jambonz_version": "v0.6.5",
"instance_type": "t2.medium",
"rtp_engine_version": "mr8.5",
"rtp_engine_version": "mr9.3.1.8",
"rtp_engine_min_port": "40000",
"rtp_engine_max_port": "60000",
"install_datadog": "no",
@@ -24,12 +26,12 @@
},
"instance_type": "{{user `instance_type`}}",
"ssh_username": "{{user `ssh_username`}}",
"ami_name": "jambonz-sbc-rtp-{{isotime |clean_resource_name }}",
"ami_name": "jambonz-sbc-rtp-{{user `jambonz_version`}}-{{isotime |clean_resource_name }}",
"ami_description": "{{user `ami_description`}}",
"launch_block_device_mappings": [
{
"device_name": "/dev/xvda",
"volume_size": 40,
"volume_size": 50,
"volume_type": "gp2",
"delete_on_termination": true
}
@@ -52,7 +54,7 @@
"inline": [
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done",
"sudo apt-get update",
"sudo apt-get -y install python lsof gcc g++ make cmake build-essential git autoconf automake mysql-client redis-tools \\",
"sudo apt-get -y install python lsof gcc g++ make cmake build-essential git autoconf automake default-mysql-client redis-tools \\",
"curl telnet libtool libtool-bin libssl-dev libcurl4-openssl-dev libz-dev systemd-coredump liblz4-tool \\",
"iptables-dev libavformat-dev liblua5.1-0-dev libavfilter-dev libavcodec-dev libswresample-dev \\",
"libevent-dev libpcap-dev libxmlrpc-core-c3-dev markdown libjson-glib-dev lsb-release \\",
@@ -60,7 +62,12 @@
"gnupg2 wget pkg-config ca-certificates libjpeg-dev libsqlite3-dev libpcre3-dev libldns-dev \\",
"libspeex-dev libspeexdsp-dev libedit-dev libtiff-dev yasm valgrind libswscale-dev haveged \\",
"libopus-dev libsndfile-dev libshout3-dev libmpg123-dev libmp3lame-dev libopusfile-dev",
"sudo chmod a+w /usr/local/src"
"sudo chmod a+w /usr/local/src",
"ssh-keyscan github.com >> ~/.ssh/known_hosts",
"mkdir ~/apps",
"cd ~/apps",
"git clone git@github.com:jambonz/sbc-rtpengine-sidecar.git -b {{user `jambonz_version`}}",
"sudo find / -name authorized_keys | sudo xargs -0 -r rm -Rf"
]
},
{
@@ -86,6 +93,20 @@
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo '{{ .Path }}' {{user `rtp_engine_version`}}",
"script": "scripts/install_rtpengine.sh"
},
{
"type": "shell",
"script": "scripts/install_nodejs.sh"
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo '{{ .Path }}' {{user `drachtio_version`}}",
"script": "scripts/install_drachtio.sh"
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo '{{ .Path }}' {{user `jambonz_version`}}",
"script": "scripts/install_app.sh"
}
]
}
+5 -5
View File
@@ -9,7 +9,7 @@ $ packer build -color=false template.json
```
### variables
There are many variables that can be specified on the `packer build` command line; however defaults (which are shown below) are appropriate for building an "all in one" jambonz server, so you generally should not need to specify values.
There are many variables that can be specified on the `packer build` command line; these are shown below with their default values.
```
"region": "us-east-1"
@@ -17,25 +17,25 @@ There are many variables that can be specified on the `packer build` command lin
The region to create the AMI in
```
"ami_description": "jambonz SBC SIP+RTP"
"ami_description": "jambonz SBC SIP+RTP+Webserver"
```
AMI description.
```
"instance_type": "t2.medium"
"instance_type": "t2.xlarge"
```
EC2 Instance type to use when building the AMI.
```
"drachtio_version": "v0.8.4"
"drachtio_version": "v0.8.10"
```
drachtio tag or branch to build
```
```
"rtp_engine_version": "mr8.3.1.4",
"rtp_engine_version": "mr9.3.1.8",
```
rtpengine version
+1 -1
View File
@@ -1,5 +1,5 @@
{
"APIKEY":"12c2a03e1ec7c467c07ce30cab621734",
"APIKEY":"API-KEY-HERE",
"LKID":"0",
"VERSION":"0.3"
}
@@ -0,0 +1,8 @@
apiVersion: 1
providers:
- name: Default
type: file
folder: 'jambonz'
options:
path: /var/lib/grafana/dashboards
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,34 @@
# config file version
apiVersion: 1
# list of datasources that should be deleted from the database
deleteDatasources:
- name: InfluxDB
orgId: 1
- name: InfluxDB-Telegraf
orgId: 1
# list of datasources to insert/update depending
# whats available in the database
datasources:
- name: InfluxDB
type: influxdb
access: proxy
database: homer
user: grafana
url: http://127.0.0.1:8086
jsonData:
timeInterval: "15s"
# <bool> allow users to edit datasources from the UI.
editable: true
- name: InfluxDB-Telegraf
type: influxdb
access: proxy
database: telegraf
user: grafana
url: http://127.0.0.1:8086
jsonData:
timeInterval: "15s"
# <bool> allow users to edit datasources from the UI.
editable: true
@@ -0,0 +1,24 @@
# Fail2Ban configuration file
#
# Regexp to catch known spambots and software alike. Please verify
# that it is your intent to block IPs which were driven by
# above mentioned bots.
[Definition]
badbotscustom = EmailCollector|WebEMailExtrac|TrackBack/1\.02|sogou music spider|(?:Mozilla/\d+\.\d+ )?Jorgee
badbots = Atomic_Email_Hunter/4\.0|atSpider/1\.0|autoemailspider|bwh3_user_agent|China Local Browse 2\.6|ContactBot/0\.2|ContentSmartz|DataCha0s/2\.0|DBrowse 1\.4b|DBrowse 1\.4d|Demo Bot DOT 16b|Demo Bot Z 16b|DSurf15a 01|DSurf15a 71|DSurf15a 81|DSurf15a VA|EBrowse 1\.4b|Educate Search VxB|EmailSiphon|EmailSpider|EmailWolf 1\.00|ESurf15a 15|ExtractorPro|Franklin Locator 1\.8|FSurf15a 01|Full Web Bot 0416B|Full Web Bot 0516B|Full Web Bot 2816B|Guestbook Auto Submitter|Industry Program 1\.0\.x|ISC Systems iRc Search 2\.1|IUPUI Research Bot v 1\.9a|LARBIN-EXPERIMENTAL \(efp@gmx\.net\)|LetsCrawl\.com/1\.0 \+http\://letscrawl\.com/|Lincoln State Web Browser|LMQueueBot/0\.2|LWP\:\:Simple/5\.803|Mac Finder 1\.0\.xx|MFC Foundation Class Library 4\.0|Microsoft URL Control - 6\.00\.8xxx|Missauga Locate 1\.0\.0|Missigua Locator 1\.9|Missouri College Browse|Mizzu Labs 2\.2|Mo College 1\.9|MVAClient|Mozilla/2\.0 \(compatible; NEWT ActiveX; Win32\)|Mozilla/3\.0 \(compatible; Indy Library\)|Mozilla/3\.0 \(compatible; scan4mail \(advanced version\) http\://www\.peterspages\.net/?scan4mail\)|Mozilla/4\.0 \(compatible; Advanced Email Extractor v2\.xx\)|Mozilla/4\.0 \(compatible; Iplexx Spider/1\.0 http\://www\.iplexx\.at\)|Mozilla/4\.0 \(compatible; MSIE 5\.0; Windows NT; DigExt; DTS Agent|Mozilla/4\.0 efp@gmx\.net|Mozilla/5\.0 \(Version\: xxxx Type\:xx\)|NameOfAgent \(CMS Spider\)|NASA Search 1\.0|Nsauditor/1\.x|PBrowse 1\.4b|PEval 1\.4b|Poirot|Port Huron Labs|Production Bot 0116B|Production Bot 2016B|Production Bot DOT 3016B|Program Shareware 1\.0\.2|PSurf15a 11|PSurf15a 51|PSurf15a VA|psycheclone|RSurf15a 41|RSurf15a 51|RSurf15a 81|searchbot admin@google\.com|ShablastBot 1\.0|snap\.com beta crawler v0|Snapbot/1\.0|Snapbot/1\.0 \(Snap Shots&#44; \+http\://www\.snap\.com\)|sogou develop spider|Sogou Orion spider/3\.0\(\+http\://www\.sogou\.com/docs/help/webmasters\.htm#07\)|sogou spider|Sogou web spider/3\.0\(\+http\://www\.sogou\.com/docs/help/webmasters\.htm#07\)|sohu agent|SSurf15a 11 |TSurf15a 11|Under the Rainbow 2\.2|User-Agent\: Mozilla/4\.0 \(compatible; MSIE 6\.0; Windows NT 5\.1\)|VadixBot|WebVulnCrawl\.unknown/1\.0 libwww-perl/5\.803|Wells Search II|WEP Search 00
failregex = ^<HOST> -.*"(GET|POST|HEAD).*HTTP.*"(?:%(badbots)s|%(badbotscustom)s)"$
ignoreregex =
datepattern = ^[^\[]*\[({DATE})
{^LN-BEG}
# DEV Notes:
# List of bad bots fetched from http://www.user-agents.org
# Generated on Thu Nov 7 14:23:35 PST 2013 by files/gen_badbots.
#
# Author: Yaroslav Halchenko
@@ -0,0 +1,8 @@
[nginx-badbots]
enabled = true
port = http,https
filter = nginx-badbots
logpath = /var/log/nginx/access.log
maxretry = 1
bantime = 86400
@@ -0,0 +1,5 @@
[Definition]
failregex = ^<HOST> -.*GET .*/~.*
ignoreregex =
@@ -0,0 +1,8 @@
[nginx-nohome]
enabled = true
port = http,https
filter = nginx-nohome
logpath = /var/log/nginx/access.log
maxretry = 1
bantime = 86400
@@ -0,0 +1,5 @@
[Definition]
failregex = ^<HOST> -.*GET http.*
ignoreregex =
@@ -0,0 +1,8 @@
[nginx-noproxy]
enabled = true
port = http,https
filter = nginx-noproxy
logpath = /var/log/nginx/access.log
maxretry = 1
bantime = 86400
@@ -0,0 +1,5 @@
[Definition]
failregex = ^<HOST> -.*GET.*(\.php|\.asp|\.exe|\.pl|\.cgi|\.scgi)
ignoreregex =
@@ -0,0 +1,8 @@
[nginx-noscript]
enabled = true
port = http,https
filter = nginx-noscript
logpath = /var/log/nginx/access.log
maxretry = 1
bantime = 86400
@@ -0,0 +1,12 @@
server {
listen 80;
server_name api.your_domain.com; # enter the app sub-domain that you setup in 11
location / {
proxy_pass http://localhost:3000; # point the reverse proxy to the api server on port 3000
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
@@ -0,0 +1,41 @@
server {
listen 80;
server_name _;
location /api/ {
rewrite ^/api/(.*)$ /$1 break;
proxy_pass http://localhost:3002;
proxy_set_header Host $host;
}
location / {
proxy_pass http://localhost:3001;
proxy_set_header Host $host;
}
}
server {
listen 80;
server_name grafana.your_domain.com;
location / {
proxy_pass http://localhost:3010;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
server {
listen 80;
server_name homer.your_domain.com;
location / {
proxy_pass http://localhost:9080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
@@ -0,0 +1,12 @@
server {
listen 80;
server_name grafana.your_domain.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
@@ -0,0 +1,12 @@
server {
listen 80;
server_name homer.your_domain.com;
location / {
proxy_pass http://localhost:9080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
@@ -0,0 +1,12 @@
server {
listen 80;
server_name public-apps.your_domain.com;
location / {
proxy_pass http://localhost:3010;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
@@ -6,12 +6,14 @@ After=syslog.target network.target local-fs.target
[Service]
; service
Type=forking
Environment="LD_LIBRARY_PATH=/usr/local/lib/"
ExecStartPre=/bin/sh -c 'systemctl set-environment LOCAL_IP=`curl -s http://169.254.169.254/latest/meta-data/local-ipv4`'
ExecStartPre=/bin/sh -c 'systemctl set-environment PUBLIC_IP=`curl -s http://169.254.169.254/latest/meta-data/public-ipv4`'
ExecStart=/usr/local/bin/rtpengine \
--interface private/${LOCAL_IP} \
--interface public/${LOCAL_IP}!${PUBLIC_IP} \
--listen-ng=22222 \
--listen-http=8080 \
--listen-udp=12222 \
--listen-cli=127.0.0.1:9900 \
--pidfile /var/run/rtpengine.pid \
@@ -1,11 +1,13 @@
#!/bin/bash
INSTANCE_ID=$1
cd /usr/local/src/
git clone https://github.com/palner/apiban.git
sudo mkdir /usr/local/bin/apiban && sudo chmod 0755 /usr/local/bin/apiban
sudo cp -r /usr/local/src/apiban/clients/go/apiban-iptables-client /usr/local/bin/apiban && sudo chmod +x /usr/local/bin/apiban/apiban-iptables-client
sudo cp /tmp/config.json /usr/local/bin/apiban/config.json
sudo chmod 0644 /usr/local/bin/apiban/config.json
APIBANKEY=$(curl -X POST -d "{\"uuid\": \"${INSTANCE_ID}\"}" -s https://apiban.org/api/newuser/drachito/add | jq -r '.ApiKey')
sudo sed -i -e "s/API-KEY-HERE/${APIBANKEY}/g" /usr/local/bin/apiban/config.json
sudo cp /tmp/apiban.logrotate /etc/logrotate.d/apiban-client
sudo chmod 0644 /etc/logrotate.d/apiban-client
cd /usr/local/bin/apiban/
@@ -2,17 +2,9 @@
VERSION=$1
cd /home/admin
mkdir apps
cp /tmp/ecosystem.config.js apps
cd apps
git clone https://github.com/jambonz/sbc-outbound.git -b ${VERSION}
git clone https://github.com/jambonz/sbc-inbound.git -b ${VERSION}
git clone https://github.com/jambonz/sbc-registrar.git -b ${VERSION}
git clone https://github.com/jambonz/sbc-call-router.git -b ${VERSION}
git clone https://github.com/jambonz/jambonz-api-server.git -b ${VERSION}
git clone https://github.com/jambonz/jambonz-webapp.git -b ${VERSION}
cd /home/admin/apps/sbc-inbound && sudo npm install --unsafe-perm
cd /home/admin/apps/sbc-outbound && sudo npm install --unsafe-perm
cd /home/admin/apps/sbc-registrar && sudo npm install --unsafe-perm
@@ -26,3 +26,20 @@ EOF
sudo cp /tmp/drachtio-fail2ban.conf /etc/fail2ban/filter.d/drachtio.conf
sudo chmod 0644 /etc/fail2ban/filter.d/drachtio.conf
# add nginx jails and filters
sudo cp /tmp/nginx-noscript.jail /etc/fail2ban/jail.d/nginx-noscript.conf
sudo cp /tmp/nginx-noproxy.jail /etc/fail2ban/jail.d/nginx-noproxy.conf
sudo cp /tmp/nginx-nohome.jail /etc/fail2ban/jail.d/nginx-nohome.conf
sudo cp /tmp/nginx-badbots.jail /etc/fail2ban/jail.d/nginx-badbots.conf
sudo cp /tmp/nginx-noscript.filter /etc/fail2ban/filter.d/nginx-noscript.conf
sudo cp /tmp/nginx-noproxy.filter /etc/fail2ban/filter.d/nginx-noproxy.conf
sudo cp /tmp/nginx-nohome.filter /etc/fail2ban/filter.d/nginx-nohome.conf
sudo cp /tmp/nginx-badbots.filter /etc/fail2ban/filter.d/nginx-badbots.conf
sudo chmod 0644 /etc/fail2ban/jail.d/*.conf
sudo chmod 0644 /etc/fail2ban/filter.d/*.conf
sudo systemctl enable fail2ban
sudo systemctl restart fail2ban
@@ -0,0 +1,18 @@
#!/bin/bash
curl -sL https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt-get install -y grafana
sudo mkdir /var/lib/grafana/dashboards
sudo mv /tmp/grafana-dashboard-default.yaml /etc/grafana/provisioning/dashboards/default.yaml
sudo mv /tmp/grafana-datasource.yml /etc/grafana/provisioning/datasources/datasource.yml
sudo mv /tmp/grafana-dashboard-heplify.json /var/lib/grafana/dashboards
sudo mv /tmp/grafana-dashboard-jambonz.json /var/lib/grafana/dashboards
sudo mv /tmp/grafana-dashboard-servers.json /var/lib/grafana/dashboards
sudo chown -R grafana:grafana /var/lib/grafana/dashboards
sudo chown -R grafana:grafana /etc/grafana/provisioning/dashboards
sudo systemctl enable grafana-server
sudo systemctl start grafana-server
@@ -0,0 +1,24 @@
#!/bin/bash
DB_USER=$2
DB_PASS=$3
curl -s https://packagecloud.io/install/repositories/qxip/sipcapture/script.deb.sh | sudo bash
sudo apt-get install -y homer-app heplify-server
sudo sed -i -e "s/homer_user/$DB_USER/g" /usr/local/homer/etc/webapp_config.json
sudo sed -i -e "s/homer_password/$DB_PASS/g" /usr/local/homer/etc/webapp_config.json
sudo homer-app -create-table-db-config
sudo homer-app -populate-table-db-config
sudo sed -i -e "s/DBUser\s*=\s*\"postgres\"/DBUser = \"$DB_USER\"/g" /etc/heplify-server.toml
sudo sed -i -e "s/DBPass\s*=\s*\"\"/DBPass = \"$DB_PASS\"/g" /etc/heplify-server.toml
sudo sed -i -e "s/PromAddr\s*=\s*\"\"/PromAddr = \"0.0.0.0:9096\"/g" /etc/heplify-server.toml
sudo sed -i -e "s/AlegIDs\s*=\s*\[\]/AlegIDs = \[\"X-CID\"]/g" /etc/heplify-server.toml
sudo sed -i -e "s/CustomHeader\s*=\s*\[\]/CustomHeader = \[\"X-Application-Sid\", \"X-Originating-Carrier\", \"X-MS-Teams-Tenant-FQDN\", \"X-Authenticated-User\"]/g" /etc/heplify-server.toml
sudo systemctl enable homer-app
sudo systemctl restart homer-app
sudo systemctl status homer-app
sudo systemctl enable heplify-server
sudo systemctl restart heplify-server
sudo systemctl status heplify-server
@@ -0,0 +1,8 @@
#!/bin/bash
sudo apt-get install -y apt-transport-https
curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
echo "deb https://repos.influxdata.com/debian stretch stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo apt-get update
sudo apt-get install -y influxdb
sudo systemctl enable influxdb
sudo systemctl start influxdb
@@ -0,0 +1,14 @@
#!/bin/bash
echo "installing nginx"
sudo apt-get install -y nginx
cd /etc/nginx/sites-available
sudo mv /tmp/nginx.default default
sudo systemctl enable nginx
sudo systemctl restart nginx
sudo systemctl status nginx
sudo journalctl -xe
@@ -0,0 +1,18 @@
#!/bin/bash
DB_USER=$2
DB_PASS=$3
echo "creating postgresql databases for homer with user ${DB_USER} and password ${DB_PASS}"
sudo apt-get update
sudo apt-get install -y postgresql
sudo systemctl daemon-reload
sudo systemctl enable postgresql
sudo systemctl restart postgresql
sudo -u postgres psql -c "CREATE DATABASE homer_config;"
sudo -u postgres psql -c "CREATE DATABASE homer_data;"
sudo -u postgres psql -c "CREATE ROLE ${DB_USER} WITH SUPERUSER LOGIN PASSWORD '${DB_PASS}';"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE homer_config to ${DB_USER};"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE homer_data to ${DB_USER};"
@@ -7,6 +7,12 @@ cd /usr/local/src
git clone https://github.com/BelledonneCommunications/bcg729.git
cd bcg729
cmake . -DCMAKE_INSTALL_PREFIX=/usr && make && sudo make install chdir=/usr/local/src/bcg729
cd /usr/local/src
git clone https://github.com/warmcat/libwebsockets.git -b v3.2.3
cd /usr/local/src/libwebsockets
sudo mkdir -p build && cd build && sudo cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo && sudo make && sudo make install
cd /usr/local/src
git clone https://github.com/sipwise/rtpengine.git -b ${VERSION}
cd rtpengine/daemon
@@ -15,3 +21,4 @@ cp /usr/local/src/rtpengine/daemon/rtpengine /usr/local/bin
sudo mv /tmp/rtpengine.service /etc/systemd/system
sudo chmod 644 /etc/systemd/system/rtpengine.service
sudo systemctl enable rtpengine
sudo systemctl start rtpengine
@@ -1,15 +1,11 @@
#!/bin/bash
echo installing telegraf..
curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
echo "deb https://repos.influxdata.com/debian stretch stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo apt-get update
sudo apt-get install -y telegraf
if [ "$1" == "yes" ]; then
sudo cp /tmp/telegraf.conf /etc/telegraf/telegraf.conf
echo installing telegraf..
curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
echo "deb https://repos.influxdata.com/debian stretch stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo apt-get update
sudo apt-get install -y telegraf
sudo cp /tmp/telegraf.conf /etc/telegraf/telegraf.conf
sudo systemctl enable telegraf
sudo systemctl start telegraf
fi
sudo systemctl enable telegraf
sudo systemctl start telegraf
+55 -17
View File
@@ -2,16 +2,17 @@
"variables": {
"region": "us-east-1",
"ssh_username": "admin",
"ami_description": "jambonz SBC SIP+RTP",
"drachtio_version": "main",
"jambonz_version": "master",
"install_datadog": "no",
"install_telegraf": "yes",
"instance_type": "t2.medium",
"rtp_engine_version": "mr8.5",
"ami_description": "jambonz SBC SIP+RTP+Webserver+monitoring",
"drachtio_version": "v0.8.10",
"jambonz_version": "v0.6.3",
"install_influxdb": "yes",
"install_homer": "yes",
"homer_user": "homer_user",
"homer_password": "XcapJTqy11LnsYRtxXGPTYQkAnI",
"instance_type": "t2.xlarge",
"rtp_engine_version": "mr9.3.1.8",
"rtp_engine_min_port": "40000",
"rtp_engine_max_port": "60000"
},
"builders": [{
"type": "amazon-ebs",
@@ -27,12 +28,12 @@
},
"instance_type": "{{user `instance_type`}}",
"ssh_username": "{{user `ssh_username`}}",
"ami_name": "jambonz-sbc-sip-rtp-{{isotime |clean_resource_name }}",
"ami_name": "jambonz-sbc-sip-rtp-{{user `jambonz_version`}}-{{isotime |clean_resource_name }}",
"ami_description": "{{user `ami_description`}}",
"launch_block_device_mappings": [
{
"device_name": "/dev/xvda",
"volume_size": 40,
"volume_size": 60,
"volume_type": "gp2",
"delete_on_termination": true
}
@@ -56,14 +57,23 @@
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done",
"sudo apt-get update",
"sudo apt-get -y install lsof python lsof gcc g++ make cmake build-essential git autoconf automake default-mysql-client redis-tools \\",
"curl telnet libtool libtool-bin libssl-dev libcurl4-openssl-dev libz-dev systemd-coredump liblz4-tool \\",
"jq curl telnet libtool libtool-bin libssl-dev libcurl4-openssl-dev libz-dev systemd-coredump liblz4-tool \\",
"iptables-dev libavformat-dev liblua5.1-0-dev libavfilter-dev libavcodec-dev libswresample-dev \\",
"libevent-dev libpcap-dev libxmlrpc-core-c3-dev markdown libjson-glib-dev lsb-release \\",
"libhiredis-dev gperf libspandsp-dev default-libmysqlclient-dev htop dnsutils gdb \\",
"libhiredis-dev gperf libspandsp-dev default-libmysqlclient-dev htop dnsutils gdb certbot python-certbot-nginx \\",
"gnupg2 wget pkg-config ca-certificates libjpeg-dev libsqlite3-dev libpcre3-dev libldns-dev \\",
"libspeex-dev libspeexdsp-dev libedit-dev libtiff-dev yasm valgrind libswscale-dev haveged \\",
"libopus-dev libsndfile-dev libshout3-dev libmpg123-dev libmp3lame-dev libopusfile-dev fail2ban",
"sudo chmod a+w /usr/local/src"
"sudo chmod a+w /usr/local/src",
"ssh-keyscan github.com >> ~/.ssh/known_hosts",
"mkdir ~/apps",
"cd ~/apps",
"git clone git@github.com:jambonz/sbc-outbound.git -b {{user `jambonz_version`}}",
"git clone git@github.com:jambonz/sbc-inbound.git -b {{user `jambonz_version`}}",
"git clone git@github.com:jambonz/sbc-registrar.git -b {{user `jambonz_version`}}",
"git clone git@github.com:jambonz/sbc-call-router.git -b {{user `jambonz_version`}}",
"git clone git@github.com:jambonz/jambonz-api-server.git -b {{user `jambonz_version`}}",
"git clone git@github.com:jambonz/jambonz-webapp.git -b {{user `jambonz_version`}}"
]
},
{
@@ -77,18 +87,22 @@
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo '{{ .Path }}' {{user `install_datadog`}}",
"script": "scripts/install_datadog.sh"
"execute_command": "chmod +x {{ .Path }}; sudo '{{ .Path }}' {{user `install_homer`}} {{user `homer_user`}} {{user `homer_password`}}",
"script": "scripts/install_postgresql.sh"
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo '{{ .Path }}' {{user `install_telegraf`}}",
"script": "scripts/install_telegraf.sh"
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo '{{ .Path }}' {{build `ID`}}",
"script": "scripts/install_apiban.sh"
},
{
"type": "shell",
"script": "scripts/install_nginx.sh"
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo '{{ .Path }}' {{user `rtp_engine_version`}}",
@@ -103,6 +117,27 @@
"execute_command": "chmod +x {{ .Path }}; sudo '{{ .Path }}' {{user `drachtio_version`}}",
"script": "scripts/install_drachtio.sh"
},
{
"type": "shell",
"script": "scripts/install_fail2ban.sh"
},
{
"type": "shell",
"script": "scripts/install_telegraf.sh"
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo '{{ .Path }}' {{user `install_homer`}} {{user `homer_user`}} {{user `homer_password`}}",
"script": "scripts/install_homer.sh"
},
{
"type": "shell",
"script": "scripts/install_influxdb.sh"
},
{
"type": "shell",
"script": "scripts/install_grafana.sh"
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo '{{ .Path }}' {{user `jambonz_version`}}",
@@ -110,7 +145,10 @@
},
{
"type": "shell",
"script": "scripts/install_fail2ban.sh"
"inline": [
"sudo rm /root/.ssh/authorized_keys",
"sudo rm /home/admin/.ssh/authorized_keys"
]
}
]
}
+1 -1
View File
@@ -1,5 +1,5 @@
{
"APIKEY":"12c2a03e1ec7c467c07ce30cab621734",
"APIKEY":"API-KEY-HERE",
"LKID":"0",
"VERSION":"0.3"
}
@@ -1,13 +1,12 @@
module.exports = {
apps : [
{
name: 'jambonz-api-server',
cwd: '/home/admin/apps/jambonz-api-server',
name: 'sbc-options-handler',
cwd: '/home/admin/apps/sbc-options-handler',
script: 'app.js',
out_file: '/home/admin/.pm2/logs/jambonz-api-server.log',
err_file: '/home/admin/.pm2/logs/jambonz-api-server.log',
combine_logs: true,
instance_var: 'INSTANCE_ID',
out_file: '/home/admin/.pm2/logs/jambonz-sbc-options-handler.log',
err_file: '/home/admin/.pm2/logs/jambonz-sbc-options-handler.log',
exec_mode: 'fork',
instances: 1,
autorestart: true,
@@ -15,18 +14,20 @@ module.exports = {
max_memory_restart: '1G',
env: {
NODE_ENV: 'production',
JAMBONES_MYSQL_HOST: '${JAMBONES_MYSQL_HOST}',
JAMBONES_MYSQL_USER: '${JAMBONES_MYSQL_USER}',
JAMBONES_MYSQL_PASSWORD: '${JAMBONES_MYSQL_PASSWORD}',
JAMBONES_MYSQL_DATABASE: 'jambones',
JAMBONES_MYSQL_CONNECTION_LIMIT: 10,
JAMBONES_CLUSTER_ID: '${JAMBONES_CLUSTER_ID}',
JAMBONES_LOGLEVEL: 'info',
DRACHTIO_HOST: '127.0.0.1',
DRACHTIO_PORT: 9022,
DRACHTIO_SECRET: 'cymru',
JAMBONES_REDIS_HOST: '${JAMBONES_REDIS_HOST}',
JAMBONES_REDIS_PORT: 6379,
JAMBONES_LOGLEVEL: 'info',
JAMBONE_API_VERSION: 'v1',
JAMBONES_CLUSTER_ID: '${JAMBONES_CLUSTER_ID}',
HTTP_PORT: 3000
},
ENABLE_METRICS: 1,
STATS_HOST: '127.0.0.1',
STATS_PORT: 8125,
STATS_PROTOCOL: 'tcp',
STATS_TELEGRAF: 1,
JAMBONES_NETWORK_CIDR: '${VPC_CIDR}',
}
},
{
name: 'sbc-call-router',
@@ -1,11 +1,13 @@
#!/bin/bash
INSTANCE_ID=$1
cd /usr/local/src/
git clone https://github.com/palner/apiban.git
sudo mkdir /usr/local/bin/apiban && sudo chmod 0755 /usr/local/bin/apiban
sudo cp -r /usr/local/src/apiban/clients/go/apiban-iptables-client /usr/local/bin/apiban && sudo chmod +x /usr/local/bin/apiban/apiban-iptables-client
sudo cp /tmp/config.json /usr/local/bin/apiban/config.json
sudo chmod 0644 /usr/local/bin/apiban/config.json
APIBANKEY=$(curl -X POST -d "{\"uuid\": \"${INSTANCE_ID}\"}" -s https://apiban.org/api/newuser/drachito/add | jq -r '.ApiKey')
sudo sed -i -e "s/API-KEY-HERE/${APIBANKEY}/g" /usr/local/bin/apiban/config.json
sudo cp /tmp/apiban.logrotate /etc/logrotate.d/apiban-client
sudo chmod 0644 /etc/logrotate.d/apiban-client
cd /usr/local/bin/apiban/
@@ -10,15 +10,13 @@ git clone https://github.com/jambonz/sbc-outbound.git -b ${VERSION}
git clone https://github.com/jambonz/sbc-inbound.git -b ${VERSION}
git clone https://github.com/jambonz/sbc-registrar.git -b ${VERSION}
git clone https://github.com/jambonz/sbc-call-router.git -b ${VERSION}
git clone https://github.com/jambonz/jambonz-api-server.git -b ${VERSION}
git clone https://github.com/jambonz/jambonz-webapp.git -b ${VERSION}
git clone https://github.com/jambonz/sbc-options-handler.git -b ${VERSION}
cd /home/admin/apps/sbc-inbound && sudo npm install --unsafe-perm
cd /home/admin/apps/sbc-outbound && sudo npm install --unsafe-perm
cd /home/admin/apps/sbc-registrar && sudo npm install --unsafe-perm
cd /home/admin/apps/sbc-call-router && sudo npm install --unsafe-perm
cd /home/admin/apps/jambonz-api-server && sudo npm install --unsafe-perm
cd /home/admin/apps/jambonz-webapp && sudo npm install --unsafe-perm && npm run build
cd /home/admin/apps/sbc-options-handler && sudo npm install --unsafe-perm
sudo -u admin bash -c "pm2 install pm2-logrotate"
sudo -u admin bash -c "pm2 set pm2-logrotate:max_size 1G"
@@ -26,3 +26,6 @@ EOF
sudo cp /tmp/drachtio-fail2ban.conf /etc/fail2ban/filter.d/drachtio.conf
sudo chmod 0644 /etc/fail2ban/filter.d/drachtio.conf
sudo systemctl enable fail2ban
sudo systemctl restart fail2ban
+20 -11
View File
@@ -4,8 +4,8 @@
"ssh_username": "admin",
"ami_description": "jambonz SBC SIP",
"instance_type": "t2.medium",
"drachtio_version": "main",
"jambonz_version": "master",
"drachtio_version": "v0.8.10",
"jambonz_version": "v0.6.0",
"install_datadog": "no",
"install_telegraf": "yes"
},
@@ -23,12 +23,12 @@
},
"instance_type": "{{user `instance_type`}}",
"ssh_username": "{{user `ssh_username`}}",
"ami_name": "jambonz-sbc-sip-{{isotime |clean_resource_name }}",
"ami_name": "jambonz-sbc-sip-{{user `jambonz_version`}}-{{isotime |clean_resource_name }}",
"ami_description": "{{user `ami_description`}}",
"launch_block_device_mappings": [
{
"device_name": "/dev/xvda",
"volume_size": 40,
"volume_size": 60,
"volume_type": "gp2",
"delete_on_termination": true
}
@@ -51,15 +51,23 @@
"inline": [
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done",
"sudo apt-get update",
"sudo apt-get -y install python gcc g++ make cmake build-essential git autoconf automake mysql-client redis-tools \\",
"curl telnet libtool libtool-bin libssl-dev libcurl4-openssl-dev libz-dev systemd-coredump liblz4-tool \\",
"sudo apt-get -y install python gcc g++ make cmake build-essential git autoconf automake default-mysql-client redis-tools \\",
"jq curl telnet libtool libtool-bin libssl-dev libcurl4-openssl-dev libz-dev systemd-coredump liblz4-tool \\",
"iptables-dev libavformat-dev liblua5.1-0-dev libavfilter-dev libavcodec-dev libswresample-dev \\",
"libevent-dev libpcap-dev libxmlrpc-core-c3-dev markdown libjson-glib-dev lsb-release \\",
"libhiredis-dev gperf libspandsp-dev default-libmysqlclient-dev htop dnsutils gdb \\",
"gnupg2 wget pkg-config ca-certificates libjpeg-dev libsqlite3-dev libpcre3-dev libldns-dev \\",
"libspeex-dev libspeexdsp-dev libedit-dev libtiff-dev yasm valgrind libswscale-dev haveged \\",
"libopus-dev libsndfile-dev libshout3-dev libmpg123-dev libmp3lame-dev libopusfile-dev fail2ban",
"sudo chmod a+w /usr/local/src"
"sudo chmod a+w /usr/local/src",
"ssh-keyscan github.com >> ~/.ssh/known_hosts",
"mkdir ~/apps",
"cd ~/apps",
"git clone git@github.com:jambonz/sbc-options-handler.git",
"git clone git@github.com:jambonz/sbc-outbound.git -b {{user `jambonz_version`}}",
"git clone git@github.com:jambonz/sbc-inbound.git -b {{user `jambonz_version`}}",
"git clone git@github.com:jambonz/sbc-registrar.git -b {{user `jambonz_version`}}",
"git clone git@github.com:jambonz/sbc-call-router.git"
]
},
{
@@ -67,6 +75,11 @@
"source": "files/",
"destination": "/tmp"
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo '{{ .Path }}' {{build `ID`}}",
"script": "scripts/install_apiban.sh"
},
{
"type": "shell",
"script": "scripts/install_chrony.sh"
@@ -81,10 +94,6 @@
"execute_command": "chmod +x {{ .Path }}; sudo '{{ .Path }}' {{user `install_telegraf`}}",
"script": "scripts/install_telegraf.sh"
},
{
"type": "shell",
"script": "scripts/install_apiban.sh"
},
{
"type": "shell",
"script": "scripts/install_nodejs.sh"
+102
View File
@@ -0,0 +1,102 @@
# packer-jambonz-mini
A [packer](https://www.packer.io/) template to build an AMI containing everything needed to run jambonz on a single EC2 instance. The base linux distro is Debian 9 (stretch).
## Installing
```
$ packer build -color=false template.json
```
### variables
There are many variables that can be specified on the `packer build` command line; however defaults (which are shown below) are appropriate for building an "all in one" jambonz server, so you generally should not need to specify values.
```
"region": "us-east-1"
```
The region to create the AMI in
```
"ami_description": "EC2 AMI jambonz mini"
```
AMI description.
```
"instance_type": "t2.medium"
```
EC2 Instance type to use when building the AMI.
```
"install_drachtio": "true"
```
whether to install drachtio
```
"install_nodejs": "false",
```
whether to install Node.js
```
"install_rtpengine": "true",
```
whether to install rtpengine
```
"install_freeswitch": "true",
```
whether to install freeswitch
```
"install_drachtio_fail2ban": "true",
```
whether to install fail2ban with drachtio filter
```
"install_redis": "true",
```
whether to install redis
```
"drachtio_version": "v0.8.3"
```
drachtio tag or branch to build
```
"nodejs_version": "v10.16.2",
```
Node.js version to install
```
"freeswitch_bind_cloud_ip": "true"
```
If freeswitch is enabled, and cloud_provider is not none then this variable dictates whether freeswitch should bind its sip and rtp ports to the cloud public address (versus the local ipv4 address).
```
"mod_audio_fork_subprotocol": "audio.jambonz.org"
```
websocket subprotocol name used by freeswitch module mod_audio_fork
```
"mod_audio_fork_service_threads": "3",
```
number of libwebsocket service threads used by freeswitch module mod_audio_fork
``
"mod_audio_fork_buffer_secs": "2",
```
max number of seconds of audio to buffer by freeswitch module mod_audio_fork
```
"freeswitch_build_with_grpc:: "true"
```
whether to build support for google speech and text-to-speech services
```
"remove_source": "true"
```
whether to remove source build directories, or leave them on the instance
```
"cloud_provider": "aws"
```
Cloud provider the AMI will be built on.
@@ -0,0 +1,27 @@
module.exports = {
apps : [
{
name: 'jambonz-api-server',
cwd: '/home/admin/apps/jambonz-api-server',
script: 'app.js',
out_file: '/home/admin/.pm2/logs/jambonz-api-server.log',
err_file: '/home/admin/.pm2/logs/jambonz-api-server.log',
combine_logs: true,
instance_var: 'INSTANCE_ID',
exec_mode: 'fork',
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '1G',
env: {
NODE_ENV: 'production',
},
},
{
name: 'jambonz-webapp',
script: 'npm',
cwd: '/home/admin/apps/jambonz-webapp',
args: 'run serve'
}
]
};
@@ -0,0 +1,24 @@
# Fail2Ban configuration file
#
# Regexp to catch known spambots and software alike. Please verify
# that it is your intent to block IPs which were driven by
# above mentioned bots.
[Definition]
badbotscustom = EmailCollector|WebEMailExtrac|TrackBack/1\.02|sogou music spider|(?:Mozilla/\d+\.\d+ )?Jorgee
badbots = Atomic_Email_Hunter/4\.0|atSpider/1\.0|autoemailspider|bwh3_user_agent|China Local Browse 2\.6|ContactBot/0\.2|ContentSmartz|DataCha0s/2\.0|DBrowse 1\.4b|DBrowse 1\.4d|Demo Bot DOT 16b|Demo Bot Z 16b|DSurf15a 01|DSurf15a 71|DSurf15a 81|DSurf15a VA|EBrowse 1\.4b|Educate Search VxB|EmailSiphon|EmailSpider|EmailWolf 1\.00|ESurf15a 15|ExtractorPro|Franklin Locator 1\.8|FSurf15a 01|Full Web Bot 0416B|Full Web Bot 0516B|Full Web Bot 2816B|Guestbook Auto Submitter|Industry Program 1\.0\.x|ISC Systems iRc Search 2\.1|IUPUI Research Bot v 1\.9a|LARBIN-EXPERIMENTAL \(efp@gmx\.net\)|LetsCrawl\.com/1\.0 \+http\://letscrawl\.com/|Lincoln State Web Browser|LMQueueBot/0\.2|LWP\:\:Simple/5\.803|Mac Finder 1\.0\.xx|MFC Foundation Class Library 4\.0|Microsoft URL Control - 6\.00\.8xxx|Missauga Locate 1\.0\.0|Missigua Locator 1\.9|Missouri College Browse|Mizzu Labs 2\.2|Mo College 1\.9|MVAClient|Mozilla/2\.0 \(compatible; NEWT ActiveX; Win32\)|Mozilla/3\.0 \(compatible; Indy Library\)|Mozilla/3\.0 \(compatible; scan4mail \(advanced version\) http\://www\.peterspages\.net/?scan4mail\)|Mozilla/4\.0 \(compatible; Advanced Email Extractor v2\.xx\)|Mozilla/4\.0 \(compatible; Iplexx Spider/1\.0 http\://www\.iplexx\.at\)|Mozilla/4\.0 \(compatible; MSIE 5\.0; Windows NT; DigExt; DTS Agent|Mozilla/4\.0 efp@gmx\.net|Mozilla/5\.0 \(Version\: xxxx Type\:xx\)|NameOfAgent \(CMS Spider\)|NASA Search 1\.0|Nsauditor/1\.x|PBrowse 1\.4b|PEval 1\.4b|Poirot|Port Huron Labs|Production Bot 0116B|Production Bot 2016B|Production Bot DOT 3016B|Program Shareware 1\.0\.2|PSurf15a 11|PSurf15a 51|PSurf15a VA|psycheclone|RSurf15a 41|RSurf15a 51|RSurf15a 81|searchbot admin@google\.com|ShablastBot 1\.0|snap\.com beta crawler v0|Snapbot/1\.0|Snapbot/1\.0 \(Snap Shots&#44; \+http\://www\.snap\.com\)|sogou develop spider|Sogou Orion spider/3\.0\(\+http\://www\.sogou\.com/docs/help/webmasters\.htm#07\)|sogou spider|Sogou web spider/3\.0\(\+http\://www\.sogou\.com/docs/help/webmasters\.htm#07\)|sohu agent|SSurf15a 11 |TSurf15a 11|Under the Rainbow 2\.2|User-Agent\: Mozilla/4\.0 \(compatible; MSIE 6\.0; Windows NT 5\.1\)|VadixBot|WebVulnCrawl\.unknown/1\.0 libwww-perl/5\.803|Wells Search II|WEP Search 00
failregex = ^<HOST> -.*"(GET|POST|HEAD).*HTTP.*"(?:%(badbots)s|%(badbotscustom)s)"$
ignoreregex =
datepattern = ^[^\[]*\[({DATE})
{^LN-BEG}
# DEV Notes:
# List of bad bots fetched from http://www.user-agents.org
# Generated on Thu Nov 7 14:23:35 PST 2013 by files/gen_badbots.
#
# Author: Yaroslav Halchenko
@@ -0,0 +1,8 @@
[nginx-badbots]
enabled = true
port = http,https
filter = nginx-badbots
logpath = /var/log/nginx/access.log
maxretry = 1
bantime = 86400
@@ -0,0 +1,5 @@
[Definition]
failregex = ^<HOST> -.*GET .*/~.*
ignoreregex =
@@ -0,0 +1,8 @@
[nginx-nohome]
enabled = true
port = http,https
filter = nginx-nohome
logpath = /var/log/nginx/access.log
maxretry = 1
bantime = 86400
@@ -0,0 +1,5 @@
[Definition]
failregex = ^<HOST> -.*GET http.*
ignoreregex =
@@ -0,0 +1,8 @@
[nginx-noproxy]
enabled = true
port = http,https
filter = nginx-noproxy
logpath = /var/log/nginx/access.log
maxretry = 1
bantime = 86400
@@ -0,0 +1,5 @@
[Definition]
failregex = ^<HOST> -.*GET.*(\.php|\.asp|\.exe|\.pl|\.cgi|\.scgi)
ignoreregex =
@@ -0,0 +1,8 @@
[nginx-noscript]
enabled = true
port = http,https
filter = nginx-noscript
logpath = /var/log/nginx/access.log
maxretry = 1
bantime = 86400
@@ -0,0 +1,41 @@
server {
listen 80;
server_name _;
location /api/ {
rewrite ^/api/(.*)$ /$1 break;
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
}
location / {
proxy_pass http://localhost:3001;
proxy_set_header Host $host;
}
}
server {
listen 80;
server_name grafana.your_domain.com;
location / {
proxy_pass http://MONITORING_SERVER_IP:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
server {
listen 80;
server_name homer.your_domain.com;
location / {
proxy_pass http://MONITORING_SERVER_IP:9080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
@@ -0,0 +1,12 @@
server {
listen 80;
server_name public-apps.your_domain.com;
location / {
proxy_pass http://localhost:3010;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
File diff suppressed because it is too large. Load diff
+16
View File
@@ -0,0 +1,16 @@
#!/bin/bash
VERSION=$1
cd /home/admin/apps
cp /tmp/ecosystem.config.js .
cd /home/admin/apps/jambonz-api-server && sudo npm install --unsafe-perm
cd /home/admin/apps/jambonz-webapp && sudo npm install --unsafe-perm && npm run build
cd /home/admin/apps/public-apps && sudo npm install --unsafe-perm
sudo -u admin bash -c "pm2 install pm2-logrotate"
sudo -u admin bash -c "pm2 set pm2-logrotate:max_size 1G"
sudo -u admin bash -c "pm2 set pm2-logrotate:retain 5"
sudo -u admin bash -c "pm2 set pm2-logrotate:compress true"
sudo chown -R admin:admin /home/admin/apps
@@ -0,0 +1,5 @@
#!/bin/bash
sudo apt-get update
sudo apt-get install -y chrony
sudo systemctl enable chrony
@@ -0,0 +1,20 @@
#!/bin/bash
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
# add nginx jails and filters
sudo cp /tmp/nginx-noscript.jail /etc/fail2ban/jail.d/nginx-noscript.conf
sudo cp /tmp/nginx-noproxy.jail /etc/fail2ban/jail.d/nginx-noproxy.conf
sudo cp /tmp/nginx-nohome.jail /etc/fail2ban/jail.d/nginx-nohome.conf
sudo cp /tmp/nginx-badbots.jail /etc/fail2ban/jail.d/nginx-badbots.conf
sudo cp /tmp/nginx-noscript.filter /etc/fail2ban/filter.d/nginx-noscript.conf
sudo cp /tmp/nginx-noproxy.filter /etc/fail2ban/filter.d/nginx-noproxy.conf
sudo cp /tmp/nginx-nohome.filter /etc/fail2ban/filter.d/nginx-nohome.conf
sudo cp /tmp/nginx-badbots.filter /etc/fail2ban/filter.d/nginx-badbots.conf
sudo chmod 0644 /etc/fail2ban/jail.d/*.conf
sudo chmod 0644 /etc/fail2ban/filter.d/*.conf
sudo systemctl enable fail2ban
sudo systemctl restart fail2ban
@@ -0,0 +1,10 @@
#!/bin/bash
echo "installing nginx"
sudo apt-get install -y nginx
sudo systemctl enable nginx
sudo systemctl restart nginx
# NB: customization of sites-availble handled in terraform / cloudformation userdatra scripts
@@ -0,0 +1,3 @@
#!/bin/bash
curl -sL https://deb.nodesource.com/setup_14.x | sudo bash - && sudo apt-get install -y nodejs
sudo npm install -g pino-pretty pm2 pm2-logrotate
@@ -0,0 +1,15 @@
#!/bin/bash
if [ "$1" == "yes" ]; then
echo installing telegraf..
curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
echo "deb https://repos.influxdata.com/debian stretch stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo apt-get update
sudo apt-get install -y telegraf
sudo cp /tmp/telegraf.conf /etc/telegraf/telegraf.conf
sudo systemctl enable telegraf
sudo systemctl start telegraf
fi
+101
View File
@@ -0,0 +1,101 @@
{
"variables": {
"region": "us-east-1",
"ssh_username": "admin",
"ami_description": "jambonz webserver",
"instance_type": "t2.medium",
"drachtio_version": "v0.8.10",
"jambonz_version": "v0.6.1",
"install_datadog": "no",
"install_telegraf": "yes"
},
"builders": [{
"type": "amazon-ebs",
"region": "{{user `region`}}",
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"name": "debian-10-amd64-*",
"root-device-type": "ebs"
},
"owners": ["136693071363"],
"most_recent": true
},
"instance_type": "{{user `instance_type`}}",
"ssh_username": "{{user `ssh_username`}}",
"ami_name": "jambonz-webserver-{{user `jambonz_version`}}-{{isotime |clean_resource_name }}",
"ami_description": "{{user `ami_description`}}",
"launch_block_device_mappings": [
{
"device_name": "/dev/xvda",
"volume_size": 80,
"volume_type": "gp2",
"delete_on_termination": true
}
],
"security_group_filter": {
"filters": {
"tag:Class": "packer"
}
},
"tags": {
"Name": "jambonz-webserver"
},
"run_tags": {
"Name": "jambonz-webserver-build"
}
}],
"provisioners": [
{
"type": "shell",
"inline": [
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done",
"sudo apt-get update",
"sudo apt-get -y install python gcc g++ make cmake build-essential git autoconf automake default-mysql-client redis-tools \\",
"curl telnet libtool libtool-bin libssl-dev libcurl4-openssl-dev libz-dev systemd-coredump liblz4-tool \\",
"iptables-dev libavformat-dev lsb-release fail2ban \\",
"nginx python3-certbot-nginx default-libmysqlclient-dev htop dnsutils gdb \\",
"gnupg2 wget pkg-config ca-certificates libjpeg-dev libsqlite3-dev libpcre3-dev libldns-dev",
"sudo chmod a+w /usr/local/src",
"ssh-keyscan github.com >> ~/.ssh/known_hosts",
"mkdir ~/apps",
"cd ~/apps",
"git clone git@github.com:jambonz/jambonz-api-server.git -b {{user `jambonz_version`}}",
"git clone git@github.com:jambonz/jambonz-webapp.git -b {{user `jambonz_version`}}",
"git clone git@github.com:jambonz/public-apps.git",
"sudo find / -name authorized_keys | sudo xargs -0 -r rm -Rf"
]
},
{
"type": "file",
"source": "files/",
"destination": "/tmp"
},
{
"type": "shell",
"script": "scripts/install_nginx.sh"
},
{
"type": "shell",
"script": "scripts/install_chrony.sh"
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo '{{ .Path }}' {{user `install_telegraf`}}",
"script": "scripts/install_telegraf.sh"
},
{
"type": "shell",
"script": "scripts/install_nodejs.sh"
},
{
"type": "shell",
"script": "scripts/install_fail2ban.sh"
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo '{{ .Path }}' {{user `jambonz_version`}}",
"script": "scripts/install_app.sh"
}
]
}
+50 -42
View File
@@ -1,13 +1,14 @@
# terraform for a jambonz development / test system
# terraform for a 2-instance jambonz system
This terraform configuration generates a jambonz deployment suitable for testing or small production deployments.
This terraform configuration generates a jambonz deployment suitable for testing or small production loads.
The deployment generated consists of:
- a VPC along with public subnets, internet gateway, routing table and the like.
- 2 EC2 instances: 1 SBC and 1 feature server (the SBC is assigned an elastic IP)
- an autoscale group containing the feature server
- an SNS topic that is used to notify autoscale lifecycle events to the feature server
- 2 EC2 instances: 1 Session Border Controller (SBC) and 1 feature server (FS)
- an EIP (elastic IP) for the SBC instance
- an autoscale group containing the FS instance, allowing for horizontal scaling of the FS
- an SNS topic that is used to notify autoscale lifecycle events to the FS instance(s)
- an aurora mysql serverless database
- an elasticache redis server
@@ -15,14 +16,25 @@ The deployment generated consists of:
### Prerequisites
Before running the terraform script you will need to have done the following:
Before running the terraform script there are two pre-requisites:
1. Provisioned accounts on AWS and GCP
1. (AWS) Created a keypair in your target region and downloaded the .pem file to your local machine.
1. (AWS) Generated an access key id and secret access key
1. (GCP) Created a project, enabled both text to speech and speech to text APIs, created a service account for the project and downloaded the json key file for the service account.
1. Copied the the GCP json key file into the `credentials\` folder in your local copy of this project.
1. Reviewed and edited the [variables.tf](./variables.tf) file in your local copy of this project to specify your desired AWS region, availability zones, EC2 instance type, and your AWS keys (alternatively, these can be specified on the command line when running the script).
1. You need to create amis for the SBC and the Feature server by running the [jambonz-sbc-sip-rtp](../../packer/jambonz-sbc-sip-rtp) and [jambonz-feature-server](../../packer/jambonz-feature-server) packer scripts.
1. You need to create an IAM role with permissions to publish SNS notifications. These are used by the feature server to gracefully respond to scale-in lifecycle events.
Please refer to the above packer scripts for generating your AMIs.
### Creating an AMI role
As mentioned above, we need to create an AMI role that has permissions to generate SNS notifications. To do, so go into the IAM dashboard in AWS and then do the following:
- click on Roles / Create role,
- under "Choose a use case" select the link at the bottom of the page titled "EC2 Auto Scaling",
- under "Select your use case" choose "EC2 Auto Scaling Notification Access" and then click "Next: Permissions"
- Leave the settings in place and click "Next: Tags"
- You do not need to add any tags, so click "Next: Review"
- Enter a Role name (e.g. "my-jambonz-sns-role") and click Create role
The role will then be created. When you run the terraform script you will provide the role name as the value for the terraform variable named "ami_role_name".
> **Note**: The creation of the AMI role is a one-time thing; you can use the created IAM role for all clusters you deploy.
### It's go time!
@@ -32,47 +44,43 @@ After [installing terraform](https://learn.hashicorp.com/terraform/getting-start
terraform init
```
Testing out the script is a good idea, particularly if you've made changes:
```
terraform plan
```
At that point you are ready to run the script. There are a couple of variables that you must supply, and some others that are optional. These variables can either be defined by editing the [./variables.tf] file or supplied on the command line in `var='variable=value'` format.
When you are ready to run it, do terraform apply, optionally passing any command-line arguments that you want to override variables.tf.
|Variable Name|Value|Required?|Default Value|
|-----|----|------|-----|
|ami_owner_account|your aws account id|Yes|None|
|ami_role_name|name of the IAM role you created above|Yes|None|
|key_name|name of existing aws key-pair to use to access the instances (e.g. my-keypair)|Yes|None|
|ssh_key_path|path to key-pair file on local machine (e.g. ~/credentials/my-keypair.pem)|Yes|None|
|region|AWS region to create instances in|No|us-west-1|
|ec2_instance_type_sbc|EC2 instance type for SBC|No|t3.medium|
|ec2_instance_type_fs|EC2 instance type for Feature Server|No|t3.medium|
|vpc_cidr_block|Network CIDR for the created VPC|No|172.31.0.0/16|
|public_subnets|Two public subnets to create within the VPC|No|{"us-west-1a" = "172.31.32.0/24""us-west-1b" = "172.31.33.0/24"}|
|cluster_id|short identifier used to prefix some names of created items|No|jb|
|prefix|name of VPC|No|jambonz|
So, if you edit variables.tf to put in your selections:
```
terraform apply
```
or, if you prefer command-line arguments, you might do:
A command line with variables supplied looks like this:
```
terraform apply \
-var='region=eu-west-3' \
-var='public_subnets={"eu-west-3a": "172.31.32.0/24", "eu-west-3b": "172.31.33.0/24"}' \
-var='aws_access_key_id_runtime=XXXX' \
-var='aws_secret_access_key_runtime=YYYYY' \
-var='ssh_key_path=~/aws/aws-dhorton-paris.pem' \
-var='key_name=aws-dhorton-paris'
-var='ami_owner_account=376029039784' \
-var='ami_role_name=my-jambonz-sns-role' \
-var='region=us-west-1' \
-var='public_subnets={"us-west-1a" = "172.31.32.0/24","us-west-1b" = "172.31.33.0/24"}' \
-var='ssh_key_path=~/aws/~/aws/aws-drachtio-us-west-1.pem' \
-var='key_name=aws-drachtio-us-west-1'
```
Enter 'yes' at the confirmation prompt, and very shortly you will be the proud owner of a brand-new jambonz cluster!
(Note: to destroy the cluster, simply run `terraform destroy`).
(Note: to destroy the cluster, simply run `terraform destroy` with the same command line arguments).
### Next steps
### Access the jambonz portal
After creating the cluster, get the elastic IP of your SBC server and navigate to:
After creating the cluster, wait a few minutes before accessing the jambonz portal for the first time. There are some userdata scripts that need to finish running, and you may get a "502 Bad Gateway" error if you attempt to access the portal before they have completed. If this happens, simply wait a few minutes and try again.
```
http://your-elastic-ip:3001
```
in your web browser to bring up the provisioning GUI.
Once the SBC instance is fully up, log into the jambonz portal by navigating to `http://eip-of-sbc-instance` in your web browser.
Log in with admin/admin.
Log in the first time with username and password 'admin'. You will then be forced to set a new password.
You'll be asked to change the password and then walked through a simple configuration of your account, applications, sip trunks and phone numbers.
Once done, you are ready to test!
Whitespace-only changes.
+7 -1
View File
@@ -4,6 +4,12 @@ resource "aws_db_subnet_group" "jambonz" {
subnet_ids = local.my_subnet_ids
}
# generate random password
resource "random_password" "password" {
length = 16
special = false
}
# create aurora database
resource "aws_rds_cluster" "jambonz" {
cluster_identifier = "aurora-cluster-${var.prefix}"
@@ -14,7 +20,7 @@ resource "aws_rds_cluster" "jambonz" {
db_subnet_group_name = aws_db_subnet_group.jambonz.name
database_name = "jambones"
master_username = "admin"
master_password = "JambonzR0ck$"
master_password = random_password.password.result
skip_final_snapshot = true
backup_retention_period = 5
preferred_backup_window = "07:00-09:00"
@@ -21,9 +21,6 @@ module.exports = {
max_memory_restart: '1G',
env: {
NODE_ENV: 'production',
GOOGLE_APPLICATION_CREDENTIALS: '/home/admin/credentials/gcp.json',
AWS_ACCESS_KEY_ID: '${AWS_ACCESS_KEY_ID}',
AWS_SECRET_ACCESS_KEY: '${AWS_SECRET_ACCESS_KEY}',
AWS_REGION: '${AWS_REGION}',
ENABLE_METRICS: 1,
STATS_HOST: '127.0.0.1',
@@ -39,7 +36,8 @@ module.exports = {
JAMBONES_MYSQL_CONNECTION_LIMIT: 10,
JAMBONES_REDIS_HOST: '${JAMBONES_REDIS_HOST}',
JAMBONES_REDIS_PORT: 6379,
JAMBONES_LOGLEVEL: 'debug',
JAMBONES_TIME_SERIES_HOST: '${MONITORING_SERVER_IP}',
JAMBONES_LOGLEVEL: 'info',
HTTP_PORT: 3000,
DRACHTIO_HOST: '127.0.0.1',
DRACHTIO_PORT: 9022,
@@ -51,9 +49,6 @@ module.exports = {
}]
};
EOF
cat << EOF > /home/admin/credentials/gcp.json
${GCP_CREDENTIALS}
EOF
echo "finished writing config file"
+14 -55
View File
@@ -1,56 +1,18 @@
# retrieve IAM role that you created manually for SNS (see README)
data "aws_iam_role" "jambonz_ami_role" {
name = var.ami_role_name
}
# create an SNS notification topic
resource "aws_sns_topic" "jambonz_sns_topic" {
resource "aws_sns_topic" "jambonz_sns_topic_open_source" {
# name = "${var.prefix}-fs-lifecycle-events"
}
resource "aws_iam_role" "jambonz_sns_publish" {
name = "${var.prefix}_sns_publish"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"autoscaling.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}
resource "aws_iam_policy" "allow_jambonz_sns_publish" {
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"sns:Publish"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "sns_publish_policy_attachment" {
role = aws_iam_role.jambonz_sns_publish.name
policy_arn = aws_iam_policy.allow_jambonz_sns_publish.arn
}
# select the most recent jambonz AMIs
data "aws_ami" "jambonz-feature-server" {
most_recent = true
name_regex = "^jambonz-feature-server"
owners = ["376029039784"]
owners = [var.ami_owner_account]
}
# create a launch configuration
@@ -62,24 +24,21 @@ resource "aws_launch_configuration" "jambonz-feature-server" {
key_name = var.key_name
user_data = templatefile("${path.module}/feature-server.ecosystem.config.js.tmpl", {
VPC_CIDR = var.vpc_cidr_block
JAMBONES_SBC_SIP_IPS = join(",", var.jambonz_sbc_sip_rtp_private_ips)
JAMBONES_SBC_SIP_IPS = aws_instance.jambonz-sbc-sip-rtp-server.private_ip
JAMBONES_MYSQL_HOST = aws_rds_cluster.jambonz.endpoint
JAMBONES_MYSQL_USER = aws_rds_cluster.jambonz.master_username
JAMBONES_MYSQL_PASSWORD = aws_rds_cluster.jambonz.master_password
JAMBONES_REDIS_HOST = aws_elasticache_cluster.jambonz.cache_nodes.0.address
AWS_ACCESS_KEY_ID = var.aws_access_key_id_runtime
AWS_SECRET_ACCESS_KEY = var.aws_secret_access_key_runtime
AWS_REGION = var.region
AWS_SNS_TOPIC_ARN = aws_sns_topic.jambonz_sns_topic.arn
GCP_CREDENTIALS = file("${path.module}/credentials/gcp.json")
MONITORING_SERVER_IP = aws_instance.jambonz-monitoring-server.private_ip
AWS_SNS_TOPIC_ARN = aws_sns_topic.jambonz_sns_topic_open_source.arn
MONITORING_SERVER_IP = aws_instance.jambonz-sbc-sip-rtp-server.private_ip
})
lifecycle {
create_before_destroy = true
}
depends_on = [aws_instance.jambonz-monitoring-server]
depends_on = [aws_instance.jambonz-sbc-sip-rtp-server]
}
@@ -110,7 +69,7 @@ resource "aws_autoscaling_group" "jambonz-feature-server" {
create_before_destroy = true
}
depends_on = [aws_sns_topic.jambonz_sns_topic]
depends_on = [aws_sns_topic.jambonz_sns_topic_open_source]
}
@@ -121,6 +80,6 @@ resource "aws_autoscaling_lifecycle_hook" "jambonz-scale-in" {
default_result = "CONTINUE"
heartbeat_timeout = 900
lifecycle_transition = "autoscaling:EC2_INSTANCE_TERMINATING"
notification_target_arn = aws_sns_topic.jambonz_sns_topic.arn
role_arn = aws_iam_role.jambonz_sns_publish.arn
notification_target_arn = aws_sns_topic.jambonz_sns_topic_open_source.arn
role_arn = data.aws_iam_role.jambonz_ami_role.arn
}
-23
View File
@@ -1,23 +0,0 @@
# Create monitoring instance
data "aws_ami" "jambonz-monitoring-server" {
most_recent = true
name_regex = "^jambonz-monitoring-server"
owners = ["376029039784"]
}
resource "aws_eip" "jambonz-monitoring-server" {
instance = aws_instance.jambonz-monitoring-server.id
vpc = true
}
resource "aws_instance" "jambonz-monitoring-server" {
ami = data.aws_ami.jambonz-monitoring-server.id
instance_type = var.ec2_instance_type_monitoring
key_name = var.key_name
vpc_security_group_ids = [aws_security_group.allow_jambonz_monitoring.id]
subnet_id = local.my_subnet_ids[0]
monitoring = true
tags = {
Name = "${var.prefix}-monitoring-server"
}
}
+27 -71
View File
@@ -52,7 +52,6 @@ resource "aws_subnet" "jambonz" {
# for ease of reference later on, create a list of public subnet ids
locals {
my_subnet_ids = [for v in aws_subnet.jambonz : v.id]
rtpengine_hostports = [for ip in var.jambonz_sbc_sip_rtp_private_ips : "${ip}:22222"]
}
# create a security group that allows any server in the VPC to access redis
@@ -204,7 +203,22 @@ resource "aws_security_group" "allow_jambonz_sbc_sip_rtp" {
}
ingress {
description = "sip from everywhere"
description = "http"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "https"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "sip over udp"
from_port = 5060
to_port = 5060
protocol = "udp"
@@ -212,17 +226,17 @@ resource "aws_security_group" "allow_jambonz_sbc_sip_rtp" {
}
ingress {
description = "sip tls for teams"
description = "sip over tls"
from_port = 5061
to_port = 5061
protocol = "tcp"
cidr_blocks = ["52.114.148.0/32", "52.114.132.46/32", "52.114.75.24/32", "52.114.76.76/32", "52.114.7.24/32", "52.114.14.70/32"]
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "sip from everywhere"
from_port = 5060
to_port = 5060
description = "sip over wss"
from_port = 4433
to_port = 4433
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
@@ -243,13 +257,12 @@ resource "aws_security_group" "allow_jambonz_sbc_sip_rtp" {
cidr_blocks = [aws_vpc.jambonz.cidr_block]
}
ingress {
description = "http api"
from_port = 3000
to_port = 3000
description = "rtpengine http protocol from VPC"
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
cidr_blocks = [aws_vpc.jambonz.cidr_block]
}
ingress {
@@ -260,49 +273,6 @@ resource "aws_security_group" "allow_jambonz_sbc_sip_rtp" {
security_groups = [aws_security_group.allow_jambonz_feature_server.id]
}
ingress {
description = "http webapp"
from_port = 3001
to_port = 3001
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "allow_${var.prefix}_sbc_sip"
}
}
# create a security group for the monitoring server
resource "aws_security_group" "allow_jambonz_monitoring" {
name = "allow_jambonz_monitoring"
description = "Allow traffic to jambonz monitoring server"
vpc_id = aws_vpc.jambonz.id
ingress {
description = "ssh"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "grafana"
from_port = 3000
to_port = 3000
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "influxdb"
from_port = 8086
@@ -319,14 +289,6 @@ resource "aws_security_group" "allow_jambonz_monitoring" {
cidr_blocks = [aws_vpc.jambonz.cidr_block]
}
ingress {
description = "homer webapp"
from_port = 9080
to_port = 9080
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "homer HEP"
from_port = 9060
@@ -335,14 +297,6 @@ resource "aws_security_group" "allow_jambonz_monitoring" {
cidr_blocks = [aws_vpc.jambonz.cidr_block]
}
ingress {
description = "Node-RED"
from_port = 1880
to_port = 1880
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
@@ -354,3 +308,5 @@ resource "aws_security_group" "allow_jambonz_monitoring" {
Name = "allow_${var.prefix}_sbc_sip"
}
}
@@ -1,17 +1,47 @@
#!/bin/bash
PUBLIC_IP=`curl -s http://169.254.169.254/latest/meta-data/public-ipv4`
PUBLIC_IPV4=`curl -s http://169.254.169.254/latest/meta-data/public-ipv4`
echo "running jambonz user data script"
# move grafana to port 3010
echo "moving grafana to port 3010"
sudo systemctl stop grafana-server
sudo sed -i -e "s/;http_port = 3000/http_port = 3010/g" /etc/grafana/grafana.ini
sudo systemctl restart grafana-server
# configure telegraph to send to the monitoring server
sudo sed -i -e "s/influxdb:8086/${MONITORING_SERVER_IP}:8086/g" /etc/telegraf/telegraf.conf
sudo systemctl restart telegraf
# point drachtio server and rtpengine to the HEP endpoint on the monitoring server
sudo sed -i -e "s/--address 0.0.0.0 --port 9022/--address 0.0.0.0 --port 9022 --homer ${MONITORING_SERVER_IP}:9060 --homer-id 10/g" /etc/systemd/system/drachtio.service
sudo sed -i -e "s/--delete-delay 0/--delete-delay 0 --homer=${MONITORING_SERVER_IP}:9060 --homer-protocol=udp --homer-id=11/g" /etc/systemd/system/rtpengine.service
# update server names for access to grafana and homer
sudo sed -i -E "s|^(\s*)server_name\s+homer.your_domain.com;|\1server_name homer.${JAMBONES_DNS_NAME};|g" /etc/nginx/sites-available/default
sudo sed -i -E "s|^(\s*)server_name\s+grafana.your_domain.com;|\1server_name grafana.${JAMBONES_DNS_NAME};|g" /etc/nginx/sites-available/default
echo "restarting services"
sudo systemctl daemon-reload
sudo systemctl restart nginx
sudo systemctl restart drachtio
sudo systemctl restart rtpengine
sudo systemctl restart telegraf
sudo systemctl restart influxdb
sudo systemctl restart postgresql
sudo systemctl restart homer-app
sudo systemctl restart heplify-server
# seed database
mysql -h ${JAMBONES_MYSQL_HOST} -u admin -D jambones -p${JAMBONES_MYSQL_PASSWORD} < /home/admin/apps/jambonz-api-server/db/jambones-sql.sql
mysql -h ${JAMBONES_MYSQL_HOST} -u admin -D jambones -p${JAMBONES_MYSQL_PASSWORD} < /home/admin/apps/jambonz-api-server/db/create-admin-token.sql
mysql -h ${JAMBONES_MYSQL_HOST} -u admin -D jambones -p${JAMBONES_MYSQL_PASSWORD} < /home/admin/apps/jambonz-api-server/db/create-default-account.sql
echo "seeding database"
mysql -h ${JAMBONES_MYSQL_HOST} -u admin -p${JAMBONES_MYSQL_PASSWORD} -D jambones < /home/admin/apps/jambonz-api-server/db/jambones-sql.sql
mysql -h ${JAMBONES_MYSQL_HOST} -u admin -p${JAMBONES_MYSQL_PASSWORD} -D jambones < /home/admin/apps/jambonz-api-server/db/seed-production-database-open-source.sql
JAMBONES_MYSQL_HOST=${JAMBONES_MYSQL_HOST} JAMBONES_MYSQL_USER=admin JAMBONES_MYSQL_PASSWORD=${JAMBONES_MYSQL_PASSWORD} JAMBONES_MYSQL_DATABASE=jambones /home/admin/apps/jambonz-api-server/db/reset_admin_password.js
# jambonz webapp
echo "building webapp.."
echo "REACT_APP_API_BASE_URL=http://$PUBLIC_IP:3000/v1" > /home/admin/apps/jambonz-webapp/.env.local
echo "REACT_APP_API_BASE_URL=http://$PUBLIC_IPV4/api/v1" > /home/admin/apps/jambonz-webapp/.env.local
echo "REACT_APP_MOBILE_BREAKPOINT=767px" >> /home/admin/apps/jambonz-webapp/.env.local
cd /home/admin/apps/jambonz-webapp/
npm run build
@@ -44,12 +74,13 @@ module.exports = {
JAMBONES_LOGLEVEL: 'info',
JAMBONE_API_VERSION: 'v1',
JAMBONES_CLUSTER_ID: '${JAMBONES_CLUSTER_ID}',
JAMBONES_TIME_SERIES_HOST: '${MONITORING_SERVER_IP}',
ENABLE_METRICS: 1,
STATS_HOST: '127.0.0.1',
STATS_PORT: 8125,
STATS_PROTOCOL: 'tcp',
STATS_TELEGRAF: 1,
HTTP_PORT: 3000
HTTP_PORT: 3002
},
},
{
@@ -93,6 +124,7 @@ module.exports = {
env: {
NODE_ENV: 'production',
JAMBONES_LOGLEVEL: 'info',
RTPENGINE_PING_INTERVAL: 30000,
DRACHTIO_HOST: '127.0.0.1',
DRACHTIO_PORT: 9022,
DRACHTIO_SECRET: 'cymru',
@@ -103,6 +135,7 @@ module.exports = {
JAMBONES_MYSQL_CONNECTION_LIMIT: 10,
JAMBONES_REDIS_HOST: '${JAMBONES_REDIS_HOST}',
JAMBONES_REDIS_PORT: 6379,
JAMBONES_TIME_SERIES_HOST: '${MONITORING_SERVER_IP}',
ENABLE_METRICS: 1,
STATS_HOST: '127.0.0.1',
STATS_PORT: 8125,
@@ -125,6 +158,7 @@ module.exports = {
env: {
NODE_ENV: 'production',
JAMBONES_LOGLEVEL: 'info',
RTPENGINE_PING_INTERVAL: 30000,
DRACHTIO_HOST: '127.0.0.1',
DRACHTIO_PORT: 9022,
DRACHTIO_SECRET: 'cymru',
@@ -136,12 +170,12 @@ module.exports = {
JAMBONES_MYSQL_CONNECTION_LIMIT: 10,
JAMBONES_REDIS_HOST: '${JAMBONES_REDIS_HOST}',
JAMBONES_REDIS_PORT: 6379,
JAMBONES_TIME_SERIES_HOST: '${MONITORING_SERVER_IP}',
ENABLE_METRICS: 1,
STATS_HOST: '127.0.0.1',
STATS_PORT: 8125,
STATS_PROTOCOL: 'tcp',
STATS_TELEGRAF: 1,
MS_TEAMS_FQDN: '${MS_TEAMS_FQDN}'
STATS_TELEGRAF: 1
}
},
{
@@ -158,6 +192,7 @@ module.exports = {
max_memory_restart: '1G',
env: {
NODE_ENV: 'production',
JAMBONES_NETWORK_CIDR: '${VPC_CIDR}',
JAMBONES_LOGLEVEL: 'info',
DRACHTIO_HOST: '127.0.0.1',
DRACHTIO_PORT: 9022,
@@ -170,6 +205,7 @@ module.exports = {
JAMBONES_MYSQL_CONNECTION_LIMIT: 10,
JAMBONES_REDIS_HOST: '${JAMBONES_REDIS_HOST}',
JAMBONES_REDIS_PORT: 6379,
JAMBONES_TIME_SERIES_HOST: '${MONITORING_SERVER_IP}',
JAMBONES_CLUSTER_ID: '${JAMBONES_CLUSTER_ID}',
ENABLE_METRICS: 1,
STATS_HOST: '127.0.0.1',
@@ -187,24 +223,13 @@ module.exports = {
}]
};
EOF
sudo sed -i -e "s/\(.*\)JAMBONES_MYSQL_PASSWORD.*/\1JAMBONES_MYSQL_PASSWORD: '${JAMBONES_MYSQL_PASSWORD}',/g" /home/admin/apps/ecosystem.config.js
echo "finished writing config file"
echo "starting applications"
sudo -u admin bash -c "pm2 start /home/admin/apps/ecosystem.config.js"
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u admin --hp /home/admin
sudo -u admin bash -c "pm2 save"
sudo systemctl enable pm2-admin.service
# configure telegraph to send to the monitoring server
sudo sed -i -e "s/influxdb:8086/${MONITORING_SERVER_IP}:8086/g" /etc/telegraf/telegraf.conf
sudo systemctl restart telegraf
# point drachtio server and rtpengine to the HEP endpoint on the monitoring server
sudo sed -i -e "s/--address 0.0.0.0 --port 9022/--address 0.0.0.0 --port 9022 --homer ${MONITORING_SERVER_IP}:9060 --homer-id 10/g" /etc/systemd/system/drachtio.service
sudo sed -i -e "s/--delete-delay 0/--delete-delay 0 --homer=${MONITORING_SERVER_IP}:9060 --homer-protocol=udp --homer-id=11/g" /etc/systemd/system/rtpengine.service
sudo systemctl daemon-reload
sudo systemctl restart drachtio
sudo systemctl restart rtpengine
echo "user data script completed"
+11 -15
View File
@@ -2,38 +2,34 @@
data "aws_ami" "jambonz-sbc-sip-rtp" {
most_recent = true
name_regex = "^jambonz-sbc-sip-rtp"
owners = ["376029039784"]
owners = [var.ami_owner_account]
}
resource "aws_eip" "jambonz-sbc-sip-rtp" {
count = length(var.jambonz_sbc_sip_rtp_private_ips)
instance = aws_instance.jambonz-sbc-sip-rtp-server[count.index].id
resource "aws_eip" "jambonz-sbc-sip-rtp" {
instance = aws_instance.jambonz-sbc-sip-rtp-server.id
vpc = true
}
resource "aws_instance" "jambonz-sbc-sip-rtp-server" {
count = length(var.jambonz_sbc_sip_rtp_private_ips)
resource "aws_instance" "jambonz-sbc-sip-rtp-server" {
ami = data.aws_ami.jambonz-sbc-sip-rtp.id
instance_type = var.ec2_instance_type_sbc
private_ip = var.jambonz_sbc_sip_rtp_private_ips[count.index]
subnet_id = local.my_subnet_ids[count.index]
key_name = var.key_name
subnet_id = local.my_subnet_ids[0]
vpc_security_group_ids = [aws_security_group.allow_jambonz_sbc_sip_rtp.id]
monitoring = true
user_data = templatefile("${path.module}/sbc-sip-rtp-server.ecosystem.config.js.tmpl", {
VPC_CIDR = var.vpc_cidr_block
JAMBONES_SBC_SIP_IPS = join(",", var.jambonz_sbc_sip_rtp_private_ips)
JAMBONES_RTPENGINE_IPS = join(",", local.rtpengine_hostports)
JAMBONES_RTPENGINE_IPS = "127.0.0.1:22222"
JAMBONES_MYSQL_HOST = aws_rds_cluster.jambonz.endpoint
JAMBONES_MYSQL_USER = aws_rds_cluster.jambonz.master_username
JAMBONES_MYSQL_PASSWORD = aws_rds_cluster.jambonz.master_password
JAMBONES_REDIS_HOST = aws_elasticache_cluster.jambonz.cache_nodes.0.address
MS_TEAMS_FQDN = var.ms_teams_fqdn
JAMBONES_CLUSTER_ID = var.cluster_id
MONITORING_SERVER_IP = aws_instance.jambonz-monitoring-server.private_ip
MONITORING_SERVER_IP = "127.0.0.1"
JAMBONES_DNS_NAME = var.domain
})
key_name = var.key_name
monitoring = true
depends_on = [aws_internet_gateway.jambonz, aws_instance.jambonz-monitoring-server, aws_elasticache_cluster.jambonz, aws_rds_cluster.jambonz]
depends_on = [aws_internet_gateway.jambonz, aws_elasticache_cluster.jambonz, aws_rds_cluster.jambonz]
tags = {
Name = "${var.prefix}-sbc-sip-rtp-server"
+12 -36
View File
@@ -1,3 +1,11 @@
variable "ami_owner_account" {
description = "AWS account id that owns the AMIs that will be installed"
default = "aws_owner_account here"
}
variable "ami_role_name" {
description = "Name of AWS AMI role that you created for SNS scale-in notifications (see README)"
default = "ami_role_name_here"
}
variable "prefix" {
description = "name of VPC and other identifiers - lower case letters only"
default = "jambonz"
@@ -6,6 +14,10 @@ variable "region" {
description = "the aws region in which to create the VPC"
default = "us-west-1"
}
variable "domain" {
description = "the domain you want to use for the portal"
default = "your_domain.com"
}
variable "vpc_cidr_block" {
description = "the CIDR block for the whole VPC"
default = "172.31.0.0/16"
@@ -17,10 +29,6 @@ variable "public_subnets" {
"us-west-1b" = "172.31.33.0/24"
}
}
variable "jambonz_sbc_sip_rtp_private_ips" {
type = list(string)
default = ["172.31.32.10"]
}
variable "ec2_instance_type_sbc" {
description = "the EC2 instance type to use for the SBC"
default = "t3.medium"
@@ -29,10 +37,6 @@ variable "ec2_instance_type_fs" {
description = "the EC2 instance type to use for the Feature server"
default = "t3.medium"
}
variable "ec2_instance_type_monitoring" {
description = "the EC2 instance type to use for the monitoring server"
default = "t3.medium"
}
variable "key_name" {
description = "name of an aws keypair that you have downloaded and wish to use to access the jambonz instance via ssh"
default = "your-key"
@@ -41,38 +45,10 @@ variable "ssh_key_path" {
description = "path to your aws keypair on your local machine"
default = "path-to-key.pem"
}
variable "aws_access_key_id_runtime" {
description = "AWS access key jambonz will use to access AWS Polly TTS"
default = "your key"
}
variable "aws_secret_access_key_runtime" {
description = "AWS secret access key jambonz will use to access AWS Polly TTS"
default = "your secret access key"
}
variable "sns_topic" {
description = "AWS SNS topic for autoscale events"
default = "jambonz-fs-lifecycle-events"
}
variable "ms_teams_fqdn" {
description = "Microsoft Teams FQDN"
default = ""
}
variable "cluster_id" {
description = "short cluster identifier"
default = "jb"
}
variable "datadog_api_key" {
description = "datadog api key - only supply if you wish to install datadog monitoring"
default = "your dd key"
}
variable "datadog_site" {
description = "datadog site"
default = "datadoghq.com"
}
variable "datadog_env_name" {
description = "environment identifier"
default = "us-west-1"
}