查看php版本
yum list php
安装zabbix及其依赖包(php-bcmath、 php-mbstring的版本要和php版本一样)
yum install zabbix-server-mysql-3.4.6-1.el7.x86_64.rpm zabbix-web-3.4.6-1.el7.noarch.rpm zabbix-web-mysql-3.4.6-1.el7.noarch.rpm php-mbstring-5.4.16-42.el7.x86_64.rpm php-bcmath-5.4.16-42.el7.x86_64.rpm fping libiksemel fping-3.10-1.el7.x86_64.rpm iksemel-1.4-2.el7.centos.x86_64.rpm
yum install mariadb-server -y
systemctl start mariadb #开启服务
数据库安全初始化
mysql_secure_installation
在mysql中给zabbix用户授予权限
mysql -p
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin; #设置数据库的默认编码为utf8
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'westos';
Query OK, 0 rows affected (0.00 sec)
将zabbix库导入数据库
cd /usr/share/doc/zabbix-server-mysql-3.4.6/
zcat create.sql.gz | mysql -u zabbix -p zabbix
mysql -p
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| zabbix |
+--------------------+
4 rows in set (0.00 sec)
编辑zabbix_server配置文件
cd /etc/zabbix/
vim zabbix_server.conf
125 DBPassword=westos
132 DBSocket=/var/lib/mysql/mysql.sock
更改时区
cd /etc/httpd/conf.d
vim zabbix.conf
19 php_value date.timezone Asia/Shanghai
开启zabbix-server、httpd 服务
systemctl start zabbix-server
systemctl start httpd
初始用户为Admin 密码为zabbix
server1以在监控中
在server2中
安装zabbix-agent,打开服务
yum install zabbix-agent-3.4.6-1.el7.x86_64.rpm
systemctl start zabbix-agent
选择配置—自动发现—Local network,编辑自动发现规则,修改ip规则,启用Local network
等待被发现
先停用自动发现动作和规则,删除server2主机
选择配置—主机—创建主机
填写主机名、ip地址 添加群组、模版
添加成功
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://172.25.31.1/zabbix/api_jsonrpc.php | python -m json.tool
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["host"]
},
"auth": "b1dafff018108c254b53a8ba0192617b",
"id": 1
}' http://172.25.31.1/zabbix/api_jsonrpc.php | python -m json.tool
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.delete",
"params": [
"10257"
],
"auth": "b1dafff018108c254b53a8ba0192617b",
"id": 1
}' http://172.25.31.1/zabbix/api_jsonrpc.php | python -m json.tool
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.create",
"params": {
"host": "server2",
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": "172.25.31.2",
"dns": "",
"port": "10050"
}
],
"groups": [
{
"groupid": "2"
}
],
"templates": [
{
"templateid": "10001"
}
]
},
"auth": "b1dafff018108c254b53a8ba0192617b",
"id": 1
}' http://172.25.31.1/zabbix/api_jsonrpc.php | python -m json.tool
在server2中
打开nginx,添加监控模块
vim /etc/nginx/conf.d/default.conf
location /status{
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
nginx -s reload
使用UserParameter自定义key
cd /etc/zabbix/zabbix_agentd.d/
cp userparameter_mysql.conf userparameter_nginx.conf
vim /etc/zabbix/zabbix_agentd.d/userparameter_nginx.conf
UserParameter=nginx.active,curl -s http://127.0.0.1/status | grep Active | awk '{print $NF}'
UserParameter=nginx.accepts,curl -s http://127.0.0.1/status | awk NR==3 | awk '{print $1}'
UserParameter=nginx.handled,curl -s http://127.0.0.1/status | awk NR==3 | awk '{print $2}'
UserParameter=nginx.requests,curl -s http://127.0.0.1/status | awk NR==3 | awk '{print $3}'
重启zabbix-agent服务
/etc/init.d/zabbix-agent restart
在server1中
安装zabbix-get工具
rpm -ivh zabbix-get-3.4.6-1.el7.x86_64.rpm
测试是否能取到值
[root@server1 ~]# zabbix_get -s 172.25.31.2 -p 10050 -k 'nginx.active'
1
[root@server1 ~]# zabbix_get -s 172.25.31.2 -p 10050 -k 'nginx.accepts'
237
[root@server1 ~]# zabbix_get -s 172.25.31.2 -p 10050 -k 'nginx.handled'
239
[root@server1 ~]# zabbix_get -s 172.25.31.2 -p 10050 -k 'nginx.requests'
209
在浏览器中访问172.25
点击配置—-主机—-server2
监控项—-创建监控项
添加监控项
点击图形—创建图形
将之前的监控项添加进去
点击预览()
安装 percona-zabbix
rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm
将conf文件放在agent端/etc/zabbix/zabbix_agentd.d/下面
cd /var/lib/zabbix/percona/templates/
cp userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/
systemctl restart zabbix-agent #开启服务
创建 .cnf 文件指定 MySQL 用户名和密码
cd /var/lib/zabbix/percona/scripts/
vim ss_get_mysql_stats.php.cnf
$mysql_user = 'root';
$mysql_pass = 'redhat';
测试是否可用,返回值为数字则证明可用
/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
查看有没有从数据库中取出数据
cd /tmp
cat localhost-mysql_cacti_stats.txt
rm -f localhost-mysql_cacti_stats.txt
写入数据库用户名和密码
vim /var/lib/zabbix/.my.cnf
[client]
user = root
password = redhat
测试是否可以监控到数据
zabbix_get -s 127.0.0.1 -p 10050 -k 'MySQL.Threads-cached'
在浏览器访问172.25.31.1/zabbix
在配置—模版—导入中,将Percona-mysql模版导入
在配置—模版中查看,查看Percona-mysql模版,它由191个监控项,比zabbix自带的mysql监控项丰富很多
将Percona-mysql模版加入到server1中
zabbix提供了一个java gateway的应用去监控jmx(Java Management Extensions,即Java管理扩展)是一个为应用程序、设备、系统等植入管理功能的框架
在server2上
安装jdk和tomcat
rpm -ivh jdk-8u121-linux-x64.rpm
tar zxf apache-tomcat-7.0.90.tar.gz -C /usr/local/
cd /usr/local/
ln -s apache-tomcat-7.0.90/ tomcat
在tomcat下的/bin/catalina.sh文件中添加以下内容
cd tomcat/bin/
vim catalina.sh
CATALINA_OPTS='-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=8888
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false'
./startup.sh #打开服务
查看8888端口是否打开
netstat -antulp | grep 8888
在server1中
安装java gateway
yum install zabbix-java-gateway-3.4.6-1.el7.x86_64.rpm
修改zabbix_server配置文件
cd /etc/zabbix/
vim zabbix_server.conf
262 JavaGateway=172.25.31.1
270 JavaGatewayPort=10052
278 StartJavaPollers=5
重启 zabbix-server服务,打开zabbix-java-gateway服务
systemctl restart zabbix-server
systemctl start zabbix-java-gateway
在浏览器访问172.25.31.1/zabbix
点击配置—-主机—-server2
添加JMX接口
点击模版,添加Template App Generic Java JMX模版
注: server1要能上网
编辑zabbix-server配置文件,修改AlertScriptsPath位置
vim /etc/zabbix/zabbix_server.conf
490 AlertScriptsPath=/usr/lib/zabbix/alertscripts
获取OneITSM agent包,解压,安装
cd /usr/lib/zabbix/alertscripts
tar zxf oneitsm_zabbix_release-1.2.0.tar.gz
cd oneitsm/bin/
./install.sh 810ebcfb-3788-d8dd-7298-6531657f0ba1
./log.sh: line 6: /usr/lib/zabbix/alertscripts/oneitsm/bin/oneitsm.conf: No such file or directory
start to create config file...
Zabbix管理地址: http://172.25.31.1/zabbix/
Zabbix管理员账号: Admin
Zabbix管理员密码:
在浏览器中登陆172.25.31.1/zabbix/
在配置—动作—操作中查看它进行的操作
在server2中关闭zabbix-agent服务
/etc/init.d/zabbix-agent stop
onealert会发送告警通知
安装配置proxy
yum install -y fping-2.4b2-16.el6.x86_64.rpm zabbix-proxy-mysql-3.4.6-1.el6.x86_64.rpm
cd /etc/zabbix/
vim zabbix_proxy.conf
24 Server=172.25.31.1
43 Hostname=server3
167 DBName=zabbix_proxy
182 DBUser=zabbix
190 DBPassword=westos
198 DBSocket=/var/lib/mysql/mysql.sock
323 JavaGateway=172.25.31.1
331 JavaGatewayPort=10052
339 StartJavaPollers=5
/etc/init.d/zabbix-proxy start #开启服务
配置数据库
yum install -y mysql-server
/etc/init.d/mysqld start
mysql_secure_installation #安全初始化
mysql -p
mysql> create database zabbix_proxy character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix_proxy.* to zabbix@localhost identified by 'westos';
cd /usr/share/doc/zabbix-proxy-mysql-3.4.6/
zcat schema.sql.gz | mysql -u zabbix -p zabbix_proxy
Enter password:
/etc/init.d/zabbix-proxy restart
配置agent主机(server2)
cd /etc/zabbix/
vim zabbix_agentd.conf
97 Server=172.25.120.3 ##指向代理服务器
138 ServerActive=172.25.120.3
/etc/init.d/zabbix-agent restart