Upgrade InfluxDB 1.8 to 2.x on Ubuntu 20.04

This procedure is based on InfluxDB installs from the official InfluxDB repo apt-based installs with all files at the default locations.

Make sure you backup all your data. All of it. Seriously. Also, AFTER backing up, take a snapshot if you are running in a virtual environment. It took me more than 12 attempts on my test system to distill down the following steps. You don’t want that amount of downtime on a production rig. I went on to complete upgrades on 8 additional production rigs (also updating from 18.04) without failure using the instructions below, typically having less than 15 minutes of downtime per system. TLS/SSL also works post migration if you have that enabled.

Make note of any admin users in the existing InfluxDB v1 install, they will NOT be migrated.

# sudo influx -username {admin user} -password ''
> SHOW USERS

Make sure the system is up-to-date.

sudo apt update
sudo apt upgrade

Check your disk space, when you run the upgrade script all your existing data is copied to a new 2.x database, effectively doubling your storage requirements temporarily. The command below will tell you how much storage space influxdb is currently using. There are loads of great tutorials for expanding your disk size depending on your disk format. Just Google it.

sudo du -sh /var/lib/influxdb/

Add the InfluxDB repository for Ubuntu 20.04 Focal and update apt.

echo "deb https://repos.influxdata.com/ubuntu focal stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo curl -sL https://repos.influxdata.com/influxdb.key |
sudo apt-key add -
sudo apt update

Upgrade InfluxDB

sudo apt install influxdb2

Once the install completes, it will tell you to run the influxdb2-upgrade.sh script to migrate the database. The file doesn’t actually exist at the location shown, so download it from GitHub and make it executable.

wget https://raw.githubusercontent.com/influxdata/influxdb/master/scripts/influxdb2-upgrade.sh
sudo chmod +x influxdb2-upgrade.sh

Stop the existing instance of InfluxDB

sudo systemctl stop influxdb

Run the upgrade script and answer the questions when prompted. The username and password are the new admin password to log into the web instance running on port 8086. All non-administrative users are migrated, but admin users ARE NOT migrated.

sudo ./influxdb2-upgrade.sh
Welcome to InfluxDB 2.0 upgrade! 
Please type your primary username: <your-username> 
Please type your password: 
Please type your password again: 
Please type your primary organization name: <your-org> 
Please type your primary bucket name: <your-bucket> 
Please type your retention period in hours. Or press ENTER for infinite: 
You have entered:  
Username:          <your-username>  
Organization:      <your-org>  
Bucket:            <your-bucket>  
Retention Period:  infinite 
Confirm? (y/n): y

Wait for the system to migrate all the data and watch for any warnings. Once done, start InfluxDB and check to ensure it started correctly.

sudo systemctl start influxdb
sudo systemctl status influxdb

Log into the new web console at http://IP-or-Host:8086 and obtain the admin token by clicking “Copy to Clipboard”.

InfluxDB Data Tokens Page
InfluxDB Data Admin Tokens Page

To make future admin tasks easier, add the admin token to the environment variable INFLUX_TOKEN.

echo "INFLUX_TOKEN=YourTokenFromTheWebInterfaceHere" | sudo tee -a /etc/default/influxdb2

If you need to add additional read or write users to all buckets:

sudo influx user create -n telegraf -o "my org" -p password
sudo influx auth create -u telegraf -o "my org" --write-buckets
sudo influx user create -n grafana -o "my org" -p password
sudo influx auth create -u grafana -o "my org" --read-buckets

To create InfluxDB v1 users for InfluxQL queries, first list the available buckets and obtain their IDs and then give a V1 user permission to read or write to that bucket.

sudo influx bucket list -o "my org"
sudo influx v1 auth create --username grafana -o "my org" --read-bucket {bucket-id} --write-bucket {bucket-id}

Update Telegraf configurations to use v2 outputs and restart the Telegraf process.

sudo vim /etc/telegraf/telegraf.conf
[outputs.influxdb_v2]
   urls = ["https://127.0.0.1:8086"]
 ## Token for authentication.
   token = "MyWriteTokenFromCLIorWebInterface"
 ## Organization is the name of the organization you wish to write to; must exist.
   organization = "my org"
 ## Destination bucket to write into.
   bucket = "MyV1DB/autogen"
sudo systemctl restart telegraf

Verify all your data is accessible and working as required. Once you are fully sure that everything is operating correctly, delete the v1 backup data by running the remove script.

sudo /var/tmp/influxdbv1-remove.sh

And that should be all.

All Code from above to make life easier:

sudo influx -ssl -username {admin user} -password ''
SHOW USERS 
sudo apt update
sudo apt upgrade
sudo du -sh /var/lib/influxdb/
echo "deb https://repos.influxdata.com/ubuntu focal stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo curl -sL https://repos.influxdata.com/influxdb.key |
sudo apt-key add -
sudo apt-get update
sudo apt install influxdb2
wget https://raw.githubusercontent.com/influxdata/influxdb/master/scripts/influxdb2-upgrade.sh
sudo chmod +x influxdb2-upgrade.sh
sudo systemctl stop influxdb
sudo ./influxdb2-upgrade.sh
Welcome to InfluxDB 2.0 upgrade! 
Please type your primary username: <your-username> 
Please type your password: 
Please type your password again: 
Please type your primary organization name: <your-org> 
Please type your primary bucket name: <your-bucket> 
Please type your retention period in hours. Or press ENTER for infinite: 
You have entered:  
Username:          <your-username>  
Organization:      <your-org>  
Bucket:            <your-bucket>  
Retention Period:  infinite 
Confirm? (y/n): y
sudo systemctl start influxdb
sudo systemctl status influxdb
echo "INFLUX_TOKEN=YourTokenFromTheWebInterfaceHere" | sudo tee -a /etc/default/influxdb2
sudo influx user create -n telegraf -o "my org" -p password
sudo influx auth create -u telegraf -o "my org" --write-buckets
sudo influx user create -n grafana -o "my org" -p password
sudo influx auth create -u grafana -o "my org" --read-buckets
sudo influx bucket list -o "my org"
sudo influx v1 auth create --username grafana -o "my org" --read-bucket {bucket-id} --write-bucket {bucket-id}
sudo vim /etc/telegraf/telegraf.conf
[outputs.influxdb_v2]
    urls = ["https://127.0.0.1:8086"]
  ## Token for authentication.
    token = "MyWriteTokenFromCLIorWebInterface"
  ## Organization is the name of the organization you wish to write to; must exist.
    organization = "my org"
  ## Destination bucket to write into.
    bucket = "MyV1DB/autogen"
sudo systemctl restart telegraf
sudo /var/tmp/influxdbv1-remove.sh

1 comment

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.