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 that 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 you can read more about it here.
To spin up a Vagrant TICK Stack, you need the following:
- A Vagrantfile
- A bootstrap script
- Any files that 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 a link at the end of this article 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" to
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 that 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 that will be mounted on our VM at
/vagrantconfig.vm.synced_folder "data/", "/vagrant", type: "virtualbox". Lastly, we are allocating 4GB of memory. This can be modified by changing the 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 that 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-184.108.40.206.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:
$ ./up.sh. 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
$ ./restore.sh. 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 development and testing purposes. All the scripts and files I mention in this article are available on GitHub here.
Now start coding!