基于LNMP架构搭建企业级开源监控系统Zabbix

环境

 

LNMP : Linux Nginx MySQL PHP

Zabbix_Server : 192.168.10.81

Zabbix_Agent : 192.168.10.82

Zabbix简介

官方网站:http://www.zabbix.com/

企业级监控解决方案:

Zabbix是一个基于Web界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案;

Zabbix能监视各种网络参数,保证服务器系统的安全运行,并且提供灵活的通知机制让系统管理员能够快速定位解决存在的各种问题。

Zabbix主要特点:

安装与配置简单,学习成本低,支持多语言(包括中文),免费开源,自动发现服务器与网络设备分布式监视以及Web集中管理功能。可以无agent监视,用户安全认证和柔软的授权通过Web界面设置或查看监视结果email等通知功能。

Zabbix主要功能:

监控CPU负载、内存使用、磁盘使用、网络状态、端口监视、日志监视、插件开发、自定义。

Zabbix运行机制:

Zabbix Server 和 Zabbix agent

Zabbix Server可以通过SNMP、Zabbix agent,Ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集功能,可以在运行Linux,Solaris、HP-UX,AIX,FreeBSD,OpenBSD,OS X,Windows 等平台;

Zabbix Agent安装在需要被监控的目标服务器上,主要完成对硬件信息与操作系统有关的内存、CPU等信息的收集;

Zabbix Server可以单独监视远程服务器的服务状态,同时也可以与Zabbix Agent结合,可以轮询Zabbix Agent主动接收监视数据(trapping传递方式),同时还可以被动接收Zabbix Agent发送的数据。

Zabbix支持多种网络方式下的监控,可以通过分布式的部署和安装监控代理Zabbix,通过C/S模式采集数据,通过B/S模式在Web端展示和配置,Agent监控端口10050;

服务端安装Zabbix Server 和 Zabbix Agent 两个服务,客户端只安装Zabbix Agent一个服务,监控原理就是Zabbix Agent 服务将从系统中获取的相关数据传送给Zabbix Server,然后Zabbix Server服务将数据分析之后以PHP页面展示出来!

搭建Zabbix

1、前期准备

配置好yum源

[root@Zabbix_Server ~]# cat /etc/yum.repos.d/yum.repo 
[yum]
name=yum
baseurl=file:///yum
enabled=1
gpgcheck=0

[root@Zabbix_Agent ~]# cat /etc/yum.repos.d/yum.repo 
[yum]
name=yum
baseurl=file:///yum
enabled=1
gpgcheck=0

修改hostname

[root@Zabbix_Server ~]# cat /etc/hostname 
Zabbix_Server


[root@Zabbix_Agent ~]# cat /etc/hostname 
Zabbix_Agent

下载LNMP和Zabbix源码包,安装 lrzsz 工具

LNMP和Zabbix

链接:https://pan.baidu.com/s/1AxCRfKfgeR1MhIk3nk-7aw

提取码:6vt7

[root@Zabbix_Server ~]# yum install -y lrzsz

[root@Zabbix_Agent ~]# yum install -y lrzsz

校正时间

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
y
date -R

2、在Zabbix_Server端搭建LNMP架构

LNMP动态网站部署架构是一套由Linux+Nginx+MySQL+PHP组成的动态网站系统解决方案。LNMP中的字母L是Linux系统的意思,不仅可以是RHEL、CentOS、Fedora,还可以是Debian、Ubuntu等系统

把准备好的LNMP源码包上传到Linux系统的/usr/local/src目录中

在Linux系统中输入 rz 命令,上传LNMP源码包

[root@Zabbix_Server ~]# cd /usr/local/src/

[root@Zabbix_Server src]# rz


[root@Zabbix_Server src]# ls
LNMP.zip
[root@Zabbix_Server src]# yum install -y unzip
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
yum                                                                         | 4.1 kB  00:00:00     
Package unzip-6.0-16.el7.x86_64 already installed and latest version
Nothing to do
[root@Zabbix_Server src]# unzip LNMP.zip 
Archive:  LNMP.zip
  inflating: tiff-4.0.3.tar.gz       
  inflating: yasm-1.2.0.tar.gz       
  inflating: zlib-1.2.8.tar.gz       
  inflating: cmake-2.8.11.2.tar.gz   
  inflating: Discuz_X3.2_SC_GBK.zip  
  inflating: freetype-2.5.3.tar.gz   
  inflating: jpegsrc.v9a.tar.gz      
  inflating: libgd-2.1.0.tar.gz      
  inflating: libmcrypt-2.5.8.tar.gz  
  inflating: libpng-1.6.12.tar.gz    
  inflating: libvpx-v1.3.0.tar.bz2   
  inflating: mysql-5.6.19.tar.gz     
  inflating: nginx-1.6.0.tar.gz      
  inflating: openssl-1.0.1h.tar.gz   
  inflating: pcre-8.35.tar.gz        
  inflating: php-5.5.14.tar.gz       
  inflating: t1lib-5.1.2.tar.gz      
[root@Zabbix_Server src]# ls
cmake-2.8.11.2.tar.gz   libmcrypt-2.5.8.tar.gz  nginx-1.6.0.tar.gz     tiff-4.0.3.tar.gz
Discuz_X3.2_SC_GBK.zip  libpng-1.6.12.tar.gz    openssl-1.0.1h.tar.gz  yasm-1.2.0.tar.gz
freetype-2.5.3.tar.gz   libvpx-v1.3.0.tar.bz2   pcre-8.35.tar.gz       zlib-1.2.8.tar.gz
jpegsrc.v9a.tar.gz      LNMP.zip                php-5.5.14.tar.gz
libgd-2.1.0.tar.gz      mysql-5.6.19.tar.gz     t1lib-5.1.2.tar.gz

安装相关包及编译工具

[root@Zabbix_Server src]# yum install -y apr* autoconf automake bison bzip2 bzip2* compat* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc* gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libtiff libtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre pcre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib zlib-devel

安装CMake编译工具

[root@Zabbix_Server src]# tar xvf cmake-2.8.11.2.tar.gz

[root@Zabbix_Server src]# cd cmake-2.8.11.2

[root@Zabbix_Server cmake-2.8.11.2]# ./configure

[root@Zabbix_Server cmake-2.8.11.2]# make

[root@Zabbix_Server cmake-2.8.11.2]# make install

配置Nginx

#检查Apache服务是否启用,如果有则停掉,systemctl stop httpd

[root@Zabbix_Server cmake-2.8.11.2]# ps -aux | grep httpd
root      20534  0.0  0.0 112648   960 pts/0    S+   06:26   0:00 grep --color=auto httpd

#创建一个用于执行Nginx服务程序的用户

[root@Zabbix_Server cmake-2.8.11.2]# useradd nginx -s /sbin/nologin

#安装nginx源码包

[root@Zabbix_Server cmake-2.8.11.2]# cd /usr/local/src/

[root@Zabbix_Server src]# tar xvf nginx-1.6.0.tar.gz

[root@Zabbix_Server src]# cd nginx-1.6.0

[root@Zabbix_Server nginx-1.6.0]# ./configure  --user=nginx  --group=nginx  --prefix=/usr/local/nginx  --with-http_stub_status_module   --with-http_sub_module   --with-http_ssl_module  --with-pcre

[root@Zabbix_Server nginx-1.6.0]# make && make install

#验证nginx是否配置有误
[root@Zabbix_Server nginx-1.6.0]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

#启动nginx

[root@Zabbix_Server nginx-1.6.0]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

#清空防火墙

[root@Zabbix_Server nginx-1.6.0]# iptables -F


#查看nginx进程

[root@Zabbix_Server nginx-1.6.0]# ps -ef | grep nginx
root      13678      1  0 20:44 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/ngin -c /usr/local/nginx/conf/nginx.conf
nginx     13679  13678  0 20:44 ?        00:00:00 nginx: worker process
root      13682   1118  0 20:45 pts/0    00:00:00 grep --color=auto nginx

在浏览器中输入Zabbix_Server端的IP地址,验证nginx服务是否正常,如果能够看到nginx的欢迎界面,则说明nginx服务正常。

配置MySQL

#创建一个用于执行MySQL服务程序的用户

[root@Zabbix_Server nginx-1.6.0]# cd ..
[root@Zabbix_Server src]# useradd mysql -s /sbin/nologin 

#创建用于保存MySQL数据库程序和数据文件的目录,并把该目录的所有者和所属组身份修改为mysql,其中,/usr/local/mysql/var则是用于保存真实数据库文件的目录

[root@Zabbix_Server src]# mkdir -p /usr/local/mysql/var
[root@Zabbix_Server src]# chown -Rf mysql:mysql /usr/local/mysql

#解压、编译、安装MySQL数据库服务程序,在编译数据库时使用的是cmake命令,其中,-DCMAKE_INSTALL_PREFIX参数用于定义数据库服务程序的保存目录,-DMYSQL_DATADIR参数用于定义真实数据库文件的目录,-DSYSCONFDIR则是定义MySQL数据库配置文件的保存目录

[root@Zabbix_Server src]# tar xvf mysql-5.6.19.tar.gz

[root@Zabbix_Server src]# cd mysql-5.6.19

[root@Zabbix_Server mysql-5.6.19]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/var -DSYSCONFDIR=/etc

[root@Zabbix_Server mysql-5.6.19]# make && make install

#为了让MySQL数据库正常运转,需要先删除/etc目录中的默认配置文件,然后在MySQL数据库程序的保存目录scripts内找到一个名为mysql_install_db的脚本程序,执行这个脚本程序并使用--user参数指定MySQL服务的对应账号名称(在前面步骤我们已经创建了),使用--basedir参数指定MySQL服务程序的保存目录,使用--datadir参数指定MySQL真实数据库的文件保存目录,这样即可生成系统数据库文件,也会生成出新的MySQL服务配置文件。

[root@Zabbix_Server mysql-5.6.19]# rm -rf /etc/my.cnf

[root@Zabbix_Server mysql-5.6.19]# cd /usr/local/mysql/

[root@Zabbix_Server mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var

#把Linux系统新生成的MySQL数据库配置文件链接到/etc目录中,然后把程序目录中的开机程序文件复制到/etc/rc.d/init.d目录中,以便通过service命令来管理MySQL数据库服务程序,记得把数据库脚本文件的权限修改成755以便于让用户有执行脚本的权限

[root@Zabbix_Server mysql]# ls
bin      data  include         lib  my.cnf      README   share      support-files
COPYING  docs  INSTALL-BINARY  man  mysql-test  scripts  sql-bench  var


[root@Zabbix_Server mysql]# ln -s my.cnf /etc/my.cnf

[root@Zabbix_Server mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld

[root@Zabbix_Server mysql]# chmod 755 /etc/rc.d/init.d/mysqld 


#编辑刚刚复制的MySQL数据库脚本文件,把第46,47行的basedir和datadir参数分别修改成MySQL数据库程序的保存目录和真是数据库的文件内容
[root@Zabbix_Server mysql]# vim /etc/rc.d/init.d/mysqld 

basedir=/usr/local/mysql
datadir=/usr/local/mysql/var

#配置好脚本文件后便可以用service命令启动mysqld数据库服务了,mysqld是MySQL数据库程序的服务名称,注意不能写错。再用chkconfig命令把mysqld服务程序加入到开机启动项中

[root@Zabbix_Server mysql]# service mysqld start
Unit mysqld.service could not be found.
Starting MySQL.. SUCCESS! 
[root@Zabbix_Server mysql]# chkconfig mysqld on

#在/etc/profile配置文件的第74行加入export PATH=$PATH:/usr/local/mysql/bin

[root@Zabbix_Server mysql]# vim /etc/profile

74 export PATH=$PATH:/usr/local/mysql/bin

[root@Zabbix_Server mysql]# source /etc/profile

#MySQL数据库服务程序还会调用一些程序文件和函数库文件,由于当前是通过源码包方式安装MySQL数据库,因此现在也必须以手动方式把这些文件链接过来

[root@Zabbix_Server mysql]# mkdir /var/lib/mysql
[root@Zabbix_Server mysql]# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
[root@Zabbix_Server mysql]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
[root@Zabbix_Server mysql]# ln -s /usr/local/mysql/include/mysql /usr/include/mysql

#现在MySQL数据库服务程序已经启动,调用的各个函数文件已经就位,PATH环境变量中也加入了MySQL数据库命令的所在目录。接下来准备对MySQL数据库进行初始化,这个初始化的配置过程与mariadb数据库是一样的,只是最后变成了Thanks for using MySQL!
#注意:如果此时mysql_secure_installation 命令找不到,需要退出当前终端,重新连接Linux系统后再使用mysql_secure_installation来初始化MySQL数据库

[root@Zabbix_Server mysql]# mysql_secure_installation



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

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, 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 MySQL
root user without the proper authorisation.

Set root password? [Y/n] y   (要为root管理员设置数据库的密码)
New password:                 输入要为root管理员设置的数据库密码
Re-enter new password:        再输入一次密码
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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] y  (删除匿名账户)
 ... Success!

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] y  (禁止root管理员从远程登录)
 ... Success!

By default, MySQL 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] y   (删除test数据库并取消对其的访问权限)
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

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

Reload privilege tables now? [Y/n] y  (刷新授权表,让初始化后的设定立即生效)
 ... Success!  




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

Thanks for using MySQL!


Cleaning up...




登录MySQL数据库,做简单操作,验证数据库是否正常

[root@Zabbix_Server mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.6.19 Source distribution

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

mysql> create database test;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.01 sec)

mysql> create database test2;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| test2              |
+--------------------+
5 rows in set (0.00 sec)

mysql> drop database test2;

Query OK, 0 rows affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

配置PHP

使用源码包的方式编译安装PHP语言环境其实并不复杂,难点在于解决PHP的程序包和其他软件的依赖关系。为此需要先安装部署将近十个用于搭建网站页面的软件程序包,然后才能正式安装PHP程序。

yasm源码包是一款常见的开源汇编器,将其解压,编译

[root@Zabbix_Server mysql]# cd /usr/local/src/

[root@Zabbix_Server src]# tar xvf yasm-1.2.0.tar.gz 

[root@Zabbix_Server src]# cd yasm-1.2.0

[root@Zabbix_Server yasm-1.2.0]# ./configure

[root@Zabbix_Server yasm-1.2.0]# make && make install

libmcrypt源码包适用于加密算法的扩展库程序,将其解压编译

[root@Zabbix_Server yasm-1.2.0]# cd ..

[root@Zabbix_Server src]# tar xvf libmcrypt-2.5.8.tar.gz 

[root@Zabbix_Server src]# cd libmcrypt-2.5.8

[root@Zabbix_Server libmcrypt-2.5.8]# ./configure

[root@Zabbix_Server libmcrypt-2.5.8]# make && make install

libvpx源码包是开源的VP8编码解码器

[root@Zabbix_Server libmcrypt-2.5.8]# cd ..

[root@Zabbix_Server src]# tar xvf libvpx-v1.3.0.tar.bz2

[root@Zabbix_Server src]# cd libvpx-v1.3.0

[root@Zabbix_Server libvpx-v1.3.0]# ./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9

[root@Zabbix_Server libvpx-v1.3.0]# make


[root@Zabbix_Server libvpx-v1.3.0]# make install


注意:
make[1]: Nothing to be done for `all'.
make[1]: Nothing to be done for `install'.
说明你已经编译好了

tiff源码包适用于提供标签图像文件格式的服务程序,将其解压,编译

[root@Zabbix_Server libvpx-v1.3.0]# cd ..

[root@Zabbix_Server src]# tar xvf tiff-4.0.3.tar.gz 

[root@Zabbix_Server src]# cd tiff-4.0.3

[root@Zabbix_Server tiff-4.0.3]# ./configure --prefix=/usr/local/tiff --enable-shared

[root@Zabbix_Server tiff-4.0.3]# make && make install

libpng源码包是用于提供png图片格式支持函数库的服务程序,将其解压、编译

[root@Zabbix_Server tiff-4.0.3]# cd ..

[root@Zabbix_Server src]# tar xvf libpng-1.6.12.tar.gz 

[root@Zabbix_Server src]# cd libpng-1.6.12

[root@Zabbix_Server libpng-1.6.12]# ./configure --prefix=/usr/local/libpng --enable-shared

[root@Zabbix_Server libpng-1.6.12]# make && make install

freetype源码包是用于提供字体支持引擎的服务程序,将其解压、编译

[root@Zabbix_Server libpng-1.6.12]# cd ..

[root@Zabbix_Server src]# tar xvf freetype-2.5.3.tar.gz 

[root@Zabbix_Server src]# cd freetype-2.5.3

[root@Zabbix_Server freetype-2.5.3]# ./configure --prefix=/usr/local/freetype --enable-shared

[root@Zabbix_Server freetype-2.5.3]# make

[root@Zabbix_Server freetype-2.5.3]# make install


注意:
如果出现make: Nothing to be done for `unix'.
进入 builds/unix 目录,然后在这个目录里运行./configure命令
没有就不需运行以下命令
[root@Zabbix_Server freetype-2.5.3]# cd builds/unix
[root@Zabbix_Server unix]# pwd
/usr/local/src/freetype-2.5.3/builds/unix
[root@Zabbix_Server unix]# ./configure --prefix=/usr/local/freetype --enable-shared
[root@Zabbix_Server unix]# cd /usr/local/src/freetype-2.5.3
[root@Zabbix_Server freetype-2.5.3]# make
[root@Zabbix_Server freetype-2.5.3]# make install

jpeg源码包是用于提供jpeg图片格式支持函数库的服务程序,其解压、编译

[root@Zabbix_Server freetype-2.5.3]# cd ..

[root@Zabbix_Server src]# tar xvf jpegsrc.v9a.tar.gz

[root@Zabbix_Server src]# cd jpeg-9a

[root@Zabbix_Server jpeg-9a]# ./configure --prefix=/usr/local/jpeg --enable-shared

[root@Zabbix_Server jpeg-9a]# make && make install

libgd源码包是用于提供图形处理的服务程序,其解压、编译。在编译libgd源码包时,请记得写入的是jpeg、libpng、freetype、tiff、libvpx等服务程序在系统中的安装路径,即在上面安装过程中使用--prefix参数指定的目录路径

[root@Zabbix_Server jpeg-9a]# cd ..

[root@Zabbix_Server src]# tar xvf libgd-2.1.0.tar.gz

[root@Zabbix_Server src]# cd libgd-2.1.0

[root@Zabbix_Server libgd-2.1.0]# ./configure --prefix=/usr/local/libgd --enable-shared --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/freetype --with-xpm=/usr/ --with-tiff=/usr/local/tiff --with-vpx=/usr/local/libvpx

[root@Zabbix_Server libgd-2.1.0]# make

[root@Zabbix_Server libgd-2.1.0]# make install

t1lib源码包是用于提供图片生成函数库的服务程序,其解压、编译。安装后把/usr/lib64目录中的函数文件链接到/usr/lib目录中,以便系统能够顺利调取到函数文件

[root@Zabbix_Server libgd-2.1.0]# cd ..

[root@Zabbix_Server src]# tar xvf t1lib-5.1.2.tar.gz 

[root@Zabbix_Server src]# cd t1lib-5.1.2

[root@Zabbix_Server t1lib-5.1.2]# ./configure --prefix=/usr/local/t1lib --enable-shared

[root@Zabbix_Server t1lib-5.1.2]# make

[root@Zabbix_Server t1lib-5.1.2]# make install

[root@Zabbix_Server t1lib-5.1.2]# ln -s /usr/lib64/libltdl.so /usr/lib/libltdl.so

[root@Zabbix_Server t1lib-5.1.2]# cp -frp /usr/lib64/libXpm.so* /usr/lib/



注意:
Configure finished!
Do: 'make' to compile the t1lib-package.
Do: 'make without_doc' to compile if you do not have LaTeX.
Do: 'make install' to install the t1lib-package.

如果出现make[1]: latex: Command not found报错,则执行 make without_doc 后再继续操作

此时我们终于把编译php服务源码包的相关软件包都已经安装部署妥当了,在开始编译php源码包之前,先定义一个名为LD_LIBRARY_PATH的全局环境变量,该环境变量的作用是帮助系统找到指定的动态链接库文件,这些文件是编译php服务源码包的必须元素之一。编译php服务源码包时,除了定义要安装到的目录之外,还需要依次定义配置php服务程序配置文件的保存目录,MySQL数据库服务程序所在目录,MySQL数据库服务程序配置文件所在目录,以及libpng、jpeg、freetype、zlib、t1lib等服务程序的安装目录路径,并通过参数启动php服务程序的诸多默认功能。

[root@Zabbix_Server t1lib-5.1.2]# cd ..

[root@Zabbix_Server src]# tar xvf php-5.5.14.tar.gz

[root@Zabbix_Server src]# cd php-5.5.14

[root@Zabbix_Server php-5.5.14]# export LD_LIBRARY_PATH=/usr/local/libgd/lib

[root@Zabbix_Server php-5.5.14]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/ --with-vpx-dir=/usr/local/libvpx/ --with-zlib-dir=/usr/local/zlib --with-t1lib=/usr/local/t1lib --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --enable-ctype

[root@Zabbix_Server php-5.5.14]# make

[root@Zabbix_Server php-5.5.14]# make install

在PHP源码包程序安装完成后,需要删除当前默认的配置文件,然后将php服务程序目录中相应的配置文件复制过来。

[root@Zabbix_Server php-5.5.14]# rm -rf /etc/php.ini

[root@Zabbix_Server php-5.5.14]# ln -s /usr/local/php/etc/php.ini /etc/php.ini

[root@Zabbix_Server php-5.5.14]# cp php.ini-production /usr/local/php/etc/php.ini

[root@Zabbix_Server php-5.5.14]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

[root@Zabbix_Server php-5.5.14]# ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf

php-fpm.conf是php服务程序重要的配置文件之一,我们需要启用该配置文件中第25行的pid文件保存目录,然后分别将第148和149行的user和group参数分别修改为nginx账户和用户组名称。

[root@Zabbix_Server php-5.5.14]# vim /usr/local/php/etc/php-fpm.conf

25 pid = run/php-fpm.pid

148 user = nginx

149 group = nginx

配置妥当后就可以把用于管理php服务的脚本文件复制到/etc/rc.d/init.d中,为了能够执行脚本,要记得为脚本赋予755权限。最后把php-fpm服务程序加入到开机启动项中。

[root@Zabbix_Server php-5.5.14]# cp /usr/local/src/php-5.5.14/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm

[root@Zabbix_Server php-5.5.14]# chmod 755 /etc/rc.d/init.d/php-fpm

[root@Zabbix_Server php-5.5.14]# chkconfig php-fpm on

由于PHP服务程序的配置参数直接会影响到Web服务的运行环境,因此,如果默认开启了一些不必要且高危的功能(比如允许用户在网页中执行linux命令),则会降低网站被入侵的难度,入侵人员甚至可以拿到整台Web服务器的管理权限。因此我们需要编辑php.ini配置文件,在305行的disable_functions参数后面追加上要禁止的功能。下面的禁用功能名单是我依据网站运行的经验而定制的,不见得适合每个生产环境,建议大家在此基础上根据自身工作需求酌情删减。

[root@Zabbix_Server php-5.5.14]# vim /usr/local/php/etc/php.ini

305 disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_     status,ini_alter,ini_alter,ini_restor e,dl,openlog,syslog,readlink,symlink,popepassthru,stream_soc     ket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,g etservbyname,getservby     port,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,     posix_getgid,po six_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_get     pgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_ getpwuid,posix_getrlimit,posix_getsid,posix_     getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_ setpgi     d,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

这样就把php服务程序配置妥当了,最后,还需要编辑Nginx服务程序的主配置文件,把第2行的#号删除,然后在后面写上负责运行Nginx服务程序的账户名称和用户组名称;把第45行的index参数后面写上网站的首页名称。最后是将第65-71行参数前的#号删除来启动参数,主要是修改69行的脚本名称路径参数,其中$document_root 变量即为网站信息存储的根目录路径,若没有设置该变量,则Nginx服务程序无法找到网站信息,因此会提示“404页面未找到”的报错信息。在确认参数信息填写正确后便可重启Nginx服务与php-fpm服务

[root@Zabbix_Server php-5.5.14]# vim /usr/local/nginx/conf/nginx.conf
1
2 user nginx nginx;
3 worker_processes 1;
4
5 #error_log logs/error.log;
6 #error_log logs/error.log notice;
7 #error_log logs/error.log info;
8
9 #pid logs/nginx.pid;
10
11
………………省略部分输出信息………………
40
41 #access_log logs/host.access.log main;
42
43 location / {
44 root html;
45 index index.html index.htm index.php;
46 }
47
………………省略部分输出信息………………
62
63 #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
64
65 location ~ \.php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
70 include fastcgi_params;
71 }
72
………………省略部分输出信息………………

重启php-fpm,重新加载nginx配置文件

[root@Zabbix_Server php-5.5.14]# systemctl restart php-fpm

[root@Zabbix_Server php-5.5.14]# /usr/local/nginx/sbin/nginx -s reload

至此,LNMP动态网站环境架构的配置全部完成!

部署Zabbix_Server

1、创建Zabbix数据库

[root@Zabbix_Server ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.6.19 Source distribution

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database zabbix character set utf8;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on zabbix.* to zabbix@localhost identified by 'zabbix';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on zabbix.* to zabbix@Zabbix_Server identified by 'zabbix';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

2、上传Zabbix源码包到/usr/local/src目录中

[root@Zabbix_Server ~]# cd /usr/local/src/
[root@Zabbix_Server src]# rz
# 此处用lrzsz工具上传源码包,用其他工具也可以
rz waiting to receive.
 zmodem trl+C ȡ

  100%   16729 KB 16729 KB/s 00:00:01       0 Errors

[root@Zabbix_Server src]# ls | grep zabbix
zabbix-3.4.3.tar.gz
[root@Zabbix_Server src]# tar xvf zabbix-3.4.3.tar.gz
[root@Zabbix_Server src]# cd zabbix-3.4.3
[root@Zabbix_Server zabbix-3.4.3]# ls
aclocal.m4  ChangeLog     config.sub    database   INSTALL      Makefile.in  NEWS    upgrades
AUTHORS     compile       configure     depcomp    install-sh   man          README
bin         conf          configure.ac  frontends  m4           misc         sass
build       config.guess  COPYING       include    Makefile.am  missing      src

3、把相关数据导入数据库

[root@Zabbix_Server zabbix-3.4.3]# mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql 
Warning: Using a password on the command line interface can be insecure.

[root@Zabbix_Server zabbix-3.4.3]# mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql 
Warning: Using a password on the command line interface can be insecure.

[root@Zabbix_Server zabbix-3.4.3]# mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql 
Warning: Using a password on the command line interface can be insecure.

#Warning: Using a password on the command line interface can be insecure. 这个告警可以忽略!如果在做分布式的环境中,Proxy 服务器只需要一个数据库 schema,代理者 agent 不需要数据库, Server 必须三个数据库同时拥有。

4、编译安装Zabbix

#创建zabbix用户

[root@Zabbix_Server zabbix-3.4.3]# groupadd zabbix

[root@Zabbix_Server zabbix-3.4.3]# useradd -s /sbin/nologin -g zabbix zabbix

#解决依赖关系

[root@Zabbix_Server zabbix-3.4.3]# yum install -y mysql-devel net-snmp-devel  libevent libevent-devel

#确认libevent相关包是否装好

[root@Zabbix_Server zabbix-3.4.3]# yum install -y libevent libevent-devel
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Package libevent-2.0.21-4.el7.x86_64 already installed and latest version
No package libevent-devel available.
Nothing to do

Libevent 是一个用C语言编写的、轻量级的开源高性能事件通知库,主要有以下几个亮点:事件驱动( event-driven),高性能;轻量级,专注于网络,不如 ACE 那么臃肿庞大;源代码相当精炼、易读;跨平台,支持 Windows、 Linux、 *BSD 和 Mac Os;支持多种 I/O 多路复用技术, epoll、 poll、 dev/poll、 select 和 kqueue 等;支持 I/O,定时器和信号等事件;注册事件优先级。

Libevent 已经被广泛的应用,作为底层的网络库;比如memcached、 Vomit、 Nylon、 Netchat等等。

出现No package libevent-devel available报错,请到以下网站去下载libevent-devel-2.0.21-4.el7.x86_64.rpm包

https://pkgs.org/download/libevent-devel

安装libevent-devel

[root@Zabbix_Server zabbix-3.4.3]# rz

[root@Zabbix_Server zabbix-3.4.3]# ls
aclocal.m4  conf          database    libevent-devel-2.0.21-4.el7.x86_64.rpm  missing
AUTHORS     config.guess  depcomp     m4                                      NEWS
bin         config.sub    frontends   Makefile.am                             README
build       configure     include     Makefile.in                             sass
ChangeLog   configure.ac  INSTALL     man                                     src
compile     COPYING       install-sh  misc                                    upgrades
[root@Zabbix_Server zabbix-3.4.3]# rpm -ivh libevent-devel-2.0.21-4.el7.x86_64.rpm 
warning: libevent-devel-2.0.21-4.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:libevent-devel-2.0.21-4.el7      ################################# [100%]


预编译

[root@Zabbix_Server zabbix-3.4.3]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl


参数说明:
--prefix=                   #指定路径
--enable-server             # Server 支持
--enable-agent              # 支持 Zabbix 客户端
--with-mysql                # 指定 MySql 库可以选择自定路径 mysql_config,mysql_config 是命令,用于编译 mysql 客户端程序
--with-net-snmp             # 支持 snmp 协议,需要安装 net-snmp-devel 包
--with-libcurl              # 支持 CURL 功能,libcurl 主要功能就是用不同的协议连接不同的服务器,libcurl 当前支持的协议有 http,https,ftp,gopher,telent,dict,file,和 ldap 协议
 
其他参数:
--enable-proxy   指的是支持 zabbix 代理服务器,zabbix proxy 是一个监控代理服务器,它收集到监控数据,选存放在缓冲区,保存的时间可以通过配置文件设定,然后再传送的 zabbix server。监控代理服务需要一个独立的数据库。
用 zabbix proxy 的好处:进程监控,当监控的位置通信不便时,当通讯上千台设备的时候,使用 zabbix_proxy 可以简化维护分布式监控,降低 zabbix server 的负载。


看到以下信息,预编译就完成了
***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <http://www.zabbix.com>                    *
***********************************************************

安装

[root@Zabbix_Server zabbix-3.4.3]# make install

[root@Zabbix_Server zabbix-3.4.3]# ls -hl /usr/local/zabbix
total 0
drwxr-xr-x. 2 root root  45 Jul  3 16:32 bin
drwxr-xr-x. 4 root root 114 Jul  3 16:33 etc
drwxr-xr-x. 2 root root   6 Jul  3 16:32 lib
drwxr-xr-x. 2 root root  48 Jul  3 16:33 sbin
drwxr-xr-x. 4 root root  31 Jul  3 16:33 share

#安装成功,产生以上相关目录

配置/usr/local/zabbix/etc/zabbix_server.conf

[root@Zabbix_Server zabbix-3.4.3]# vim /usr/local/zabbix/etc/zabbix_server.conf
DBHost=Zabbix_Server     #默认注释掉了,直接取消注释即可(85)
DBName=zabbix            #数据库用户,授权的用户也是 zabbix(95)
DBUser=zabbix            #默认是 root,授权的用户是 zabbix(111)
DBPassword=zabbix        #授权的密码是 zabbix(119)

监控Zabbix_Server 本身

监控本身,意思是本身作为服务器之外,自己也做自己的客户端,也要使用agentd这个代理者,配置文件中有 agentd 和 agent 两个配置文件,前者是守护进程,后者依赖于xinetd

xinetd(eXtended InterNET services daemon)已经取代了inetd,并且提供了访问控制、加强日志和资源管理功能,已经成了Red Hat 7 和Mandrake 7.2的Internet标准超级守护进程。

[root@Zabbix_Server zabbix-3.4.3]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
#默认监控服务器自己,以下三行不用改

Server=127.0.0.1    

ServerActive=127.0.0.1

Hostname=Zabbix server

UnsafeUserParameters=1    #允许所有的字符是在用户定义的参数,参数传递,也就是支持自定义脚本(280行)

其中Server和ServerActive都指定zabbixserver的IP地址,不同的是,前者是被动,后者是主动,也就是说前者允许127.0.0.1这个IP地址来我这取数据,而serverActive的127.0.0.1的意思是:客户端主动提交数据给它。

启动Zabbix服务

如果Zabbix用户不存在,将以root运行,新建之后,如果Zabbix存在,那么直接可以用Zabbix运行

[root@Zabbix_Server zabbix-3.4.3]# /usr/local/zabbix/sbin/zabbix_server

#如果启动报错,可能会遇到如下情况
[root@Zabbix_Server zabbix-3.4.3]# /usr/local/zabbix/sbin/zabbix_server
sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory

[root@Zabbix_Server zabbix-3.4.3]# vim /etc/ld.so.conf #解决库文件找不到

include ld.so.conf.d/*.conf

/var/lib/mysql/lib/   #根据实际路径添加此行

[root@Zabbix_Server zabbix-3.4.3]# ldconfig #使库文件生效

[root@Zabbix_Server zabbix-3.4.3]# echo /usr/local/zabbix/sbin/zabbix_server >> /etc/rc.local
 # 开机启动
 

#server运行端口10051

[root@Zabbix_Server zabbix-3.4.3]# netstat -pantul | grep zabbix
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      12425/zabbix_server

或者通过启动脚本启动 zabbix 服务

Zabbix默认有部分启动脚本,可以通过自定义脚本的方式来实现,也可以使用Zabbix的模板脚本来实现。脚本在源码目录的 misc/init.d/下面(使用 fedora 下面的 core 即可,也可以使用 fedroa core5 的脚本均可)

[root@Zabbix_Server zabbix-3.4.3]# cd /usr/local/src/zabbix-3.4.3/misc/init.d

[root@Zabbix_Server init.d]# cp fedora/core/*  /etc/rc.d/init.d

[root@Zabbix_Server init.d]# vim /etc/init.d/zabbix_server

BASEDIR=/usr/local/zabbix  # 找到此行,并修改    

[root@Zabbix_Server init.d]# vim /etc/init.d/zabbix_agentd

BASEDIR=/usr/local/zabbix  # 找到此行,并修改

[root@Zabbix_Server init.d]# /etc/init.d/zabbix_server start

Starting zabbix_server (via systemctl):  [  OK  ]

[root@Zabbix_Server init.d]# /etc/init.d/zabbix_agentd start

Starting zabbix_agentd (via systemctl):  [  OK  ]

[root@Zabbix_Server init.d]# netstat -pantu | grep zabbix
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      37191/zabbix_agentd 
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      37025/zabbix_server
# 如果某个进程启动异常,很可能是主机名的影响,用初始的localhost应该没问题
# [root@localhost ~]# cat /etc/hostname
# localhost.localdomain
# [root@localhost ~]# cat /usr/local/zabbix/etc/zabbix_server.conf | grep DBHost
# ### Option: DBHost
# DBHost=localhost
[root@Zabbix_Server init.d]# chkconfig zabbix_server on
[root@Zabbix_Server init.d]# chkconfig zabbix_agentd on

编辑php页面控制文件

[root@Zabbix_Server init.d]# rm -rf /usr/local/nginx/html/*.html
[root@Zabbix_Server init.d]# cp -r /usr/local/src/zabbix-3.4.3/frontends/php/* /usr/local/nginx/html

重新加载 nginx 配置文件,重启php-fpm服务、zabbix服务

[root@Zabbix_Server init.d]# /usr/local/nginx/sbin/nginx -s reload

[root@Zabbix_Server init.d]# /etc/init.d/php-fpm restart

Gracefully shutting down php-fpm . done
Starting php-fpm  done

[root@Zabbix_Server init.d]# /etc/init.d/zabbix_server restart

Restarting zabbix_server (via systemctl):  [  OK  ]

打开网页安装 zabbix web

在浏览器输入 server 端的 IP 地址 192.168.10.81

 开始检查环境,发现有些参数不符合要求

编辑 php.ini 文件,修改参数

[root@Zabbix_Server ~]# vim /usr/local/php/etc/php.ini

post_max_size = 16M        # 修改    663行

max_execution_time = 300   # 修改    375

max_input_time = 300       # 修改    385

date.timezone = Asia/Shanghai  # 此行有注释,取消注释并修改   913

always_populate_raw_post_data = -1  # 此行有注释,取消注释并修改  689

# Setting always_populate_raw_post_data to -1 will opt into the new behaviour that will be implemented in a future version of PHP, in which $HTTP_RAW_POST_DATA is never defined.
mysqli.default_socket = /var/lib/mysql/mysql.sock    1129   #指定php连接mysql的sock路径;mysql.sock是mysql的主机和客户机在同一host上的时候,使用unix domain socket做为通讯协议的载体,它比tcp快。


[root@Zabbix_Server ~]# /etc/init.d/php-fpm restart  # 重启 php-fpm

刷新页面:

LDAP是轻量目录访问协议,英文全称是Lightweight Directory Access Protocol,一般都简称为LDAP

如果提示没有安装PHP LDAP模块,为了不影响后面的功能,现在把这个模块重新编译安装进去。

可以单独把这个模块编译安装进来:

[root@Zabbix_Server ~]# cd /usr/local/src/php-5.5.14/ext/ldap/

[root@Zabbix_Server ldap]# /usr/local/php/bin/phpize 
Configuring for:
PHP Api Version:         20121113
Zend Module Api No:      20121212
Zend Extension Api No:   220121212



phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块
比如你想在原来编译好的php中加入memcached或者ImageMagick等扩展模块,可以使用phpize

[root@Zabbix_Server ldap]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-ldap

上面的过程会报错,提示缺少库文件:

configure: error: Cannot find ldap libraries in /usr/lib.

解决方法:

[root@Zabbix_Server ldap]# yum install -y openldap-devel openldap

[root@Zabbix_Server ldap]# rsync -avz /usr/lib64/libldap* /usr/lib/

再次configure即可通过预编译

[root@Zabbix_Server ldap]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-ldap
[root@Zabbix_Server ldap]# make && make install


[root@Zabbix_Server ldap]# vim /usr/local/php/etc/php.ini
# 添加:extension=ldap.so

 [root@Zabbix_Server ldap]# /etc/init.d/php-fpm restart
# 再次刷新页面即可

 授权的用户和密码

 默认直接下一步

 默认直接下一步

 点击Finish

 如果写入失败,直接点击 Download the configuration file 下载这个配置文件,然后上传 /usr/local/nginx/html/conf/ 目录中

[root@Zabbix_Server ldap]# cd /usr/local/nginx/html/conf
[root@Zabbix_Server conf]# rz

[root@Zabbix_Server conf]# ls
maintenance.inc.php  zabbix.conf.php  zabbix.conf.php.example

#上传的文件为zabbix.conf.php

刷新页面,如果显示成功安装 Zabbix,点击 Finish,完成安装

登录 Zabbix 并做优化

Username: admin

Password: zabbix

点击右上角的用户图标,然后更改语言

点击 Update,页面会显示中文

 点击配置-主机 启用本主机(默认没有启用,点击后面红色的“停用的”,则启用)

监测中

从图表中可以看出,有部分中文乱码,解决方法如下:

在 Windows 系统中找一个字体文件

字体文件位置 C:\Windows\Fonts

[root@Zabbix_Server conf]# cd /usr/local/nginx/html/fonts/

[root@Zabbix_Server fonts]# ls

DejaVuSans.ttf

[root@Zabbix_Server fonts]# rz

[root@Zabbix_Server fonts]# ls
DejaVuSans.ttf  simsun.ttc

[root@Zabbix_Server fonts]# mv DejaVuSans.ttf DejaVuSans.ttf.bak

[root@Zabbix_Server fonts]# mv simsun.ttc DejaVuSans.ttf

[root@Zabbix_Server fonts]# ls

DejaVuSans.ttf  DejaVuSans.ttf.bak

刷新页面

 

配置监控远程主机

部署Zabbix_Agent

解决依赖关系

[root@Zabbix_Agent ~]# yum install -y curl curl-devel net-snmp net-snmp-devel perl-DBI gcc*

# DBI=Database Interface 数据库接口

创建Zabbix用户

[root@Zabbix_Agent ~]# useradd -M -s /sbin/nologin zabbix

源码安装Zabbix_Agent

[root@Zabbix_Agent ~]# cd /usr/local/src

[root@Zabbix_Agent src]# rz

[root@Zabbix_Agent src]# ls

zabbix-3.4.3.tar.gz

[root@Zabbix_Agent src]# tar xvf zabbix-3.4.3.tar.gz

[root@Zabbix_Agent src]# cd zabbix-3.4.3

[root@Zabbix_Agent zabbix-3.4.3]# ./configure --prefix=/usr/local/zabbix --enable-agent
# 被监控端只需要部署 agnet

根据提示直接执行make install

***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <http://www.zabbix.com>                    *
***********************************************************


[root@Zabbix_Agent zabbix-3.4.3]# make install

查看Zabbix服务

[root@Zabbix_Agent zabbix-3.4.3]# cat /etc/services | grep zabbix

zabbix-agent    10050/tcp               # Zabbix Agent
zabbix-agent    10050/udp               # Zabbix Agent
zabbix-trapper  10051/tcp               # Zabbix Trapper
zabbix-trapper  10051/udp               # Zabbix Trapper

启动agent

[root@Zabbix_Agent zabbix-3.4.3]# /usr/local/zabbix/sbin/zabbix_agentd

也可以使用系统启动脚本来启动agent

配置agent开机启动

[root@Zabbix_Agent zabbix-3.4.3]# cp /usr/local/src/zabbix-3.4.3/misc/init.d/fedora/core5/zabbix_agentd  /etc/init.d/

[root@Zabbix_Agent zabbix-3.4.3]# vim /etc/init.d/zabbix_agentd

ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd"  # 修改此行   
                            
[root@Zabbix_Agent zabbix-3.4.3]# chkconfig --add zabbix_agentd

[root@Zabbix_Agent zabbix-3.4.3]# chkconfig zabbix_agentd on

拓展:core 和 core5 里面的文件都可以实现 zabbix 代理启动,core 是测试版本,core5 是稳定版本

修改 Zabbix_Agent 端的配置文件

[root@Zabbix_Agent zabbix-3.4.3]# vim /usr/local/zabbix/etc/zabbix_agentd.conf

Server=192.168.10.81         # zabbix server 地址,可以多个;用,隔开
ServerActive=192.168.10.81   # 主动检查的意思,主动检查主机的数据的数据发送给 Zabbix Server
Hostname=Zabbix_Agent        # 或者用默认的Hostname= localhost.localdomain
UnsafeUserParameters=1       # Zabbix添加自定义监控脚本

重启agent服务,清空防火墙

[root@Zabbix_Agent zabbix-3.4.3]# /etc/init.d/zabbix_agentd restart

Restarting zabbix_agentd (via systemctl):  [  OK  ]

[root@Zabbix_Agent zabbix-3.4.3]# netstat -pantu | grep zabbix

tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      10220/zabbix_agentd

[root@Zabbix_Agent zabbix-3.4.3]# iptables -F

在Zabbix_server测试通讯

[root@Zabbix_Server fonts]# /usr/local/zabbix/bin/zabbix_get -s 192.168.10.82 -p10050 -k system.uname

zabbix_get [42964]: Check access restrictions in Zabbix agent configuration

看到 Check access restrictions in Zabbix agent configuration 或者获取对方系统版本信息说明通讯没问题。

添加主机

 ​​​​​​​

 

 

选择模板

 

 

 

 

 

等几分钟,刷新界面,ZBX 变为绿色后即可查看监控图表;如果 ZBX 一直没变为绿色,则在服务端和客户端分别重启 Zabbix 相关服务后再刷新页面

 Zabbix 已经正常监控远程主机

 Zabbix 的监控配置可以调整的,比如调整图形

 

 

 

 

 

 

 由此可见,图形的颜色已经改变

更改阈值

找出当前主机应用的模板

 

 默认的值是20%

 修改成自己设定的值

 

至此,基于LNMP架构搭建企业级开源监控系统Zabbix已全部完成!Zabbix的其他监控功能请自行研究!

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WeMeHM

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值