linux 6 yum安装 Zabbix服务

Linux(centos6)环境zabbix 3.4监控安装部署及zabbix agent配置

监控的范畴

 

 

监控工具应具备采集信息、存储信息、展示信息、报警通知等功能,Zabbix 是由 Alexei Vladishev 开发的一种网络监视、管理系统,基于 Server-Client 架构。可用于监视各种网络服务、服务器和网络机器等状态,实现集中监控管理的应用程序。

 

 

 

zabbix agent:部署在被监控主机上,负责被监控主机的数据,并将数据发送给zabbix server。

zabbix server:负责接收agent的报告信息,并组织配置信息、统计信息、操作数据等。

zabbix database:用于存储所遇到zabbix的配置信息、监控数据的数据库。使用如 MySQL, PostgreSQL, SQLite, Oracle 或 IBM DB2 储存资料。

zabbix web:zabbix的web界面是基于 PHP 的,管理员通过web界面管理zabbix配置以及查看zabbix相关监控信息,可以单独部署在独立的服务器上。

部署zabbix服务端

部署zabbix服务端需要LNMP环境(nginx,mysql,php)

环境

[root@nginx ~]# cat /etc/redhat-release
CentOS release 6.10 (Final)
[root@nginx ~]# uname -r
2.6.32-754.el6.x86_64

添加用户

对于所有Zabbix的守护进程,需要一个无特权的用户。如果Zabbix守护进程以一个无特权的用户账户启动,那么它会使用该用户运行。然而,如果一个守护进程以‘root’用户启动,它会切换为‘zabbix’用户账户,且这个用户必须存在。

[root@nginx ~]# groupadd -r zabbix
[root@nginx ~]# useradd -r -g zabbix -s /sbin/nologin zabbix

安装

安装依赖

[root@nginx zabbix-3.4.14]# yum install  -y unixODBC-devel mysql-devel net-snmp-devel libxml2-devel libcurl-devel libevent-devel  OpenIPMI OpenIPMI-devel mysql-devel gcc net-snmp-devel curl-devel perl-DBI php-gd php-mysql php-bcmath php-mbstring php-xml  libssh2*

编译安装

[root@nginx download]# wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.4.14/zabbix-3.4.14.tar.gz/download -O zabbix-3.4.14.tar.gz

[root@nginx download]# tar -zxf zabbix-3.4.14.tar.gz
[root@nginx download]# cd zabbix-3.4.14
[root@nginx zabbix-3.4.14]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-ipv6 --with-mysql --with-libxml2 --with-net-snmp --with-libevent --with-openssl --with-libcurl --with-libpcre --with-iconv --with-ssh2 --with-ladp --with-openipmi

编译过程中也许会出现报错,缺少某些依赖库,对应安装缺少的库然后重新编译,知道出现下面这个提示

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

[root@nginx zabbix-3.4.14]# make && make install

配置zabbix环境变量

[root@nginx zabbix-3.4.14]# vim /etc/profile.d/zabbix.sh
export PATH=/usr/local/zabbix/bin:/usr/local/zabbix/sbin:$PATH

创建zabbix数据库

[root@nginx zabbix-3.4.14]# mysql -uroot -p -h localhost
Enter password:

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

mysql>
mysql> show databases
-> ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test01 |
| test02 |
| test03 |
| test04 |
+--------------------+
6 rows in set (0.02 sec)

mysql>
mysql> create database zabbix character set utf8;                   #创建zabbix数据库,并设置utf8格式
Query OK, 1 row affected (0.00 sec)

mysql> grant all on *.* to zabbix@'127.0.0.1' identified by '111';               #赋予zabbix用户管理权限
Query OK, 0 rows affected (0.00 sec)

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

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

mysql>
mysql> use mysql;                       #连接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
mysql>
mysql>
mysql> select user,host,password from user;                      #查看用户信息
+--------+---------------+-------------------------------------------+
| user | host | password |
+--------+---------------+-------------------------------------------+
| root | localhost | *832EB84CB764129D05D498ED9CA7E5CE9B8F83EB |
| root | nginx | |
| root | 127.0.0.1 | |
| | localhost | |
| | nginx | |
| tongbu | % | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| zabbix | 127.0.0.1 | *832EB84CB764129D05D498ED9CA7E5CE9B8F83EB |
| zabbix | localhost | *832EB84CB764129D05D498ED9CA7E5CE9B8F83EB |
| zabbix | 192.168.10.18 | *832EB84CB764129D05D498ED9CA7E5CE9B8F83EB |
+--------+---------------+-------------------------------------------+
9 rows in set (0.00 sec)

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

mysql> quit;
Bye
[root@nginx zabbix-3.4.14]#  mysql -u zabbix -p                         #使用zabbix登录数据库

mysql> use  zabbix;                                                                      #链接创建的zabbix数据库

Database changed
mysql>
mysql> source /root/download/zabbix-3.4.14/database/mysql/schema.sql;               #导入schema.sql数据到zabbix数据库中

mysql> source /root/download/zabbix-3.4.14/database/mysql/images.sql;               #导入images.sql数据

mysql> source /root/download/zabbix-3.4.14/database/mysql/data.sql;               #导入data.sql数据

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

mysql> quit
Bye
[root@nginx zabbix-3.4.14]#

查看和编辑zabbix_server配置文件,启动zabbix_server进程

[root@nginx ~]# ln -sv /usr/local/zabbix/etc/ /usr/local/etc/                   #链接zabbix server及agentd配置文件
`/usr/local/etc/etc' -> `/usr/local/zabbix/etc/'[root@nginx ~]# cp /root/download/zabbix-3.4.14/misc/init.d/fedora/core/zabbix_server /etc/init.d/zabbix_server     

#拷贝zabbix server启动脚本

[root@nginx ~]# mkdir /var/run/zabbix/
[root@nginx ~]# mkdir /var/lock/zabbix/
[root@nginx ~]# chown zabbix.zabbix /var/run/zabbix/                    #为zabbix pid文件目录设置zabbix用户读写权限
[root@nginx ~]# chown zabbix.zabbix /var/lock/zabbix/                   #为zabbix sock文件目录设置zabbix用户读写权限

[root@nginx ~]# mkdir /var/log/zabbix/
[root@nginx ~]# chown zabbix.zabbix /var/log/zabbix/                    #为zabbix log文件目录设置zabbix用户读写权限

# 调整zabbix_server 配置文件

[root@nginx ~]# cp /usr/local/zabbix/etc/zabbix_server.conf /usr/local/zabbix/etc/zabbix_server.conf.bak
[root@nginx ~]# echo > /usr/local/zabbix/etc/zabbix_server.conf
[root@nginx ~]# vim /usr/local/zabbix/etc/zabbix_server.conf

DBName=zabbix              #指定数据库名称zabbix
DBUser=zabbix                #指定访问数据库的用户名zabbix
Timeout=4                   #指定等待代理、SNMP设备或外部检查的时间(秒)
LogSlowQueries=3000            #记录数据库查询可能需要多长时间(以毫秒为单位)。
ListenPort=10051                                                 #启动zabbix_server监听端口
LogFile=/var/log/zabbix/zabbix_server.log         
LogFileSize=1024
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/lock/zabbix
DBHost=locahost              #指定DBhost主机
DBPassword=111
DBSocket=/var/lock/mysql/msyql.sock
DBPort=2206

#调整zabbix_server启动脚本

[root@nginx ~]# vim /etc/init.d/zabbix_server
#!/bin/bash
#
# chkconfig: - 90 10
# description: Starts and stops Zabbix Server using chkconfig
# Tested on Fedora Core 2 - 5
# Should work on all Fedora Core versions
#
# @name: zabbix_server
# @author: Alexander Hagenah <hagenah@topconcepts.com>
# @created: 18.04.2006
#
# Modified for Zabbix 2.0.0
# May 2012, Zabbix SIA
#
# Source function library.
. /etc/init.d/functions

# Variables
# Edit these to match your system settings

# Zabbix-Directory
BASEDIR=/usr/local/zabbix                              # 调整zabbix安装路径

# Binary File
BINARY_NAME=zabbix_server

# Full Binary File Call
FULLPATH=$BASEDIR/sbin/$BINARY_NAME

# PID file                
PIDFILE=/var/run/zabbix/$BINARY_NAME.pid          # 调整zabbix_server启动pid文件

# Establish args
ERROR=0
STOPPING=0

#将服务加入开机自启,启动zabbix_server

[root@nginx ~]# chkconfig --add zabbix_server
[root@nginx ~]# chkconfig zabbix_server on
[root@nginx ~]# service zabbix_server start
Starting zabbix_server: [ OK ]

 

查看和编辑zabbix_agentd配置文件,启动zabbix_agentd进程

[root@nginx ~]# cp /usr/local/zabbix/etc/zabbix_agentd.conf /usr/local/zabbix/etc/zabbix_agentd.conf.bak
[root@nginx ~]#
[root@nginx ~]# echo > /usr/local/zabbix/etc/zabbix_agentd.conf

[root@nginx ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
LogFile=/var/log/zabbix/zabbix_agentd.log
PidFile=/var/run/zabbix/zabbix_agentd.pid
Server=192.168.10.18
ListenPort=10050
ServerActive=127.0.0.1
Hostname=Zabbix server

[root@nginx ~]# vim /etc/init.d/zabbix_agentd
#!/bin/bash
#
# chkconfig: - 90 10
# description: Starts and stops Zabbix Agent using chkconfig
# Tested on Fedora Core 2 - 5
# Should work on all Fedora Core versions
#
# @name: zabbix_agentd
# @author: Alexander Hagenah <hagenah@topconcepts.com>
# @created: 18.04.2006
#
# Modified for Zabbix 2.0.0
# May 2012, Zabbix SIA
#
# Source function library.
. /etc/init.d/functions

# Variables
# Edit these to match your system settings

# Zabbix-Directory
BASEDIR=/usr/local/zabbix

# Binary File
BINARY_NAME=zabbix_agentd

# Full Binary File Call
FULLPATH=$BASEDIR/sbin/$BINARY_NAME

# PID file
PIDFILE=/var/run/zabbix/$BINARY_NAME.pid

# Establish args
ERROR=0
STOPPING=0

#

[root@nginx ~]# chkconfig zabbix_agentd on
[root@nginx ~]# chkconfig --add zabbix_agentd
[root@nginx ~]# service zabbix_agentd start
Starting zabbix_agentd: [ OK ]
[root@nginx ~]#

安装zabbix web界面

复制php文件

# 把zabbix web主页拷贝到nginx html目录

[root@zabbix zabbix]# cp /root/download/zabbix-3.4.14/frontends/php     /usr/local/nginx/html/zabbix -af

[root@zabbix zabbix]# service nginx restart                     # 重启nginx服务

Stopping nginx: [ OK ]

Starting nginx: [ OK ]

 

 通过web页面对zabbix进行配置

 

posted @ 2019-10-09 15:58  Justtosee  阅读(437)  评论(0编辑  收藏  举报