监控服务zabbix部署
zabbix简介:
zabbix([`zæbiks])是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
zabbix由2部分构成,zabbix server与可选组件zabbix agent。
zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。
使用:
zabbix agent需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。zabbix agent可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD, OS X, Tru64/OSF1, Windows NT4.0, Windows (2000/2003/XP/Vista)等系统之上。
zabbix server可以单独监视远程服务器的服务状态;同时也可以与zabbix agent配合,可以轮询zabbix agent主动接收监视数据(agent方式),同时还可被动接收zabbix agent发送的数据(trapping方式)。
另外zabbix server还支持SNMP (v1,v2),可以与SNMP软件(例如:net-snmp)等配合使用。
zabbix 服务器安装
//安装依赖包
[root@localhost ~]# yum -y install net-snmp-devel libevent-devel
//解压
[root@localhost ~]# tar xf zabbix-5.2.0.tar.gz //解压
//创建账户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin zabbix
[root@localhost ~]# id zabbix
uid=990(zabbix) gid=988(zabbix) groups=988(zabbix)
//配置zabbix数据库
创建数据库
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
//授权
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix123';
Query OK, 0 rows affected, 2 warnings (0.00 sec)
//刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)
[root@localhost zabbix-5.2.0]# cd database/
[root@localhost database]# ls
elasticsearch Makefile.in oracle sqlite3
Makefile.am mysql postgresql
[root@localhost database]# cd mysql/
[root@localhost mysql]# pwd
/root/zabbix-5.2.0/database/mysql
[root@localhost mysql]# ll
total 10232
-rw-r--r-- 1 1000 1000 8308118 Oct 26 23:44 data.sql
-rw-r--r-- 1 1000 1000 282 Oct 26 19:18 double.sql
-rw-r--r-- 1 1000 1000 1978341 May 11 01:36 images.sql
-rw-r--r-- 1 1000 1000 482 Oct 26 19:18 Makefile.am
-rw-r--r-- 1 1000 1000 15982 Oct 26 23:44 Makefile.in
-rw-r--r-- 1 1000 1000 160579 Oct 26 23:44 schema.sql
[root@localhost mysql]#
[root@localhost mysql]# mysql -uzabbix -p'zabbix123' zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -p'zabbix123' zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -p'zabbix123' zabbix <data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost zabbix-5.2.0] ./configure --enable-server \
--enable-agent \
--with-mysql \
--with-net-snmp \
--with-libcurl \
--with-libxml2
make install
zabbix服务端配置
[root@localhost ~]# cd /usr/local/etc/
[root@localhost etc]# ls
zabbix_agentd.conf zabbix_server.conf
zabbix_agentd.conf.d zabbix_server.conf.d
//修改服务端配置文件
//设置数据库信息
[root@localhost etc]# vim zabbix_server.conf
DBPassword=zabbix123 //设置zabbix数据库连接密码
//启动zabbix_server和zabbix_agentd
[root@localhost etc]# zabbix_server
[root@localhost etc]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@localhost etc]#
[root@localhost ~]# mkdir /var/lib/mysql
[root@localhost ~]# ll /var/lib/mysql/ -d
drwxr-xr-x 2 root root 6 Nov 4 00:03 /var/lib/mysql/
//改权限
[root@localhost ~]# chown -R mysql.mysql /var/lib/mysql
[root@localhost ~]# zabbix_agentd
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
zabbix服务端web界面安装与配置
zabbix web界面安装前配置
[root@localhost zabbix-5.2.0]# mkdir /usr/local/apache/htdocs/zabbix
[root@localhost zabbix-5.2.0]# cp -a ui/* /usr/local/apache/htdocs/zabbix/
[root@localhost ~]# chown -R apache.apache /usr/local/apache/htdocs/
[root@localhost ~]# ll /usr/local/apache/htdocs/
total 12
-rw-r--r--. 1 apache apache 45 Jun 12 2007 index.html
-rw-r--r--. 1 apache apache 24 Oct 29 19:04 index.php
drwxr-xr-x 12 apache apache 4096 Nov 4 00:15 zabbix
//配置apache虚拟主机
[root@localhost ~]# vim /etc/httpd24/extra/httpd-vhosts.conf
//在配置文件的末尾加如下内容
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/zabbix"
ServerName zabbix.example.com
ErrorLog "logs/www.example.com-error_log"
CustomLog "logs/www.example.com-access_log" common
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix
<Directory "/usr/local/apache/htdocs/zabbix">
Require all granted
</Directory>
</VirtualHost>
//修改/etc/php.ini的配置并重启php-fpm
[root@localhost ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@localhost ~]#
//重启
[root@localhost ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@localhost ~]#
[root@localhost ~]# ll /usr/local/apache/htdocs/zabbix/conf -d
drwxr-xr-x 3 apache apache 94 Oct 26 23:44 /usr/local/apache/htdocs/zabbix/conf
[root@localhost ~]# chmod 777 /usr/local/apache/htdocs/zabbix/conf
[root@localhost ~]# chmod 755 /usr/local/apache/htdocs/zabbix/conf
[root@localhost ~]# ll /usr/local/apache/htdocs/zabbix/conf -d
drwxr-xr-x 3 apache apache 117 Nov 4 00:45 /usr/local/apache/htdocs/zabbix/conf
[root@localhost ~]#
在浏览器上访问域名进行安装