一、zabbix部署浏览器访问Download and install Zabbix1.1部署配置配置仓库[rootserver1 ~]# rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/9/x86_64/zabbix-release-latest-6.0.el9.noarch.rpm安装zabbix server、web前端、agent[rootserver1 ~]# dnf install zabbix-server-mysql zabbix-web-mysql zabbix-apache-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent安装mysql数据库[rootserver1 ~]# dnf install -y mysql-server[rootserver1 ~]# systemctl enable --now mysqld.service[rootserver1 ~]# mysqlmysql create database zabbix character set utf8mb4 collate utf8mb4_bin;mysql create user zabbixlocalhost identified by password;mysql grant all privileges on zabbix.* to zabbixlocalhost;mysql set global log_bin_trust_function_creators 1;mysql quit;导入zabbix初始架构和数据[rootserver1 ~]# zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-setutf8mb4 -uzabbix -p zabbix 等待命令行出现[rootserver1 ~]# mysql -uroot -p 注意密码为空mysql set global log_bin_trust_function_creators 0;mysql quit;修改zabbix server 连接数据库的密码[rootserver1 ~]# vim /etc/zabbix/zabbix_server.con[rootserver1 ~]# systemctl enable --now zabbix-server zabbix-agent httpd php-fpm1.2zabbix前端初始化使用浏览器访问前端http://192.168.164.160/zabbix检查环境填写前端连接数据库使用的用户和密码填写zabbix server的信息初始化完成进入zabbix前端界面汉化安装中文locale支持[rootserver1 ~]# dnf install glibc-langpack-zh -y生成/刷新locale[rootserver1 ~]# localectl list-locales | grep zh_CN[rootserver1 ~]# cp simkai.ttf /usr/share/zabbix/assets/fonts[rootserver1 ~]# cd /usr/share/zabbix/assets/fonts重做软连接[rootserver1 fonts]# rm -f graphfont.ttf[rootserver1 fonts]# ln -s simkai.ttf graphfont.ttf二、添加zabbix-agent2.1server2配置设置yum源[rootserver2 ~]# rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/9/x86_64/zabbix-release-latest-6.0.el9.noarch.rpm[rootserver2 ~]# dnf install -y zabbix-agent[rootserver2 ~]# vim /etc/zabbix/zabbix_agentd.conf[rootserver2 ~]# systemctl enable --now zabbix-agent查看监听端口[rootserver2 ~]# netstat -antlp|grep :100502.2server3配置[rootserver3 ~]# rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/zabbix-release-latest-6.0.el7.noarch.rpm[rootserver3 ~]# yum install -y zabbix-agent[rootserver3 ~]# vim /etc/zabbix/zabbix_agentd.conf[rootserver3 ~]# systemctl enable --now zabbix-agent前端zabbix需要手动添加[rootserver3 ~]# cat /var/log/zabbix/zabbix_agentd.log手动测试连通性key值也可以先手动测试是否有返回值server1上[rootserver1 ~]# yum install -y zabbix-get[rootserver1 ~]#zabbix_get -s 192.168.36.162-p 10050 -k agent.ping[rootserver1 ~]# zabbix_get -s 192.168.164.161 -p 10050 -k system.hostname三、zabbix前端服务3.1创建监控项1监控CPU负载检测server2上[rootserver2 ~]# md5sum /dev/zero [rootserver2 ~]# fg 记住退出否则一直消耗内存2监控根分区使用量3监控根分区空闲百分比测试消耗磁盘空间[rootserver2 ~]# dd if/dev/zero of/bigfile bs1G count30[rootserver2 ~]# df -h /3.2创建触发器1检测cpu负载情况[rootserver2 ~]# md5sum /dev/zero [rootserver2 ~]# fg2检测根分区空闲空间[rootserver2 ~]# df -h /告警及处理、确认3.3创建图形主机创建图形以图表的形式展现3.4媒介邮件Email使用网易邮箱测试发送邮件接收邮件报警媒介禁用email以外所有媒介用户添加报警媒介启用触发器动作server2上进行测试[rootserver2 ~]# md5sum /dev/zero 收到问题邮件[rootserver2 ~]# fg收到解决问题邮件3.5用户群组添加用户群组添加权限创建用户添加报警媒介添加权限添加触发器动作3.6模板自动注册动作自动发现创建模板复制server2的配置给创建的模板删除server2启用发现动作先发现动作在自动发现发现server2关闭发现动作、自动发现创建自动注册动作设置发现后的操作启用自动注册动作修改server2配置文件[rootserver2 ~]# vim /etc/zabbix/zabbix_agentd.conf[rootserver2 ~]# systemctl restart zabbix-agent.service查看主机发现server2,server2自动配置四、服务监控4.1nginxagent安装软件server2上[rootserver2 ~]# yum install -y nginx修改配置文件[rootserver2 ~]# vim /etc/nginx/nginx.conf[rootserver2 ~]# systemctl enable --now nginx测试[rootserver2 ~]# curl localhost/basic_status主机关联服务监控模板4.2mysql安装mysql服务[rootserver2 ~]# yum install -y mysql-server[rootserver2 ~]# systemctl enable --now mysqld[rootserver2 ~]# cp /usr/share/doc/zabbix-agent/userparameter_mysql.conf /etc/zabbix/zabbix_agentd.d/[rootserver2 ~]# systemctl restart zabbix-agent配置数据库监控用户[rootserver2 ~]# mysqlmysql CREATE USER zbx_monitor% IDENTIFIED BY westos;mysql GRANT REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO zbx_monitor%;mysql quit创建mysql客户端配置[rootserver2 ~]# mkdir /var/lib/zabbix[rootserver2 ~]# vim /var/lib/zabbix/.my.cnf[rootserver2 ~]# systemctl restart zabbix-agent主机关联服务监控模板percona数据库监控模板serfer3上[rootserver3 ~]# rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm[rootserver3 ~]# cd /var/lib/zabbix/percona/templates拷贝模板[rootserver3 templates]# cp userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/[rootserver3 templates]# systemctl restart zabbix-agent[rootserver3 templates]# yum search mysql[rootserver3 templates]# yum install -y mariadb-server.x86_64[rootserver3 templates]# yum install -y php php-mysql[rootserver3 templates]# systemctl enable --now mariadb.service[rootserver3 templates]# mysqlMariaDB [(none)] grant all on *.* to rootlocalhost identified by westos;[rootserver3 templates]# mysql -pwestos[rootserver3 templates]# cd /var/lib/zabbix/percona/scripts[rootserver3 scripts]# vim ss_get_mysql_stats.php测试[rootserver3 scripts]# su -s /bin/sh -c /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg zabbix 不能使用超户4.3tomcat安装jmx[rootserver1 ~]# yum install zabbix-java-gateway.x86_64[rootserver1 ~]# systemctl enable --now zabbix-java-gateway查看端口[rootserver1 ~]# netstat -antlp|grep :10052配置zabbix serverserver1上[rootserver1 ~]# vim /etc/zabbix/zabbix_server.conf[rootserver1 ~]# systemctl restart zabbix-serveragent上部署tomcat服务server3上[rootserver3 ~]# yum install java-1.8.0-openjdk.x86_64[rootserver3 ~]# tar zxf apache-tomcat-9.0.120.tar.gz -C /usr/local/[rootserver3 ~]# cd /usr/local/[rootserver3 local]# ln -s apache-tomcat-9.0.120/ tomcat[rootserver3 local]# cd tomcat/修改配置[rootserver3 tomcat]# vim bin/catalina.shtomcat9启动服务[rootserver3 tomcat]# /usr/local/tomcat/bin/shutdown.sh[rootserver3 tomcat]# /usr/local/tomcat/bin/startup.sh[rootserver3 tomcat]# netstat -antlp|grep :8888前端添加jmx接口JMX开启五、集成外部告警使用睿象云智能告警平台绑定微信、邮箱等可以通知告警通知策略分派策略六、zabbix api使用api可以进行大量机器的配置操作登录获取认证token[rootserver1 ~]# curl -s -X POST -H Content-Type:application/json -d {jsonrpc: 2.0,method: user.login,params: {user: Admin,password: zabbix},id: 1,auth: null} http://192.168.164.160/zabbix/api_jsonrpc.php | python -m json.tool返回{jsonrpc: 2.0,result: 8b989509fa36d7fd7d3ade7ce6a3cf3c,id: 1}result内字符串就是auth token 复制保存用于后续接口查询主机列表[rootserver1 ~]# vim zabbix-api.shcurl -s -X POST -H Content-Type:application/json -d {jsonrpc: 2.0,method: host.get,params: {output: [hostid,host],selectInterfaces: [interfaceid,ip]},id: 2,auth: 8b989509fa36d7fd7d3ade7ce6a3cf3c} http://192.168.164.160/zabbix/api_jsonrpc.php | python -m json.tool[rootserver1 ~]# chmod x zabbix-api.sh[rootserver1 ~]# ./zabbix-api.sh得到hostid删除主机[rootserver1 ~]# vim zabbix-api.shcurl -s -X POST -H Content-Type:application/json -d {jsonrpc: 2.0,method: host.delete,params: [10444],auth: 8b989509fa36d7fd7d3ade7ce6a3cf3c,id: 1} http://192.168.164.160/zabbix/api_jsonrpc.php | python -m json.tool添加主机[rootserver1 ~]# vim zabbix-api.shcurl -s -X POST -H Content-Type:application/json -d {jsonrpc: 2.0,method: host.create,params: {host: server2, agent名称interfaces: [{type: 1,main: 1,useip: 1,ip: 192.168.164.161,agent主机IPdns: ,port: 10050}],groups: [{groupid: 2主机组ID}],tags: [{tag: Host name,value: Linux server}],templates: [{templateid: 10001模板ID}]},id: 1,auth: 8b989509fa36d7fd7d3ade7ce6a3cf3c} http://192.168.164.160/zabbix/api_jsonrpc.php | python -m json.tool