Centos7 nginx 虛擬主機、反向代理伺服器及負載均衡,多臺主機分離php-fpm實驗,之強化篇,部署zab...
一、簡介
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) 2Requires: 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.
fpingRequired for ICMP ping items.
yum install -y zabbix-server-mysql zabbix-web-mysql
yum install zabbix-get
1 Installed: 2zabbix-server-mysql.x86_64 0:4.0.4-1.el7 3 4 Dependency Installed: 5OpenIPMI-libs.x86_64 0:2.0.23-2.el7OpenIPMI-modalias.x86_64 0:2.0.23-2.el7iksemel.x86_64 0:1.4-2.el7.centos 6 7 Complete!
1 [root@web5 yum.repos.d]# rpm -qa |grep zabbix 2 zabbix-server-mysql-4.0.4-1.el7.x86_64 3 zabbix-get-4.0.4-1.el7.x86_64 4 zabbix-release-4.0-1.el7.noarch 5 zabbix-web-mysql-4.2.0-0.3alpha3.el7.noarch 6 zabbix-web-4.2.0-0.3alpha3.el7.noarch 7 [root@web5 yum.repos.d]#
然後看一下文件
1 [root@web5 yum.repos.d]# rpm -ql zabbix-server-mysql 2 /etc/logrotate.d/zabbix-server 3 /etc/zabbix/zabbix_server.conf 4 /usr/lib/systemd/system/zabbix-server.service 5 /usr/lib/tmpfiles.d/zabbix-server.conf 6 /usr/lib/zabbix/alertscripts 7 /usr/lib/zabbix/externalscripts 8 /usr/sbin/zabbix_server_mysql 9 /usr/share/doc/zabbix-server-mysql-4.0.4 10 /usr/share/doc/zabbix-server-mysql-4.0.4/AUTHORS 11 /usr/share/doc/zabbix-server-mysql-4.0.4/COPYING 12 /usr/share/doc/zabbix-server-mysql-4.0.4/ChangeLog 13 /usr/share/doc/zabbix-server-mysql-4.0.4/NEWS 14 /usr/share/doc/zabbix-server-mysql-4.0.4/README 15 /usr/share/doc/zabbix-server-mysql-4.0.4/create.sql.gz #zabbix資料庫sql指令碼 16 /usr/share/man/man8/zabbix_server.8.gz 17 /var/log/zabbix 18 /var/run/zabbix
2、初始化資料庫
2.1、準備好資料庫機器mysql1,ip-56
關閉selinux,firewall,安裝資料庫
yum install mariadb-embedded mariadb-libs mariadb-bench mariadb mariadb-sever
systemctl start mariadb
systemctl enable mariadb
1 [root@mysql1 /]# netstat -untlp | grep 3306 2 tcp00 0.0.0.0:33060.0.0.0:*LISTEN37059/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 /]# mysql 2 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 Server 5 6 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. 7 8 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 9 10 MariaDB [(none)]> use mysql; 11 Reading table information for completion of table and column names 12 You can turn off this feature to get a quicker startup with -A 13 14 Database changed 15 MariaDB [mysql]> update user set password=password('newpassword') where user='root'; 16 Query OK, 4 rows affected (0.01 sec) 17 Rows matched: 4Changed: 4Warnings: 0 MariaDB [mysql]> flush privileges;
測試web5-55 測試連線資料庫
1 [root@web5 web]# vim index.php 2 3 <?php 4 #echo ("55"); 5 $link=mysql_connect('192.168.216.56','zabbix','admin123'); 6 if($link) echo "<h1>The database connection was successful!</h1>"; 7 else echo "<h1>The database connection was Fail!!</h1>"; 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 [email protected]:/
2.5、匯入資料庫
mysql -uroot zabbix < /create.sql -p
3、配置nginx
web2-52 -nginx,配置檔案
1 [root@web2 zabbix]# cat /etc/nginx/conf.d/default.conf 2 upstream php-cluster { 3#server 127.0.0.1:9000 max_fails=3 fail_timeout=10s; #首先註釋本地得php-fpm 4server 192.168.216.55:9000 max_fails=3 fail_timeout=10s; 5} 6 7 server { 8listen 80; 9server_name 192.168.216.52; 10index index.html index.htm index.phpi; 11root /usr/share/zabbix; #更換web目,zabbix預設目錄,測試無所事先用預設得吧 12location / { 13 14root/usr/share/nginx/html; 15} 16 17location ~.*\.php$ { 18 19fastcgi_passphp-cluster; 20fastcgi_indexindex.php; 21fastcgi_paramSCRIPT_FILENAME $document_root$fastcgi_script_name; 22includefastcgi_params; 23} 24 }
4、配置zabbix
web5-55
4.1、修改zabbix配置
vim /etc/zabbix/zabbix_server.conf
修改下面幾項即可
1 ### Option: DBHost 2 DBHost=192.168.216.56 3 ### Option: DBName 4 # DBName= 5 DBName=zabbix 6 # DBUser= 7 DBUser=zabbix 8 ### Option: DBPassword 9 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
1 display_errors 2 錯誤回顯,一般常用語開發模式,但是很多應用在正式環境中也忘記了關閉此選項。錯誤回顯可以暴露出非常多的敏感資訊,為攻擊者下一步攻擊提供便利。推薦關閉此選項。 3 display_errors = On 4 開啟狀態下,若出現錯誤,則報錯,出現錯誤提示 5 dispaly_errors = Off 6 關閉狀態下,若出現錯誤,則提示:伺服器錯誤。但是不會出現錯誤提示
問題2、269的warning,給許可權
再次訪問www.web1.com/index.php,發現是269得warning,因為是nginx啟動得php-fpm我們可以給一下許可權
1 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 269 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 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
<em><code> </code></em>
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 [email protected]:/
web2
cd /
tar -jxvf zabbix.tar.bz2
完成在訪問一下,成功
那麼放在 httpd伺服器的效果那
web5-55
scp zabbix.tar.bz2 [email protected]:/
web4-54
cd /
tar -jxvf zabbix.tar.bz2
chown -R apache:apache zabbix
vim /etc/httpd/conf/httpd.conf
1 DocumentRoot "/zabbix" 2 <Directory "/zabbix"> 3 AllowOverride None 4 # Allow open access: 5 Require all granted 6 </Directory> 7 <Directory "/zabbix"> 8# 9# Possible values for the Options directive are "None", "All", 10# or any combination of: 11#Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews 12# 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 see 17# http://httpd.apache.org/docs/2.4/mod/core.html#options 18# for more information. 19# 20Options Indexes FollowSymLinks 21 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 Limit 26# 27AllowOverride None 28 29# 30# Controls who can get stuff from this server. 31# 32Require all granted 33 </Directory>
systemctl restart httpd
訪問一下www.web1.com/index.php
三、開始配置zabbix
1、welcome,進入zabbix介面我們開始部署,點next
2、check of pre-requisites
編輯解決這三個問題
web5
vim /etc/php.ini
post_max_size = 16M # PHP將接受的POST資料的最大大小
max_execution_time = 300 #每個指令碼最大執行時間
max_input_time = 300 #每個指令碼可能花費在解析請求資料上的最大時間
systemctl restart php-fpm
重新整理網頁
3、configure DB connect
4、zabbix server details
5、pre-installation summary
6、insatll
總結,這個例子主要是試試看的心態,並沒有向下做下去,因為還有很多問題,需要很多精力,下一篇只對zabbix---》mysql做分離實驗。並介紹一些用法。謝謝