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

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

一、简介

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

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

  Centos7 nginx 虚拟主机、反向代理服务器及负载均衡,多台主机分离php-fpm实验,之强化篇,部署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

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

  

 Error: Package: zabbix-server-mysql-4.0.-.el7.x86_64 (zabbix)
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-get

 Installed:
zabbix-server-mysql.x86_64 :4.0.-.el7 Dependency Installed:
OpenIPMI-libs.x86_64 :2.0.-.el7 OpenIPMI-modalias.x86_64 :2.0.-.el7 iksemel.x86_64 :1.4-.el7.centos Complete!

  

 [root@web5 yum.repos.d]# rpm -qa |grep zabbix
zabbix-server-mysql-4.0.-.el7.x86_64
zabbix-get-4.0.-.el7.x86_64
zabbix-release-4.0-.el7.noarch
zabbix-web-mysql-4.2.-.3alpha3.el7.noarch
zabbix-web-4.2.-.3alpha3.el7.noarch
[root@web5 yum.repos.d]#

  然后看一下文档

 [root@web5 yum.repos.d]# rpm -ql zabbix-server-mysql
/etc/logrotate.d/zabbix-server
/etc/zabbix/zabbix_server.conf
/usr/lib/systemd/system/zabbix-server.service
/usr/lib/tmpfiles.d/zabbix-server.conf
/usr/lib/zabbix/alertscripts
/usr/lib/zabbix/externalscripts
/usr/sbin/zabbix_server_mysql
/usr/share/doc/zabbix-server-mysql-4.0.
/usr/share/doc/zabbix-server-mysql-4.0./AUTHORS
/usr/share/doc/zabbix-server-mysql-4.0./COPYING
/usr/share/doc/zabbix-server-mysql-4.0./ChangeLog
/usr/share/doc/zabbix-server-mysql-4.0./NEWS
/usr/share/doc/zabbix-server-mysql-4.0./README
/usr/share/doc/zabbix-server-mysql-4.0.4/create.sql.gz #zabbix数据库sql脚本
/usr/share/man/man8/zabbix_server..gz
/var/log/zabbix
/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 mariadb

 [root@mysql1 /]# netstat -untlp | grep
tcp 0.0.0.0:3306 0.0.0.0:* LISTEN /mysqld

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

 CREATE DATABASE zabbix character set utf8 collate utf8_bin;   

 GRANT all privileges ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123';

 MariaDB [mysql]> flush privileges;

      2.3、修改数据库root密码

 [root@mysql1 /]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 5.5.-MariaDB MariaDB Server Copyright (c) , , Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
MariaDB [mysql]> update user set password=password('newpassword') where user='root';
Query OK, rows affected (0.01 sec)
Rows matched: Changed: Warnings: 0

MariaDB [mysql]> flush privileges;

 

    测试web5-55  测试连接数据库

 [root@web5 web]# vim index.php 

 <?php
#echo ("");
$link=mysql_connect('192.168.216.56','zabbix','admin123');
if($link) echo "<h1>The database connection was successful!</h1>";
else echo "<h1>The database connection was Fail!!</h1>";
mysql_close();
# phpinfo();
?>

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

   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,配置文件

  

 [root@web2 zabbix]# cat /etc/nginx/conf.d/default.conf
upstream php-cluster {
#server 127.0.0.1: max_fails= fail_timeout=10s;        #首先注释本地得php-fpm
server 192.168.216.55:9000 max_fails=3 fail_timeout=10s;
} server {
listen ;
server_name 192.168.216.52;
index index.html index.htm index.phpi;
root /usr/share/zabbix;                          #更换web目,zabbix默认目录,测试无所事先用默认得吧
location / { root /usr/share/nginx/html;                          
} location ~.*\.php$ { fastcgi_pass php-cluster;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

  4、配置zabbix 

    web5-55

    4.1、修改zabbix配置

    vim  /etc/zabbix/zabbix_server.conf

    修改下面几项即可

  

 ### Option: DBHost
DBHost=192.168.216.56
### Option: DBName
# DBName=
DBName=zabbix
# DBUser=
DBUser=zabbix
### Option: DBPassword
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-fpm

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

    问题2、269的warning,给权限

    再次访问www.web1.com/index.php,发现是269得warning,因为是nginx启动得php-fpm我们可以给一下权限

 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  Fatal error: require_once(): Failed opening required '/etc/zabbix/web/maintenance.inc.php' (include_path='.:') in /usr/share/zabbix/include/classes/core/ZBase.php on line 

   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、没有图片效果,因为架构是动静分离,所以静态内容需要放到静态服务器上

   

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

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

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

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

 
 // :: [error] #: * open() "/usr/share/zabbix/styles/blue-theme.css" failed (: 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"
// :: [error] #: * open() "/usr/share/zabbix/js/browsers.js" failed (: 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"
// :: [error] #: * open() "/usr/share/zabbix/js/browsers.js" failed (: 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"
// :: [error] #: * open() "/usr/share/zabbix/styles/blue-theme.css" failed (: 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

  完成在访问一下,成功

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

  那么放在  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

 

 DocumentRoot "/zabbix"
<Directory "/zabbix">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<Directory "/zabbix">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks #
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None #
# Controls who can get stuff from this server.
#
Require all granted
</Directory>

  systemctl restart httpd

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

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

三、开始配置zabbix

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

    2、check of pre-requisites

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

    编辑解决这三个问题

    web5

    vim /etc/php.ini

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

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

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

    systemctl restart php-fpm

    刷新网页

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

  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