論如何使用zabbix監控LNMP架構

zabbix介紹php

zabbix是一個基於WEB界面的分佈式監控系統,zabbix能監控各類網絡參數,保證服務器系統的安全運營,並提供靈活的通知機制,讓系統管理員快手定位解決存在的各類問題,主要有監控CPU負載,內存使用、磁盤使用、網絡狀態、端口監視,日誌監視、插件開發自定義等功能。 html

zabbix Server 經過SNMP、zabbix agent,ping、端口監視等方法提供對遠程服務器/網絡狀態的監視,數據收集功能。能夠在運行Linux 、Solaris、HP-UX、AIX、FreeBSD、OpenBSD、Windows等多平臺運行。 mysql

常見商業功能: nginx

  • 主機性能監控
  • 網絡設備性能監控
  • 數據庫性能監控
  • ftp等通用協議的監控
  • 可以利用靈活的可定製警告機制
  • 容許用戶對事件發送基於 E-mail的警告,能夠保證相關維護人員對問題作出快速響應
  • 能夠利用存儲數據提供傑出的報表及實時的圖形化數據處理,實現對 Linux、 Windows主機的7×24小時集中監控
  • 監控的項目可包括CPU、內存、磁盤、網卡流量、服務可用性等各類資源。

其中組件: web

zabbix_agent 安裝在須要被監控的目標服務器上,主要完成對硬件信息與操做系統有關的內存,CPU、硬盤等信息的收集,功能十分強大。 sql

zabbix_server 能夠單獨監視遠程服務器的服務狀態,同時也能夠與zabbix_agent 結合,能夠輪詢zabbix Agent 主動接收監控數據,還能夠被動接收zabbix_agent 發送的數據。 數據庫

如圖: vim

微信截圖_20181028154920

 

環境介紹: centos

經過C/S模式採集數據 安全

經過B/S模式在WEB端展現和配置

Agent 監控端口10050

服務端端口10051

以LNMP爲監測環境  LNMP=Linux+Nginx+Mysql+PHP

 

環境表:

主機 操做系統 IP地址 主要軟件
Zabbix服務器 Centos 7 192.168.10.11 Zabbix
客戶機 Centos 7 192.168.10.12 Zabbix

 

操做步驟:

LAMP環境部署

#Zabbix服務器 和客戶機 關閉防火牆
systemctl stop firewalld.service
setenforce 0  #不關,Zabbix沒法啓動

 

安裝nginx

獲取安裝源

wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enable=1

yum list
yum install nginx –y

http防火牆設置,關閉防火牆則無需此步驟。


firewall-cmd --permanent --add-service=http --zone=public
firewall-cmd –reload

開啓nginx

systemctl start nginx
netstat -ntap | grep nginx       #查看端口

安裝mariadb

yum install mariadb-server mariadb -y
systemctl start mariadb.service
systemctl enable mariadb.service
mysql_secure_installation          ##配置安裝

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):    #默認空密碼,直接回車
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y      #建立新密碼
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] n   #不刪除匿名用戶
... skipping.

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n      #遠程ROOT登錄
... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n    #刪除測試數據庫
... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y     #從新加載權限表
... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

安裝PHP

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install -y php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql

編輯PHP配置文件

vim /etc/php-fpm.d/www.conf
8 user = nginx
10 group = nginx

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  //時區設置上海

vim /etc/nginx/conf.d/default.conf
10         index  index.php index.html index.htm;  //添加PHP支持
  30     location ~ \.php$ {
31         root           /usr/share/nginx/html;
32         fastcgi_pass   127.0.0.1:9000;
33         fastcgi_index  index.php;
34         fastcgi_param  SCRIPT_FILENAME  $document_r    oot$fastcgi_script_name;
35         include        fastcgi_params;
36     }

開啓php服務

systemctl start php-fpm.service
systemctl enable php-fpm.service
netstat -ntap | grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      76012/php-fpm: mast
systemctl restart nginx

進入數據庫給Zabbix建立提供數據庫

mysql -uroot -p1
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on *.* to 'zabbix'@'%' identified by 'admin123';
flush privileges;

寫入一個頁面測試PHP是否能鏈接數據庫

vim info.php
<?php
$link=mysqli_connect('127.0.0.1','root','1');
if($link) echo "true!";
else echo "Fail!!";
?>

成功:

 

微信截圖_20181026150159

 

-----------若是出現沒法登錄問題------------

select user,host from mysql.user;
看見有空用戶,刪除即解決
drop user ''@localhost;
drop user ''@cent;
再次檢測

 

安裝zabbix

rpm -i http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent –y

編輯配置文件

vim /etc/zabbix/zabbix_server.conf
91 DBHost=localhost
125 DBPassword=admin123

-----------防止出現zabbix頁面亂碼問題------------


vim /usr/share/zabbix/include/defines.inc.php
%s /graphfont/kaiti/g        //全局替換

https://pan.baidu.com/s/1f5XCKPMusD1weN6AfB2UYQ
把上面這個文件放到/usr/share/zabbix/fonts/下

給zabbix相關加權,否則後面開啓zabbix會出現不少問題。

cp -r /usr/share/zabbix/ /usr/share/nginx/html/
chown -R zabbix:zabbix /etc/zabbix/
chown -R zabbix:zabbix /usr/share/nginx/
chown -R zabbix:zabbix /usr/lib/zabbix/
chmod -R 755 /etc/zabbix/web/
chmod -R 777 /var/lib/php/session/
zcat /usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz | mysql -uzabbix -p zabbix

重啓改動服務以及啓動zabbix

systemctl stop php-fpm.service
systemctl stop nginx.service
systemctl start php-fpm.service
systemctl start nginx.service
systemctl start zabbix-server.service
systemctl start zabbix-agent.service
netstat -ntap | grep 10051

 

登錄 Zabbix 並配置
默認用戶名和密碼分別爲  admin,zabbix
http://192.168.10.11/zabbix/

微信截圖_20181025151215

 

--------------------安裝過程當中若是出現---------------------

 

微信截圖_20181026154159

 

解決方法以下


cp /bao/zabbix.conf.php /etc/zabbix/web/
chown zabbix.zabbix /etc/zabbix/web/zabbix.conf.php

中文能夠在網站設置裏面調。

 微信截圖_20181028171925

進去以後測試一下,咱們添加一個SSH監控模塊

微信截圖_20181026155150

 

幹掉這個SSH

systemctl stop sshd

等個十幾秒,刷新一下這個頁面

微信截圖_20181026155228

 

至此就完成了zabbix的監控流程。

相關文章
相關標籤/搜索