在server2上(被监控端):
1.监控apache
yum install httpd -y
systemctl enable --now httpd
cd /var/www/html/
echo server2 > index.html
curl localhost
添加模板
2.nginx
yum install tar -y
tar zxf nginx-1.18.0.tar.gz
yum install gcc pcre-devel openssl-devel -y
vim auto/cc/gcc
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
yum install make -y
make && make install
cd /usr/local/nginx/sbin
ls
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin
which nginx
cd /usr/local/nginx/conf
vim nginx.conf
location /status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
nginx -t #检测语法错误
nginx
curl localhost
apache和nginx都是80端口,需要禁用apache
curl http://127.0.0.1/status
1
cd /etc/zabbix/zabbix_agentd.d/
cp userparameter_mysql.conf userparameter_nginx.conf
vim userparameter_nginx.conf
UserParameter=nginx.active,curl -s http://127.0.0.1/status | grep Active | awk '{print $3}'
编辑完文件重启服务
systemctl restart zabbix-agent.service
[root@server1 ~]# yum install zabbix-get -y
zabbix_get -s 192.168.3.202 -p 10050 -k "nginx.active"
添加nginx.active监控项—右上角选择创建监控项
添加图形—右上角选择创建图形
效果:
2
vim /etc/zabbix/zabbix_agentd.d/userparameter_nginx.conf
UserParameter=nginx.active,curl -s http://127.0.0.1/status | grep Active | awk '{print $3}'
UserParameter=nginx.accept,curl -s http://127.0.0.1/status | awk 'NR==3{print $1}'
UserParameter=nginx.handled,curl -s http://127.0.0.1/status | awk 'NR==3{print $2}'
UserParameter=nginx.request,curl -s http://127.0.0.1/status | awk 'NR==3{print $3}'
重启服务:
systemctl restart zabbix-agent.service
在server1端:
zabbix_get -s 192.168.3.202 -p 10050 -k "nginx.accept"
zabbix_get -s 192.168.3.202 -p 10050 -k "nginx.handled"
zabbix_get -s 192.168.3.202 -p 10050 -k "nginx.request"
在前端页面添加nginx.accept,nginx.handled,nginx.request监控项,与nginx.active相同
添加图形
效果:
3.mysql
在server1端:
mysqladmin password westos
mkdir /var/lib/zabbix
cd /var/lib/zabbix
vim .my.cnf
[mysql]
user=root
password=westos
socket=/var/lib/mysql/mysql.sock
[mysqladmin]
user=root
password=westos
socket=/var/lib/mysql/mysql.sock
[root@server1 zabbix]# systemctl restart zabbix-agent.service
[root@server1 zabbix]# pwd
重启服务:
systemctl restart zabbix-agent.service
测试:
zabbix_get -s 127.0.0.1 -p 10050 -k "mysql.ping"
在前端页面给server1添加模板
效果:
agent端
rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm
cd /var/lib/zabbix/percona/templates
cp userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/
systemctl restart zabbix-agent.service
cd /var/lib/zabbix/percona/scripts
vim ss_get_mysql_stats.php
$mysql_user = 'root';
$mysql_pass = 'westos';
/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
cd /tmp/
ls
cat localhost-mysql_cacti_stats.txt
/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gk
vim /etc/zabbix/zabbix_agentd.d/userparameter_percona_mysql.conf #查找gk
rm -rf /tmp/localhost-mysql_cacti_stats.txt
#此文件是root的,zabbix不能写
server端
导入模板
取消链接并清理mysql模板 添加新的
cd /etc/zabbix/zabbix_agentd.d/
grep gg userparameter_percona_mysql.conf
zabbix_get -s 127.0.0.1 -p 10050 -k "MySQL.Key-read-requests"
cd /tmp
ll localhost-mysql_cacti_stats.txt
效果: