默认用户是apache,这里使用LNMP架构所以改成nginx
[root@zabbix ~]# vim /etc/php-fpm.d/www.conf user = nginx group = nginx在nginx的配置文件里增加index.php让nginx可以访问php页面
[root@zabbix ~]# vim /etc/nginx/conf.d/default.conf server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.php index.html index.htm; }修改fastcgi参数
location ~ \.php$ { root /usr/share/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }修改php配置文件
[root@zabbix ~]# vim /etc/php.ini 202 short_open_tag = On //支持php短标签 359 expose_php = Off //隐藏php版本 368 max_execution_time = 300 378 max_input_time = 300 389 memory_limit = 128M 656 post_max_size = 16M 799 upload_max_filesize = 2M 800 lways_populate_raw_post_data = -1 //新增一行 877 date.timezone = Asia/Shanghai启动php
[root@zabbix ~]# systemctl start php-fpm [root@zabbix ~]# systemctl enable php-fpm Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.重启nginx
[root@zabbix ~]# systemctl restart nginx创建php测试网页
[root@zabbix ~]# vim /usr/share/nginx/html/info.php <?php phpinfo(); ?>真机访问验证:http://192.168.245.203/info.php
测试连接数据库
[root@zabbix ~]# vim /usr/share/nginx/html/info.php <?php $link=mysqli_connect('127.0.0.1','root','abc123'); if ($link) echo "连接成功 !!!"; else echo "连接失败 !!!"; ?>真机访问验证:http://192.168.245.203/info.php
进入数据库新建zabbix账户,用户名zabbix,密码是admin123,并授予权限
[root@zabbix ~]# mysql -u root -p Enter password: //输入密码abc123 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 7 Server version: 5.5.65-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> MariaDB [(none)]> MariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> GRANT all privileges ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123'; Query OK, 0 rows affected (0.01 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> quit Bye创建测试页面
[root@zabbix ~]# vim /usr/share/nginx/html/info.php <?php $link=mysqli_connect('127.0.0.1','zabbix','admin123'); if ($link) echo "Zabbix数据库连接成功!"; else echo "Zabbix数据库连接失败!"; ?>这时访问网页会提示连接失败
进入数据库发现有2个空用户,删除空用户即可
[root@zabbix ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 9 Server version: 5.5.65-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> MariaDB [(none)]> MariaDB [(none)]> select user,host from mysql.user; +--------+-----------+ | user | host | +--------+-----------+ | zabbix | % | | root | 127.0.0.1 | | root | ::1 | | | localhost | | root | localhost | | | zabbix | | root | zabbix | +--------+-----------+ 7 rows in set (0.01 sec) MariaDB [(none)]> drop user ''@localhost; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> drop user ''@zabbix; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> quit Bye重新访问测试页面就可以连接成功了
导入zabbix数据库脚本
[root@zabbix ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix Enter password: //密码是admin123修改配置文件
[root@zabbix ~]# vim /etc/zabbix/zabbix_server.conf 91:DBHost=localhost 124:DBPassword=admin123 //修改这两行内容 [root@zabbix ~]# grep -n '^'[a-Z] /etc/zabbix/zabbix_server.conf 38:LogFile=/var/log/zabbix/zabbix_server.log 49:LogFileSize=0 72:PidFile=/var/run/zabbix/zabbix_server.pid 82:SocketDir=/var/run/zabbix 91:DBHost=localhost 100:DBName=zabbix 116:DBUser=zabbix 124:DBPassword=admin123 356:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log 473:Timeout=4 516:AlertScriptsPath=/usr/lib/zabbix/alertscripts 527:ExternalScripts=/usr/lib/zabbix/externalscripts 563:LogSlowQueries=3000把zabbix文件复制到nginx的默认主页站点并设置权限
[root@zabbix ~]# cp -r /usr/share/zabbix/ /usr/share/nginx/html/ [root@zabbix ~]# chown -R zabbix:zabbix /etc/zabbix/ [root@zabbix ~]# chown -R zabbix:zabbix /usr/share/nginx/ [root@zabbix ~]# chown -R zabbix:zabbix /usr/lib/zabbix/ [root@zabbix ~]# chmod -R 755 /etc/zabbix/web/ [root@zabbix ~]# chmod -R 777 /var/lib/php/session/启动zabbix和zabbix-agent
[root@zabbix ~]# systemctl start zabbix-server.service [root@zabbix ~]# systemctl enable zabbix-agent.service Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service. [root@zabbix ~]# systemctl start zabbix-agent.service [root@zabbix ~]# systemctl enable zabbix-agent.service查看端口状态
[root@zabbix ~]# netstat -anpl | grep zabbix tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 111746/zabbix_agent tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 111646/zabbix_serve tcp6 0 0 :::10050 :::* LISTEN 111746/zabbix_agent tcp6 0 0 :::10051 :::* LISTEN 111646/zabbix_serve重启php模块和nginx
[root@zabbix ~]# systemctl restart php-fpm.service [root@zabbix ~]# systemctl restart nginx真机访问http://192.168.245.203/zabbix
配置步骤如下
这里会出现配置失败需要下载文件
这里,我们把要下载的文件已经下载好了,把zabbix.conf.php拷贝到etc/zabbix/web/,配置权限并重启zabbix服务
[root@zabbix ~]# cd /etc/zabbix/web/ [root@zabbix web]# chown zabbix.zabbix /etc/zabbix/web/zabbix.conf.php [root@zabbix web]# systemctl restart zabbix-server.service重新刷新一下网页就好了
在客户端上下载安装zabbix-agent
[root@localhost ~]# rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm [root@localhost ~]# yum install -y zabbix-agent配置agent端参数
[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf 98 Server=192.168.245.203 //指向zabbix服务器 139 ServerActive=192.168.245.203 //指向zabbix服务器 150 Hostname=test //随便起个名字重启agent
[root@localhost ~]# systemctl enable zabbix-agent.service Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service. [root@localhost ~]# systemctl restart zabbix-agent.service [root@localhost ~]# netstat -anpt | grep zabbix tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 87972/zabbix_agentd tcp6 0 0 :::10050 :::* LISTEN 87972/zabbix_agentd刷新页面,页面添加被监控的主机
添加要监控哪些服务的模板
因为被监控主机没有安装apache服务,所以这里告警了
如果想取消监控某个服务,点击取消并更新
重新刷新页面告警就没了