How to Set Up Apache OpenWhisk on Ubuntu 18.04 — Part II

What Is Couch DB?

CouchDB is one of many offerings available in the NoSQL space and is a document-based database. All the data is stored in the JSON documents as a key value pairs as a map. The unique feature of CouchDB is there is also a _rev(revision) along with _id(Unique identifier) shows how many changes are made.

  • CouchDB is constructed in such a way that, it can grow easily into a cluster depends upon your needs
  • CouchDB also has an in-built managed cache, which is responsible for fast responses
  • You can also listen to the _changes(changes) feed to keep tracking of changes which are made.

Installing CouchDB

Adding the CouchDB GPG key to the keyring, by executing following command

~root@iZa2d4spx9n9e90jofcyxoZ:~# curl -L https://couchdb.apache.org/repo/bintray-pubkey.asc | apt-key add -
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
100 3100 100 3100 0 0 1429 0 0:00:02 0:00:02 --:--:-- 1429
OK
~root@iZa2d4spx9n9e90jofcyxoZ:~# echo "deb https://apache.bintray.com/couchdb-deb bionic main" | tee -a /etc/apt/sources.list
~root@iZa2d4spx9n9e90jofcyxoZ:~# sudo apt-get update
~root@iZa2d4spx9n9e90jofcyxoZ:~# apt-get install -y couchdb
~root@iZa2d4spx9n9e90jofcyxoZ:~# sudo service couchdb status
couchdb.service - Apache CouchDB[m
Loaded: loaded (/lib/systemd/system/couchdb.service; enabled; vendor preset: enabled)
Active: active (running) since Sat CST; 28s ago
Main PID: 27987 (beam.smp)
Tasks: 27 (limit: 4915)
CGroup: /system.slice/coucdb.service
├─27987 /opt/couchdb/bin/../erts-8.3.5.4/bin/beam.smp -K true -A 16 -Bd -- -root /opt/couchdb/bin/.. -progname couchdb -- -home /opt/couchdb -- -boot /opt
├─27997 /opt/couchdb/bin/../erts-8.3.5.4/bin/epmd -daemon
├─28028 erl_child_setup 1024
├─28036 sh -s disksup
├─28037 /opt/couchdb/bin/../lib/os_mon-2.4.2/priv/bin/memsup
└─28038 /opt/couchdb/bin/../lib/os_mon-2.4.2/priv/bin/cpu_sup
root@iZa2d4spx9n9e90jofcyxoZ:~# curl http://127.0.0.1:5984/
{"couchdb":"Welcome","version":"2.2.0","git_sha":"2a16ec4","features":["pluggable-storage-engines","scheduler"],"vendor":{"name":"The Apache Software Foundation"}}
curl http://127.0.0.1:5984/_all_dbs
{"error":"unauthorized","reason":"You are not a server admin."}
curl http://admin:password@127.0.0.1:5984/_all_dbs
["_global_changes","_replicator","_users"]
curl http://admin:password@127.0.0.1:5984/_global_changes
{"db_name":"_global_changes","update_seq":"4-g1AAAAFTeJzLYWBg4MhgTmEQTM4vTc5ISXLIyU9OzMnILy7JAUoxJTIkyf___z8rkQGPoiQFIJlkD1bHiE-dA0hdPGHzEkDq6gmal8cCJBkagBRQ6Xz8ZkLULoCo3U-M2gMQtfeJUfsAohboXqYsANYbbzI","sizes":{"file":13699,"external":16,"active":860},"purge_seq":0,"other":{"data_size":16},"doc_del_count":0,"doc_count":4,"disk_size":13699,"disk_format_version":6,"data_size":860,"compact_running":false,"cluster":{"q":8,"n":1,"w":1,"r":1},"instance_start_time":"0"}

Install OpenWhisk

Now we have completed the setup of CouchDB, we will install the Apache OpenWhisk.

root@iZa2d4spx9n9e90jofcyxoZ:~# git clone https://github.com/apache/incubator-openwhisk.git openwhisk
~root@iZa2d4spx9n9e90jofcyxoZ:~# cd openwhisk/
root@iZa2d4spx9n9e90jofcyxoZ:~/openwhisk# (cd tools/ubuntu-setup && ./all.sh)+ JAVA_SOURCE=open
+ SOURCE=./all.sh
++ dirname ./all.sh
+ SCRIPTDIR=.
+ echo '*** installing basics'
*** installing basics
+ /bin/bash ./misc.sh
+ export DEBIAN_FRONTEND=noninteractive
+ DEBIAN_FRONTEND=noninteractive
docker-ce is already the newest version (5:18.09.0~3-0~ubuntu-bionic).
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
+ sudo -E bash -c 'echo '\''DOCKER_OPTS="-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock --storage-driver=aufs"'\'' >> /etc/default/docker'
++ whoami
+ sudo gpasswd -a root docker
Adding user root to group docker
+ sudo service docker restart
root@iZa2d4spx9n9e90jofcyxoZ:~/openwhisk# cd ansible
export OW_DB=CouchDB
root@iZa2d4spx9n9e90jofcyxoZ:~/openwhisk/ansible# export OW_DB_PROTOCOL=http
root@iZa2d4spx9n9e90jofcyxoZ:~/openwhisk/ansible# export OW_DB_HOST=<public IP>
root@iZa2d4spx9n9e90jofcyxoZ:~/openwhisk/ansible# export OW_DB_PORT=5984
root@iZa2d4spx9n9e90jofcyxoZ:~/openwhisk/ansible# export OW_DB_USERNAME=admin
root@iZa2d4spx9n9e90jofcyxoZ:~/openwhisk/ansible# export OW_DB_PASSWORD=password
root@iZa2d4spx9n9e90jofcyxoZ:~/openwhisk/ansible# ansible-playbook setup.ymlGathering Facts -------------------- 0.81s
gen hosts if 'local' env is used --- 0.48s
generate invoker certificates ------ 0.48s
generate controller certificates --- 0.47s
ensure controller files directory exists ----- 0.46s
gen untrusted client certificate for host ---- 0.41s
ensure invoker files directory exists -------- 0.38s
gen untrusted server certificate for host ---- 0.37s
prepare db_local.ini --------------- 0.32s
check if db_local.ini exists? ------ 0.18s
ensure kafka files directory exists 0.04s
get the docker-machine ip ---------- 0.04s
gen hosts for docker-machine ------- 0.03s
clean up old kafka keystore -------- 0.03s
generate kafka certificates -------- 0.03s
find the ip of docker-machine ------ 0.03s
root@iZa2d4spx9n9e90jofcyxoZ:~/openwhisk/ansible# ansible-playbook prereq.ymlGathering Facts ------------------------ 0.78s
prereq : install docker for python ----- 0.66s
prereq : install requests -------------- 0.64s
prereq : install httplib2 -------------- 0.64s
Gathering Facts ------------------------ 0.55s
Gathering Facts ------------------------ 0.55s
Gathering Facts ------------------------ 0.55s
prereq : check for pip ----------------- 0.44s
prereq : install pip ------------------- 0.03s
prereq : remove docker ----------------- 0.03s
prereq : remove requests --------------- 0.03s
prereq : remove httplib2 --------------- 0.02s
root@iZa2d4spx9n9e90jofcyxoZ:~/openwhisk# ./gradlew distDocker
root@iZa2d4spx9n9e90jofcyxoZ:~/openwhisk/ansible# ansible-playbook initdb.yml
root@iZa2d4spx9n9e90jofcyxoZ:~/openwhisk/ansible# ansible-playbook wipe.yml
root@iZa2d4spx9n9e90jofcyxoZ:~/openwhisk/ansible# ansible-playbook openwhisk.yml
root@iZa2d4spx9n9e90jofcyxoZ:~/openwhisk/ansible# ansible-playbook postdeploy.yml
root@iZa2d4spx9n9e90jofcyxoZ:~/openwhisk/ansible# docker ps
CONTAINER ID        IMAGE                            COMMAND                  CREATED             STATUS              PORTS                                                                                                 NAMES
73c17753ad74 nginx:1.13 "nginx -g 'daemon of…" 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:8443->8443/tcp nginx
b51d882d6295 openwhisk/nodejs6action:latest "/bin/sh -c 'node --…" 2 minutes ago Up 2 minutes wsk00_4_prewarm_nodejs6
cb6d90d7fce5 openwhisk/nodejs6action:latest "/bin/sh -c 'node --…" 2 minutes ago Up 2 minutes wsk00_2_prewarm_nodejs6
e83e0a8ff8a3 whisk/invoker:latest "/bin/sh -c 'exec /i…" 2 minutes ago Up 2 minutes 0.0.0.0:17000->17000/tcp, 0.0.0.0:18000->18000/tcp, 0.0.0.0:12001->8080/tcp invoker0
3f1287e56e07 whisk/controller:latest "/bin/sh -c 'exec /i…" 10 minutes ago Up 10 minutes 0.0.0.0:15000->15000/tcp, 0.0.0.0:16000->16000/tcp, 0.0.0.0:8000->2551/tcp, 0.0.0.0:10001->8080/tcp controller0
e4f4b8a35182 wurstmeister/kafka:0.11.0.1 "start-kafka.sh" 10 minutes ago Up 10 minutes 0.0.0.0:9072->9072/tcp, 0.0.0.0:9093->9093/tcp kafka0
db10c72113e4 zookeeper:3.4 "/docker-entrypoint.…" 10 minutes ago Up 10 minutes 0.0.0.0:2181->2181/tcp, 0.0.0.0:2888->2888/tcp, 0.0.0.0:3888->3888/tcp zookeeper0
71df5847d252 redis:3.2 "docker-entrypoint.s…" 22 minutes ago Up 22 minutes 0.0.0.0:6379->6379/tcp redis
root@iZa2d4spx9n9e90jofcyxoZ:~/openwhisk/ansible# ansible-playbook -i environments/local openwhisk.yml
root@iZa2d4spx9n9e90jofcyxoZ:~/openwhisk/bin# export PATH=$PATH:$PWDroot@iZa2d4spx9n9e90jofcyxoZ:~/openwhisk/bin# wsk        ____      ___                   _    _ _     _     _
/\ \ / _ \ _ __ ___ _ __ | | | | |__ (_)___| | __
/\ /__\ \ | | | | '_ \ / _ \ '_ \| | | | '_ \| / __| |/ /
/ \____ \ / | |_| | |_) | __/ | | | |/\| | | | | \__ \ <
\ \ / \/ \___/| .__/ \___|_| |_|__/\__|_| |_|_|___/_|\_\
\___\/ tm |_|
sudo nano hello.js
/**
* Hello world as an OpenWhisk action.
*/
function main(params) {
var name = params.name || 'World';
return {payload: 'Hello, ' + name + '!'};
}
wsk action create hello hello.js
wsk action invoke hello --result{
"payload": "Hello, World!"
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com