Error message here!

Hide Error message here!

忘记密码?

Error message here!

请输入正确邮箱

Hide Error message here!

密码丢失?请输入您的电子邮件地址。您将收到一个重设密码链接。

Error message here!

返回登录

Close

Centos7 nginx 虚拟主机、反向代理服务器及负载均衡,多台主机分离php-fpm实验,之强化篇,部署zabbix为例

乐章 2019-02-21 15:12:00 阅读数:225 评论数:0 点赞数:0 收藏数:0

一、简介

1、由于zabbix是php得,所有lnmp环境这里测试用的上一个实验环境,请查看https://www.cnblogs.com/zhangxingeng/p/10330735.html ;

2、就是上一个例子得架构图加上zabbix,架构图如下;

3、系统环境CentOS Linux release 7.6.1810 (Core);

4、zabbix4,就zabbix3来说,安装起来还是很简单得,这次测试zabbix4.0+

5、添加zabbix源;

yum install http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm

注意:如果不是使用这个源,出现如下这个报错那么请更换正确得源就能解决

1 Error: Package: zabbix-server-mysql-4.0.4-1.el7.x86_64 (zabbix)2 Requires: libiksemel.so.3()(64bit)

 

二、开始部署(由于动静分离架构,稍微麻烦些)

1、web5-55-php-fpm 部署zabbix动态内容

安装依赖,zabbix没有单独得包,安装zabbix-server-mysql即可

zabbix-server-mysql    /#主程序包及数据库文件

    zabbix-web-mysql  /#

zabbix-get /#为了便于agent端发起测试采集数据请求用得

iksemel

libiksemel  Required for Jabber support.

fping Required for ICMP ping items.

 

   yum install -y  zabbix-server-mysql zabbix-web-mysql 

yum install zabbix-get1 Installed:2 zabbix-server-mysql.x8664 0:4.0.4-1.el73 4 Dependency Installed:5 OpenIPMI-libs.x8664 0:2.0.23-2.el7 OpenIPMI-modalias.x8664 0:2.0.23-2.el7 iksemel.x8664 0:1.4-2.el7.centos6 7 Complete!

1 [root@web5 yum.repos.d]/# rpm -qa |grepzabbix2 zabbix-server-mysql-4.0.4-1.el7.x86_643 zabbix-get-4.0.4-1.el7.x86_644 zabbix-release-4.0-1.el7.noarch5 zabbix-web-mysql-4.2.0-0.3alpha3.el7.noarch6 zabbix-web-4.2.0-0.3alpha3.el7.noarch7 [root@web5 yum.repos.d]/#

然后看一下文档

1 [root@web5 yum.repos.d]/# rpm -ql zabbix-server-mysql2 /etc/logrotate.d/zabbix-server3 /etc/zabbix/zabbix_server.conf4 /usr/lib/systemd/system/zabbix-server.service5 /usr/lib/tmpfiles.d/zabbix-server.conf6 /usr/lib/zabbix/alertscripts7 /usr/lib/zabbix/externalscripts8 /usr/sbin/zabbix_server_mysql9 /usr/share/doc/zabbix-server-mysql-4.0.4 10 /usr/share/doc/zabbix-server-mysql-4.0.4/AUTHORS11 /usr/share/doc/zabbix-server-mysql-4.0.4/COPYING12 /usr/share/doc/zabbix-server-mysql-4.0.4/ChangeLog13 /usr/share/doc/zabbix-server-mysql-4.0.4/NEWS14 /usr/share/doc/zabbix-server-mysql-4.0.4/README15 /usr/share/doc/zabbix-server-mysql-4.0.4/create.sql.gz /#zabbix数据库sql脚本16 /usr/share/man/man8/zabbix_server.8.gz17 /var/log/zabbix18 /var/run/zabbix

2、初始化数据库

2.1、准备好数据库机器mysql1,ip-56

关闭selinux,firewall,安装数据库

yum install  mariadb-embedded mariadb-libs mariadb-bench mariadb mariadb-server

systemctl start mariadb

systemctl enable mariadb1 [root@mysql1 /]/# netstat -untlp | grep 3306 2 tcp 0 0 0.0.0.0:3306 0.0.0.0:/* LISTEN 37059/mysqld

2.2、创建zabbix数据库及zabbix用户

1 CREATE DATABASE zabbix character set utf8 collate utf8_bin; 2 3 GRANT all privileges ON /*./* TO 'zabbix'@'%' IDENTIFIED BY 'admin123';4 5 MariaDB [mysql]> flush privileges;

 

   2.3、修改数据库root密码1 [root@mysql1 /]/# mysql2 Welcome to the MariaDB monitor. Commands end with ; or g.3 Your MariaDB connection id is 2 4 Server version: 5.5.60-MariaDB MariaDB Server5 6 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.7 8 Type 'help;' or 'h' for help. Type 'c' to clearthe current input statement.9 10 MariaDB [(none)]>use mysql;11 Reading table information forcompletion of table and column names12 You can turn off this feature to get a quicker startup with -A13 14 Database changed15 MariaDB [mysql]> update user set password=password('newpassword') where user='root';16 Query OK, 4 rows affected (0.01sec)17 Rows matched: 4 Changed: 4 Warnings: 0

MariaDB [mysql]> flush privileges;

 

 

测试web5-55  测试连接数据库1 [root@web5 web]/# vim index.php2 3 The database connection was successful!";7 else echo "

The database connection was Fail!!

";8 mysql_close();9 /# phpinfo();10 ?>

 

 

2.4、解压缩zabbix数据库脚本,并发送到数据库服务器 

gunzip /usr/share/doc/zabbix-server-mysql-4.0.4/create.sql.gz

cd /usr/share/doc/zabbix-server-mysql-4.0.4/

scp create.sql root@192.168.216.56:/

2.5、导入数据库

mysql -uroot zabbix < /create.sql  -p

3、配置nginx

web2-52 -nginx,配置文件

1 [root@web2 zabbix]/# cat /etc/nginx/conf.d/default.conf2 upstream php-cluster {3 /#server 127.0.0.1:9000 max_fails=3 fail_timeout=10s; /#首先注释本地得php-fpm4 server 192.168.216.55:9000 max_fails=3 fail_timeout=10s;5 }6 7 server {8 listen 80;9 server_name 192.168.216.52;10 index index.html index.htm index.phpi;11 root /usr/share/zabbix; /#更换web目,zabbix默认目录,测试无所事先用默认得吧12 location /{13 14 root /usr/share/nginx/html; 15 }16 17 location ~./*.php$ {18 19 fastcgi_pass php-cluster;20 fastcgi_index index.php;21 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;22 include fastcgi_params;23 }24 }

  4、配置zabbix 

web5-55 

4.1、修改zabbix配置

vim  /etc/zabbix/zabbix_server.conf 

修改下面几项即可

1 /#/#/# Option: DBHost2 DBHost=192.168.216.56 3 /#/#/# Option: DBName4 /# DBName= 5 DBName=zabbix6 /# DBUser= 7 DBUser=zabbix8 /#/#/# Option: DBPassword9 DBPassword=admin123

systemctl start zabbix-server

 

4.2、解决error问题

测试访问www.web1.com/index.php,报错500,网上查询说display_errors没配置得原因,这里可以设置成on

问题1、网页返回500错误码,修改display_errors

web5-55

vim /etc/php.ini

display_errors = On

systemctl restart php-fpm1 displayerrors2 错误回显,一般常用语开发模式,但是很多应用在正式环境中也忘记了关闭此选项。错误回显可以暴露出非常多的敏感信息,为攻击者下一步攻击提供便利。推荐关闭此选项。3 displayerrors =On4 开启状态下,若出现错误,则报错,出现错误提示5 dispaly_errors =Off6 关闭状态下,若出现错误,则提示:服务器错误。但是不会出现错误提示

问题2、269的warning,给权限

再次访问www.web1.com/index.php,发现是269得warning,因为是nginx启动得php-fpm我们可以给一下权限1 Warning: requireonce(/etc/zabbix/web/maintenance.inc.php): failed to open stream: Permission denied in /usr/share/zabbix/include/classes/core/ZBase.php on line 269 Fatal error: requireonce(): Failed opening required '/etc/zabbix/web/maintenance.inc.php' (include_path='.:') in /usr/share/zabbix/include/classes/core/ZBase.php on line 269

chown nginx:nginx -R /etc/zabbix

chown nginx:nginx -R /usr/share/zabbix

chmod 755 -R /etc/zabbix

chmod 755 -R /usr/share/zabbix

问题3、没有图片效果,因为架构是动静分离,所以静态内容需要放到静态服务器上

先访问一下,什么鬼,文字模式,没有图片效果

我们先用访问192.168.216.52/index.php,效果一样,也是文字模式,那我们看一下nginx的error.log

tail -5  /var/log/nginx/error.log**

1 2019/02/20 18:37:45 [error] 3595/#0: /*8 open() "/usr/share/zabbix/styles/blue-theme.css" failed (2: No such file or directory), client: 192.168.216.1, server: 192.168.216.52, request: "GET /styles/blue-theme.css HTTP/1.1", host: "192.168.216.52", referrer: "http://192.168.216.52/setup.php" 2 2019/02/20 18:37:45 [error] 3595/#0: /*9 open() "/usr/share/zabbix/js/browsers.js" failed (2: No such file or directory), client: 192.168.216.1, server: 192.168.216.52, request: "GET /js/browsers.js HTTP/1.1", host: "192.168.216.52", referrer: "http://192.168.216.52/setup.php" 3 2019/02/20 18:37:47 [error] 3595/#0: /*9 open() "/usr/share/zabbix/js/browsers.js" failed (2: No such file or directory), client: 192.168.216.1, server: 192.168.216.52, request: "GET /js/browsers.js HTTP/1.1", host: "192.168.216.52", referrer: "http://192.168.216.52/setup.php" 4 2019/02/20 18:37:47 [error] 3594/#0: /*11 open() "/usr/share/zabbix/styles/blue-theme.css" failed (2: No such file or directory), client: 192.168.216.1, server: 192.168.216.52, request: "GET /styles/blue-theme.css HTTP/1.1", host: "192.168.216.52", referrer: "http://192.168.216.52/setup.php"

提示没有找到/usr/share/zabbix/styles,/usr/share/zabbix/js,提示找不到这两个目录,我们把目录复制过来,看看,为了方便可以先把所有目录一起复制过来

web5

cd /usr/share/

tar -jcvf zabbix.tar.bz2 zabbix

scp zabbix.tar.bz2 root@192.168.216.52:/

web2

cd /

tar -jxvf zabbix.tar.bz2

完成在访问一下,成功

那么放在  httpd服务器的效果那

web5-55

scp zabbix.tar.bz2 root@192.168.216.54:/

web4-54

cd /

tar -jxvf zabbix.tar.bz2

chown -R apache:apache zabbix

vim /etc/httpd/conf/httpd.conf

1 DocumentRoot "/zabbix" 2 3 AllowOverride None4 /# Allow open access:5 Require all granted6 7 8 /#9 /# Possible values for the Options directive are "None", "All",10 /# or any combination of:11 /# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews12 /#13 /# Note that "MultiViews" must be named /explicitly/ --- "Options All" 14 /# doesn't give it to you. 15 /#16 /# The Options directive is both complicated and important. Please see17 /# http://httpd.apache.org/docs/2.4/mod/core.html/#options 18 /# for moreinformation.19 /#20 Options Indexes FollowSymLinks21 22 /#23 /# AllowOverride controls what directives may be placed in.htaccess files.24 /# It can be "All", "None", or any combination of the keywords:25 /# Options FileInfo AuthConfig Limit26 /#27 AllowOverride None28 29 /#30 /# Controls whocan get stuff from this server.31 /#32 Require all granted33

 

systemctl restart httpd

 

访问一下www.web1.com/index.php

 

三、开始配置zabbix

1、welcome,进入zabbix界面我们开始部署,点next

     2、check of pre-requisites

编辑解决这三个问题

web5

vim /etc/php.ini

postmaxsize = 16M         /# PHP将接受的POST数据的最大大小

maxexecutiontime = 300 /#每个脚本最大执行时间

maxinputtime = 300        /#每个脚本可能花费在解析请求数据上的最大时间

systemctl restart php-fpm

刷新网页

3、configure  DB connect

4、zabbix server details

5、pre-installation summary

6、insatll

 下面几步,请参考Centos7+lnmp+zabbix+分离mysql实验

 总结,这个例子主要是试试看的心态,并没有向下做下去,下一篇只对zabbix---》mysql做分离实验。并介绍一些用法。谢谢

 

 

 

转载请注明出处:https://www.cnblogs.com/zhangxingeng/p/10402917.html 

 

版权声明
本文为[乐章]所创,转载请带上原文链接,感谢
https://www.cnblogs.com/zhangxingeng/p/10402917.html

编程之旅,人生之路,不止于编程,还有诗和远方。
阅代码原理,看框架知识,学企业实践;
赏诗词,读日记,踏人生之路,观世界之行;

支付宝红包,每日可领