目录
服务监控
nginx监控
server2安装nginx
[root@server2 ~]# tar zxf nginx-1.23.3.tar.gz
[root@server2 ~]# cd nginx-1.23.3/
[root@server2 nginx-1.23.3]# yum install -y gcc make openssl-devel pcre-devel
[root@server2 nginx-1.23.3]# ./configure --with-http_stub_status_module --with-http_ssl_module
[root@server2 nginx-1.23.3]# make && make install
[root@server2 nginx]# ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
[root@server2 ~]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name localhost;
...
location = /basic_status {
stub_status;
}
...
[root@server2 conf]# nginx
[root@server2 conf]# curl localhost/basic_status //向本地主机(localhost)发送一个名为“basic_status”的CURL(客户端URL)请求命令,以获取基本的状态信息。
在server端为主机关联nginx服务监控模版
稍作等待,监控数据就会出来
mysql监控
zabbix自带mysql模版
拷贝模版、创建数据库连接用户
[root@server1 ~]# cp /usr/share/doc/zabbix-agent-5.0.31/userparameter_mysql.conf /etc/zabbix/zabbix_agentd.d/
[root@server1 zabbix_agentd.d]# systemctl restart zabbix-agent.service
[root@server1 zabbix_agentd.d]# mysql -p
mysql> CREATE USER 'zbx_monitor'@'%' IDENTIFIED BY 'Westos+007';
mysql> GRANT REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO 'zbx_monitor'@'%';
mysql> flush privileges;
创建数据库连接文件
[root@server1 ~]# mkdir /var/lib/zabbix/
[root@server1 ~]# vim /var/lib/zabbix/my.cnf
[client]
user=zbx_monitor
password=Westo+007
为zabbix server链接mysql监控模板
percona数据库模版
zabbix自带的mysql模板比较简单,所以推荐使用percona的数据库模板
[root@server1 ~]# rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm
[root@server1 scripts]# cd /var/lib/zabbix/percona/templates
[root@server1 templates]# cp userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/
[root@server1 templates]# systemctl restart zabbix-agent.service
[root@server1 zabbix_agentd.d]# cd /var/lib/zabbix/percona/scripts/
[root@server1 scripts]# vim ss_get_mysql_stats.php
...
$mysql_user = 'root';
$mysql_pass = 'Westos+007';
测试脚本
[root@server1 scripts]# ln -s /opt/rh/rh-php72/root/usr/bin/php /usr/bin/php
[root@server1 scripts]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
有数据显示就表示正常
删除tmp下的缓存文件
[root@server1 tmp]# rm -f localhost-mysql_cacti_stats.txt
导入模版文件
关联模版
等待监控数据出来
只要/tmp生成缓存文件就表示成功
tomcat监控
server3上安装java应用
[root@server3 ~]# yum install -y java-1.8.0-openjdk.x86_64
[root@server3 ~]# tar zxf apache-tomcat-7.0.37.tar.gz -C /usr/local/
[root@server3 ~]# cd /usr/local/
[root@server3 local]# ln -s apache-tomcat-7.0.37/ tomcat
[root@server3 local]# cd tomcat/
[root@server3 tomcat]# cd bin/
[root@server3 bin]# vim catalina.sh
CATALINA_OPTS='-Dcom.sun.management.jmxremote.port=8888
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false'
[root@server3 bin]# ./startup.sh
server1安装zabbix-java-gateway
[root@server1 ~]# yum install -y zabbix-java-gateway
[root@server1 zabbix]# systemctl enable --now zabbix-java-gateway.service
修改server配置
[root@server1 zabbix]# vim /etc/zabbix/zabbix_server.conf
...
JavaGateway=192.168.81.15
JavaGatewayPort=10052
StartJavaPollers=5
[root@server1 zabbix]# systemctl restart zabbix-server.service
前端配置
添加jmx接口
关联模版
集成告警平台
注册用户:
创建appkey
部署探针
[root@server1 ~]# cd /usr/lib/zabbix/alertscripts
[root@server1 alertscripts]# tar xf ca_zabbix_release-4.0.1.tar.gz
[root@server1 alertscripts]# cd cloudalert/bin
[root@server1 bin]# ./install.sh cc9bbeb176b14bf09abad37165bdf429
请输入Zabbix管理地址:http://192.168.81.15/zabbix
Check connection success!
请输入Zabbix管理员账号:Admin
[root@server1 alertscripts]# chown zabbix.zabbix cloudalert/ -R
配置通知策略
停止agent服务
[root@server2 ~]# systemctl stop zabbix-agent.service
等待片刻后会触发报警,并发送到外部告警平台
可以在告警平台查看到完整到处理流程
认领后start zabbix
分布式监控
新建proxy节点,删除server2 agent作为proxy节点
[root@server2 ~]# systemctl disable --now zabbix-agent.service
[root@server2 ~]# hostnamectl set-hostname proxy
[root@proxy ~]# vim /etc/hosts
192.168.81.16 server2 proxy
安装proxy软件
[root@proxy ~]# yum install zabbix-proxy-mysql
在server1上创建proxy数据库
[root@server1 ~]# mysql -p
mysql> create database zabbix_proxy character set utf8 collate utf8_bin;
mysql> create user 'zabbix'@'%' identified by 'Westos+007';
mysql> grant all privileges on zabbix_proxy.* to 'zabbix'@'%' identified by 'Westos+007';
从proxy拷贝数据库文件
[root@proxy ~]# cd /usr/share/doc/zabbix-proxy-mysql-5.0.31/
[root@proxy zabbix-proxy-mysql-5.0.31]# scp schema.sql.gz server1:
导入proxy数据库
[root@server1 ~]# zcat schema.sql.gz | mysql -uzabbix -pWestos+007 zabbix_proxy
修改proxy配置
[root@proxy ~]# vim /etc/zabbix/zabbix_proxy.conf
Server=192.168.81.15 //指向zabbix_server
Hostname=proxy //主机名
DBHost=192.168.81.15 //proxy数据库配置
DBName=zabbix_proxy
DBUser=zabbix
DBPassword=Westos+007
JavaGateway=192.168.81.15 //jmx配置
JavaGatewayPort=10052
StartJavaPollers=5
[root@proxy ~]# systemctl restart zabbix-proxy.service
创建proxy
agent代理程序
为主机配置代理
再重启proxy服务
修改agent配置,指向proxy地址
[root@server3 ~]# vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.81.16
ServerActive=192.168.81.16
[root@server3 ~]# systemctl restart zabbix-agent.service
查看日志,没有报错就代表成功
[root@server3 ~]# cat /var/log/zabbix/zabbix_agentd.log
如果agent日志中出现类似的报错,说明proxy还没有完全同步server端数据,需要再重启proxy服务
最终配置完毕后,逐渐监控状态也是可用的