Zabbix on FreeBSD

Useful Commands for Newbies:

How to install phpMyAdmin on FreeBSD to manage MySQL: http://www.freebsdmadeeasy.com/tutorials/web-server/use-phpmyadmin-to-manage-mysql-on-freebsd.php

Sometimes the zabbix DB tables history and history_log get full and Zabbix stop giving you access to graphs, or graphs become chappy and broke. You have to TRUNCATE those two tables to free up some space.

 

df -a ( or df -h) to see the disc slices utilization
Ctrl+O – jumping between MC and command lines
Scroll Lock + Pg Up and Pg Down – to navigate up and down the console output.
make rmconfig -delete temp config
ee -text editor  ee filename
pwd- to see what directory you currently are
make install
make install all
make clean – to delete compilated config
pkg_info – to see what packages are installed
make search | grep
ps -ax | grep mysql (или Zabbix) to see what processes are running
1>Esc+Enter-clear log file output
Cat – to put on the screen the file content
cat /etc/passwd-to print the password
cat /etc/group- to print the groups
rehash-
touch /var/log/zabbix/zabbix_server.log – a sample of file creation
Ctrl+X и потом C – in MC Privileges granted for the file
uname-a -to see FreeBSD version FreeBSD
bin   sbin /usr/loacl/sbin
Logs will allways be in /var/logs

To navigate around MC (between lower and Upper control panel) to File Properties press  to enter F9 and  F10 to exit

MySQL Commands:
create database zabbix
drop database zabbix

******************************************************************

ZABBIX 2.0.6 and 2.2.4  INSTALL

1. Dowload FreeBSD .iso from freebsd.org
2. Install the OS on your machine create the following partitions during the install
/var 80GB ;
/ (it’s called root)500MB ;
/usr 50GB ;
/tmp 4GB;
/swap 4GB it’s recommended to allocate as much memmory as you have in your RAM for SWAP)

3. # portsnap fetch
# portsnap extract
# portsnap update

4. Next step
/etc/make.conf
WITHOUT_X11=yes

5.
/etc/rc.conf
keymap=”ru.koi8-r”
hostname=”NMS”
ifconfig_em0=”DHCP”
mysql_enable=”YES”
apache22_enable=”YES”
zabbix2_server_enable=”YES”
sshd2_enable=”YES”
ntpd_enable=”YES”

ntpdate_enable=”YES”
ntpdate_program=”/usr/sbin/ntpdate”
ntpdate_flags=”-u ru.pool.ntp.org

If this line are in..do not duplicate them

6. Midnight Commander Installation
cd /usr/ports/misc/mc
make install clean

7.NTP Pools
/etc/ntp.conf
server 0.us.pool.ntp.org
server 1.us.pool.ntp.org
server 2.us.pool.ntp.org
server 3.us.pool.ntp.org

8.ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime

/etc/sysctl.conf
kern.ipc.shmall=2097152
kern.ipc.shmmax=2147483648
kern.ipc.shmmni=4096

***********************************************************************************
***********************************************************************************
FreeBSD is installed we proceed with Zabbix components installation

SQL;Apache;Zabbix Server;Zabbix Frontend
***********************************************************************************
***********************************************************************************

9.### MYSQL
cd /usr/ports/databases/mysql55-server/
make WITH_XCHARSET=all
make install clean

10.ee /etc/rc.conf
mysql_enable=”YES

11.cp /usr/local/share/mysql/my-small.cnf /etc/my.cnf
ee /etc/my.cnf
innodb_data_file_path = ibdata1:10M:autoextend:max:20G
innodb_buffer_pool_size = 1024M (50-80% of RAM)

/usr/local/etc/rc.d/mysql-server start
ps -ax | grep mysql (проверить что MySql запустился)
+

configure password for SQL client:
mysqladmin -u root password Password  –this is an example credentials
+
для справки Tune MySQL ссылка:
http://www.zabbix.com/forum/showthread.php?t=9925
+
для проверки что база доступна:

mysql -uroot -p
Enter password:
> quit

*********************************************************************************

Apache:

When Table pops up for APR choose MySQL.
If no table appear do “pkg_info | grep apr” to see what packege is already installe e.g apr-1.4.6.1.4.1_3
delete the installed package “pkg_delete apr-1.4.6.1.4.1_3″
Install Apache again ARP must the the default part of it and get installed automatically.

### APACHE
cd /usr/ports/www/apache22
make config
make install clean

apache22_enable=”YES” -> /etc/rc.conf
accf_http_load=”YES” -> /boot/loader.conf
/usr/local/etc/apache22/httpd.conf – This is a main Apache config file

ee /usr/local/etc/apache22/httpd.conf
ADD index.php
<IfModule dir_module>
DirectoryIndex index.php index.html

ADD appz
<IfModule mime_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
THIS IDENTIFY WHAT URL ZABBIX WILL HAVE AFTER INSTALL e.g HTTP://10.10.x.x/ZABBIX
ADD ZABBIX DIR & ALIAS
Alias /zabbix “/usr/local/www/zabbix/”
<Directory />
AllowOverride All
Options Indexes FollowSymLinks
Order allow,deny
Allow from all
AllowOverride Options Fileinfo
</Directory>
If you still have problems with Apache
go to ee /etc/hosts  and add these two lines (example)

x.x.x.x    nms.yourconpanydomain.net
x.x.x.x    nms

and save

apachectl stop
apachectl start

********************************************************************************
********************************************************************************

### ZABBIX
cd /usr/ports/net-mgmt/zabbix2-server/
make config
make install clean

CREATE DB Zabbix
mysql -u root -p
Enter password:
mysql> create database zabbix character set utf8;

mysql> grant all on zabbix.* to ‘zabbix’@’localhost’ identified by ‘P@ssw0rd’;
mysql> flush privileges;
mysql> quit

cd /usr/local/share/zabbix22/server/database/mysql

IN DIRECTORY mysql WILL BE FILES .sql. WE HAVE TO IMPORT THEM INTO OUR NEWLY CREATED DB.
DO IT ONE BY ONE IN SEQUENCE LISTED BELOW. FREEBSD WON’T TAKE AN ENTIRE PORTION WITH ALL FILES

cat schema.sql | mysql -u zabbix -p zabbix
Enter password: (in our case password is P@ssw0rd)

cat images.sql | mysql -u zabbix -p zabbix
Enter password: (in our case password is P@ssw0rd)

cat data.sql | mysql -u zabbix -p zabbix
Enter password: (in our case password is P@ssw0rd)
NOW WE HAVE TO CHANGE THE CONFIG IN THE ZABBIX FILE
cd /usr/local/etc/zabbix/
cp zabbix_server.conf.sample zabbix_server.conf
ee zabbix_server.conf

ListenPort=10051
HousekeepingFrequency=2
CacheSize=32M
SenderFrequency=60
DebugLevel=3
Timeout=5
UnreachablePeriod=90
PidFile=/var/tmp/zabbix_server.pid
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=1
AlertScriptsPath=/home/zabbix/bin/
FpingLocation=/usr/local/sbin/fping
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=P@ssw0rd
DBSocket=/tmp/mysql.sock

***************************************************************************************************************

NOW WE HAVE TO GIVE READ/WRITE RIGHTS FOR THE  LOG FILES, WHERE ZABBIX WILL BE DUMPING THE LOG INFO.

mkdir /var/log/zabbix
chown zabbix:zabbix /var/log/zabbix  ( IN THIS CASE zabbix:zabbix  ARE user zabbix AND GROUP zabbix. IF YOU WANT TO SEE
WHO ELSE HAS R/W PERMISSIONS FOR THIS FOLDER IN MC PRESS Ctrl+X+C )
touch /var/log/zabbix/zabbix_server.log
chown zabbix:zabbix /var/log/zabbix/zabbix_server.log
chmod 666 /var/log/zabbix/zabbix_server.log

zabbix_server_enable=”YES” -> /etc/rc.conf

THIS COMMAND IS NECESSARY TO LAUNCH MYSQL A BIT PRIOR TO ZABBIX. THIS COMMAND TELLS ZABBIX WAIT FOR 60 SEC AFTER FREEBSD IS FULLY LOADED)
sleep 60 -> /usr/local/etc/rc.d/zabbix_server
/usr/local/etc/rc.d/zabbix_server start

 

**********************************************************************************************************************
### ZABBIX-FRONTEND (installs PHP&PHP-extensions)
cd /usr/ports/net-mgmt/zabbix2-frontend/
make install clean

Options for PHP:
[X] CLI        Build CLI version
[X] CGI        Build CGI version
[X] APACHE     Build Apache module
[ ] DEBUG      Enable debug
[X] MULTIBYTE  Enable zend multibyte support
[ ] IPV6       Enable ipv6 support
[X] MAILHEAD   Enable mail header patch
[X] LINKTHR

Options for php5-gd:
[X] T1LIB     Include T1lib support
[X] TRUETYPE  Enable TrueType string function
[ ] JIS       Enable JIS-mapped Japanese font support

Options for php5-mbstring:
[X] REGEX  Enable multibyte regex support

Options for php5-mysql:
[ ] MYSQLND  Use MySQL Native Driver

Check httpd.conf for the following strings inside the:
<IfModule mime_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini

max_execution_time = 600
max_input_time = 600
memory_limit = 256M
post_max_size = 32M
upload_max_filesize = 16M
date.timezone = Europe/Moscow
OR
date.timezone = America/New_York

apachectl graceful

VERY IMPORTANT!!!
Since version 9.X PHP must be installed separeletly
The FreeBSD upgrade from 8.3 to 9.2
1.freebsd-update upgrade -r 9.2-RELEASE
freebsd-update install
It will ask you to rebuild 3rd party software. You need to install portupgrade
whereis portupgrade  -= it should be in /usr/ports/ports-mgmt/portupgrade
make install clean
portupgrade -af
it will take long time
after you make freebsd-update install

shutdown -r now

pkg install php5
after go to ports and install the moduel mod_php5

/usr/ports/www/mod_php5
make install clean

After install is fininshed we go to /usr/local/etc/apache22/httpd.conf
and delete:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

put this line in as well
LoadModule php5_module libexec/apache22/libphp5.so

Replacing it to:
<FilesMatch “\.php$”>
SetHandler application/x-httpd-php
</FilesMatch>

<FilesMatch “\.phps$”>
SetHandler application/x-httpd-php-source
</FilesMatch>

 

*********************************************************************************************************************************
NOW WE OPEN THE WEB BROWSER AND GO TO http://ip add/zabbix. zabbix is used in this example because this Alias was specified in httpd.conf.
Follow the configuration steps. The reult of web browser config will be zabbix.conf.php. It’s short. You can either import it into zabbix or manually
re-write it. Follow the instructions below.

### web install
open http://ip_addr/zabbix
perform 8 steps
save zabbix.conf.php
put it into “/usr/local/www/zabbix/conf/zabbix.conf.php”

Example file already exist – zabbix.conf.php You can copy and edit it, make sure Apache have admin wrights to access and edit file.ыли прова. Выберите файл в MC и дайте права на Read and Write by others (Ctrl+X и С)

The sample file id ussually ther. you can either copy and edit it oppropriately. Apache must have the r/w rights to that file.
Choose this file in MC and  press (Ctrl+X and C) and Read and Write by others.

You can change read/write previleges to that file with the following command.
chmod 444 /usr/local/www/zabbix2/conf/zabbix.conf.php

login as admin/zabbix

****************************************************************************************************************
### Zabbix AGENT on FreeBSD
cd /usr/ports/net-mgmt/zabbix-agent
make install clean

cd /usr/local/etc/zabbix
cp zabbix_agentd.conf.sample zabbix_agentd.conf

touch /var/log/zabbix/zabbix_agentd.log
chown zabbix:zabbix /var/log/zabbix/zabbix_agentd.log
chmod 666 /var/log/zabbix/zabbix_agentd.log

ee /usr/local/etc/zabbix/zabbix_agentd.conf
LogFile=/var/log/zabbix/zabbix_agentd.log

zabbix_agentd_enable=”YES” -> /etc/rc.conf

Zabbix AGENT on Windows

Step by step:

1. You have a Win Serveryou want to install Zabbix agent on
2 Go to http://www.zabbix.com/download.php download and unzipthe agent on to the server.
3.Create the folder in C://Zabbix and copy zabbix_agentd.exe;zabbix_send.exe ; zabbix_get.exe; into that folder. Choose 32-Bit or 64-Bit depending on your system.3.Rename zabbix_agentd.win.conf into zabbix_agentd.conf and put it on C:\

4. Create the c:\zabbix_agentd.log
5.Open zabbix_agentd.conf with wordpad. Change the location of the zabbix_agentd.log into C:/Program Files/Zabbix/zabbix_agentd.log
:Hostname=MUN-DVS ; Server=10.25.200.248; LogFile=c:\zabbix_agentd.log Don’t touch the rest
6. Open the DOS commandline cd..to C:/Program Files/Zabbix and execute the following command: zabbix_agentd.exe –config “c:\zabbix\zabbix_agentd.conf” –install6 It should say successful.

7.Goto windows services and make sure that Zabbix agent service started. Start it manually if needed.

 

### SNMPD
ee /etc/snmpd.config
# Change this!
read := “123456”

# open standard SNMP ports
begemotSnmpdPortStatus.0.0.0.0.161 = 1
begemotSnmpdPortStatus.10.10.40.122.161 = 1

snmpd_enable=”YES” -> /etc/rc.conf
snmptrapd_enable=”YES” -> /etc/rc.conf

cd /usr/local/share/snmp
cp snmpd.conf.example snmpd.conf
rocommunity 12345
comment # trapsink
uncomment trap2sink

snmpwalk -v 2c -c 12345 10.10.40.122
run snmpconf
OR
touch /usr/local/share/snmp/snmptrapd.conf

format2  “Trap From %b”
donotlogtraps false
traphandle  default /usr/local/share/snmp/snmptraphandler.pl
ignoreauthfailure  yes
disableAuthorization yes

add -> /usr/local/etc/rc.d/snmptrapd
commecnt #snmptrapd_flags=${snmptrapd_flags-“-p /var/run/snmptrapd.pid”}
add snmptrapd_flags=${snmptrapd_flags-“-a -p /var/run/snmptrapd.pid -Ls 2 -Lf /var/log/snmptraps.log -m ALL”}

put into snmptrapd.conf:
traphandle  default /usr/local/share/snmp/snmptraphandler.pl
&
copy snmptraphandler.pl to
/usr/local/share/snmp

and EDIT snmptraphandler.pl

my $ZABBIX_SERVER = “10.10.x.x”;                     # Hostname/IP-Address of
my $ZABBIX_PORT = 10051;                                # Port of zabbix-server
my $ZABBIX_ITEM = “snmptraps”;                          # Default item name to s
my $ZABBIX_SENDER = “/usr/local/bin/zabbix_sender”;    # Path to your zabbix-sent
my $WILDCARD_HOST =  “SNMP_TRAP_HOST”;                       # Hostname or IP-Ad
my $SEND_ALL_TO_WILDCARD = 0;                       # Send all traps to wildcard
my $ZABBIX_DB_HOST=”127.0.0.1″;
my $ZABBIX_DB_NAME=”zabbix”;
my $ZABBIX_DB_USER=”zabbix”;
my $ZABBIX_DB_PASS=”P@ssw0rd”;

 

 

### NOTE
In the site directory
touch phpinfo.php
ee phpinfo.php

<?php
phpinfo();
?>
start Apache and test www.my_site/phpinfo.php
### SYSLOG
syslogd_enable=”YES”
syslogd_flags=”-a 10.10.0.0/16:* -a 192.168.2.0/24:*”
-> rc.conf

add local0.none ->
*.notice;local0.none;authpriv.none;kern.debug;lpr.info;mail.crit;news.err<—–>/var/log/messages
&
!*
local0.*<——><——><——><——><——>/var/log/cisco.log
after !*

1>/var/log/cisco.log && chmod 600 or whatever

Cisco:
logging buffered 8192
no logging console
logging trap debugging
logging facility local0
logging source-interface Vlan2
logging 10.10.40.122

 

 

***************************************************************************
OPTIONAL USEFUL TIPS. NOT NECESSARY TO BE INSTALLED

***************************************************************************

DISTRIBUTED MONITORING
1. Stop the running zabbix server:
/usr/local/etc/rc.d/zabbix_server stop

2. Go to directory:
/usr/local/etc/zabbix

type:
zabbix_server -n 1 (1 if this is a Master node. 2, 3,5 and so on, depending on the number of your node)

This command may be executed once, because it may corrupt the database.

***********************************************************************************

FreeBSD Ports update

### CVSUP
cd /usr/ports/net/cvsup-without-gui/
make install clean && rehash
cp /usr/share/examples/cvsup/ports-supfile /etc/
ee /etc/ports-supfile
*default host=cvsup2.ru.FreeBSD.org
cvsup -g -L 2 /etc/ports-supfile

OR
http://www.freebsd-ufa.org/?p=1754
portsnap + freebsd-update

 

Reduce ibdata1 file size:
1. Stop Zabbix and issue:
/usr/local/etc/rc.d/zabbix_server stop
/usr/local/bin/mysqldump -p –extended-insert –all-databases –add-drop-database –disable-keys –flush-privileges –quick –routines –triggers > /usr/all-databases.sql

2. Stop the MySQL server;
/usr/local/etc/rc.d/mysql-server stop
3. Rename or remove (in case you’ve already backed it up) the MySQL data
directory and create an empty one with the same name and permissions;
4. Make the appropriate changes in /etc/my.cnf;
5. Re-initialize the database with the following command (replace the ‘mysql’
with the login of the user your MySQL server runs as):
sudo -u mysql mysql_install_db
6. Start the MySQL server;
7. Get into the ‘mysql -p’ console and type:

SET FOREIGN_KEY_CHECKS=0;
SOURCE all-databases.sql;
SET FOREIGN_KEY_CHECKS=1;

8. Restart the MySQL server
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Tune MySQL:
http://www.zabbix.com/forum/showthread.php?t=9925
********************************************

Zabbix Maps and Screens options:

ScreenHunter_02 Jan. 14 19.42

 

 

ScreenHunter_03 Jan. 14 19.43

 

You have an option to create a custom screens to output the most crtical and sensative monitoring sensors.

 

ScreenHunter_04 Jan. 14 19.43