Install Tyk on Vagrant

Tyk has a streamlined quickstart setup for Vagrant, this demo works with Ubuntu Precise and makes use of direct-pipes to bash from a web script, we do not recommend doing any of this on a prouction machine.

Full, detailed instructions on how to install Tyk on Ubunutu Server (LTS) or how to install Tyk on Red hat Enterprise linux (RHEL) are available and go through the entire process manually.

Given this caveat, lets get you up and running.

Since we are installing on Vagrant, we’re assuming that you are demoing Tyk, and so we’ll be going through a full Tyk Pro install. This demo will install Tyk Gateway, Tyk Pump and Tyk Dashboard on an Ubuntu box in a vagrant instance, we are going to do a little bit of hosts hacking to make your portal URL work properly, but apart from that this is a standard installation.

Installation Steps

0. Initial steps

Edit your /etc/hosts file to give yourself a domain for your portal:

Later, when you have logged into your Dashboard, you can use “Your Developer Portal” -> “Set your portal domain” to set it to this value.

1. Create a folder for testing:

mkdir tyktest && cd tyktest

2. Create a vagrant image:

vagrant init

3. Configure the Vagrantfile

A new file called Vagrantfile has been created, we need to expose port 3000 and use the precise64 base box (we assume you’ve got this, otherwise download it). To do this open the default vagrant file in a text editor and replace the following line: = "base"

with this: = "hashicorp/precise64"

then replace this line: :forwarded_port, guest: 80, host: 8080

with this: :forwarded_port, guest: 3000, host: 3000 :forwarded_port, guest: 8080, host: 8080

4. Spin up your vagrant instance and ssh to it:

vagrant up && vagrant ssh

5. Update the hosts file inside the vagrant box:

sudo vim /etc/hosts


6. Install Mongo and Redis

In order for everything to work, you’ll need MongoDB and Redis installed, this can be done as follows (instructions accurate at time of writing):

sudo apt-key adv --keyserver hkp:// --recv 7F0CEB10

echo 'deb dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list

sudo apt-get update

sudo apt-get install mongodb-org redis-server vim curl

This could take a while as there’s a lot to install, but it will set up a default MongoDB instance and Redis instance on your vagrant box, we don;t recommend doing this in production.

7. The environment is ready, now to install Tyk!

We’re going to install Tyk the fast and dirty way, using a special script that detects your environment and handles the full installation from our APT repository:

curl -s | sudo bash

curl -s | sudo bash

curl -s | sudo bash

sudo apt-get install tyk-gateway tyk-dashboard tyk-pump

Your terminal will update as dependencies and packages are installed, at the end you will be able to bootstrap your new Tyk services.

8. Configure Tyk Gateway

You can set up the core settings for Tyk Gateway with a single setup script, however for more involved deployments, you will want to provide your own configuration file, to get things running lets run:

sudo /opt/tyk-gateway/install/ --dashboard= --listenport=8080 --redishost=localhost --redisport=6379 --domain=""

What we’ve done here is told the setup script that:

  • --dashboard=http://YOUR-DASHBOARD_DOMAIN:3000: We want to use the dashboard, since Tyk Gateway gets all it’s API Definitions from the dashboard service, we need to tell it where the dashboard is. This MUST be the same domain that you use in step 4 below
  • --listenport=8080 Tyk should listen on port 8080 for API traffic
  • --redishost=localhost Use redis on the hostname: localhost
  • --redisport=6379 Use the default redis port
  • --domain="" Do not set a domain for the gateway, see the note on domains below for more about this

9. Configure Tyk Dashboard

We can set the dashboard up with a similar setup command, the below will get the dashboard set up for the local instance, make sure to use the actual DNS hostname or the public IP of your instance as the last parameter:

sudo /opt/tyk-dashboard/install/ --listenport=3000 --redishost=localhost --redisport=6379 --mongo=mongodb:// --tyk_api_hostname=$HOSTNAME --tyk_node_hostname=http://localhost --tyk_node_port=8080 --portal_root=/portal --domain=""

What we have done here is:

  • --listenport=3000 Told Tyk Dashboard (and Portal) to listen on port 3000
  • --redishost=localhost Tyk Dashboard should use the local redis instance
  • --redisport=6379 Tyk Dashboard should use the default port
  • --domain="XXX.XXX.XXX.XXX" Bind the dashboard to the IP or DNS hostname of this instance (required)
  • --mongo=mongodb:// Use the local MongoDB (should always be the same as the gateway)
  • --tyk_api_hostname=$HOSTNAME – Tyk Dashboard has no idea what hostname has been given to Tyk, so we need to tell it, in this instance we are just using the local HOSTNAME env variable, but you could set this to the public-hostname/IP of the instance
  • --tyk_node_hostname=http://localhost – Tyk Dashboard needs to see a Tyk node in order to create new tokens, so we need to tell it where we can find one, in this case, use the one installed locally
  • --tyk_node_port=8080 Tell the dashboard that the Tyk node it should communicate with is on port 8080
  • --portal_root=/portal – We want the portal to be shown on /portal of whichever domain we set for the portal

10. Configure Tyk Pump

If you don’t complete this step, you won’t see any analytics in your dashboard, so to enable the analytics service, we need to ensure Tyk Pump is running and configured properly, to configure Tyk Pump is very simple:

sudo /opt/tyk-pump/install/ --redishost=localhost --redisport=6379 --mongo=mongodb://

11. Start Tyk Pump and Tyk dashboard:

    sudo service tyk-dashboard start
    sudo service tyk-pump start

12. Enter your dashboard license

Go to http://your-host-name:3000/

And you will see a screen asking for a license, enter it in the section marked “Already have a license?” and click Use this license

That’s it, your Dashboard is now ready to be bootstrapped.

Note: You can bypass this step by adding your license manually to the /var/opt/tyk-dashboard/tyk_analytics.conf file directly in the field marked license.

If all is going well, you will be taken to a log in screen – we’ll get to that soon.

13. Restart the dashboard and start the gateway process

Because we’ve just entered a license via the UI, we need to make sure that these changes get picked up, so to make sure things run smoothly, we restart the dashboard process (you only ned to do this once) and then start the gateway:

sudo service tyk-dashboard restart 
sudo service tyk-gateway start

14. Bootstrap the dashboard with an initial user and organisation:

When Tyk Dashboard is created for the first time, it has no initial user base or organisation to add data to, so we need to add this.

The best way to add this data is with the Admin API, to make it really easy we’ve supplied a bootstrap script that will set you up. If you want to customise it, take a look at the file in /opt/tyk-dashboard/install/

To bootstrap your instance, run from INSIDE the vagrant box:

sudo /opt/tyk-dashboard/install/

This command tells the bootstrap script to use the localhost as the base for the API calls, you can run the bootstrap remotely and change the first command line parameter to the DNS hostname of your instance.

You will now be able to log into and test your Tyk instance with the values given to you by the bootstrap script.

Next Steps

Was this article helpful to you? Yes No