企业实战(8)CentOS 6.8安装Zabbix-agent 5.0监控主机性能与Mysql数据库

本文涉及的产品
RDS MySQL DuckDB 分析主实例,集群系列 4核8GB
RDS AI 助手,专业版
简介: 企业实战(8)CentOS 6.8安装Zabbix-agent 5.0监控主机性能与Mysql数据库

环境介绍:


CentOS 6.8


Zabbix-agent 5.0


Zabbix-server:192.168.2.128


Zabbix-agent:192.168.2.131


一、Zabbix-server端安装配置


传送门 --->Zabbix 5.0监控平台搭建与被监控端的添加


二、Zabbix-agent安装


1.设置Selinux为disabled

[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# vim /etc/sysconfig/selinux
SELINUX=disabled

2.设置Iptables防火墙规则

[root@localhost ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
[root@localhost ~]# iptables -I INPUT -p tcp --dport 10050 -j ACCEPT
----放行zabbix端口10050
[root@localhost ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:zabbix-agent
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

3.安装Zabbix Yum源仓库

[root@localhost ~]# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/6/x86_64/zabbix-release-5.0-1.el6.noarch.rpm
Retrieving https://repo.zabbix.com/zabbix/5.0/rhel/6/x86_64/zabbix-release-5.0-1.el6.noarch.rpm
warning: /var/tmp/rpm-tmp.8Lm2y3: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing...                ########################################### [100%]
   1:zabbix-release         ########################################### [100%]
[root@localhost ~]# yum clean all
已加载插件:fastestmirror
Cleaning repos: base extras updates zabbix zabbix-non-supported
清理一切
Cleaning up list of fastest mirrors

4.安装Zabbix-agent

[root@localhost ~]# yum -y install zabbix-agent
已加载插件:fastestmirror
设置安装进程
Loading mirror speeds from cached hostfile
 * base: mirrors.bfsu.edu.cn
 * extras: mirrors.bfsu.edu.cn
 * updates: mirrors.bfsu.edu.cn
解决依赖关系
--> 执行事务检查
---> Package zabbix-agent.x86_64 0:5.0.0-1.el6 will be 安装
--> 完成依赖关系计算
依赖关系解决
===============================================================================================================================
 软件包                           架构                       版本                             仓库                        大小
===============================================================================================================================
正在安装:
 zabbix-agent                     x86_64                     5.0.0-1.el6                      zabbix                     435 k
事务概要
===============================================================================================================================
Install       1 Package(s)
总下载量:435 k
Installed size: 1.7 M
下载软件包:
http://repo.zabbix.com/zabbix/5.0/rhel/6/x86_64/^H^H^H^Hzabbix-agent-5.0.0-1.el6.x86_64.rpm              18% [=======          zabbix-agent-5.0.0-1.el6.x86_64.rpm                                                                     | 435 kB     00:08
warning: rpmts_HdrFromFdno: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
Importing GPG key 0xA14FE591:
 Userid : Zabbix LLC <packager@zabbix.com>
 Package: zabbix-release-5.0-1.el6.noarch (installed)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
运行 rpm_check_debug
执行事务测试
事务测试成功
执行事务
Warning: RPMDB altered outside of yum.
  正在安装   : zabbix-agent-5.0.0-1.el6.x86_64                                                                             1/1
  Verifying  : zabbix-agent-5.0.0-1.el6.x86_64                                                                             1/1
已安装:
  zabbix-agent.x86_64 0:5.0.0-1.el6
完毕!

注意:


 如果下载的zabbix-agent 5.0安装包使用rpm安装时提示“错误:依赖检测失败:libpcre.so.0()(64bit)”,则可以使用zabbix 5.0 Yum源来安装zabbix-agent 5.0软件。  


----> 传送门安装zabbix-agent5.0 报错解决


5.修改zabbix-agent配置文件:

[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf
119 Server=127.0.0.1,192.168.2.128
160 ServerActive=192.168.2.128
171 Hostname=192.168.2.131
[root@localhost ~]# service zabbix-agent start
Starting Zabbix agent:                                     [确定]
[root@localhost ~]# service zabbix-agent enable
用法: /etc/init.d/zabbix-agent {start|stop|status|restart|try-restart|force-reload}
[root@localhost ~]# ss -antulp | grep :10050
tcp    LISTEN     0      128                   :::10050                :::*      users:(("zabbix_agentd",2963,5),("zabbix_agentd",2965,5),("zabbix_agentd",2966,5),("zabbix_agentd",2967,5),("zabbix_agentd",2968,5),("zabbix_agentd",2969,5))
tcp    LISTEN     0      128                    *:10050                 *:*      users:(("zabbix_agentd",2963,4),("zabbix_agentd",2965,4),("zabbix_agentd",2966,4),("zabbix_agentd",2967,4),("zabbix_agentd",2968,4),("zabbix_agentd",2969,4))

三、Zabbix-server端Web界面配置


--主机系统性能监控


1.添加Zabbix-agent主机

3.png

2.添加主机信息

4.png

3.选择主机性能监控模板

5.png

4.查看被监控主机状态


 现在可以看到在Zabbix-server端web页面上centos6主机状态显示绿色,说明被监控主机已经添加成功。

6.png

5.查看被监控主机系统性能监控信息

7.png

6.以图形形式查看性能监控信息

8.png9.png

--Mysql数据库监控


Zabbix-agent端配置


1.基础环境配置

[root@localhost ~]# yum install tree net-tool net-snmp vim ntpdate  wget                 #安装部分基础软件包
[root@localhost ~]# cd /etc/yum.repos.d/         #修改yum源 更改为阿里云 
[root@localhost ~]# mv CentOS-Base.repo CentOS-Base.repo.bak    #备份文件    
[root@localhost ~]# wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo            #下载阿里云镜像仓库
[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo     #下载epel仓库
[root@localhost ~]# yum clean all    #清理缓存            
[root@localhost ~]# yum makecache   #重新生成缓存

2.安装Mysql数据库


Mysql5.7下载

[root@localhost ~]# wget https://repo.mysql.com//mysql57-community-release-el6-9.noarch.rpm     //下载Mysql5.7 Yum源
[root@localhost ~]# ls mysql57-community-release-el6-9.noarch.rpm
mysql57-community-release-el6-9.noarch.rpm
[root@localhost ~]# rpm -ivh mysql57-community-release-el6-9.noarch.rpm      //安装Mysql5.7 Yum源
[root@localhost ~]# yum -y install mysql-server    //安装Mysql
...
已安装:
  mysql-community-libs.x86_64 0:5.7.30-1.el6                  mysql-community-libs-compat.x86_64 0:5.7.30-1.el6
  mysql-community-server.x86_64 0:5.7.30-1.el6
作为依赖被安装:
  mysql-community-client.x86_64 0:5.7.30-1.el6   mysql-community-common.x86_64 0:5.7.30-1.el6   numactl.x86_64 0:2.0.9-2.el6
作为依赖被升级:
  postfix.x86_64 2:2.6.6-8.el6
完毕!
[root@localhost ~]# service mysqld start    //启动Mysqld服务
初始化 MySQL 数据库:                                      [确定]
正在启动 mysqld:                                          [确定]
[root@localhost ~]# service mysqld enable    //开机自启mysql
用法:/etc/init.d/mysqld {start|stop|status|restart|condrestart|try-restart|reload|force-reload}
[root@localhost ~]# ss -antulp | grep :3306
tcp    LISTEN     0      80                    :::3306                 :::*      users:(("mysqld",23473,21))
[root@localhost ~]# grep 'root@localhost:' /var/log/mysqld.log   //查看初始密码
2020-05-26T21:29:44.571409Z 1 [Note] A temporary password is generated for root@localhost: haiwhAT<g1O+
[root@localhost ~]# mysql -hlocalhost -uroot -p'haiwhAT<g1O+'  //使用初始密码登陆
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.30
...
mysql>
mysql> alter user root@"localhost" identified by "123qqq...A";   修改登陆密码
[root@localhost ~]# mysql -uroot -p123qqq...A    //使用新密码登陆

3.授权Zabbix用户,用于发送数据

[root@localhost ~]# mysql -uroot -p123qqq...A
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.30 MySQL Community Server (GPL)
...
mysql> grant all on *.* to zabbix@"localhost" identified by "123qqq...A";
Query OK, 0 rows affected, 1 warning (0.06 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.04 sec)

4.测试使用Zabbix用户登录数据库

[root@localhost ~]# mysql -uzabbix -p123qqq...A
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.30 MySQL Community Server (GPL)
...
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)
mysql> select user();
+------------------+
| user()           |
+------------------+
| zabbix@localhost |
+------------------+
1 row in set (0.01 sec)

5.查看mysql的sock文件路径

[root@localhost ~]# find / -name mysql.sock
/var/lib/mysql/mysql.sock

6.查找并拷贝Zabbix监控Mysql模板文件

[root@localhost ~]# find / -name user*_mysql.conf
/usr/share/doc/zabbix-agent-5.0.0/userparameter_mysql.conf
[root@localhost ~]# cp /usr/share/doc/zabbix-agent-5.0.0/userparameter_mysql.conf /etc/zabbix/zabbix_agentd.d/
[root@localhost ~]# id zabbix
uid=498(zabbix) gid=498(zabbix) 组=498(zabbix)
[root@localhost ~]# chown -R zabbix:zabbix /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf   //设置模板文件归属
[root@localhost ~]# ll /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
-rw-r--r--. 1 zabbix zabbix 1081 5月  27 06:07 /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf

7.查看Zabbix自带的监控模板文件


由配置文件可以知道,在Linux系统中需要在zabbix-agent home目录中创建.my.cnf(默认情况下为/var/lib/zabbix),并且文件必须以下有三个字符串:


  • [client]

  • user=zbx_monitor

  • password=``
[root@localhost ~]# cat /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
#template_db_mysql.conf created by Zabbix for "Template DB MySQL" and Zabbix 4.2
#For OS Linux: You need create .my.cnf in zabbix-agent home directory (/var/lib/zabbix by default)
#For OS Windows: You need add PATH to mysql and mysqladmin and create my.cnf in %WINDIR%\my.cnf,C:\my.cnf,BASEDIR\my.cnf https://dev.mysql.com/doc/refman/5.7/en/option-files.html
#The file must have three strings:
#[client]
#user=zbx_monitor
#password=<password>
#
UserParameter=mysql.ping[*], mysqladmin -h"$1" -P"$2" ping
UserParameter=mysql.get_status_variables[*], mysql -h"$1" -P"$2" -sNX -e "show global status"
UserParameter=mysql.version[*], mysqladmin -s -h"$1" -P"$2" version
UserParameter=mysql.db.discovery[*], mysql -h"$1" -P"$2" -sN -e "show databases"
UserParameter=mysql.dbsize[*], mysql -h"$1" -P"$2" -sN -e "SELECT SUM(DATA_LENGTH + INDEX_LENGTH) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='$3'"
UserParameter=mysql.replication.discovery[*], mysql -h"$1" -P"$2" -sNX -e "show slave status"
UserParameter=mysql.slave_status[*], mysql -h"$1" -P"$2" -sNX -e "show slave status"

8.在/var/lib/zabbix目录下创建.my.cnf配置文件

[root@localhost ~]# mkdir /var/lib/zabbix
[root@localhost ~]# vim /var/lib/zabbix/.my.cnf
[mysql]
host=localhost
user=zabbix           //数据库中授权的zabbix用户
password=123qqq...A     //授权用户密码
socket=/var/lib/mysql/mysql.sock   
[mysqladmin]
host=localhost
user=zabbix
password=123qqq...A
socket=/vsr/lib/mysql/mysql.sock
[root@localhost ~]# service zabbix-agent restart    //重启Zabbix-agent服务
Shutting down Zabbix agent:                                [确定]
Starting Zabbix agent:                                     [确定]

Zabbix-server Web端配置


1.选择Mysql监控模板

10.png

11.png

2.查看Mysql监控数据


 要查看单个监控项的数据图形,直接点击监控项末尾的“图形”即可。

12.png

3.查看所有监控项图形信息

13.png14.png



相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
相关文章
|
5月前
|
安全 关系型数据库 MySQL
CentOS 7 yum 安装 MySQL教程
在CentOS 7上安装MySQL 8,其实流程很清晰。首先通过官方Yum仓库来安装服务,然后启动并设为开机自启。最重要的环节是首次安全设置:需要先从日志里找到临时密码来登录,再修改成你自己的密码,并为远程连接创建用户和授权。最后,也别忘了在服务器防火墙上放行3306端口,这样远程才能连上。
940 16
|
6月前
|
存储 关系型数据库 MySQL
在CentOS 8.x上安装Percona Xtrabackup工具备份MySQL数据步骤。
以上就是在CentOS8.x上通过Perconaxtabbackup工具对Mysql进行高效率、高可靠性、无锁定影响地实现在线快速全量及增加式数据库资料保存与恢复流程。通过以上流程可以有效地将Mysql相关资料按需求完成定期或不定期地保存与灾难恢复需求。
506 10
|
10月前
|
关系型数据库 MySQL Linux
CentOS 7系统下详细安装MySQL 5.7的步骤:包括密码配置、字符集配置、远程连接配置
以上就是在CentOS 7系统下安装MySQL 5.7的详细步骤。希望这个指南能帮助你顺利完成安装。
2506 26
|
6月前
|
存储 Ubuntu Linux
VMware-安装CentOS系统教程及安装包
虚拟机相当于是一个独立于你电脑的环境,在这个环境上面,你可以安装Linux、Windows、Ubuntu等各个类型各个版本的系统,在这个系统里面你不用担心有病读等,不用担心文件误删导致系统崩溃。 虚拟机也和正常的电脑系统是一样的,也可以开关机,不用的时候,你关机就可以了,也不会占用你的系统资源,使用起来还是比较方便 这里也有已经做好的CentOS 7系统,下载下来解压后直接用VMware打开就可以使用
1199 69
|
5月前
|
存储 分布式计算 Linux
安装篇--CentOS 7 虚拟机安装
VMware 装 CentOS 7 不知道从哪下手?这篇超详细图文教程手把手教你在 VMware Workstation 中完成 CentOS 7 桌面系统的完整安装流程。从 ISO 镜像下载、虚拟机配置,到安装图形界面、设置用户密码,每一步都有截图讲解,适合零基础新手快速上手。装好之后无论你是要搭 Hadoop 集群,还是练 Linux ,这个环境都够你折腾一整天!
2115 3
|
6月前
|
Ubuntu Linux 索引
Centos 7、Debian及Ubuntu系统中安装和验证tree命令的指南。
通过上述步骤,我们可以在CentOS 7、Debian和Ubuntu系统中安装并验证 `tree`命令。在命令行界面中执行安装命令,然后通过版本检查确认安装成功。这保证了在多个平台上 `tree`命令的一致性和可用性,使得用户无论在哪种Linux发行版上都能使用此工具浏览目录结构。
533 78
|
7月前
|
Linux 网络安全 Apache
针对在Centos/Linux安装Apache过程中出现的常见问题集锦
以上每个问题的解决方案应深入分析错误日志、系统消息和各种配置文件,以找到根本原因并加以解决。务必保持系统和Apache软件包更新到最新版本,以修复已知的bugs和安全漏洞。安装和管理Web服务器是一项需要细致关注和不断学习的任务。随着技术的发展,推荐定期查看官方文档和社区论坛,以保持知识的更新。
298 80
|
8月前
|
机器人 Linux
CentOS 7系统中安装特定版本CMake 3.21.2的方法。
到这里,过程已经全部完成。如果你跟随上面的步骤来,那么你现在已经拥有了一个全新的CMake版本在你的CentOS 7系统上了。这个过程就像是你通过一系列仪式,唤醒了一个沉睡已久的古老机器人,它现在完全按照你的意愿来帮你构建和编译软件了。
611 18
|
7月前
|
人工智能 数据挖掘 Linux
Centos安装Python3.7(亲测可用)
本指南详细介绍了在基于Linux(以CentOS系统为例,使用yum包管理器)的系统上安装Python 3.7版本的完整流程。Python是一种广泛使用的高级编程语言,在各种领域如软件开发、数据分析、人工智能和区块链开发等都有着重要的应用。
650 2
|
6月前
|
运维 网络协议 Linux
CentOS下Bind服务的安装与故障排查
通过以上的步骤,您应该能够在CentOS系统上安装并配置BIND DNS服务,并进行基本的故障排查。
545 0