部署zabbix 5.0 server

#1、关闭防火墙
[root@zbx-server ~]#systemctl stop firewalld
[root@zbx-server ~]#service iptables stop
[root@zbx-server ~]#sed -i 's/SELINUX=enforcing/SELINUX=disable/' /etc/selinux/config
[root@zbx-server ~]#systemctl disable --now firewalld

[root@zbx-server ~]#getenforce
Disabled
[root@zbx-server ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source 

[root@zbx-server ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
     
#2、内存尽量大
[root@zbx-server ~]#free -m

#3、获取zabbix的下载源
[root@zbx-server ~]#rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
[root@zbx-agent01 ~]# ls /etc/yum.repos.d
CentOS-Base.repo       CentOS-fasttrack.repo  CentOS-Vault.repo          epel.repo          zabbix.repo
CentOS-CR.repo         CentOS-Media.repo      CentOS-x86_64-kernel.repo  epel-testing.repo
CentOS-Debuginfo.repo  CentOS-Sources.repo    docker-ce.repo             nginx.repo?

#4、更换zabbix.repo源为阿里源
[root@zbx-server ~]#sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo

#5、清空yum缓存
[root@zbx-server ~]#yum clean all
[root@zbx-server ~]#yum makecache

#6、安装zabbix server 和 agent
[root@zbx-server ~]#yum install zabbix-server-mysql zabbix-agent -y

#7、安装SCL,可以安装多个版本的软件,而不影响系统依赖
[root@zbx-server ~]#yum install centos-release-scl -y

#8、修改/etc/yum.repos.d/zabbix.repo内容中的enable=1
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1

#9、安装zabbix前端环境,安装到SCL环境下,安装包位置/opt/rh/
[root@zbx-server ~]#yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y

#10、安装数据库
[root@zbx-server ~]#yum install mariadb-server -y

#11、配置数据库开机自动启动
[root@zbx-server ~]#systemctl enable --now mariadb

#12、查看数据库服务状态
[root@zbx-server ~]#systemctl status mariadb
[root@zbx-server ~]# netstat -tunlp
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      1179/mysqld  

#13、数据库初始化
[root@zbx-server ~]#mysql_secure_installation
1、输入root密码:空
2、设置root密码:y
3、输入root密码
4、是否移除匿名用户:y
5、禁止root远程登录:n
6、是否移除测试数据库:y
7、是否刷新授权表:y

#14、登录数据库
[root@zbx-server ~]#mysql -uroot -p

#15、创建zabbix数据库和zabbix用户和授权
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> create user zabbix@localhost identified by '123456';
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;

#16、导入数据库信息,将create.sql.gz文件拷贝到/root下
[root@zbx-server ~]zcat /root/create.sql.gz | mysql -uzabbix -p zabbix

#17、修改zabbix server配置文件,修改数据库的密码
[root@zbx-server ~]#vi /etc/zabbix/zabbix_server.conf
输入/DBPass查找DBPass  输入N下一个匹配
修改DBPassword=123456
检查修改是否成功
[root@zbx-server ~]#grep '^DBPa' /etc/zabbix/zabbix_server.conf
DBPassword=123456

#18、修改zabbix的PHP配置文件
[root@zbx-server ~]#vi /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
修改配置
php_value[date.timezone] = Asia/Shanghai

#19、启动zabbix及相关服务
[root@zbx-server ~]#systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
[root@zbx-server ~]#systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
打开浏览器输入服务器IP地址/zabbix,初始化步骤

#20、访问zabbix入口
用户名:Admin
密码:zabbix

部署zabbix-agent2

agent2新版本采用golang语言开发

agent2默认用10050端口

#1、确保时间正确性和时区的统一,服务器也需要保证
[root@zbx-agent01 ~]# yum install ntpdate -y
[root@zbx-agent01 ~]# ntpdate -u ntp.aliyun.com

[root@zbx-agent01 ~]# mv /etc/localtime{,.bak}
[root@zbx-agent01 ~]# ls -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

#2、首先配置zabbix的yum源,参考服务端的配置
[root@zbx-agent01 ~]# yum install zabbix-agent2

#3、查看配置文件和启动文件
[root@zbx-agent01 ~]# vi /etc/zabbix/zabbix_agent2.conf
[root@zbx-agent01 ~]# ls -l /usr/sbin/zabbix_agent2

#4、设置开机自启并且立即启动
[root@zbx-agent01 ~]# systemctl disable zabbix-agent
[root@zbx-agent01 ~]# systemctl enable --now zabbix-agent2
[root@zbx-agent01 ~]# netstat -tnlp|grep zabbix

#4、修改agent配置文件
[root@zbx-agent01 ~]# hostnamectl set-hostname 主机名称
[root@zbx-agent01 ~]# vi /etc/zabbix/zabbix_agent2.conf
Hostname=主机名称
Server=服务器地址
ServerActive=服务器地址

#5、重启服务
[root@zbx-agent01 ~]# systemctl restart zabbix-agent2

验证zabbix-agent2的连通性

#1、安装zabbix-get工具
[root@zbx-server ~]# yum install zabbix-get -y

#2、命令检测服务端是否能够连上客户端
[root@zbx-server ~]# zabbix_get -s '192.168.1.17' -p 10050 -k 'agent.ping'
1
#3、输出1则说明正常,如果报错,需在客户端的配置文件中查看Server和ServerActive两项的正确性,关闭防火墙

解决zabbix-server查看的乱码问题

#安装字体
[root@zbx-server ~]# yum -y install wqy-microhei-fonts
[root@zbx-server ~]# \cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf
最后修改:2022 年 05 月 10 日
如果觉得我的文章对你有用,请随意赞赏