/ Tyk

Setting up Tyk on Ubuntu

First of all, you need to know that Tyk it's divided in three different components:

  • Tyk Gateway: This is the implementation of the API Gateway
  • Tyk Dashboard: This is the easy Administration panel with it's UI to configure all.
  • Tyk Pump: And this one is the daemon that gets the logs from the Gateway to the Dashboard.

Now, we'll guide you on how to setup your the Tyk Suite in your local environment.

Dependencies

The Tyk Gateway requires RedisDB in order to run, so that's our first step. Fortunately, it will ship with most Ubuntu In-Release versions (For any special installations please refer to the official RedisDB documentation):

sudo apt-get update && sudo apt-get install -y redis-server

Once that's done, the dashboard and the pump both rely on MongoDB as their persistence solution. And to install Mongo we'll need the public key to their repositories on our system:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6

Now we need to set the repositories depending on our Ubuntu In-Release version(For any special installations please refer to the official MongoDB documentation):

  • Ubuntu 12.04 - Precise
echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
  • Ubuntu 14.04 - Trusty
echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
  • Ubuntu 16.04 - Xenial
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

And finally we are really to install Mongo, so let's run the following commands to update our repositories, download and install Mongo:

sudo apt-get update && sudo apt-get install -y mongodb-org

On to Tyk Installation

An important remark to make about the Tyk Suite is the fact that the Dashboard and the Pump components of the suite are behind a pay wall (A free license is available). Nevertheless, the core functionality is implemented on the Gateway and the Dashboard is just to ease the final user with GUI and the Pump to get analytics going.

With that out of the way, will need to setup the repository key and select the right version for our system; but for our ease will be using a script that will add the key and detect our operating system (if it fails, it will mean that our OS is not supported so please refer to the official Tyk documentation):

  • Tyk Gateway
curl -s https://packagecloud.io/install/repositories/tyk/tyk-gateway/script.deb.sh | sudo bash
  • Tyk Dashboard
curl -s https://packagecloud.io/install/repositories/tyk/tyk-dashboard/script.deb.sh | sudo bash
  • Tyk Pump
curl -s https://packagecloud.io/install/repositories/tyk/tyk-pump/script.deb.sh | sudo bash

Now that our repositories are setup correctly, we'll need to install every component:

  • Tyk Gateway
sudo apt-get install -y tyk-gateway
  • Tyk Dashboard
sudo apt-get install -y tyk-dashboard
  • Tyk Pump
sudo apt-get install -y tyk-pump

And finally everything it's installed on our system, but of course we aren't done over here. We are missing configurations and starting each service. Since we are gonna need MongoDB and RedisDB services for our Tyk suite make sure they're running:

  • MongoDB
sudo service mongod start
  • RedisDB
sudo service redis-server start

Lets start with the Dashboard, because the Gateway is capable of detecting the dashboard, so it's important to install the Dashboard first:

sudo /opt/tyk-dashboard/install/setup.sh --listenport=3000 --redishost=localhost --redisport=6379 --mongo=mongodb://127.0.0.1/tyk_analytics --tyk_api_hostname=$HOSTNAME --tyk_node_hostname=http://localhost --tyk_node_port=8080 --portal_root=/portal --domain="XXX.XXX.XXX.XXX"
  • --listenport: On which port the dashboard will listen to.
  • --redishost: What's the domain for RedisDB server.
  • --redisport: And which port it is using.
  • --domain: The domain the dashboard is going to be binded to.
  • --mongo: Mongo's host and database that it will use (It should be the same as the Gateway).
  • --tyk_api_hostname: The host where Tyk it's running or any public hostname.
  • --tyk_node_hostname: This is the Gateways location, it should be localhost if it was installed locally.
  • --tyk_node_port: On which port the Gateway is listening.
  • --portal_root: And the root folder on which the dashboard is gonna be shown.

And finally proceed to start the service:

sudo service tyk-dashboard start

Next is the Pump:

sudo /opt/tyk-pump/install/setup.sh --redishost=localhost --redisport=6379 --mongo=mongodb://127.0.0.1/tyk_analytics
  • --redishost: What's the domain for RedisDB server.
  • --redisport: And which port it is using.
  • --mongo: Mongo's host and database that it will use (It should be the same as the Gateway).
    And finally proceed to start the service:
sudo service tyk-pump start

And finally the core part, the Gateway:

sudo /opt/tyk-gateway/install/setup.sh --dashboard=1 --listenport=8080 --redishost=localhost --redisport=6379
  • --dashboard: This is actually binary since the Gateway can auto detect the Dashboard.
  • --redishost: What's the domain for RedisDB server.
  • --redisport: And which port it is using.
  • --mongo: Mongo's host and database that it will use (It should be the same as the Gateway).
sudo service tyk-gateway start

And everything should be ready to start setting up your API's and everything!