centos7+zabbix5.0+Grafana部署方案

[08:37:53][root@localhost ~]# ip addr show查看服务器ip地址
[08:37:53]1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
[08:37:53]    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
[08:37:53]    inet 127.0.0.1/8 scope host lo
[08:37:53]       valid_lft forever preferred_lft forever
[08:37:53]    inet6 ::1/128 scope host
[08:37:53]       valid_lft forever preferred_lft forever
[08:37:53]2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
[08:37:53]    link/ether 00:0c:29:65:a7:5b brd ff:ff:ff:ff:ff:ff
[08:37:53]    inet 192.168.60.133/24 brd 192.168.60.255 scope global noprefixroute dynamic ens33
[08:37:53]       valid_lft 1649sec preferred_lft 1649sec
[08:37:53]    inet6 fe80::9f3:28d6:bbf1:66f4/64 scope link noprefixroute
[08:37:53]       valid_lft forever preferred_lft forever
[08:37:53]3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
[08:37:53]    link/ether 00:0c:29:65:a7:65 brd ff:ff:ff:ff:ff:ff
[08:37:53]    inet 192.168.60.132/24 brd 192.168.60.255 scope global noprefixroute dynamic ens37
[08:37:53]       valid_lft 1466sec preferred_lft 1466sec
[08:37:53]    inet6 fe80::cb5a:6a96:309b:d962/64 scope link noprefixroute
[08:37:53]       valid_lft forever preferred_lft forever
[09:57:44][root@localhost ~]# yum list installed | grep zabbix查询已经安装的包
[09:57:44]zabbix-release.noarch                4.0-2.el8                         installed
[09:58:05][root@localhost ~]# yum -y remove zabbix-release.noarch删除已经安装的包
........
[09:58:06]Complete!
[09:59:36][root@localhost ~]# systemctl disable -now firewalld
[09:59:36]Too few arguments.
[10:00:26][root@localhost ~]# hostnamectl set-hostname zbx-server
[10:00:58][root@localhost ~]# su
[10:03:27][root@zbx-server ~]#
[10:03:27][root@zbx-server ~]# yum install ntpdate 安装包否则 # ntpdate ntp.aliyun.com  无法执行
.........
[10:03:46]Complete!
[10:04:13][root@zbx-server ~]# ntpdate ntp.aliyun.com   设置同步时间
[10:04:20]26 Jan 10:04:19 ntpdate[9292]: adjust time server 203.107.6.88 offset 0.095264 sec
[10:06:26][root@zbx-server ~]# systemctl disable --now firewalld 切换防火墙类型
[10:06:26]Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
[10:06:26]Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[10:06:38][root@zbx-server ~]# setenforce 0  临时关闭防火墙
[10:06:44][root@zbx-server ~]# su
[10:07:28]warning: /var/tmp/rpm-tmp.BH6nQw: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
[10:07:28]Preparing...                          ################################# [100%]
[10:07:28]Updating / installing...
[10:07:28]   1:zabbix-release-5.0-1.el7         ################################# [100%]
#更换 zabbix.repo 为阿里源
[10:08:58][root@zbx-server ~]# cd /etc/yum.repos.d
[10:09:32][root@zbx-server yum.repos.d]# sed -i 's# http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix# ' zabbix.repo
[10:09:44][root@zbx-server yum.repos.d]# yum clean all && yum makecache
[10:10:31][root@zbx-server yum.repos.d]# yum install -y zabbix-server-mysql zabbix-agent
[10:10:31]Loaded plugins: fastestmirror
[10:10:31]Loading mirror speeds from cached hostfile
............
[10:10:35]
[10:10:35]Complete!
#安装SCL(Software Collections),便于后续安装高版本的 php,默认 yum 安装的 php 版本为 5.4,版本过低,zabbix 5.0 版本对 php 版本最低要 7.2.0 版本。SCL 可以使得在同一台机器上使用多个版本的软件,而又不会影响整个系统的依赖环境。软件包会安装在 /etc/opt/rh/ 目录下。
[10:10:47][root@zbx-server yum.repos.d]# yum install -y centos-release-scl
[10:10:47]Loaded plugins: fastestmirror
[10:10:47]Loading mirror speeds from cached hostfile
............                                                                         
[10:10:47]
[10:10:47]Complete!
还需要修改一下zabbix源,开启前端环境下载
[10:12:12][root@zbx-server yum.repos.d]# vi /etc/yum.repos.d/zabbix.repo
[10:12:12][zabbix]
[10:12:12]name=Zabbix Official Repository - $basearch
[10:12:12]enabled=1
[10:12:12]gpgcheck=1
[10:12:12]gpgkey= file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[10:12:12]
[10:12:12][zabbix-frontend]
[10:12:12]name=Zabbix Official Repository frontend - $basearch
[10:12:12 ]enabled=1        改为1  并保存:wq
[10:12:12]gpgcheck=1
[10:12:12]gpgkey= file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[10:12:12]
[10:12:12][zabbix-debuginfo]
[10:12:12]name=Zabbix Official Repository debuginfo - $basearch
[10:12:12]enabled=0
[10:12:12]gpgkey= file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[10:12:12]gpgcheck=1
[10:12:12]
[10:12:12][zabbix-non-supported]
[10:12:12]name=Zabbix Official Repository non-supported - $basearch
[10:12:12]enabled=1
[10:12:12]gpgkey= file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
[10:12:12]gpgcheck=1
批量替换内容
:s#enabled=0#enabled=1#g
#安装前端环境
[10:13:57][root@zbx-server yum.repos.d]# yum install -y zabbix-web-mysql-scl zabbix-apache-conf-scl
..........
[10:14:37]Complete!   安装成功
#安装 zabbix 所需的数据库
[10:14:48][root@zbx-server yum.repos.d]# yum install -y mariadb-server mariadb
[10:14:49]Loaded plugins: fastestmirror
.................
[10:15:10]Complete!
[10:15:18][root@zbx-server yum.repos.d]# systemctl enable --now mariadb
[10:15:18]Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
#初始化数据库
[10:15:43][root@zbx-server yum.repos.d]# mysql_secure_installation
[10:15:43]
[10:15:43]NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
[10:15:43]      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
[10:15:43]
[10:15:43]In order to log into MariaDB to secure it, we'll need the current
[10:15:43]password for the root user.  If you've just installed MariaDB, and
[10:15:43]you haven't set the root password yet, the password will be blank,
[10:15:43]so you should just press enter here.
[10:15:43]
[10:15:54]Enter current password for root (enter for none):        回车
[10:15:54]OK, successfully used password, moving on...
[10:15:54]
[10:15:54]Setting the root password ensures that nobody can log into the MariaDB
[10:15:54]root user without the proper authorisation.
[10:15:54]
[10:16:05]Set root password? [Y/n] y
[10:16:18]New password:                       设置root用户密码
[10:16:22]Re-enter new password:
[10:16:22]Password updated successfully!
[10:16:22]Reloading privilege tables..
[10:16:22] ... Success!
[10:16:22]
[10:16:22]
[10:16:22]By default, a MariaDB installation has an anonymous user, allowing anyone
[10:16:22]to log into MariaDB without having to have a user account created for
[10:16:22]them.  This is intended only for testing, and to make the installation
[10:16:22]go a bit smoother.  You should remove them before moving into a
[10:16:22]production environment.
[10:16:22]
[10:16:43]Remove anonymous users? [Y/n] y           是否移除匿名用户
[10:16:43] ... Success!
[10:16:43]
[10:16:43]Normally, root should only be allowed to connect from 'localhost'.  This
[10:16:43]ensures that someone cannot guess at the root password from the network.
[10:16:43]
[10:16:53] Disallow root login remotely? [Y/n] n           是否允许root远程访问
[10:16:53] ... skipping.
[10:16:53]
[10:16:53]By default, MariaDB comes with a database named 'test' that anyone can
[10:16:53]access.  This is also intended only for testing, and should be removed
[10:16:53]before moving into a production environment.
[10:16:53]
[10:17:00]Remove test database and access to it? [Y/n] y            是否移除默认存在的test数据库
[10:17:00] - Dropping test database...
[10:17:00] ... Success!
[10:17:00] - Removing privileges on test database...
[10:17:00] ... Success!
[10:17:00]
[10:17:00]Reloading the privilege tables will ensure that all changes made so far
[10:17:00]will take effect immediately.
[10:17:00]
[10:17:04]Reload privilege tables now? [Y/n] y             是否刷新表权限
[10:17:04] ... Success!
[10:17:04]
[10:17:04]Cleaning up...
[10:17:04]
[10:17:04]All done!  If you've completed all of the above steps, your MariaDB
[10:17:04]installation should now be secure.
[10:17:04]
[10:17:04]Thanks for using MariaDB!                            完成数据库初始化
[10:18:59][root@zbx-server yum.repos.d]# mysql -u root -pzabbix       登录数据库
[10:18:59]Welcome to the MariaDB monitor.  Commands end with ; or \g.
[10:18:59]Your MariaDB connection id is 9
[10:18:59]Server version: 5.5.68-MariaDB MariaDB Server
[10:18:59]
[10:18:59]Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
[10:18:59]
[10:18:59]Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
[10:54:30]MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;     创建 zabbix 数据库 Utf8字符集 ,用于更好的支持中文界面
[10:54:30]Query OK, 1 row affected (0.00 sec)
[10:54:30]
[10:57:45]MariaDB [(none)]> grant all on zabbix.* to 'zabbix'@'%' identified by 'zabbix';      为zabbix用户授权zabbix库中的所有表,允许所有地址访问,密码设置为zabbix
[10:57:45]Query OK, 0 rows affected (0.00 sec)
[10:57:45]
[10:58:08]MariaDB [(none)]> flush privileges;    刷新授权
[10:58:08]Query OK, 0 rows affected (0.00 sec)
[10:58:08]
[10:58:15]MariaDB [(none)]> quit;    退出
[10:58:15]Bye
#导入数据库信息   进入 create.sql.gz  所在的目录 执行数据导入命令
[11:02:04][root@zbx-server yum.repos.d]# cd /usr/share/doc/ zabbix-server-mysql-5.0.40     进入文件夹
[11:03:17][root@zbx-server zabbix-server-mysql-5.0.40]# ls    列出文件内容准备导入数据
[11:03:17]AUTHORS  ChangeLog  COPYING   create.sql.gz  double.sql  NEWS  README
[11:08:58][root@zbx-server zabbix-server-mysql-5.0.40]# zcat create.sql.gz | mysql -uroot -pzabbix zabbix    导入数据
[11:09:11][root@zbx-server zabbix-server-mysql-5.0.40]# cd /
[11:09:39][root@zbx-server /]# mysql -uroot -pzabbix
[11:09:39]Welcome to the MariaDB monitor.  Commands end with ; or \g.
[11:09:39]Your MariaDB connection id is 16
[11:09:39]Server version: 5.5.68-MariaDB MariaDB Server
[11:09:39]
[11:09:39]Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
[11:09:39]
[11:09:39]Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
[11:09:39]
[11:09:54]MariaDB [(none)]> use zabbix    进入zabbix库
[11:09:54]Reading table information for completion of table and column names
[11:09:54]You can turn off this feature to get a quicker startup with -A
[11:09:54]
[11:09:54]Database changed
[11:10:03]MariaDB [zabbix]> show tables;    查看zabbix库中是否有导入成功的表
[11:10:03]+----------------------------+
[11:10:03]| Tables_in_zabbix           |
[11:10:03]+----------------------------+
.................
[11:10:03]+----------------------------+
[11:10:03]166 rows in set (0.00 sec)
[11:10:03]
[11:10:21]MariaDB [zabbix]> quit    退出zabbix数据库
[11:10:21]Bye
#修改 zabbix server 配置文件,修改数据库登录账号root和密码zabbix,否则zabbix-server无法启动无10051端口
[11:10:57][root@zbx-server /]# vi /etc/zabbix/zabbix_server.conf
#数据库配置
[11:12:03]DBName= zabbix
[11:12:06]DBUser= root
[11:12:11]DBPassword= zabbix
#缓存配置
[15:36:50]### Option: CacheSize
[15:36:50]#       Size of configuration cache, in bytes.
[15:36:50]#       Shared memory size for storing host, item and trigger data.
[15:36:50]#
[15:36:50]# Mandatory: no
[15:36:50]# Range: 128K-64G
[15:36:50]# Default:
[15:36:50 ] CacheSize=4096M
# 修改 zabbix 的 php 配置文件
[11:14:01][root@zbx-server /]# vi /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
[11:14:01] php_value[date.timezone] = Asia/Shanghai       #24行,取消;注释,修改时区
# 启动 zabbix 相关服务
[11:15:27][root@zbx-server /]# systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
[11:16:04][root@zbx-server /]# systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
[11:18:49][root@zbx-server /]# ip addr show 查看服务器地址
浏览器访问zabbix: http://192.168.60.133/zabbix
默认填写数据库zabbix  用户名 root  密码 zabbix
默认管理账号Admin密码zabbix   账号区分大小写
安装图形界面中文支持
[11:38:22][root@zbx-server /]# yum install -y wqy-microhei-fonts
...............
[11:38:36]Complete!
[11:38:43][root@zbx-server /]# \cp -f /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf
[11:45:17][root@zbx-server /]# yum install -y net-tools    安装netstat包
................
[11:45:20]Complete!
[11:45:26][root@zbx-server /]# netstat -an | grep LIS    查询监听的当前端口,确认10051端口是否存在,不存在代表 zabbix-server 服务器未启动
[15:52:45]tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN     
[15:52:45]tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN     
[15:52:45]tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN     
[15:52:46]tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN     
[15:52:46]tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
[15:52:46]tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
[15:52:46]tcp        0     52 192.168.60.133:22       192.168.60.1:57252      ESTABLISHED
[15:52:46]tcp6       0      0 :::10050                :::*                    LISTEN     
[15:52:46]tcp6       0      0 :::10051                :::*                    LISTEN     
[15:52:46]tcp6       0      0 :::80                   :::*                    LISTEN     
[15:52:46]tcp6       0      0 :::22                   :::*                    LISTEN     
[15:52:46]tcp6       0      0 ::1:25                  :::*                    LISTEN   
[15:52:54][root@zbx-server ~]# netstat -tnlp|grep -w 10051     查询10051端口是否存在,不存在代表 zabbix-server 服务器未启动
[15:52:54]tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      1508/zabbix_server  
[15:52:54]tcp6       0      0 :::10051                :::*                    LISTEN      1508/zabbix_server  
[12:00:58][root@zbx-server /]# vi /etc/zabbix/web/zabbix.conf.php    查看配置文件是否正确
[12:00:58]<?php
[12:00:58]// Zabbix GUI configuration file.
[12:00:58]
[12:00:58]$DB['TYPE']                             = ' MYSQL';
[12:00:58]$DB['SERVER']                   = 'localhost';
[12:00:58]$DB['PORT']                             = '0';
[12:00:58]$DB['DATABASE']                 = 'zabbix';
[12:00:58]$DB['USER']                             = 'root';
[12:00:58]$DB['PASSWORD']                 = 'zabbix';
[12:00:58]
[15:24:42][root@zbx-server ~]# getenforce    查看防火墙状态
[15:24:42]Enforcing
[15:27:38][root@zbx-server ~]# vi /etc/selinux/config    修改防火墙配置文件关闭防火墙
[15:27:38]# This file controls the state of SELinux on the system.
[15:27:38]# SELINUX= can take one of these three values:
[15:27:38]#     enforcing - SELinux security policy is enforced.
[15:27:38]#     permissive - SELinux prints warnings instead of enforcing.
[15:27:38]#     disabled - No SELinux policy is loaded.
[15:27:38]#SELINUX=enforcing
[15:27:38]SELINUX= Disabled    关闭防火墙,该方法关闭防火墙后需要重启服务器
[15:27:38]# SELINUXTYPE= can take one of three two values:
[15:27:38]#     targeted - Targeted processes are protected,
[15:27:38]#     minimum - Modification of targeted policy. Only selected processes are protected.
[15:27:38]#     mls - Multi Level Security protection.
[15:27:38]SELINUXTYPE=targeted
[15:30:18][root@zbx-server ~]# reboot    重启服务器
[15:30:18]PolicyKit daemon disconnected from the bus.
[15:30:18]We are no longer a registered authentication agent.
[15:31:57][20240126_15:31:57]
[15:31:57]Last login: Fri Jan 26 15:31:44 2024 from 192.168.60.1
[15:32:10][root@zbx-server ~]# getenforce    查看防火墙状态
[15:32:10] Disabled
[15:43:46][root@zbx-server ~]# cat /var/log/zabbix/zabbix_server.log    查看 zabbix_server.log  分析错误
[15:43:46] 10380:20240126:111527.084 using configuration file: /etc/zabbix/zabbix_server.conf
[15:43:46] 10380:20240126:111527.091 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: YES)     服务器密码错误
[15:43:46] 10380:20240126:111527.091 database is down: reconnecting in 10 seconds

Grafana官方安装说明Download Grafana | Grafana Labs
Centos yum安装
[13:53:13][root@zbx-server ~]# sudo yum install -y https://dl.grafana.com/enterprise/release/grafana-enterprise-10.3.1-1.x86_64.rpm
[13:53:13]Loaded plugins: fastestmirror
[13:53:40]grafana-enterprise-10.3.1-1.x86_64.rpm                                                                                                               | 105 MB  00:00:23     
........
[13:54:14]Dependency Updated:
[13:54:14]  freetype.x86_64 0:2.8-14.el7_9.1                                                                                                                                          
[13:54:14]
[13:54:14]Complete!
[13:54:42][root@zbx-server ~]# service grafana-server restart
[13:54:44]Restarting grafana-server (via systemctl):  [  OK  ]
  • 5
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值