zabbix是一个基于web界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案,zabbix能监视各种网络参数,保证服务器系统的安全运营,并提供友好的通知机制以让系统管理员快速定位解决存在的各种问题
1、安装nginx服务
(1)创建nginx的镜像源
[root@localhost ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
[root@localhost ~]# yum list
(2)下载nginx并启动服务
[root@localhost ~]# yum install nginx -y
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl enable nginx
[root@localhost ~]# yum install mariadb-server mariadb -y
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# systemctl enable mariadb.service
#执行下面的操作设置数据库的登陆密码及其他的设置操作
[root@localhost ~]# mysql_secure_installation
3、安装PHP服务
[root@localhost ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
[root@localhost ~]# yum install php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql -y
[root@localhost ~]# php -v
PHP 7.2.27 (cli) (built: Jan 26 2020 15:49:49) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
4、配置nginx服务支持php
#修改php-fpm的配置文件,将apache改为nginx
[root@localhost ~]# vim /etc/php-fpm.d/www.conf
user = nginx
group = nginx
#更改nginx的默认配置文件,配置location,在index中添加index.php
[root@localhost ~]# vim /etc/nginx/conf.d/default.conf
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
//配置php请求被传送到后端的php-fpm模块,默认情况下php配置块是被注释的,将注释取消即可使用
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;
}
//把fastcgi_param中的/scripts改为$document_root
#修改php的配置文件
[root@localhost ~]# vim /etc/php.ini
359 expose_php = Off //隐藏php版本
202 short_open_tag = On //支持php标签
//以下为zabbix配置要求
368 max_execution_time = 300 //执行时间
378 max_input_time = 300 //接收数据等待时间
389 memory_limit = 128M //每个脚本占用内存
656 post_max_size = 16M //POST数据大小
799 upload_max_filesize = 2M //下载文件大小
800 always_populate_raw_post_data = -1 //手动添加,表示可以用$HTTP_RAW_POST_DATA接收post raw data
878 date.timezone = Asia/Shanghai //设置时区
#启动服务
[root@localhost ~]# systemctl start php-fpm.service
[root@localhost ~]# systemctl enable php-fpm.service
[root@localhost ~]# systemctl restart nginx
5、PHP测试
(1)创建php测试页面
[root@localhost ~]# vim /usr/share/nginx/html/info.php
http://192.168.7.168/info.php
[root@localhost ~]# vim /usr/share/nginx/html/info.php
6、在数据库中创建zabbix的用户及数据库
[root@localhost ~]# mysql -uroot -p
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> grant all privileges on *.* to 'zabbix'@'%' identified by 'admin123';
MariaDB [(none)]> flush privileges;
[root@localhost ~]# mysql -uzabbix -p
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 |
| | 192.168.7.168 |
| root | 192.168.7.168 |
| root | ::1 |
| | localhost |
| root | localhost |
+--------+---------------+
7 rows in set (0.00 sec)
#将空用户删除即可使用zabbix用户登陆数据库
MariaDB [(none)]> drop user ''@'localhost';
MariaDB [(none)]> drop user ''@'192.168.7.128';
MariaDB [(none)]> select user,host from mysql.user;
+--------+---------------+
| user | host |
+--------+---------------+
| zabbix | % |
| root | 127.0.0.1 |
| root | 192.168.7.168 |
| root | ::1 |
| root | localhost |
+--------+---------------+
5 rows in set (0.00 sec)
[root@localhost ~]# vim /usr/share/nginx/html/info.php
[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 zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
#更改zabbix_server的配置文件
[root@localhost ~]# vim /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
#修正图表中文乱码
[root@localhost ~]# vim /usr/share/zabbix/include/defines.inc.php
//将文中的graphfont改为kaiti
#从微软系统下复制相应的字体文件到/usr/share/zabbix/fonts
[root@localhost ~]# cd /usr/share/zabbix
[root@localhost zabbix]# mkdir fonts
[root@localhost zabbix]# cd fonts/
#上传后查看
[root@localhost fonts]# ls
STKAITI.TTF