运维yum搭建zabbix

前言:
           zabbix([`zæbiks])是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
           zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
           zabbix由2部分构成,zabbix server与可选组件zabbix agent。
           zabbix server可以单独监视远程服务器的服务状态;同时也可以与zabbix agent配合,可以轮询zabbix agent主动接收监视数据(agent方式),同时还可被动接收zabbix agent发送的数据(trapping方式)。
           zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。

 

一、搭建环境:
1、系统:CentOS7

 

注:如果使用yum过程中出现“yum Cannot find a valid baseurl for repo: base/7/x86_64”问题,请参考:https://blog.csdn.net/weixin_37973929/article/details/85317619 解决

 

如果出现:“Another app is currently holding the yum lock; waiting for it to exit...”问题,请参考:https://blog.csdn.net/weixin_37973929/article/details/85246422 解决

 

二、准备工作:
1、关闭SELinux!开启selinux会引起一连串问题,甚至zabbix的discovery功能也不能正常使用。

1.1、关闭SELinux方法:修改 /etc/selinux/config 文件

SELINUX分为临时关闭,和永久关闭。临时关闭后重启失效,我们这里使用永久关闭

[root@localhost ~]# vim /etc/selinux/config

在文件中可以看到这一行

SELINUX=enforcing

把后面的参数修改为disabled

SELinux=disabled


-------------------------分割线,下面是两种关闭方法-------------------------

临时关闭:

[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive



永久关闭(修改文件):

[root@localhost ~]# vim /etc/sysconfig/selinux

SELINUX=enforcing 改为 SELINUX=disabled

重启服务reboot
2、关闭防火墙

防火墙也为测试方便,我就给关闭了,并不随开机启动。
[root@localhost ~]#systemctl stop firewalld

[root@localhost ~]systemctl disable firewalld.service


防火墙相关命令:

(1)设置开机启用防火墙:systemctl enable firewalld.service

(2)设置开机禁用防火墙:systemctl disable firewalld.service

(3)启动防火墙:systemctl start firewalld

(4)关闭防火墙:systemctl stop firewalld

(5)检查防火墙状态:systemctl status firewalld
 

 

三、部署过程
1、安装MariaDB数据库(注:MariaDB就是Mysql)

安装mysql数据库
yum -y install mariadb-server mariadb-devel


开启mysql数据库
systemctl start mariadb.service

查看mysql数据库是否启动
ps aux | grep mysqld
1.1、配置数据库

//进入数据库
[root@localhost ~]# mysql


Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.52-MariaDB MariaDB Server

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

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


//创建一个zabbix库
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)


//创建一个zabbix用户 密码为123456
MariaDB [(none)]> grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)


//刷新表权限
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)


//退出
MariaDB [(none)]> exit
Bye
 

2、安装zabbix

2.1、获取并安装zabbix的yum源:

[root@localhost ~]#wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm

[root@localhost ~]#rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
2.2、生成yum源快照,这样可以直接用tab键来补全安装:

yum makecache
2.3、查看文件:

[root@localhost ~]# yum search zabbix
输出内容解读,可忽略直接跳到2.4

输出:

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
==================================================================== N/S matched: zabbix ====================================================================
pcp-export-pcp2zabbix.x86_64 : Performance Co-Pilot tools for exporting PCP metrics to Zabbix
pcp-export-zabbix-agent.x86_64 : Module for exporting PCP metrics to Zabbix agent
zabbix-agent.x86_64 : Zabbix Agent
zabbix-get.x86_64 : Zabbix Get
zabbix-java-gateway.x86_64 : Zabbix java gateway
zabbix-proxy-mysql.x86_64 : Zabbix proxy for MySQL or MariaDB database
zabbix-proxy-pgsql.x86_64 : Zabbix proxy for PostgreSQL database
zabbix-proxy-sqlite3.x86_64 : Zabbix proxy for SQLite3 database
zabbix-release.noarch : Zabbix repository configuration
zabbix-sender.x86_64 : Zabbix Sender
zabbix-server-mysql.x86_64 : Zabbix server for MySQL or MariaDB database
zabbix-server-pgsql.x86_64 : Zabbix server for PostgresSQL database
zabbix-web.noarch : Zabbix web frontend common package
zabbix-web-mysql.noarch : Zabbix web frontend for MySQL
zabbix-web-pgsql.noarch : Zabbix web frontend for PostgreSQL
zabbix-web-japanese.noarch : Japanese font settings for frontend

Name and summary matches only, use "search all" for everything.
解读:

解读:

zabbix-agent.:zabbix客户端,用来收集客户端各种参数
zabbix-get:zabbix的一个工具,用来检查是否可以获取服务器信息(一般服务端要安装)
zabbix-java-gateway:用于监控JMX应用的程序,它把收集到的信息发送个(这个看需求安装,我暂时没装)
zabbix-proxy:zabbix proxy可以代替zabbix server检索客户端的数据,然后把数据汇报给zabbix server,并且在一定程度上分担了zabbix server的压力。zabbix proxy可以非常简便的实现了集中式、分布式监控。
zabbix-release:会生成一个zabbix的yum源,可以直接下载相关软件包。
zabbix-sender:用于发送数据给server或者proxy。
zabbix-web:zabbix要使用web界面,这个包是用来处理Apache和php,mysql等之间的依赖关系。
zabbix-web-mysql:这个是zabbix前段支持mysql的
zabbix-web-japanese:支持日语
 

2.4、选择自己需要的安装包进行安装,我只选了几个需要的:

[root@localhost ~]#yum install zabbix-get zabbix-sender zabbix-server-mysql zabbix-web zabbix-web-mysql zabbix-agent
 

2.5、生成查找快照

[root@localhost ~]# updatedb
2.6、查找create.sql文件位置

[root@localhost ~]# locate create.sql

输出:
/usr/share/doc/zabbix-server-mysql-3.2.11/create.sql.gz
/usr/share/pgsql/conversion_create.sql
/usr/share/pgsql/snowball_create.sql
2.7、切换到zabbix-server目录

[root@localhost ~]# cd /usr/share/doc/zabbix-server-mysql-3.2.11/
2.8、查看目录下文件详细信息

[root@localhost zabbix-server-mysql-3.2.4]# ll

输出:

total 1936
-rw-r--r--. 1 root root 98 Dec 27 2017 AUTHORS
-rw-r--r--. 1 root root 783414 Dec 27 2017 ChangeLog
-rw-r--r--. 1 root root 17990 Dec 27 2017 COPYING
-rw-r--r--. 1 root root 1161488 Dec 27 2017 create.sql.gz
-rw-r--r--. 1 root root 52 Dec 27 2017 NEWS
-rw-r--r--. 1 root root 188 Dec 27 2017 README
2.9、解压create.sql.gz这个文件:

[root@localhost zabbix-server-mysql-3.2.11]# gunzip create.sql.gz
3.0、把这个create.sql导入到数据库中,时间可能稍微有些长,多等一会:

[root@localhost zabbix-server-mysql-3.2.11]# mysql -uzabbix -p zabbix < create.sql

注:需要输入密码,我们上边mysql的zabbix账户密码是“123456”
3.1、查找这个mysql.sock文件路径,记下来,一会要用到:

[root@localhost zabbix-server-mysql-3.2.11]# locate mysql.sock

输出:
/var/lib/mysql/mysql.sock
3.2、修改zabbix_server_conf这个配置文件:

编辑 /etc/zabbix/zabbix_server.conf文件
[root@localhost zabbix-server-mysql-3.2.11]# vim /etc/zabbix/zabbix_server.conf

修改以下两部分内容:

# DBPassword=
在下面再写一行
DBPassword=123456


再找到这行:
# DBSocket=/tmp/mysql.sock
在下面再写一行
DBSocket=/var/lib/mysql/mysql.sock


------------------------注释------------------------

这个密码是你DariaDB里面之前设置zabbix用户的密码,可以根据自己喜好改。

这个路径就是上面locate mysql.scok找到的那个路径
验证一下修改参数是否和我的一样:

使用命令:

[root@localhost zabbix-server-mysql-3.2.11]# egrep -vn "^#|^$" /etc/zabbix/zabbix_server.conf
验证内容:

38:LogFile=/var/log/zabbix/zabbix_server.log
49:LogFileSize=0
72:PidFile=/var/run/zabbix/zabbix_server.pid
91:DBName=zabbix
107:DBUser=zabbix
116:DBPassword=123456
124:DBSocket=/var/lib/mysql/mysql.sock
289:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
415:Timeout=4
457:AlertScriptsPath=/usr/lib/zabbix/alertscripts
467:ExternalScripts=/usr/lib/zabbix/externalscripts
503:LogSlowQueries=3000
3.3、修改/etc/httpd/conf.d/zabbix.conf文件,把时区修改如下:

    <IfModule mod_php5.c>
        php_value max_execution_time 300
        php_value memory_limit 128M
        php_value post_max_size 16M
        php_value upload_max_filesize 2M
        php_value max_input_time 300
        php_value always_populate_raw_post_data -1
        php_value date.timezone Asia/Shanghai                                //改为亚洲/上海
    </IfModule>


3.4、开启一些列服务,包括Apache、Mariadb、zabbix-server、zabbix-agent

[root@localhost zabbix-server-mysql-3.2.11]# systemctl start httpd.service
[root@localhost zabbix-server-mysql-3.2.11]# systemctl start mariadb
[root@localhost zabbix-server-mysql-3.2.11]# systemctl start zabbix-server
[root@localhost zabbix-server-mysql-3.2.11]# systemctl start zabbix-agent
3.5、下面把上面4个服务设置成开机启动:

[root@localhost zabbix-server-mysql-3.2.11]# systemctl enable httpd
输出:
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

[root@localhost zabbix-server-mysql-3.2.11]# systemctl enable mariadb
输出:
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

[root@localhost zabbix-server-mysql-3.2.11]# systemctl enable zabbix-server
输出:
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.servic.

[root@localhost zabbix-server-mysql-3.2.11]# systemctl enable zabbix-agent
输出:
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.servic


四、web页面安装zabbix

1、查看ip,直接用浏览器来安装zabbix

http://本机IP/zabbix
 

2、根据截图安装

 

查看是否全是OK,如果是,直接Next step,如果不是,缺什么装什么,什么没改改什么。

 

默认账号“Admin” 默认密码“zabbix”

 

 

点击箭头所指的人形按钮,调整语言为中文。

 

 

至此zabbix的service端已经安装好了,下一篇我们来部署安装客户端的agent。

 

posted @ 2019-04-29 11:04  三冬三夏  阅读(255)  评论(0编辑  收藏  举报