For notes / info please scroll to bottom of page. Most commands can just be copy-pasted.
# Finch users should update to get the latest fixes
[ "$(echo "$(finch --shortver) >= 1.25" | bc)" = 1 ] || sudo finch update -y
sudo finch chroot
# Read the page "jail-ip-addresses" before choosing a jail IP address
jail_ip="192.168.1.212"
# Set a matching ip address for the jail's 'lo0' ifconfig device (for localhost)
jail_loopback="lo0|127.0.0.212"
# Give an appropriate server name to your jail
jailname="zabbix"
# Create a basic jail, with local console access
qjail create -4 "$jail_ip,$jail_loopback" "$jailname"
# Enable unix sockets
qjail config -k "$jailname"
# Enable sysvipc semaphores
qjail config -y "$jailname"
# Start the jail
qjail start "$jailname"
# Login to our new jail as root
qjail console "$jailname"
# Update local pkgng database, to avoid 'failed checksum' for 'pkg install'
pkg update -f
# Install zabbix and dependencies
ASSUME_ALWAYS_YES="yes" pkg install "mysql55-server" "nginx" "zabbix22-server" "zabbix22-agent" "zabbix22-frontend"
# Enable mysql rc.d service
sysrc "mysql_enable=YES"
service mysql-server start
# Create zabbix database
mysql -u root <<- EOF
create database zabbix character set utf8;
grant all privileges on zabbix.* to zabbix@localhost identified by '';
flush privileges;
quit
EOF
# Populate zabbix database
cd /usr/local/share/zabbix22/server/database
cat mysql/schema.sql mysql/images.sql mysql/data.sql | mysql -u zabbix zabbix
# Create /var folders for zabbix log & pid files
mkdir -p /var/run/zabbix /var/log/zabbix
chown zabbix:zabbix /var/run/zabbix /var/log/zabbix
# Configure zabbix server
cd /usr/local/etc/zabbix22
cat > zabbix_server.conf <<- "EOF"
LogFile=/var/log/zabbix/zabbix_server.log
PidFile=/var/run/zabbix/zabbix_server.pid
DBName=zabbix
DBUser=zabbix
Include=/usr/local/etc/zabbix22/zabbix_server.conf.d/
EOF
# Enable zabbix_server rc.d service
sysrc "zabbix_server_enable=YES"
service zabbix_server start
# Configure zabbix agentd
jail_ip="$(ifconfig -a | grep -v "inet 127" | grep -m 1 inet | cut -d ' ' -f 2)"
zabbix_server_ip="$jail_ip"
cd /usr/local/etc/zabbix22
cat > zabbix_agentd.conf <<- EOF
LogFile=/var/log/zabbix/zabbix_agentd.log
PidFile=/var/run/zabbix/zabbix_agentd.pid
Hostname=Zabbix server
EnableRemoteCommands=1
Server=$zabbix_server_ip
Include=/usr/local/etc/zabbix22/zabbix_agentd.conf.d/
EOF
# Configure zabbix agent (cli)
jail_ip="$(ifconfig -a | grep -v "inet 127" | grep -m 1 inet | cut -d ' ' -f 2)"
zabbix_server_ip="$jail_ip"
cd /usr/local/etc/zabbix22
cat > zabbix_agent.conf <<- EOF
Server=$zabbix_server_ip
Include=/usr/local/etc/zabbix22/zabbix_agent.conf.d/
EOF
# Enable zabbix_agentd rc.d service
sysrc "zabbix_agentd_enable=YES"
service zabbix_agentd start
# Configure nginx
cd /usr/local/etc/nginx
cat > nginx.conf <<- "EOF"
user www www;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
include /usr/local/etc/nginx/conf.d/*.conf;
}
EOF
mkdir -p cd /usr/local/etc/nginx/conf.d
cd /usr/local/etc/nginx
cat > conf.d/zabbix.conf <<- "EOF"
server {
listen 80;
root /usr/local/www/zabbix22;
server_name localhost;
location / {
deny all;
include conf.d/zabbix_allowed_hosts.conf;
index index.php index.html index.htm;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
EOF
# Allow only certain hosts, others get forbidden
allowed_ip="192.168.1.XXX"
echo "allow ${allowed_ip};" >> /usr/local/etc/nginx/conf.d/zabbix_allowed_hosts.conf
# Configure php-fpm
cd /usr/local/etc
cat > php-fpm.conf <<- "EOF"
[global]
pid = /var/run/php-fpm.pid
[WWW]
listen = /var/run/php5-fpm.sock
listen.owner = www
listen.group = www
listen.mode = 0666
listen.backlog = -1
catch_workers_output = yes
user = www
group = www
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 500
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
EOF
# Configure php
cd /usr/local/etc
cp php.ini-production php.ini
sed -i '' -e 's/post_max_size = ..*/post_max_size = 16M/g' php.ini
sed -i '' -e 's/max_execution_time = ..*/max_execution_time = 300/g' php.ini
sed -i '' -e 's/max_input_time = ..*/max_input_time = 300/g' php.ini
echo "date.timezone = Europe/London" >> php.ini
# Let the nginx 'www' user write zabbix.conf file for zabbix frontend (webgui)
chown -R www:www /usr/local/www/zabbix22/conf
# Enable php-fpm rc.d service
sysrc "php_fpm_enable=YES"
service php-fpm start
# Enable nginx rc.d service
sysrc "nginx_enable=YES"
service nginx start
# Reboot the Host system
# Login to http://{$jail_ip} from a web browser
# username: admin
# password: zabbix
After installing zabbix, it must be configured to monitor your devices.
New how-To:
zabbix configuration - monitor CPU temperature & hdd status (smart attributes)
https://gist.github.com/dreamcat4/1935177aafc8bb674675