此处我们假设php和nginx都已经安装完成了;
1、通过yum方式安装zabbix;:
rpm -Uvh https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-release-4.2-1.el7.noarch.rpm
yum clean all
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
2、创建zabbix所需要的数据库和文件;
grant all on zabbix.* to 'zabbix'@'l27.0.0.1' identified by 'feye-zabbix';
flush privileges;
3、将zabbix的初始化输入导入到数据库;通过如下两种方式:
命令行导入:
zcat /usr/share/doc/zabbix-server-mysql-4.2.5/create.sql.gz | mysql -uroot -pyuanhh2019 zabbix
或者本地解压后再次导入:
zcat /usr/share/doc/zabbix-server-mysql-4.2.5/
gzip create.sql.gz
mysql -uroot -pyuanhh2019 < create.sql
4、zabbix的配置文件存在在/etc/zabbix目录下: 修改数据库连接信息
[root@fenye2019 zabbix]# cat zabbix_server.conf |grep -v ^#
DBHost=127.0.0.1
DBName=zabbix
DBUser=zabbix
DBPassword=feye-zabbix
DBSocket=/tmp/mysq.sock
5、启动zabbix
[root@fenye2019 zabbix]# systemctl enable zabbix-server
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to
/usr/lib/systemd/system/zabbix-server.service.
[root@fenye2019 zabbix]# systemctl restart zabbix-server
6、在防火墙里放行端口 10050 10051
cp /usr/lib/firewalld/services/zabbix-server.xml /etc/firewalld/services/
cp /usr/lib/firewalld/services/zabbix-agent.xml /etc/firewalld/services/
frewall-cmd --get-default-zones
firewall-cmd --zone=public --add-port=10050/tcp --permanent
firewall-cmd --zone=public --add-port=10051/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --add-service=zabbix-server --permanent
firewall-cmd --zone=public --add-service=zabbix-agent --permanent
firewall-cmd --reload
firewall-cmd --list-ports
7、此时网页还是无法访问: zabbix.forebix.com
查看zabbix的错误日记:
cat /var/log/zabbix/zabbix_server.log
发现zabbix-server服务正常启动,nginx服务也正常响应了,响应码是500,说明nginx的配置没问题,问题出现在php-fpm上;
因为php-fpm的日记默认是输出的,所有需要打开并定向到某个文件里;
vim /usr/local/php-fpm/etc/php.ini
display_errors = oN
error_log = /var/log/php_error.log
查看报错信息如下:
Warning: require_once(/etc/zabbix/web/maintenance.inc.php): failed to open stream: Permission denied in
/usr/share/zabbix/include/classes/core/ZBase.php on line 279
Fatal error: require_once()
此处我们假设php和nginx都已经安装完成了;
1、通过yum方式安装zabbix;
rpm -Uvh https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-release-4.2-1.el7.noarch.rpm
yum clean all
# b. Install Zabbix server, frontend, agent
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
2、创建zabbix所需要的数据库和文件;
grant all on zabbix.* to 'zabbix'@'localhost' identified by 'feye-zabbix';
flush privileges;
3、将zabbix的初始化输入导入到数据库;通过如下两种方式:
命令行导入:
zcat /usr/share/doc/zabbix-server-mysql-4.2.5/create.sql.gz | mysql -uroot -pyuanhh2019 zabbix
或者本地解压后再次导入:
zcat /usr/share/doc/zabbix-server-mysql-4.2.5/
gzip create.sql.gz
mysql -uroot -pyuanhh2019 < create.sql
4、zabbix的配置文件存在在/etc/zabbix目录下: 修改数据库连接信息
[root@fenye2019 zabbix]# cat zabbix_server.conf |grep -v ^#
DBHost=127.0.0.1
DBName=zabbix
DBUser=zabbix
DBPassword=feye-zabbix
DBSocket=/tmp/mysq.sock
5、启动zabbix
[root@fenye2019 zabbix]# systemctl enable zabbix-server
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to
/usr/lib/systemd/system/zabbix-server.service.
[root@fenye2019 zabbix]# systemctl restart zabbix-server
6、在防火墙里放行端口 10050 10051
cp /usr/lib/firewalld/services/zabbix-server.xml /etc/firewalld/services/
cp /usr/lib/firewalld/services/zabbix-agent.xml /etc/firewalld/services/
firewall-cmd --zone=public --add-port=10050/tcp --permanent
firewall-cmd --zone=public --add-port=10051/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --add-service=zabbix-server --permanent
firewall-cmd --zone=public --add-service=zabbix-agent --permanent
firewall-cmd --reload
7、此时网页还是无法访问: zabbix.forebix.com
查看zabbix的错误日记:
cat /var/log/zabbix/zabbix_server.log
发现zabbix-server服务正常启动,nginx服务也正常响应了,响应码是500,说明nginx的配置没问题,问题出现在php-fpm上;
因为php-fpm的日记默认是输出的,所有需要打开并定向到某个文件里;
vim /usr/local/php-fpm/etc/php.ini
display_errors = oN
error_log = /var/log/php_error.log
查看报错信息如下:
Warning: require_once(/etc/zabbix/web/maintenance.inc.php): failed to open stream: Permission denied in
/usr/share/zabbix/include/classes/core/ZBase.php on line 279
Fatal error: require_once(): Failed opening required '/etc/zabbix/web/maintenance.inc.php'
(include_path='.:/usr/local/php-fpm/lib/php') in /usr/share/zabbix/include/classes/core/ZBase.php on line 279
vim /usr/local/php-fpm/etc/php.ini
display_errors = oN
error_log = /var/log/php_error.log
如上图报错可知:
Failed opening required '/etc/zabbix/web/maintenance.inc.php'
这是一个权限问题导致的,因为我们nginx的启动用户组是 nobody nobody ,而/etc/zabbix/web这个目录的所属组所属主是root,导致nginx无法读取文件/etc/zabbix/web/maintenance.inc.php,尝试修改/etc/zabbix/web的所属组主为nobody nobody,再次启动zabbix-server;
[root@fenye2019 conf]# ls -ld /etc/zabbix/web/
drwxr-x--- 2 apache apache 4096 Aug 21 14:41 /etc/zabbix/web/
[root@fenye2019 conf]# head -2 /usr/local/nginx/conf/nginx.conf
user nobody nobody; #以那个用户的身份来启动nginx;
worker_processes 2; #子进程有几个;
[root@fenye2019 conf]# chown -R nobody:nobody /etc/zabbix/web
[root@fenye2019 conf]# systemctl restart zabbix-server
或者如下操作:
[root@fenye2019 conf]# chmod -R 755 /etc/zabbix/web
修改相关信息:
在php的配置文件/usr/loca/php-fpm/etc/php.ini下修修改;
报着两个错误:
PHP bcmath extension missing (PHP configuration parameter --enable-bcmath).
PHP sockets extension missing (PHP configuration parameter --enable-sockets).
第一个是缺少一个模块;需要编译安装;
扩展模块:php的源码包中没有第三方模块的包,但是在PHP源码包的/ext/目录下有好多扩展模块,如果所需要的扩展模块在该目录下,可以直接进行安装;
需要先做phppize的操作,目的是生成configure文件,因为编译一个源码包,必须要先有configure文件,否则是无法去配置的;
[root@fenye2019 bcmath]# cd /usr/local/src/php-7.3.0/ext/bcmath/
[root@fenye2019 bcmath]# /usr/local/php-fpm/bin/phpize
[root@fenye2019 bcmath]# ./configure --with-php-config=/usr/local/php-fpm/bin/php-config
[root@fenye2019 bcmath]# make
[root@fenye2019 bcmath]# make install
Installing shared extensions: /usr/local/php-fpm/lib/php/extensions/no-debug-non-zts-20180731/
添加到vim /usr/local/php-fpm/etc/php.ini
extension=bcmath.so
重启php-fpm 服务;
安装第二个模块;
[root@fenye2019 ~]# cd /usr/local/src/
[root@fenye2019 src]# cd php-7.3.0/ext/sockets/
[root@fenye2019 sockets]# /usr/local/php-fpm/bin/phpize
[root@fenye2019 sockets]# ./configure --with-php-config=/usr/local/php-fpm/bin/php-config
[root@fenye2019 sockets]# make
[root@fenye2019 sockets]# make install
vim /usr/local/php-fpm/etc/php.ini
extension=sockets.so
重启php-fpm 服务;
zabbix的配置文件:
[root@fenye2019 vhost]# cat zabbix.conf
server
{
listen 80;
server_name zabbix.forebix.com;
index index.html index.htm index.php;
root /usr/share/zabbix;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ [^/]\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/zabbix$fastcgi_script_name;
include fastcgi.conf;
}
}