Install required packages for Zabbix server setup on CentOS 7:
yum install -y mariadb mariadb-server php php-mysql httpd
Enable and start the MariaDB service:
systemctl enable mariadb
systemctl start mariadb
mysql_secure_installation
Secure the MariaDB enstallation by setting a root password, removing anonymous users, and deleting the test database.
Create a dedicated database and user for Zabbix:
mysql -uroot -p'your_password' -e "CREATE DATABASE zabbix_db CHARACTER SET utf8 COLLATE utf8_bin;"
mysql -uroot -p'your_password' -e "GRANT ALL PRIVILEGES ON zabbix_db.* TO 'zabbix_user'@'%' IDENTIFIED BY 'secure_pass';"
Verify database creation:
mysql -uzabbix_user -psecure_pass -e "SHOW DATABLES;"
Start the Apache web server and check open ports:
systemctl start httpd
netstat -tulpn | grep -E ':80|:3306'
Add the Zabbix repository and install server components:
rpm -Uvh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-get
Import the Zabbix database schema:
cd /usr/share/doc/zabbix-server-mysql-3.4.3/
zcat create.sql.gz | mysql -uroot -p'your_password' zabbix_db
Configure the Zabbix server database connection in /etc/zabbix/zabbix_server.conf:
DBHost=localhost
DBName=zabbix_db
DBUser=zabbix_user
DBPassword=secure_pass
Set the PHP timezone in /etc/httpd/conf.d/zabbix.conf:
php_value date.timezone Asia/Shanghai
Enable and start the Zabbix server service:
systemctl enable zabbix-server
systemctl start zabbix-server
systemctl restart httpd
Access the Zabbix web interface at http://server_ip/zabbix/setup.php to complete installation.
Configure SNMP monitoring for network devices:
yum install -y net-snmp net-snmp-utils
Edit /etc/snmp/snmpd.conf with community string settings:
com2sec readonly default monitor_community
group MyROGroup v2c readonly
view all included .1
access MyROGroup "" any noauth exact all none none
Test SNMP connectivity:
snmpwalk -v2c -c monitor_community localhost .1.3.6.1.2.1.1.1
Monitor Nginx service status with custom Zabbix agent checks. First, configure the agent to allow custom parameters in /etc/zabbix/zabbix_agentd.conf:
UnsafeUserParameters=1
Include=/etc/zabbix/zabbix_agentd.d/
Create a script to check Nginx availability:
cat > /etc/zabbix/zabbix_agentd.d/nginx_check.conf << 'EOF'
UserParameter=nginx.alive,curl -s -o /dev/null -w "%{http_code}" http://localhost/ | grep -c '^200$'
EOF
Restart the agent and test locally:
systemctl restart zabbix-agent
zabbix_get -s 127.0.0.1 -k nginx.alive
Enable Nginx status module for detailed metrics by adding to /etc/nginx/nginx.conf:
server {
listen 127.0.0.1:80;
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}
Create a comprehensive monitoring script at /usr/local/bin/nginx_monitor.sh:
#!/bin/bash
PORT=${1:-80}
METRIC=$2
case $METRIC in
active)
curl -s "http://127.0.0.1:$PORT/nginx_status" | awk '/Active/ {print $NF}'
;;
reading)
curl -s "http://127.0.0.1:$PORT/nginx_status" | awk '/Reading/ {print $2}'
;;
writing)
curl -s "http://127.0.0.1:$PORT/nginx_status" | awk '/Writing/ {print $4}'
;;
waiting)
curl -s "http://127.0.0.1:$PORT/nginx_status" | awk '/Waiting/ {print $6}'
;;
accepts)
curl -s "http://127.0.0.1:$PORT/nginx_status" | awk 'NR==3 {print $1}'
;;
handled)
curl -s "http://127.0.0.1:$PORT/nginx_status" | awk 'NR==3 {print $2}'
;;
requests)
curl -s "http://127.0.0.1:$PORT/nginx_status" | awk 'NR==3 {print $3}'
;;
esac
Define the Zabbix agent parameter:
echo 'UserParameter=nginx.stats[*],/usr/local/bin/nginx_monitor.sh $1 $2' > /etc/zabbix/zabbix_agentd.d/nginx_stats.conf
Test the metric collection:
zabbix_get -s 127.0.0.1 -k "nginx.stats[80,active]"
Create a custom Zabbix template for Nginx monitoring through the web interface:
- Navigate to Configuration → Templates → Create template
- Add items for each Nginx metric using the
nginx.stats[]key - Configure triggers based on metric thresholds
- Design graphs to visualize Nginx performance data
- Apply the template to monitored hosts
For TCP connection monitoring, implement a script to track connection states:
cat > /usr/local/bin/tcp_connections.sh << 'EOF'
#!/bin/bash
STATE=$1
ss -ant | awk 'NR>1 {count[$1]++} END {print count["'$STATE'"]+0}'
EOF
chmod +x /usr/local/bin/tcp_connections.sh
echo 'UserParameter=tcp.conn[*],/usr/local/bin/tcp_connections.sh $1' > /etc/zabbix/zabbix_agentd.d/tcp_monitor.conf