# Setting Up Cacti On FreeBSD 7.0



## nabsta (Nov 16, 2008)

There seems to be a lot for Cacti on linux forums but none or very few on FreeBSD, so here you go,Comments are welcome.

*About Cacti*

Cacti is a complete network graphing solution designed to harness the power of RRDTool's data storage and graphing functionality. Cacti provides a fast poller, advanced graph templating, multiple data acquisition methods, and user management features out of the box. All of this is wrapped in an intuitive, easy to use interface that makes sense for LAN-sized installations up to complex networks with hundreds of devices.

Assuming that freebsd has been installed on a machine,Installation instructions can be found at the FreeBSD Website: http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/index.html.If you have not updated the ports tree, do this now by :

_#portsnap fetch update
#portaudit -F
#portmaster -a
_
- Now you have the latest snapshot of the ports tree


*Install Apache + PHP*
Since Cacti needs a web server to serve its php based pages, we need to install Apache + PHP5 

_#cd /usr/ports/www/apache22
# make config _
- make sure Mysql Support is enbaled as Cacti will use this its backend db.
_# make install clean_

Now install PHP 5
_#cd /usr/ports/lang/php5
#make config _
- make sure apache module is selected here or else PHP will not work
_#make install clean_

Now lets configure apache to work with PHP:

There will need to be some lines to /usr/local/etc/apache22/httpd.conf so that the php modules will work, and load php pages. At the end of the LoadModules section of httpd.conf: 
_AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps_
Append this to the line for DirectoryIndex: 
_index.php_

Add this to /etc/rc.conf to autostart Apache at boot:

_apache22_enable="YES"_

Now test if apache is working by starting it using :

_# /usr/local/etc/rc.d/apache22 start_

*System Graphing, powered by MySQL & Cacti*

Compile MySQL 5.0 Server 
_# cd /usr/ports/databases/mysql50-server; make install clean_

- Configure MySQL server to load at boot, add this to /etc/rc.conf: 
_mysql_enable="YES"_
and then start MySQL server by :
_# /usr/local/etc/rc.d/mysql-server start_

Install net-snmp
_# cd /usr/ports/net-mgmt/net-snmp; make install clean_

Cacti is a powerful network graphing utility that front ends Rrdtool. This process will compile Rrdtool and all of its dependencies for you. 
_# cd /usr/ports/net-mgmt/cacti; make install clean
_


By Now we have are almost there,check that we have installed all the dependencies and requirements:

- Apache
- PHP
- Cacti (this included its dependencies, rrd's etc)
- MySql
- Net-snmp

In order to access the Cacti web directory, we have to add a directory listing to our apache httpd-local.conf file . Edit the file /usr/local/etc/apache22/Includes/httpd-local.conf, and add these lines: 

_<Directory /usr/local/share/cacti>
    AllowOverride None
    Order Allow,deny
    Allow from all
</Directory>
Alias /graphs /usr/local/share/cacti/_

The following needs to be added to your /etc/crontab, to poll your system information every 5 minutes. 

_*/5 * * * * cacti /usr/local/bin/php /usr/local/share/cacti/poller.php > /dev/null 2>&1
_

Setup The Database

_#mysqladmin --user=root create cacti_

Set the passwd for the cacti user. 
_# passwd cacti_
Changing local password for cacti
New Password: [cactipasswd]
Retype New Password: [cactipasswd]

note that you may need to add a user with nologin 

Edit the /usr/local/share/cacti/include/db-settings.php file for the proper database permissions: 

_$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cactipasswd";
$database_port = "3306";_

Set the Cacti database's permissions. 

_#echo "GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'cactipasswd'; FLUSH PRIVILEGES;" | mysql
_

Import the default tables. 
_#mysql cacti < /usr/local/share/cacti/cacti.sql_

Finally, restart apache and mysql , then log into the page, using the /graphs alias that was set up earlier. The default login and password is admin:admin, and you will be prompted to change it on your first successful login. 

http://yourserver.yourdomain.com/graphs


----------



## lazyBSD (Nov 16, 2008)

net-mgmt/cacti-spine poller is more preferable than internal one.


----------



## cnr (Nov 17, 2008)

[font="Trebuchet MS"]a faultless exposition for cacti.. thanks :stud[/font]


----------



## terminus (Nov 17, 2008)

He-he, fellow, AFAIK it is just retyping from oficial cacti's installation instructions? I know it because I have been installed cacti a couple of days ago  Anyway, thanks for this how-to - it is nice to have this kind of step-by-step instructions...

Right now I spend time to "get into" the logic of cacti - there is no trivial design (all this Data Input Methods, Data Queries, Templates and so on...) - I'm a litle confused because there is too many fresh concepts 

May be you can provide also step-by-step instructions about how-to build new custom graph in cacti and show there explanation/usage examples for all this misty things? I do not found any clear explanation jet in cactis's manuals (looks like I'm toooo lazy or they a hid some there)

P.S.
Sorry for my English if any...


----------



## APseudoUtopia (Nov 17, 2008)

terminus said:
			
		

> May be you can provide also step-by-step instructions about how-to build new custom graph in cacti and show there explanation/usage examples for all this misty things?



I agree, something like that would be extremely helpful. Maybe a quick guide on how to setup some basic graphs and options, like memory usage, server load, stuff like that.

Thanks a lot for the guide!

Also:


			
				lazyBSD said:
			
		

> net-mgmt/cacti-spine poller is more preferable than internal one.


Any more info on that? I quickly read up about it, and it definitely seems like it would be much faster. The pkg-descr says: "Cactid is a replacement for the default cmd.php poller so you must decide if using Cactid makes sense for your installation."

So, is there any reason _NOT_ to use the spine poller?

Thanks for the info.


----------



## taromaru (Nov 17, 2008)

APseudoUtopia said:
			
		

> I agree, something like that would be extremely helpful. Maybe a quick guide on how to setup some basic graphs and options, like memory usage, server load, stuff like that.
> 
> Thanks a lot for the guide!



Count me in too 

Thanks for the guide and if somebody could provide some info on the first steps to create customs graphs... I would be thankful.

When using cacti, I also found that actually using it was the difficult thing, rather than installing it, which is pretty straight forward if you follow the documentation.


----------



## nabsta (Nov 18, 2008)

If you need help on the graphing side of things i am always available for help, you can find my: Aim,Skype and msn Ids to nudge me.

cheers


----------



## dave (Nov 20, 2008)

*Localhost Memory Usage*

Here is some help for getting your localhost memory usage graph working:

http://forums.cacti.net/about5794.html


----------



## chrcol (Nov 21, 2008)

I found that the latest 1.3.x rrdtool produced graphs with misaligned legend text so am using rrdtool-1.2.28.

Then set title font file and Legend font file in the user preferences to this.

/usr/local/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf


----------



## vivek (Nov 21, 2008)

Excellent, can you edit post and add use code tags for actual commands?


----------



## APseudoUtopia (Nov 21, 2008)

chrcol said:
			
		

> I found that the latest 1.3.x rrdtool produced graphs with misaligned legend text



Is this what you're talking about?
http://img88.imageshack.us/img88/6886/graphimageec1.png

I added a few extra spaces in front of "Inbound", hoping it would align everything properly, but it didn't.

I'm using RRDTool v1.3.3 from the ports system.

Anyone know of a fix for that? Other than installing RRDTool v1.2.x. I'd rather not play around with switching versions and such...I just finished setting this up, I don't wanna break it already, haha.


----------



## chrcol (Nov 24, 2008)

unfortenatly imageshack is very unreliable and for the last 30 minutes I have been trying to load the image but just times out 

if it is the same problem then going down to rrdtool 1.2 should fix it as cacti wasnt coded for use with 1.3.  Its a mistake on the port dependency config to move to 1.3.


----------



## coolest (Jan 14, 2009)

Hi,

I'm following all the instructions provided and completed all the installations but when I visit the URL locahost/graphs I have this error



> Invalid PHP_SELF Path



Any Ideas?:q

I'm using 7.1 release...

Thanks.


----------



## coolest (Jan 15, 2009)

Solved the problem by uninstalling the cacti ports and install from the cacti website.


----------



## blackjack (Jan 15, 2009)

For monitoring big traffic flow you can make snmp with counter64 and then use this to get counters value 


```
cd /usr/ports/net-mgmt/net-snmp && make WITH_MFD_REWRITES=yes install clean
```


```
/usr/local/bin/snmpget -v2c -c admin -Oqv localhost F-MIB::ifHCInOctets.1
```


```
/usr/local/bin/snmpget -v2c -c admin -Oqv localhost F-MIB::ifHCOutOctets.1
```

or change configuration cacti to get counter value from ifHCInOctets, ifHCOutOctets


----------



## chrcol (Jan 23, 2009)

APseudoUtopia said:
			
		

> Is this what you're talking about?
> http://img88.imageshack.us/img88/6886/graphimageec1.png
> 
> I added a few extra spaces in front of "Inbound", hoping it would align everything properly, but it didn't.
> ...



yes I can confirm this is same problem.

rrdtool-1.2.28 is the fix unfortenatly.


----------



## dbolton (Nov 8, 2011)

nabsta,
I know this original howto is 'old' at this point but wanted to add my two cents on getting it installed on FBSD version 8.2
Three things. Thanks for this write up as it helped me get about 90% there on installing/configuring Cacti. Two things missing though, and maybe a typo:
I had to remove "cacti" from the crontab as it error-ed out (right after the */5 * * * *...)
I had to install SNMP support into PHP5, this is available only in the php5-extensions port.
Lastly, cacti requires the rrdtool database as well. 

I had everything configured and yet could not get rrdtool to create the graphs. I went back through my config files on each port install and noticed that SNMP was not checked on the php5-extensions port. After a renewal of the config file with SNMP support, cacti began graphing. correctly!
Thanks again
-David


----------



## SirDice (Nov 8, 2011)

dbolton said:
			
		

> I went back through my config files on each port install and noticed that SNMP was not checked on the php5-extensions port.


All this does is install net-mgmt/php5-snmp.


----------



## dbolton (Nov 10, 2011)

SirDice, you are correct. I also saw that the correct version of RRDTool (1.4) _was_ installed with the cacti port. Installing rrdtool directly caused other problems for me so I had to uninstall that package too. My cacti installation seems to be a little happier now. 

Ah, the error's of one's ways and the humility to accept them...never gets old ;-P


----------



## nabsta (Nov 11, 2011)

Hi Guys,

Yes the cacti install is quite old but the same concept. A point to note, Makefile in the ports directory already contains:


```
RUN_DEPENDS=    rrdtool:${PORTSDIR}/databases/rrdtool
```

so you dont have to install it separately. 

I dont know why the cron job did not run


```
*/5 * * * * cacti /usr/local/bin/php /usr/local/share/cacti/poller.php > /dev/null 2>&1
```

Maybe your paths were different. But anyway, I assume all works now.

Great to be of assistance.


----------



## SirDice (Nov 11, 2011)

nabsta said:
			
		

> I dont know why the cron job did not run
> 
> 
> ```
> ...



Not the best way to do it. It looks like you added it to /etc/crontab.
You should add it like so:
`# crontab -u cacti -e`
Then it needs to look like this:

```
*/5 * * * * /usr/local/bin/php /usr/local/share/cacti/poller.php > /dev/null 2>&1
```

Don't add things to /etc/crontab. It's mainly used for system related things and it might be modified when you update your system. Use the crontab(1) command.


----------

