zabbix

    xiaoxiao2021-04-12  55

    1.Install安装

    [server1]---->zabbix_server Installed: fping.x86_64 0:2.4b2-16.el6 iksemel.x86_64 0:1.4-2.el6 iksemel-utils.x86_64 0:1.4-2.el6 php-bcmath.x86_64 0:5.3.3-26.el6 php-mbstring.x86_64 0:5.3.3-26.el6 zabbix.x86_64 0:2.4.5-1.el6 zabbix-sender.x86_64 0:2.4.5-1.el6 zabbix-server.x86_64 0:2.4.5-1.el6 zabbix-server-mysql.x86_64 0:2.4.5-1.el6 zabbix-web.noarch 0:2.4.5-1.el6 zabbix-web-mysql.noarch 0:2.4.5-1.el6

    [server1]----->zabbix_agent nstalling: zabbix x86_64 2.4.5-1.el6 /zabbix-2.4.5-1.el6.x86_64 599 k zabbix-agent x86_64 2.4.5-1.el6 /zabbix-agent-2.4.5-1.el6.x86_64

    [server2]----->zabbix_agent Installing: zabbix x86_64 2.4.5-1.el6 /zabbix-2.4.5-1.el6.x86_64 599 k zabbix-agent x86_64 2.4.5-1.el6 /zabbix-agent-2.4.5-1.el6.x86_64

    2.基本配置

    (1)配置zabbix-server

      1)安装和配置mysql

    [server1] [root@server1 ~]#yum install -y mysql mysql-server [root@server1 create]# /etc/init.d/mysqld start [root@server1 mysql]# mysql mysql> create database zabbix character set utf8 collate utf8_bin;##创建数据库,设置编码 Query OK, 1 row affected (0.00 sec) mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'westos';##授权给zabbix

    [root@server1 create]# pwd /usr/share/doc/zabbix-server-mysql-2.4.5/create [root@server1 create]# mysql -uzabbix -pwestos zabbix < schema.sql##导入一些数据 [root@server1 create]# mysql -uzabbix -pwestos zabbix < images.sql [root@server1 create]# mysql -uzabbix -pwestos zabbix < data.sql

     2)zabbix-server

    [root@server1 create]# vim /etc/zabbix/zabbix_server.conf ##配置zabbix-server文件 ### Option: DBHost DBHost=localhost ##本机 ### Option: DBName DBName=zabbix ##数据库名 ### Option: DBUser DBUser=zabbix ##数据库用户名 ### Option: DBPassword DBPassword=westos ##数据库用户对应密码

      3) php

    [root@server1 create]# vim /etc/php.ini [Date] ; Defines the default timezone used by the date functions ; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone date.timezone =Asia/Shanghai ##添加时区 http://172.25.38.1/zabbix 4)测试,打开浏览器

    输入:  http://172.25.38.1/zabbix

    注意:初始用户密码,可更改密码

    Username: Admin

    Password: zabbix

    (2)配置zabbix-agent

    [server1] [root@server1 create]# vim /etc/zabbix/zabbix_agentd.conf ### Option: Server Server=172.25.38.1 ##指向zabbix-server ### Option: ServerActive ServerActive=127.0.0.1 ### Option: Hostname Hostname=server1.example.com ##本机主机名

    [root@server1 create]# /etc/init.d/zabbix-agent start Starting Zabbix agent: [root@server2 ~]# vim /etc/zabbix/zabbix_agentd.conf ### Option: Server Server=172.25.38.1 ### Option: ServerActive ServerActive=127.0.0.1 ### Option: Hostname Hostname=server2.example.com [root@server2 ~]# /etc/init.d/zabbix-agent start Starting Zabbix agent:

    (3)添加监控

    3.自制模板nginx为例

    [root@server2 ~]# tar zxf nginx-1.10.3.tar.gz [root@server2 ~]# cd nginx-1.10.3 [root@server2 nginx-1.10.3]# vim auto/cc/gcc ##去除版本号 #CFLAGS="$CFLAGS -g" [root@server2 nginx-1.10.3]# ./configure --help --with-http_stub_status_module enable ngx_http_stub_status_module [root@server2 nginx-1.10.3]# yum install -y pcre pcre-devel [root@server2 nginx-1.10.3]# ./configure --with-http_stub_status_module [root@server2 nginx-1.10.3]# ./configure --with-http_stub_status_module --prefix=/usr/local/nginx##指定模块,路径 [root@server2 nginx-1.10.3]# make [root@server2 nginx-1.10.3]# make install [root@server2 nginx-1.10.3]# cd /usr/local/nginx/ [root@server2 nginx]# cd conf/ [root@server2 conf]# vim nginx.conf error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location /status { stub_status on;##开启模块 access_log off; } [root@server2 conf]# /usr/local/nginx/sbin/nginx -t ##检验 nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful [root@server2 conf]# /usr/local/nginx/sbin/nginx ##开启nginx [root@server2 conf]# netstat -antlpe ##查看端口 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 0 22631 12341/nginx [root@server2 conf]# curl http://172.25.38.2/status ##以获取访问连接数为例 Active connections: 2 server accepts handled requests 5 5 5 Reading: 0 Writing: 1 Waiting: 1 [root@server2 conf]# curl -s http://172.25.38.2/status |grep Active|awk '{print $NF}' 1 [root@server2 conf]# cd /etc/zabbix/zabbix_agentd.d/ [root@server2 zabbix_agentd.d]# vim nginx.conf UserParameter=nginx.active, curl -s http://172.25.38.2/status |grep Active|awk '{print $NF}' [root@server2 zabbix_agentd.d]# /etc/init.d/zabbix-agent restart Shutting down Zabbix agent: [ OK ] Starting Zabbix agent: [ OK ]

    [root@server1 ~]# rpm -ivh zabbix-get-2.4.5-1.el6.x86_64.rpm warning: zabbix-get-2.4.5-1.el6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 79ea5ed4: NOKEY Preparing... ########################################### [100%] 1:zabbix-get ########################################### [100%] [root@server1 ~]# zabbix_get -s 172.25.38.2 -p 10050 -k "nginx.active" ##获取 1 [root@server1 ~]# ab -c 100 -t 20 http://172.25.38.2/ ##模拟访问量

     

    4.下载模板,进行监控

    [root@server1 ~]# rpm -vih percona-zabbix-templates-1.1.6-1.noarch.rpm warning: percona-zabbix-templates-1.1.6-1.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID cd2efd2a: NOKEY Preparing... ########################################### [100%] 1:percona-zabbix-template########################################### [100%] Scripts are installed to /var/lib/zabbix/percona/scripts Templates are installed to /var/lib/zabbix/percona/templates [root@server1 ~]# cd /var/lib/zabbix/scripts/ [root@server1 scripts]# rpm -q php php-mysql php-5.3.3-26.el6.x86_64 php-mysql-5.3.3-26.el6.x86_6 [root@server1 scripts]# vim ss_get_mysql_stats.php $mysql_user = 'cacti'; $mysql_pass = 'westos'; [root@server1 scripts]# mysqladmin -u root password westos##设置密码 [root@server1 templates]# pwd /var/lib/zabbix/percona/templates [root@server1 templates]# cp userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/ [root@server1 zabbix_agentd.d]# vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf <?php $mysql_user='root'; $mysql_pass='westos'; [root@server1 zabbix_agentd.d]# cd /var/lib/zabbix [root@server1 zabbix_agentd.d]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg [root@server1 zabbix]# vim .my.cnf [client] user=root password=westos [root@server1 zabbix]# /etc/init.d/zabbix-agent restart Shutting down Zabbix agent: [ OK ] Starting Zabbix agent: [ OK ] [root@server1 tmp]# chown zabbix.zabbix localhost-mysql_cacti_stats.txt [root@server1 tmp]# cd /var/lib/zabbix/percona/templates/ [root@server1 templates]# ls userparameter_percona_mysql.conf zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.6.xml [root@server1 templates]# scp zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.6.xml 172.25.38.250:/home/kiosk/Desktop

    5.监控报警

    [root@server1 ~]# tar zxf alert-agent-4.1.3.1-linux-x64.tar.gz [root@server1 ~]# cp -r alert-agent /usr/lib/zabbix/ [root@server1 ~]# cp -r alert-agent /usr/lib/zabbix/alertscripts/ [root@server1 ~]# cd /usr/lib/zabbix/alertscripts/ [root@server1 alertscripts]# cp alert-agent/plugin/zabbix-plugin/110monitor /usr/lib/zabbix/alertscripts/

    6.代理

    [root@server3 ~]# yum install -y zabbix-2.4.5-1.el6.x86_64.rpm zabbix-proxy-2.4.5-1.el6.x86_64.rpm zabbix-proxy-mysql-2.4.5-1.el6.x86_64.rpm fping-2.4b2-16.el6.x86_64.rpm OpenIPMI-libs [root@server3 ~]# mysql mysql> create database zabbix character set utf8 collate utf8_bin; Query OK, 1 row affected (0.00 sec) mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'westos'; Query OK, 0 rows affected (0.00 sec) [root@server3 ~]# cd /usr/share/doc/zabbix-proxy-mysql-2.4.5/create/ [root@server3 create]# cd /etc/zabbix/ [root@server3 zabbix]# vim zabbix_proxy.conf Server=172.25.38.1 Hostname=server3.example.com DBName=zabbix DBUser=zabbix DBPassword=westos [root@server3 zabbix]# /etc/init.d/zabbix-proxy start Starting Zabbix proxy: [ OK ] [root@server2 ~]# vim /etc/zabbix/zabbix_agentd.conf ServerActive=172.25.38.3 [root@server2 ~]# /etc/init.d/zabbix-agent restart Shutting down Zabbix agent: [ OK ] Starting Zabbix agent: [ OK ]

    7.监控 java

    [root@server2 ~]# tar zxf apache-tomcat-7.0.37.tar.gz [root@server2 ~]# cd apache-tomcat-7.0.37/bin/ [root@server2 bin]# vim catalina # $Id: catalina.sh 1202062 2011-11-15 06:50:02Z mturk $ # ----------------------------------------------------------------------------- CATALINA_OPTS= "-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8888 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=172.25.38.1" [root@server2 ~]# rpm -ivh jdk-8u121-linux-x64.rpm [root@server2 ~]# which java /usr/bin/java [root@server2 apache-tomcat-7.0.37]# bin/startup.sh Using CATALINA_BASE: /root/apache-tomcat-7.0.37 Using CATALINA_HOME: /root/apache-tomcat-7.0.37 Using CATALINA_TMPDIR: /root/apache-tomcat-7.0.37/temp Using JRE_HOME: /usr/local/java Using CLASSPATH: /root/apache-tomcat-7.0.37/bin/bootstrap.jar:/root/apache-tomcat-7.0.37/bin/tomcat-juli.jar [root@server2 apache-tomcat-7.0.37]# netstat -antlpe tcp 0 0 :::8888 :::* LISTEN 0 15417 2076/java

     在zabbix-server和zabbix-proxy配置文件中

    zabbix-server.conf

    zabbix-agent.conf

    要指定JavaGateway地址为安装Java机的IP

    要指定JavaGatewayPort端口,默认为10052

    要设置JavaPollers数量,小于等于zabbix-java-gateway的JavaPollers

     

     

    转载请注明原文地址: https://ju.6miu.com/read-667170.html

    最新回复(0)