InfluxDB Installation
Line 1: | Line 1: | ||
− | [[InfluxDB_Installation|Ubuntu Installation]] | [[InfluxDB_Installation\Oracle_Installation| | + | [[InfluxDB_Installation|Ubuntu Installation]] | [[InfluxDB_Installation\Oracle_Installation|OracleLinux Installation]] |
==Ubuntu 14.04 Installation== | ==Ubuntu 14.04 Installation== | ||
===Add Repo=== | ===Add Repo=== |
Revision as of 09:56, 26 September 2016
Ubuntu Installation | OracleLinux Installation
Ubuntu 14.04 Installation
Add Repo
~$ curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add - ~$ source /etc/lsb-release ~$ echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
Install InfluxDB
~$ sudo apt-get update && sudo apt-get install influxdb -y ~$ sudo service influxdb start
Verify Dev Web Portal
By default, InfluxDB creates a simple web portal that developers can use to verify or generate query strings. You should be able to access it by going to:
http://domain.com:8083/
Database config
Login and create a DB
~$ influx Connected to http://localhost:8086 version 0.13.0 InfluxDB shell version: 0.13.0 > CREATE DATABASE influxdb > SHOW DATABASES name: databases --------------- name _internal influxdb
Testing DB
~$ influx > USE influxdb > INSERT cpu,host=serverA value=0.64 > SELECT * from cpu name: cpu --------- time host value 1467318896821675352 serverA 0.64
Setting up an external write into the database. Open a new shell on the same host.
~$ curl -i -XPOST 'http://localhost:8086/write?db=influxdb' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.60' HTTP/1.1 204 No Content Request-Id: d333c2a3-3f03-11e6-800b-000000000000 X-Influxdb-Version: 0.13.0 Date: Thu, 30 Jun 2016 20:47:14 GMT
Write the same string multiple times to the influxdb, but remember to change the value
~$ curl -i -XPOST 'http://localhost:8086/write?db=influxdb' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.30' ~$ curl -i -XPOST 'http://localhost:8086/write?db=influxdb' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.40'
Verify the data is there
~$ influx > USE influxdb Using database influxdb > SELECT * from cpu_load_short name: cpu_load_short -------------------- time host region value 1434055562000000000 server01 us-west 0.64
Adding an Administrator Account
~$ influx > CREATE USER root WITH PASSWORD 'TuTewlyQsjhMregggQbF' WITH ALL PRIVILEGES
Creating User account with access to Database
~$ influx > CREATE USER influx WITH PASSWORD 'influxdb' > GRANT ALL ON influxdb TO influx
Verify Users and Rights
~$ influx > SHOW USERS user admin root true influx false > SHOW GRANTS FOR influx database privilege influxdb ALL PRIVILEGES
Add Authentication for HTTP requests
Note: I started out with this enabled, then I had to set it back to false in order for collectd to report metrics. As with anything, lock down traffic to your trusted hosts.
Change auth-enabled = false
to auth-enabled = true
~$ sudo vi /etc/influxdb/influxdb.conf [http] enabled = true bind-address = ":8086" auth-enabled = true # log-enabled = true write-tracing = false pprof-enabled = false https-enabled = false https-certificate = "/etc/ssl/influxdb.pem" max-row-limit = 10000
Restart the Service
~$ sudo service influxdb restart
Verify local authentication
Make sure you can still authenticate with your accounts. Non-Admin accounts cannot SHOW DATABASES
or SHOW USERS
~$ influx Connected to http://localhost:8086 version 0.9.4.1 InfluxDB shell 0.9.4.1 > auth root TuTewlyQsjhMregggQbF >
OR
~$ influx -username root -password TuTewlyQsjhMregggQbF
Inserting data with Authentication
This is an example:
~$ curl -i -XPOST 'http://localhost:8086/write?db=influxdb' -u influx:influxdb --data-binary 'cpu_load_short,host=server01,region=us-west value=0.10'
Grafana Test Graph
Verify Data
Before you begin with grafana, you should verify that the data has been inserted into the DB. You can do this quickly by navigating to the Dev Page for InfluxDB: http://domain.com:8083/
Once there, make sure you input the correct
- hostname
- user
- password
- database
- database user
- database user password
Use a simple query that will show your data, like this:
SELECT * FROM cpu_load_short
You can also try to look at 100 values of each type with something like this:
SELECT * FROM /.*/ limit 100
Also, only pull the values from current to (1) hour ago
SELECT * FROM memory_value WHERE time > now() - 1h
Grafana Dashboard
Watch this video: https://youtu.be/sKNZMtoSHN4?list=PLDGkOdUX1Ujo3wHw9-z5Vo12YLqXRjzg2
Remember to click the "Eye" icon once you've selected the Measurement. Without this being selected, the query will never be passed to the InfluxDB and you'll get error messages like:
influxdb error: response missing required parameter q
Influx DB data capture test
SSH Established connections
Determine numeric value
obtain a single numeric value for established connections on specific port(s).
~$ netstat -an | grep -w '22\|2222' | grep ESTABLISHED | wc -l 1
POST to influxdb
~$ curl -i -XPOST 'http://localhost:8086/write?db=collectd' -u influx:influxdb --data-binary 'established_connections,host=localhost,type=ssh value=1' HTTP/1.1 204 No Content Request-Id: d4c9a7bc-40ec-11e6-962c-000000000000 X-Influxdb-Version: 0.13.0 Date: Sun, 03 Jul 2016 07:07:40 GMT
Create script
Capture data point every 5 seconds and post to DB
~$ sudo vi /bin/established_connections.sh #!/bin/bash #script using netstat to look for established connections on either port 22 or 2222 (ssh and custom ssh alt) and report the numeric value to an influx db every (5) seconds. while true; do ec_ssh=$(netstat -an | grep -w '22\|2222' | grep 'ESTABLISHED' | wc -l) db_string='established_connections,host=localhost,type=ssh value='"$ec_ssh" curl -i -XPOST 'http://localhost:8086/write?db=collectd' -u influx:influxdb --data-binary "$db_string" sleep 5 done
~$ sudo chmod +x /bin/established_connections.sh
Create init.d script
Auto Start service at boot, plus start, stop, restart, and status options
~$ sudo vi /etc/init.d/established.connections #!/bin/sh ## BEGIN INIT INFO # Provides: established.connections # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start established.connections at boot time # Description: Load established.connectios at startup to report active connections to InfluxDB ### END INIT INFO #startup function start_established_connections() { printf "Starting Established Connections Monitoring ...\n" /bin/established_connections.sh > /dev/null 2>&1 & printf "... started.\n" } #stopping function stop_established_connections () { printf "Stopping Established Connections Monitoring ...\n" killall -9 established_connections.sh > /dev/null 2>&1 & printf "... stopped.\n" } #restarting function that stops and starts established connections restart_established_connections () { printf "Restarting Established Connections Monitoring ..." stop_established_connections start_established_connections } #status determination status_established_connections () { if [ $(ps -ef | grep -v grep | grep 'established_connections.sh' | wc -l) = 1 ]; then printf "Established Conections Monitoring is running.\n" else printf "Established Connections Monitoring is not running.\n" fi } case "$1" in start) start_established_connections ;; stop) stop_established_connections ;; restart) restart_established_connections ;; status) status_established_connections ;; *) printf "Usage: /etc/init.d/established.connections {start|stop|restart|status}\n" exit 1 ;; esac exit 0
~$ chmod 755 /etc/init.d/iptables.rules ~$ update-rc.d iptables.rules defaults