Influx Vagrant Boxes
By Dave Patton / Nov 03, 2017 / InfluxDB, Community, Telegraf, Developer
One of the great things about InfluxDB and the TICK Stack as a whole is its ease of use. InfluxData provides downloads for a variety of operating systems and architectures and even an official Docker image. But what if I just want to spin up a quick TICK Stack to test something out like a TICKscript or a new Telegraf plugin I am building (hint at future blog article)? Enter Vagrant. For those of you who have never used Vagrant, it is a tool for building and managing virtual machine environments in a single workflow. It was created by HashiCorp and more can be read about it at: https://www.vagrantup.com
In order to spin up a Vagrant TICK Stack, you will need the following:
- A Vagrantfile
- A bootstrap script
- Any files you want to test such as config files or your great new plugin.
The Vagrantfile defines the parameters of our VM such as memory, mount points, network etc. I have provided links below to a Github project to fully deploy TICK on Vagrant. Although this blog post is not a tutorial on Vagrant there are some things to note. We are using Centos7 as the OS for our Vagrantbox. You can change this to Ubuntu if you like by changing:
config.vm.box = "centos/7"
config.vm.box = "ubuntu/xenial64"
We have also defined a private network for the VM:
config.vm.network "private_network", ip: "192.168.70.101"
And a shared/synced folder which will allow us to share files from our host to our VM. In this case, we are sharing the data folder on our local machine which will be mounted on our VM at
config.vm.synced_folder "data/", "/vagrant", type: "virtualbox"
Lastly we are allocating 4GB of memory. This can be modified by changing the following line:
vb.memory = "4096"
Our bootstrap script is just a bash script that installs the TICK Stack and sets up our environment. One thing you will need to change are the versions of the TICK Stack you want to install. Set this at the top of the file:
TELEGRAF_VERSION=telegraf-1.3.5-1.x86_64.rpm INFLUX_VERSION=influxdb-1.3.2.x86_64.rpm CHRONO_VERSION=chronograf-18.104.22.168.x86_64.rpm KAPACITOR_VERSION=kapacitor-1.3.1.x86_64.rpm
The rest of this script downloads, installs and starts each component for you. It will also move any configuration files you might have in the data dir to
/etc/[component]. This way you can use custom config files. As an example for Telegraf, we have the following:
# Install Telegraf wget -nv -O $TELEGRAF_VERSION https://dl.influxdata.com/telegraf/releases/$TELEGRAF_VERSION yum localinstall -y $TELEGRAF_VERSION if [ ! -f /vagrant/telegraf/telegraf.conf ]; then echo "Found telegraf.conf. Installing." mv /vagrant/telegraf/telegraf.conf /etc/telegraf fi systemctl start telegraf
Lastly, we are also installing NodeJS. I use Node a lot for quickly developing other tools I might need such as a Telegraf Traffic Generator or an HTTPListener. If you don’t like Node, feel free to comment this out.
Once you have your Vagrantfile and bootstrap script the way you want them, there are two ways to bring up your VM. The first is to simply use:
$ vagrant up
The second way is to use the wrapper scripts in the project:
This will bring the box up and create an initial snapshot called “initial” of the VM. If, after you have been doing things, you want to reset your VM to its initial state use:
Once the VM has started, you start using and testing your TICK Stack. Chronograf should already be running, so open up a browser and start using that, or you can ssh into the VM by using:
$ vagrant ssh
As you see, it’s pretty easy to use Vagrant to spin up a full TICK Stack on a single VM. I think once you start using this you will find it very useful for any development or testing purposes. All the scripts and files I mention in this article are available on Github at: https://github.com/dp1140a/InfluxSandbox
Now start coding.