[root@localhost ~]# mysql -uroot -p
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin; #创建一个zabbix数据库
MariaDB [(none)]> grant all on zabbix.* to 'zabbix'@'%' identified by '123123'; #为zabbix数据库创建管理用户
MariaDB [(none)]> flush privileges;
创建PHP测试首页
[root@localhost ~]# vim /var/www/html/index.php
<?php
phpinfo();
?>
编写测试脚本,测试PHP能否连接数据库
<?php
$link=mysql_connect('192.168.199.129','zabbix','123123');
if($link) echo "<h1>success</h1>";
else echo "fail";
mysql_close();
?>
在使用zabbix用户进行登录数据库时有时会出现登录失败的现象,这是因为里面有空用户占用导致本地用户无法登录,所以需要删除空用户
[root@localhost ~]# mysql -u zabbix -p #登录失败
Enter password:
ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES)
[root@localhost ~]# mysql -u root -p
MariaDB [(none)]> select user,host from mysql.user; #有空用户占用导致本地用户无法登陆
+--------+-----------------------+
| user | host |
+--------+-----------------------+
| zabbix | % |
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | localhost.localdomain |
| root | localhost.localdomain |
+--------+-----------------------+
7 rows in set (0.00 sec)
MariaDB [(none)]> drop user ''@'localhost'; #删除空用户
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> drop user ''@'localhost.localdomain'; #删除空用户
Query OK, 0 rows affected (0.00 sec)
[root@localhost ~]# mysql -u zabbix -p #再次登录就可以了
MariaDB [(none)]>
到此为止,LAMP架构就部署完了
二、部署zabbix server
[root@localhost ~]# yum install php-bcmath php-mbstring -y #下载两个PHP依赖包
[root@localhost~]#rpm -ivh #下载zabbix yum源,安装完成后会自动产生repo文件
[root@localhost ~]# yum install zabbix-server-mysql zabbix-web-mysql -y #安装zabbix软件包
修改zabbix配置文件
[root@localhost ~]# 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
101:DBName=zabbix
117:DBUser=zabbix
125:DBPassword=123123 #密码改为zabbix登陆密码
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@localhost ~]# vim /etc/httpd/conf.d/zabbix.conf #修改时区
php_value date.timezone Asia/Shanghai
[root@localhost ~]# vim /usr/share/zabbix/include/defines.inc.php #修正图表中文乱码
:%s /graphfont/kaiti/g #将配置文件中的graphfont替换为kaiti
[root@localhost ~]# cp STKAITI.TTF /usr/share/zabbix/fonts/ #从微软系统下复制相应的字体文件到/usr/share/zabbix/fonts/
开启zabbix服务端
[root@localhost ~]# systemctl start zabbix-server.service
[root@localhost ~]# systemctl enable zabbix-server.service
[root@localhost ~]# netstat -ntap | grep 10051 #查看端口
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 40703/zabbix_server
tcp6 0 0 :::10051 :::* LISTEN 40703/zabbix_server
[root@localhost ~]# systemctl restart httpd.service #重启Apache服务
首先看见的是zabbix的版本: