[root@promote html]# mysql -u root -p
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> grant all privileges on *.* to 'zabbix'@'%' identified by '123123';
MariaDB [(none)]> flush privileges;
解决本地无法登陆问题:
[root@promote ~]# mysql -u zabbix -p #现在用zabbix用户是无法登陆数据库的,因为有空用户在进行占用
Enter password:
ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES)
MariaDB [(none)]> select user,host from mysql.user;
+--------+-------------------------+
| user | host |
+--------+-------------------------+
| zabbix | % |
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | promote.cache-dns.local |
| root | promote.cache-dns.local |
+--------+-------------------------+
7 rows in set (0.00 sec)
MariaDB [(none)]> drop user ''@'localhost'; #删除库中的空用户
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> drop user ''@'promote.cache-dns.local'; #删除空用户
Query OK, 0 rows affected (0.00 sec)
测试zabbix用户能否连接PHP:
[root@promote ~]# vim /usr/share/nginx/html/index.php
<?php
$link=mysqli_connect('127.0.0.1','zabbix','123123');
if ($link) echo "true";
else echo "false";
?>
在浏览器上访问
到此为止LNMP架构就搭建完成了,下面开始部署zabbix服务
二、部署zabbix server:
[root@promote~]#rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
[root@promote ~]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
[root@promote ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix #将zabbix脚本文件导入到zabbix数据库中
[root@promote ~]# mysql -u zabbix -p
MariaDB [(none)]> use zabbix
MariaDB [zabbix]> show tables; #查看zabbix数据库中的表,如果脚本导入成功,就应该会看到很多表
修改zabbix配置文件,需要修改以下内容:
[root@promote ~]# 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 #去掉注释
101:DBName=zabbix
117:DBUser=zabbix
125:DBPassword=123123 #修改密码
357:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
475:Timeout=4
518:AlertScriptsPath=/usr/lib/zabbix/alertscripts
529:ExternalScripts=/usr/lib/zabbix/externalscripts
565:LogSlowQueries=3000
修正图表中文乱码:
[root@promote ~]# vim /usr/share/zabbix/include/defines.inc.php
[root@promote zabbix]# cp STKAITI.TTF /usr/share/zabbix/fonts/ #从微软系统下复制相应的字体文件到/usr/share/zabbix/fonts/
赋予文件权限:
[root@promote ~]# cp -r /usr/share/zabbix/ /usr/share/nginx/html/
[root@promote ~]# chown -R zabbix.zabbix /etc/zabbix/
[root@promote ~]# chown -R zabbix.zabbix /usr/share/nginx/
[root@promote ~]# chown -R zabbix.zabbix /usr/lib/zabbix/
[root@promote ~]# chmod -R 755 /etc/zabbix/web/
[root@promote ~]# chmod -R 777 /var/lib/php/session/
启动服务:
[root@promote ~]# systemctl start zabbix-server.service
[root@promote ~]# systemctl enable zabbix-server.service
[root@promote ~]# systemctl start zabbix-agent.service
[root@promote ~]# systemctl enable zabbix-agent.service
[root@promote ~]# systemctl restart php-fpm.service
[root@promote ~]# systemctl restart nginx #这两个服务一定要重启,不然在登陆zabbix监控页面时会出错
在浏览器上登录zabbix界面:
版本显示为4.0