Linux之企业实训篇——布置zabbix监控及添加监控服务项(一)

一、zabbix简介

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

二、实验环境

  • server1 :172.25.2.1/24
    • 版本号: redhat7.3,配置zabbix-server
  • server6: 172.25.2.6/24
    • 版本号: redhat6.5,配置zabbix-agent

三、实验

(1)配置zabbix-server

1.1安装软件

 //安装的时候一定要注意选择安装的版本与系统相匹配。
[root@server1 ~]# yum install fping-3.10-1.el7.x86_64.rpm  php-bcmath-5.4.16-42.el7.x86_64.rpm 
php-mbstring-5.4.16-42.el7.x86_64.rpm 
iksemel-1.4-2.el7.centos.x86_64.rpm 
zabbix-server-mysql-3.4.6-1.el7.x86_64.rpm 
zabbix-web-3.4.6-1.el7.noarch.rpm
zabbix-web-mysql-3.4.6-1.el7.noarch.rpm
 -y
[root@server1 ~]# yum install mariadb-server -y //安装数据库
[root@server1 ~]# systemctl start mariadb  //开启服务

1.2初始化数据库


[root@server1 ~]# mysql_secure_installation  //安全证书设置

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

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

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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
 ... Success!

By default, MariaDB 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] 
 - 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] 
 ... Success!

Cleaning up...

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

Thanks for using MariaDB!

1.3 创建zabbix组及用户

[root@server1 ~]# mysql -p
Enter password: 
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin; //创建
Query OK, 1 row affected (0.01 sec)

MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'westos';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit
Bye

1.4导入数据库

[root@server1 ~]# cd /usr/share/doc/zabbix-server-mysql-3.4.6/
[root@server1 zabbix-server-mysql-3.4.6]# ls
AUTHORS  ChangeLog  COPYING  create.sql.gz  NEWS  README
[root@server1 zabbix-server-mysql-3.4.6]# zcat create.sql.gz | mysql -u zabbix -p zabbix
Enter password:  //输入授权用户zabbix的密码

1.5配置修改

[root@server1 zabbix-server-mysql-3.4.6]# cd /etc/zabbix
[root@server1 zabbix]# vim zabbix_server.conf 
//修改内容 
125         DBPassword=westos   //密码
132         DBSocket=/var/lib/mysql/mysql.sock //数据库链接

[root@server1 zabbix]# yum install httpd  
[root@server1 zabbix]# vim /etc/httpd/conf.d/zabbix.conf 
//修改内容
19         php_value date.timezone Asia/Shanghai //时区
[root@server1 zabbix]# systemctl start zabbix-server  //开启服务
[root@server1 zabbix]# systemctl start httpd

1.6 安装zabbix-angent监控本机

[root@server1 zabbix]# cd
[root@server1 ~]# yum install zabbix-agent-3.4.6-1.el7.x86_64.rpm -y
[root@server1 ~]# systemctl start zabbix-agent

1.7 浏览器访问

这里写图片描述
这里写图片描述
//数据库默认监听3306端口
这里写图片描述
//zabbix-server为10051端口
这里写图片描述
//初始用户为Admin,密码为zabbix
这里写图片描述
//点击右上角人头,修改语言与密码,重新登陆
这里写图片描述
//监控主页
这里写图片描述

(2)配置zabbix-agent

[root@server6 ~]# rpm -ivh zabbix-agent-3.4.6-1.el6.x86_64.rpm 
warning: zabbix-agent-3.4.6-1.el6.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing...                ########################################### [100%]
   1:zabbix-agent           ########################################### [100%]
[root@server6~]# cd /etc/zabbix/
[root@server6 zabbix]# vim zabbix_agentd.conf 
//修改内容
 97 Server=172.25.2.1  //zabbix-server的ip
138 ServerActive=172.25.2.1
149 Hostname=server6 //本机名称,一定要在本机解析
[root@server6 zabbix]# /etc/init.d/zabbix-agent start //开启服务
[root@server6 zabbix]# netstat -antlp
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      2110/zabbix_agentd  

(3)添加agent

方法一:自动发现

//动作->事件源:自动发现 状态:->启用
这里写图片描述
//自动发现,点击Local network添加网段
这里写图片描述
//点击启用
这里写图片描述
//过一会会检测出来
这里写图片描述

方法二:创建主机

1.先关闭自动发现,再关闭动作,全为停用,删掉之前发现的server6
点击创建主机
这里写图片描述
主机名称为客户端主机名称,群组,ip
这里写图片描述
选择添加模版
这里写图片描述
点击下面的小添加,将模版添加上去
这里写图片描述
点击添加,即成功
这里写图片描述
重新加载:变成可用
这里写图片描述

方法三:自动注册

1.删除刚刚添加的server6
动作–>选择自动注册–>点击创建动作
这里写图片描述
添加名称:
这里写图片描述
操作–>点击新的
这里写图片描述
添加主机、添加到主机群组选择linux servers、连接到模版选择Template OS linux这里写图片描述
点击启用
这里写图片描述
等一会即可看见自动添加进去
这里写图片描述

方式四:api的添加与删除

1.api删除

[root@server1 ~]# vim zabbix-api.sh 
curl -s -X POST -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {
        "user": "Admin",
        "password": "westos"
    },
    "id": 1,
    "auth": null
}' http://172.25.2.1/zabbix/api_jsonrpc.php | python -m json.tool

[root@server1 ~]# chmod +x ./zabbix-api.sh   //添加可执行权限
[root@server1 ~]# ./zabbix-api.sh   //运行脚本
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": "3b31002c01ecc1bf9164c67eb17f5e14"
}

[root@server1 ~]# vim zabbix-api.sh
curl -s -X POST -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["host"] //修改parms模块
    },
    "auth": "3b31002c01ecc1bf9164c67eb17f5e14",
    "id": 1
}' http://172.25.2.1/zabbix/api_jsonrpc.php | python -m json.tool
[root@server1 ~]# ./zabbix-api.sh  //运行脚本
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": [
        {
            "host": "Zabbix server",
            "hostid": "10084"
        },
        {
            "host": "server6",
            "hostid": "10261"
        }
    ]
}

[root@server1 ~]# vim zabbix-api.sh  //修改
curl -s -X POST -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "host.delete",
    "params": [
        "10261"
    ],
    "auth": "3b31002c01ecc1bf9164c67eb17f5e14",
    "id": 1
}' http://172.25.2.1/zabbix/api_jsonrpc.php | python -m json.tool
[root@server1 ~]# ./zabbix-api.sh 
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10261"
        ]
    }
}

刷新浏览器,刚才添加的已经删除:
这里写图片描述

1.api添加

[root@server1 ~]# vim zabbix-api.sh 
curl -s -X POST -H 'Content-Type:application/json' -d '
{
    "jsonrpc": "2.0",
    "method": "host.create",
    "params": {
        "host": "server6",
        "interfaces": [
            {
                "type": 1,
                "main": 1,
                "useip": 1,
                "ip": "172.25.2.1",
                "dns": "",
                "port": "10050"
            }
        ],
        "groups": [
            {
                "groupid": "2"
            }
        ],
        "templates": [
            {
                "templateid": "10001"
            }
        ]
    },
    "auth": "3b31002c01ecc1bf9164c67eb17f5e14",
    "id": 1
}' http://172.25.2.1/zabbix/api_jsonrpc.php | python -m json.tool

[root@server1 ~]# ./zabbix-api.sh 
{
    "error": {
        "code": -32602,
        "data": "Host with the same name \"server6\" already exists.",
        "message": "Invalid params."
    },
    "id": 1,
    "jsonrpc": "2.0"
}

浏览器查看已经添加:
这里写图片描述

猜你喜欢

转载自blog.csdn.net/yifan850399167/article/details/81741570