Skip to content

Instantly share code, notes, and snippets.

@kylemarsh
Last active March 18, 2016 02:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylemarsh/f8e7b99c83afdd2589c7 to your computer and use it in GitHub Desktop.
Save kylemarsh/f8e7b99c83afdd2589c7 to your computer and use it in GitHub Desktop.
Install and Run InfluxDB on a DreamHost VPS

Installing InfluxDB on a DreamHost VPS

Get the VPS

  1. If you don't already have one (or you want InfluxDB to have its own) Head to the panel and get thyself a VPS!
  2. Hit the "Configure" button and on the next page, the "Public Keys" link in the "Root SSH Keys" section.
  3. Create (or upload) a new keypair for your VPS. Safe the private key to your local ~/.ssh/ps123456.rsa or something.
  4. Head over to the users section and add a new, non-admin user (this example will use newinfluxdb). We'll come back to this later.

Install InfluxDB

  1. Log in to your VPS as root using something like this:

    ssh -i ~/.ssh/ps123456.rsa root@ps123456.dreamhostps.com
    
  2. Follow the installation instructions for debian/ubuntu here.

Congratulations! You've installed InfluxDB on your VPS. However, there's one catch left...

Tweak InfluxDB

Unfortunately, installing InfluxDB from the .deb package provided creates a user named influxdb to run the daemon as, and DreamHost's configuration tools will destroy that user since they don't know about it. So next we have to tell InfluxDB to use the newinfluxdb user we created earlier.

  1. Find the groupname for your new user:

    root@ps392475:~# su -c id newinfluxdb
    uid=17482136(newinfluxdb) gid=483726(pg2043729) groups=483726(pg2043729)
    
  2. Create /etc/default/influxdb and put the following two lines, changing the user and group as appropriate:

    RUNAS_USER=newinfluxdb
    RUNAS_GROUP=pg2043729
    
  3. Copy /etc/init.d/influxdb to ~/influxdb.orig in case of trouble and update /etc/init.d/influxdb to match this patch:

    root@ps392475:~# diff -u ./influxdb.orig /etc/init.d/influxdb
    --- ./influxdb.orig 2015-01-09 09:32:27.506643044 -0800
    +++ /etc/init.d/influxdb    2015-01-09 09:32:42.937666881 -0800
    @@ -39,6 +39,16 @@
         STDOUT=/dev/null
     fi
    
    +# If you change either of these, then you'll need to manually chown
    +# whatever the default user already owns.
    +if [ "x$RUNAS_USER" == "x" ]; then
    +        RUNAS_USER=influxdb
    +fi
    +
    +if [ "x$RUNAS_GROUP" == "x" ]; then
    +        RUNAS_GROUP=influxdb
    +fi
    +
     echo "Setting ulimit -n $NOFILES"
     if ! ulimit -n $NOFILES >/dev/null 2>&1; then
         echo -n "Cannot set the max number of open file descriptors"
    @@ -113,11 +123,11 @@
             # Log the message appropriately
             cd /
             if which start-stop-daemon > /dev/null 2>&1; then
    -            nohup start-stop-daemon --chuid influxdb:influxdb -d / --start --quiet --oknodo --pidfile $pidfile --exec $daemon -- -pidfile $pidfile -config $config >> $STDOUT 2>&1 &
    +            nohup start-stop-daemon --chuid ${RUNAS_USER}:${RUNAS_GROUP} -d / --start --quiet --oknodo --pidfile $pidfile --exec $daemon -- -pidfile $pidfile -config $config >> $STDOUT 2>&1 &
             elif set | egrep '^start_daemon' > /dev/null 2>&1; then
    -            start_daemon -u influxdb ${daemon}-daemon -pidfile $pidfile -config $config >> $STDOUT 2>&1
    +            start_daemon -u ${RUNAS_USER} ${daemon}-daemon -pidfile $pidfile -config $config >> $STDOUT 2>&1
             else
    -            su -s /bin/sh -c "${daemon}-daemon -pidfile $pidfile -config $config >> $STDOUT 2>&1" influxdb
    +            su -s /bin/sh -c "${daemon}-daemon -pidfile $pidfile -config $config >> $STDOUT 2>&1" ${RUNAS_USER}
             fi
             log_success_msg "$name process was started"
             ;;
    
  4. Change the ownership for all the files installed by the package:

    1. Note the UID and GID for the old influxdb user (both are 998 here):

      root@ps389191:~# grep influxdb /etc/passwd
      influxdb:x:998:998::/home/influxdb:/bin/sh
      
    2. Change the owner of all files owned by influxdb to newinfluxdb (change uid and username as necessary): find / -uid 998 -exec chown newinfluxdb {} +

    3. Change the group of all files in the old group (change gid and groupname as necessary): find / -gid 998 -exec chgrp pg2043729 {} +

  5. Start the daemon and test it out!

    1. Start the daemon with /etc/init.d/influxdb start
    2. Check it out by pointing your browser to http://ps123456.dreamhostps.com:8083
    3. Log in using "root" as both the username and password.
    4. Click "Cluster Admins" at the top of the page, make a new administrator, and delete the old one.

Point a Domain at it

At this point you have influxdb running on your VPS, and you can connect to it using the IP address assigned to your VPS or the VPS's hostname on the dreamhostps.com domain. However, if you'd like a more friendly DNS name to use that will update automatically when your IP address changes or you get migrated to a different VPS, you should create a domain in DreamHost's panel and host it on the machine.

  1. Go to the manage domains section of the panel
  2. Click the "Add Hosting to a Domain / Sub-Domain" button
  3. Fill in the topmost form ("Fully Hosted"), making sure to host the domain under the user on your influxdb VPS

Just wait for DNS to propagate and you now can access your influxdb installation at the domain or subdomain you hosted on that machine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment