码迷,mamicode.com
首页 > 其他好文 > 详细

Zabbix

时间:2019-04-19 11:46:16      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:start   debug   4.0   my.cnf   mysqld   schema   level   输入   src   

技术图片
技术图片
Zabbix官网:https://www.zabbix.com/cn/download
阿里云镜像站:https://mirrors.aliyun.com/zabbix/zabbix/4.0.rhel/7/x86_64/
agent客户端:yum install https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.6-1.el7.x86_64.rpm -y
使用阿里云镜像yum安装Zabbix:1、yum install https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm -y
准备环境:172.18.9.150:zabbix-server、172.18.9.201:zabbix-mysql、
rpm包安装步骤:先选择4.0LTS版本的源码包:
技术图片
一、在172.18.9.150:server主机:
1、安装数据库:yum install https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm -y
2、安装Zabbix server,web前端,agent :yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
3、创建数据库:在172.18.9.201主机:安装mysql:
1】、[root@201 src]#ls
my.cnf mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz mysql-install.sh
[root@201 src]#vim mysql-install.sh
#!/bin/bash
DIR=pwd
NAME="mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz"
FULL_NAME=${DIR}/${NAME}
DATA_DIR="/data/mysql"
yum install vim gcc gcc-c++ wget autoconf net-tools lrzsz iotop lsof iotop bash-completion -y
yum install curl policycoreutils openssh-server openssh-clients postfix -y
if [ -f ${FULL_NAME} ];then
echo "安装文件存在"
else
echo "安装文件不存在"
exit 3
fi
if [ -h /usr/local/mysql ];then
echo "Mysql 已经安装"
exit 3
else
tar xvf ${FULL_NAME} -C /usr/local/src
ln -sv /usr/local/src/mysql-5.6.43-linux-glibc2.12-x86_64 /usr/local/mysql
if id mysql;then
echo "mysql 用户已经存在,跳过创建用户过程"
fi
useradd mysql -s /sbin/nologin
if id mysql;then
chown -R mysql.mysql /usr/local/mysql/* -R
if [ ! -d /data/mysql ];then
mkdir -pv /data/mysql /var/lib/mysql && chown -R mysql.mysql /data -R
/usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql/
cp /usr/local/src/mysql-5.6.43-linux-glibc2.12-x86_64/support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
cp ${DIR}/my.cnf /etc/my.cnf
ln -sv /usr/local/mysql/bin/mysql /usr/bin/mysql
ln -sv /data/mysql/mysql.sock /var/lib/mysql/mysql.sock #此连接便于在server主机的/etc/zabbix/zabbix_server.conf文件中的“DBSocket=”使用。
/etc/init.d/mysqld start
else
echo "MySQL数据目录已经存在,"
exit 3
fi
fi
fi
[root@201 src]#vim my.cnf
[mysqld]
socket=/data/mysql/mysql.sock
user=mysql
symbolic-links=0
datadir=/data/mysql
innodb_file_per_table=1
max_connections=10000 #该值务必调大,

[client]
port=3306
socket=/var/lib/mysql/mysql.sock

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/tmp/mysql.sock

2】、[root@201 src]#bash my.cnf #安装mysql
[root@201 src]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::3306 :::*

4、mysql数据库做授权:
[root@201 src]#mysql
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.01 sec)
mysql> grant all privileges on zabbix.* to zabbix@"172.18.%.%" identified by ‘12345‘ ;
Query OK, 0 rows affected (0.01 sec)

5、在150server主机远程连接mysql数据库:
[root@150 ~]#mysql -uzabbix -h172.18.9.201 -p"<123gxy>"; #注意:此时-p中的<123gxy>才是密码。
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.6.43 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
| zabbix | # zabbix用户已被成功创建!!
+--------------------+
3 rows in set (0.01 sec)

6、[root@150 zabbix]#vim zabbix_server.conf
ListenPort=10051
DebugLevel=3
DBHost=172.18.9.201
DBName=zabbix
DBUser=zabbix
DBPassword=123gxy
HistoryCacheSize=16M
HistoryIndexCacheSize=4M
CacheSize=8M
Timeout=30 #默认是4s,建议设置最长时长30s。

7、开启zabbix-server,并查看端口,但是无端口:因为数据库没有初始化。

8、该步骤为准备工作,按此顺序执行操作,我们在开头就已安装好了,所以不做展示:
[root@150 zabbix]#yum install yum-utils
[root@150 zabbix]#yum-config-manager --enable rhel-7-server-optional-rpms
Loaded plugins: fastestmirror, langpacks #开启数据库!
[root@150 yum.repos.d]#yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent

9、创建数据库:
1】、先查看201主机的zabbix数据库为空:
[root@201 ~]#mysql
mysql> use zabbix;
Database changed
mysql> show tables;
Empty set (0.00 sec)
2】、将数据导入mysql数据库:
[root@150 ~]#zcat /usr/share/doc/zabbix-server-mysql-4.0.6/create.sql.gz |mysql -uzabbix -h172.18.9.201 -p"<123gxy>" zabbix #注意:库名、密码错误均失败。
3】、此时在201数据库主机的mysql> show tables;中,已导入数据:
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
+----------------------------+
144 rows in set (0.03 sec)
4】、[root@150 src]#systemctl restart httpd zabbix-server zabbix-agent
[root@150 src]#ss -ntl #此时,10051端口已开启!
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :10051 :*
注意:(我在此处遇到了zabbix密码输入错误,150主机给zabbix用户grant授权问题,)
此时,访问页面:
技术图片
10、[root@150 zabbix]#vim /etc/php.ini
date.timezone =Aisa/shanghai
[root@150 conf.d]#vim /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai #注意,此处的php.ini与zabbix.conf文件的date.timezone 都需要更改才行。

11、[root@150 conf.d]#systemctl restart zabbix-server httpd zabbix-agent 并访问zabbix页面:
技术图片
技术图片
我们在网页配置好的zabbix的信息如下:
技术图片
技术图片
12、各配置均完成后,点击登录,会出现如下界面:
技术图片
13、设置开机自启zabbix-agent;并访问页面:
[root@150 conf.d]#systemctl restart zabbix-agent
[root@150 conf.d]#systemctl enable zabbix-agent
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
技术图片
14、在150server主机上安装上zabbix-agent包。150主机的“/etc/zabbix/zabbix_agentd.conf”中:Hostname=Zabbix server,此时去172.18.9.150/zabbix/php 官网网页进行配置即可。

如何监控其他主机:
1】、在201mysql主机安装上zabbix-agent包其中的“/etc/zabbix/zabbix_agentd.conf”中:Hostname=172.18.9.201 #用IP地址来做区分。
技术图片
15、修改该文件,内容如下:
[root@201 ~]#grep -v "#" /etc/zabbix/zabbix_agentd.conf|grep -v "^$"
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=172.18.9.150
ServerActive=127.0.0.1
Hostname=172.18.9.201
Include=/etc/zabbix/zabbix_agentd.d/*.conf

[root@201 ~]#systemctl restart zabbix-agent
[root@201 ~]#systemctl enable zabbix-agent
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
16、访问网页:#此时150mysql数据库主机的监控已实现连接:
技术图片
为了方便在网页页面查看,我们将字体改为中文:
先在电脑的控制面板上选择一款字体,
在150server主机:[root@150 ~]#cd /usr/share/zabbix/fonts
[root@150 fonts]#ll
total 10332
lrwxrwxrwx. 1 root root 33 Apr 15 22:33 graphfont.ttf -> /etc/alternatives/zabbix-web-font
-rw-r--r--. 1 root root 10578152 Aug 9 2018 simfang.ttf
[root@150 zabbix]#vim include/defines.inc.php
把该文件中的graphfont改为simfang。
load averge:
技术图片

zabbix的主动与被动模式:

技术图片
一、创建主动模式的数据库:在201mysql主机:
mysql> create database zabbix_proxy_active character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.01 sec)
mysql> grant all privileges on zabbix_proxy_active.* to zabbix_active@"172.18.%.%" identified by ‘123456‘;
Query OK, 0 rows affected (0.05 sec)

二、将源码包上传至家目录:主/被模式都是同一个包
[root@200 ~]#ls zabbix-proxy-mysql-4.0.6-1.el7.x86_64.rpm
[root@200 ~]#yum install zabbix-proxy-mysql-4.0.6-1.el7.x86_64.rpm
技术图片
在201mysql主机:创建被动模式:
mysql> create database zabbix_proxy_passive character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.01 sec)
mysql> grant all privileges on zabbix_proxy_passive.* to zabbix_passive@"172.18.%.%" identified by ‘123456‘;
Query OK, 0 rows affected (0.00 sec)

三、配置该文件:[root@200 ~]#grep -v "#" /etc/zabbix/zabbix_proxy.conf |grep -v "^$"
ProxyMode=0
Server=172.18.9.150
ServerPort=10051
Hostname=huayi_proxy_active
ListenPort=10051
LogFile=/var/log/zabbix/zabbix_proxy.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_proxy.pid
SocketDir=/var/run/zabbix
DBHost=172.18.9.201
DBName= zabbix_proxy_active
DBUser=zabbix_active
DBPassword=123456
ProxyLocalBuffer=720
ProxyOfflineBuffer=720
HeartbeatFrequency=60
ConfigFrequency=60
DataSenderFrequency=5
StartPollers=20
JavaGateway=172.18.9.150
StartJavaPollers=10
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
CacheSize=16M
HistoryCacheSize=16M
Timeout=30
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000

四、查看200主机的初始化脚本在何方:
[root@200 ~]#rpm -qpl zabbix-proxy-mysql-4.0.6-1.el7.x86_64.rpm
/usr/share/doc/zabbix-proxy-mysql-4.0.6/schema.sql.gz #该包即是初始化脚本

五、这时,我们要安装mysql,通过mysql命令来把脚本执行:
[root@200 ~]#yum install -y mysql
[root@200 ~]#mysql -uzabbix_active -h172.18.9.201 -p123456 #在zabbix_active:200主机上远程连接201mysql数据库:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 251
Server version: 5.6.43 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MySQL [(none)]> show databases;
+---------------------+
| Database |
+---------------------+
| information_schema |
| test |
| zabbix_proxy_active |
+---------------------+
3 rows in set (0.00 sec)

六、把该sql.gz脚本传给mysql,并做初始化:
[root@200 ~]#zcat /usr/share/doc/zabbix-proxy-mysql-4.0.6/schema.sql.gz |mysql -uzabbix_active -h172.18.9.201 -p123456 zabbix_proxy_active

七、在201mysql数据库主机查询:
mysql> use zabbix_proxy_active
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> show tables;
+-------------------------------+
| Tables_in_zabbix_proxy_active |
+-------------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
| applications |
| auditlog |
| auditlog_details |
| autoreg_host |
+-------------------------------+
144 rows in set (0.00 sec) #此时,mysql数据库已经同步导入了paroxy_active的数据了!!

八、[root@150 src]#vim /etc/zabbix/zabbix_agentd.conf
ServerActive=172.18.9.200 该IP要指向proxy的地址,不能指向server的IP。

九、在200zabbix-proxy主机开启该proxy应用:
[root@200 ~]#systemctl start zabbix-proxy
[root@200 ~]#systemctl enable zabbix-proxy
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-proxy.service to /usr/lib/systemd/system/zabbix-proxy.service.
监控页面出现此页面就是proxy的主动模式成功开启了!
技术图片

至此,zabbix主动模式proxy已经实现!!

Zabbix

标签:start   debug   4.0   my.cnf   mysqld   schema   level   输入   src   

原文地址:https://blog.51cto.com/14128387/2381114

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!