This is a update to my original installation guide for OSX Server 10.8 I just recently re-did my entire install and this is how I did it. I currently find it easier to use phpMyAdmin to do most of my php lifting but for the purpose of this guide I kept it as close to the last one as possible for ease of use.
Getting your server setup
I started running OSX server, as I was looking for something with an insanely low power draw, and something that had a little power. I settled on a mac mini server and haven’t looked back. I have been running some form of a mac server since 2010 and while it has it’s drawbacks like any os I find that is is a super stable, relatively secure (with a little knowledge and elbow grease), and just easy to use server for home / small business use. It also has an amazing wiki with workgroup support. Well I could turn this into a reason’s why I like OSX server but I wont. Ill just say I use it so were setting up cacti on it.
On OSX server this is pretty simple, open up your server tool and go to websites, make sure you check Enable PHP web applications and click the on button. You could set it up all fancy like with its own directory and dns settings, but thats beyond the scope of this article and just getting it running is the idea you can gussy it up later. For now we will install it into a sub directory of the default placeholder website.
The next thing you want to do is download cacti, MYSQL, XQuartz and install homebrew.
I downloaded cacti 0.8.8b from here.
I downloaded MySQL Community Server 5.6.15 from here. (grab the Mac OS X 10.7 (x86, 64-bit), DMG Archive)
I downloaded the latest copy of MySQL Workbench from here.
I downloaded XQuartx 2.7.5 from here.
I installed homebrew from here. (just wait we will install it later)
Ok now we have all the ingredients, lets start making some cacti soup.
Install the Prerequisites
First off lets install Xquartz, open that installer and just click on through. It will tell you at the end of the install that it needs to reboot, go ahead and reboot then we will proceed.
Open your terminal up and type this:
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
I then reccomend you do a brew update to grab all the latest sources and whatnot, just to be sure.
Now that homebrew is installed we will install the prerequisites for cacti. Copy and paste these commands in order this will install rrdtool and its dependencies.
brew install rrdtool
This will take a while but once your done continue on to MYSQL.
Like any good web tool you need a database for your data, on previous versions of OSX server MySQL was installed, they removed it on 10.7 in favor of PostgreSQL so we will be installing a fresh copy of MySQL.
To install mysql open the DMG image you downloaded and just click the installer. Once thats finished click the MySQL StartupItem package, and then the MySQL PrefPane. The startup item will add the prerequisite files for the System Preference pane to run. This last one will add a preference pane to your System Preferences, and will allow the server to stay running and automatically start on reboot.
Next install the MySQL workbench tool.
Open the DMG image and drag it to your applications folder.
Now once all this is installed we need to create a database for our cacti installation. This is pretty easy with the MySQL workbench tool. Open that up and on the right side you should see a little “button” called New Server Instance
Hit this button and basically just hit next a couple times. It will tell you that there is an error but ignore it and hit finish. Now on the right and the left side you should see your new connection It will (if you chose all the defaults) say localhost on the left side under SQL Development, and mysqld@localhost on the right side under Server Administration.
Double click the one on the left side first. You should see a test database and above it you should see a couple buttons. The one you want is called create a new schema in the connected server. Click on this (the Yellow one in the photo below).
For Schema Name type cacti. (or whatever you want to call your database its up to you) Click apply and apply and close and you should see your database setup on the left side.
Ok now close this tab and go back to the default screen in the workbench. Next step is to create a user with access to that database. On the right side click on Manage Security. This will bring up the user and privileges tab. On the bottom of this tab hit add account.
For the purpose of this guide we will just use the defaults you can call the user whatever you want.
Call your user cactiuser and make the password cactiuser limit the connectivity to localhost and hit apply. (you can call this whatever you want and use whatever password you want but for the purpose of this guide this is what Ill refer to from now on)
Now go to the schema privileges tab and select the user you just created cactiuser.
On the right side there is a button that says add entry, select that.
Pick localhost and then select schema select the database we setup earlier cacti now we will define privileges for this user, hit the select all button and hit save changes.
Once your done go back to the SQL Development side and open the database up one more time.
Select cacti (or the database you setup) unzip the cacti download you grabbed earlier. I like to place it in a folder called cacti. Inside the root of that folder there is a file called cacti.sql open that file with a text editor and copy the entire contents of that file to the sql query window.
Once its pasted double click the database you want to use it on for our purposes cacti is the database we want so double click that, and then hit the little lightning bolt on the top.
Once this is done your finally ready to setup the website.
Installing the website
In the previous step we unzipped the cacti site into a folder called cacti, if you didn’t do this, do it now. Now copy this folder to the following location. /Library/Server/Web/Data/Sites/Default/ in order to see this folder on 10.9.* you will need to open finder in the tool bar and hit go to go to folder from the go menu.
You will be asked for an admin name and password and it will copy on over.
Now you will need to edit a file in there so it can connect to your database, Edit the /include/config.php and add your settings to there. I like to do it from the command line. So from the command line type the following.
sudo nano /Library/Server/Web/Data/Sites/Default/cacti/include/config.php (you will have to type your password)
Scroll down until you see the settings above and put your information in there, if you followed along and set it up with the default settings it should look like the photo above. Make sure to change localhost to 127.0.0.1 for some reason OSX 10.7 kinda broke localhost for some programs.
Once the settings above are saved, you should be able to access the install page on the server. Open up your browser and type this.
This will run you through the setup process and then your up and running. Log in with the default username and password. Admin Admin, it will ask you to change your password and then your in.
Make cacti collect data every 5 minutes
Now the last part to make this work successfully is to have it poll the devices, there is a separate poller called spline but for the time being lets just use the default poller. Open up terminal again and type the following. We will be using Apples Launchd service to run this script. Cron while it is still supported is being depreciated, so we will make our install future proof, well as future proof as you can with Apple.
sudo nano /Library/LaunchDaemons/cacti.plist
You will be presented with a black slate after typing your admin password. We are going to create a plist that tells the poller to run every 5 minutes. Or to be more exact every 300 seconds.
?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
Ok now lets give the system ownership of the file so we don’t have any problems with it loading at startup.
chown root /Library/LaunchDaemons/cacti.plist
Now lets tell it to startup.
launchctl load -w /Library/LaunchDaemons/cacti.plist
This should do it, give it about 5 - 10 minutes and see if you start seeing data. Once you do, you can add new devices to the list. I used the this guide to add my Airport Base Station to cacti so I could monitor it properly.
Your installation should now work but just to make sure open up the graphs tab and see if anything shows up. If your unlucky like me it won’t and you will need to change a couple things to get this working right.
If the graphs don’t show up after about 10 minutes, open terminal and do the following.
sudo chown -R _www:_www rra/ log/
sudo chmod -R 777 log rra
This should give the appropriate permissions to the log and the rra folder so cacti can start collecting data.
You may also need to go to system utilities and then hit the rebuild poller cache link.