zabbix5.0的在线部署步骤

zabbix5.0的在线部署步骤

一、部署环境

整个部署过程在VMware® Workstation 16 Pro 16.1.2 中进行

zabbix版本:5.0 LTS

系统:CentOS7.9

WEB应用:Apache

PHP版本:自带的php 72

数据库:MariaDB

在这里插入图片描述

二、服务器系统CentOS 7.9安装后的IP地址的配置(一般都使用静态IP地址)

1、配置静态IP地址(网卡名称使用“ip add”查看)

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens32  //最后的ifcfg-ens32为自己网卡名称
bootproto=static         //修改地址获取方式为静态
onboot=yes               //将no修改为yes
IPADDR=192.168.1.160          //添加IP地址
NETMASK=255.255.255.0        //添加子网掩码
GATEWAY=192.168.1.1            //添加网关
DNS1=119.29.29.29                  //添加第一个dns
DNS2=8.8.8.8                           //添加第二个dns
[root@localhost ~]# systemctl restart network  //重启网卡服务

2、centos7有些版本没有自带ifconfig工具,安装相应工具包

[root@localhost ~]#yum -y install net-tools    //就可以是用ifconfig等命令

三、zabbix服务器部署

1、关闭防火墙

[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@localhost ~]# systemctl disable --now firewalld

2、获取zabbix的下载源

[root@localhost ~]# rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm    //安装源仓库

3、时间的统一

[root@localhost ~]#yum install ntpdate -y            //安装时间守护进程ntpdate
[root@localhost ~]#ntpdate -u ntp.aliyun.com     //同步阿里云时间
[root@localhost ~]#mv /etc/localtime{,.bak}   //备份本地时间
[root@localhost ~]#ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime   //修改时区为上海

4、更换源为阿里云,提升下载文件速度

[root@localhost ~]# sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo

5、缓存

[root@localhost ~]# yum clean  all  //清空缓存
[root@localhost ~]#yum make cache  //创建缓存

6、下载zabbix服务端,安装zabbix

[root@localhost ~]# yum install zabbix-server-mysql zabbix-agent -y

7、安装工具,可以在系统上使用多个版本的软件,并且不会影响整个系统的依赖环境

[root@localhost ~]# yum install centos-release-scl -y

8、 修改zabbix-front前端源,修改如下参数

[root@localhost ~]#vi /etc/yum.repos.d/zabbix.repo and enable zabbix-frontend repository
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1    //开启这里的参数
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

9、安装zabbix前端环境

[root@localhost ~]#yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y

10、安装zabbix所需要的数据库,mariadb

[root@localhost ~]# yum info mariadb   //查看是否安装mariadb数据库
[root@localhost ~]# yum install mariadb-server -y

说明:

  • MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可
  • MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。
  • 现在MariaDB的数据特性、性能等都超越了MySQL。

11、配置数据库,开机启动

[root@localhost ~]#systemctl enable --now mariadb

12、初始化数据库,设置密码

[root@localhost ~]# systemctl status mariadb  //查看数据库状态
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2021-09-09 01:00:50 CST; 4min 17s ago
 Main PID: 2681 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─2681 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─2846 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=...
[root@localhost ~]# 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, we'll 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      //是否设置root密码
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      //删除多余user
 ... 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] y   //删除测试数据库
 \- 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] y   //刷新授权表
 ... 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!

13、添加数据库用户以及zabbix数据库信息

[root@localhost ~]# mysql -uroot -p    //进入数据库,“-u用户名”
Enter password:       //自己设置的密码
MariaDB [(none)]> show databases;     //查看数据库
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> create user xzd@localhost identified by 'xzd';    //创建用户名为xzd,密码为xzd
MariaDB [(none)]> grant all privileges on zabbix.* to xzd@localhost;     //授权
MariaDB [(none)]> flush privileges;   //刷新授权
MariaDB [(none)]> quit      //退出,也可以使用exit

14、使用zabbix-mysql命令,导入数据库信息

[root@localhost ~]# ls /usr/share/doc/zabbix-server-mysql*/create.sql.gz     //查看文件是否存在
/usr/share/doc/zabbix-server-mysql-5.0.15/create.sql.gz 
[root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uxzd -p zabbix   //mysql -u用户名  -p   数据库名  
Enter password:     //自己设置的密码
[root@localhost ~]# mysql -uxzd -pxzd     //进入数据库,用户名为xzd,密码为xzd,查看数据是否导入成功
MariaDB [(none)]> show databases;
MariaDB [(none)]> use zabbix;
MariaDB [zabbix]> show tables;
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| application_discovery      |
| application_prototype      |
| application_template       |

15、修改zabbix server配置文件,修改数据库用户名和密码

[root@localhost ~]#vi /etc/zabbix/zabbix_server.conf     //修改“DBPassword=密码”,去掉前面的“#”
DBUser=zabbix       //未更改前  
DBUser=xzd           //更改后,xzd为登陆数据库的用户名
\### Option: DBPassword
\#       Database password.
\#       Comment this line if no password is used.
\#
\# Mandatory: no
\# Default:
\# DBPassword=        //未更改前  
DBPassword=xzd     //更改后,xzd为登陆数据库的密码
[root@localhost ~]#grep 'DBPassword' /etc/zabbix/zabbix_server.conf   //查看文件中有Passwoed字段行
DBPassword=xzd
[root@zabbix_server02 ~]# grep -Ev '^#|^$' /etc/zabbix/zabbix_server.conf   //查看文件中不带#并且没有空行的字段行
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBName=zabbix
DBUser=xzd        //这里就是更改的数据库用户名
DBPassword=xzd    //这里就是更改的数据库密码
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1

16、修改zabbix的PHP配置文件

[root@localhost ~]# vi /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf   //修改“timezone=Asia/Shanghai” ,去掉前面的“;”   
;php_value[date.timezone] = Europe/Riga     //未更改前 
php_value[date.timezone] = Asia/Shanghai     //更改后
[root@localhost ~]# grep 'timezone' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf   //查看更改内容
php_value[date.timezone] = Asia/Shanghai
[root@localhost ~]# vi /etc/zabbix/web/zabbix.conf.php     //查看数据库用户名是否与“/etc/zabbix/zabbix_server.conf  ”中的"DBUser"是否一致

在这里插入图片描述

17、启动zabbix相关服务器

[root@localhost ~]# systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
[root@localhost ~]# systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
[root@localhost ~]# reboot         //重启设备

18、系统相关状态查看

[root@localhost ~]# netstat -tunlp    //端口监听命令
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1002/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1444/master         
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      1023/zabbix_agentd  
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      1762/zabbix_server  
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      999/php-fpm: master 
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      1379/mysqld         
tcp6       0      0 :::22                   :::*                    LISTEN      1002/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1444/master         
tcp6       0      0 :::10050                :::*                    LISTEN      1023/zabbix_agentd  
tcp6       0      0 :::10051                :::*                    LISTEN      1762/zabbix_server  
tcp6       0      0 :::80                   :::*                    LISTEN      998/httpd           
udp        0      0 127.0.0.1:323           0.0.0.0:*                           721/chronyd         
udp6       0      0 ::1:323                 :::*                                721/chronyd     
[root@localhost ~]# service zabbix-server status    //服务器的运行状态
Redirecting to /bin/systemctl status zabbix-server.service
● zabbix-server.service - Zabbix Server
   Loaded: loaded (/usr/lib/systemd/system/zabbix-server.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-09-07 11:27:36 EDT; 1h 3min ago
  Process: 1760 ExecStart=/usr/sbin/zabbix_server -c $CONFFILE (code=exited, status=0/SUCCESS)
 Main PID: 1762 (zabbix_server)
   CGroup: /system.slice/zabbix-server.service
​           ├─1762 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
[root@localhost ~]# cat /var/log/zabbix/zabbix_server.log   //查看报错日志

19、浏览器访问zabbix入口

http://IP地址/zabbix
查看红框处要全为OK,正常则下一步

在这里插入图片描述

设置数据库名称。用户名。密码,下一步

在这里插入图片描述

在这里插入图片描述

20、安装成功后,默认账号密码

用户名:Admin
密码:zabbix

在这里插入图片描述

在这里插入图片描述

设置成中文

在这里插入图片描述

21、解决zabbix服务器web界面中图形中乱码问题

[root@localhost ~]# yum -y install wqy-microhei-fonts   //安装字体库
[root@localhost ~]# \cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc  /usr/share/fonts/dejavu/DejaVuSans.ttf    //拷贝字体库

22、验证与客户端的连通性

[root@localhost ~]# yum install zabbix-get -y   //安装get运行库
[root@localhost ~]# zabbix_get -s '192.168.100.249' -p 10050 -k "agent.ping"
1
[root@localhost ~]# zabbix_get -s '192.168.100.249' -p 10050 -k "system.hostname"
xzd01                          //获取客户端的主机名

四、被监控服务器的的部署

1、agent2介绍

  • 未来可能会替代原Zabbix agent

  • 新版本采用golang语言开发的客户端

  • 默认用10050端口。也就是zabbix客户端的端口

      • 旧版客户端:zabbix-agent
    • 新版客户端:zabbix-agent2

2、机器环境准备:一台linux系统服务器做客户端

3、关闭防火墙和同步时间

[root@localhost ~]# setenforce 0
[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@localhost ~]# systemctl disable --now firewalld

4、yum源配置

[root@localhost ~]#rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm      //安装仓库
[root@localhost ~]#sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo   //替换源为阿里云

5、时间的统一

[root@localhost ~]#yum install ntpdate -y            //安装时间守护进程ntpdate
[root@localhost ~]#ntpdate -u ntp.aliyun.com     //同步阿里云时间
[root@localhost ~]#mv /etc/localtime{,.bak}    //备份本地时间
[root@localhost ~]#ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime   //修改时区为上海

6、zabbix-agent2具体部署(在线)

[root@localhost ~]#yum install zabbix-agent2 -y
//安装好以后默认配置文件   /etc/zabbix/zabbix_agent2.conf   
//默认二进制文件     /usr/sbin/zabbix_agent2
[root@localhost ~]# ls -l /usr/sbin/zabbix_agent2      //查看启动文件
-rwxr-xr-x. 1 root root 17721128 Aug 30 17:32 /usr/sbin/zabbix_agent2
[root@localhost ~]#systemctl enable --now zabbix-agent2       //设置开机自启动
[root@localhost ~]# netstat -tunlp|grep zabbix     //检查端口状态
tcp6       0      0 :::10050                :::*                    LISTEN      10154/zabbix_agent2 

7、修改配置文件vi /etc/zabbix/zabbix_agent2.conf

[root@localhost ~]#grep -Ev '^#|^$'  /etc/zabbix/zabbix_agent2.conf //查看排除带#和$的zabbix_agent2.conf 文件
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=127.0.0.1                    // 需要更改为的服务器地址
ServerActive=127.0.0.1           // 需要更改为的服务器地址
Hostname=Zabbix server         // 需要更改为的本机的Hostname
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock
[root@localhost ~]#vim  /etc/zabbix/zabbix_agent2.conf
Server=192.168.11.151
ServerActive=192.168.11.151
Hostname=hostname    //当前客户端主机名,使用hostname命令查看,重命名命令“hostnamectl set-hostname xzd01”
Include=/etc/zabbix/zabbix_agent2.d/*.conf

注意:

  • Server 和 ServerActive 配置为zabibx server 或 zabbix proxy 地址,Hostname 配置为主机名。( zabbix proxy以后再弄,本文直接使用zabbix server的IP地址)
  • Agent2 没有组件依赖,可直接拷贝编译好的二进制文件和配置文件在其他主机上运行
  • 更改配置文件后,注意重启agent2

8、重启服务

[root@localhost ~]# systemctl restart zabbix-agent2

9、添加被监控的服务器到web界面主机中

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

注:群组根据自己服务器选择对应群组

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

至此添加完成,刚开始添加需等待1-2min

在这里插入图片描述

五、日常故障处理

1、web界面密码重置

[root@localhost ~]# mysql -uroot -p -e "select * from zabbix.users\G"    //查看密码,是MD5加密的
Enter password: 
*************************** 1. row ***************************
        userid: 1
         alias: Admin
          name: Zabbix
       surname: Administrator
        passwd: $2y$10$IHk8NyNwH3mrfSgjJ821QeXqcxLD9ZCyFfxgmWA8/ey4PyWR7KfvC
           url: 
     autologin: 1
    autologout: 0
          lang: zh_CN
       refresh: 30s
          type: 3
         theme: default
attempt_failed: 0
    attempt_ip: 172.16.1.27
 attempt_clock: 1640922000
 rows_per_page: 50
*************************** 2. row ***************************
        userid: 2
         alias: guest
          name: 
       surname: 
        passwd: $2y$10$89otZrRNmde97rIyzclecuk6LwKAsHN0BcvoOKGjbT.BwMBfm7G06
           url: 
     autologin: 0
    autologout: 15m
          lang: en_GB
       refresh: 30s
          type: 1
         theme: default
attempt_failed: 0
    attempt_ip: 
 attempt_clock: 0
 rows_per_page: 50
[root@localhost ~]# 
[root@localhost ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 154328
Server version: 5.5.68-MariaDB MariaDB Server

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

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

MariaDB [(none)]> show database;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'database' at line 1
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| zabbix             |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> use zabbix;
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
MariaDB [zabbix]> update users set passwd='5fce1b3e34b520afeffb37ce08c7cd66' where userid='1';   
//'5fce1b3e34b520afeffb37ce08c7cd66'代表密码为'zabbix'
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
MariaDB [zabbix]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [zabbix]> 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Dianer01

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值