Zabbix

centos7 安装zabbix 5.0 监控系统

2022-06-09  本文已影响0人  Rami

一、安装zabbix server 端

1.准备工作

systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

hostnamectl set-hostname zabbix
 
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

二、配置zabbix源并安装程序

1.配置zabbix源

rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm

2.修改zabbix源地址为阿里云的zabbix镜像地址

vim /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
 
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/frontend
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
 
[zabbix-debuginfo]
name=Zabbix Official Repository debuginfo - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/debuginfo/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
gpgcheck=0
 
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/x86_64/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=0

#将zabbix官方的地址替换为阿里云的zabbix地址

3.必要时候执行下面两步

yum clean all
yum makecache

4.安装zabbix主服务和agent程序

yum install zabbix-server-mysql zabbix-agent -y

5.安装SCL组件

yum install centos-release-scl -y
yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y
#如果提示没有php的话请安装
yum install rh-php72-php-mbstring rh-php72-php-bcmath rh-php72-php-gd rh-php72-php-mysqlnd rh-php72-php-xml rh-php72-php-ldap rh-php72-php-fpm rh-php72 -y

三、安装数据库

1.安装mariadb数据库(也可以选择mysql)

yum install mariadb-server mariadb -y
systemctl start mariadb
systemctl enable mariadb

2.初始化mariadb数据库

[root@zabbix ~]# mysql_secure_installation
Enter current password for root (enter for none):  ##这里回车一次
Set root password? [Y/n] y  ##这里输入y并回车一次
New password:   ##这里输入一次root账号的密码,并回车一次。啰嗦,这里输入密码是不会显示的。
Re-enter new password:     ##这里再输入一次root账号的密码,并回车一次。
Password updated successfully!
Reloading privilege tables..
 ... Success!
 
Remove anonymous users? [Y/n] y  ##这里输入y并回车一次
 ... Success!
 
Disallow root login remotely? [Y/n] n  ##这里输入n并回车一次
 ... skipping.
 
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] n  ##这里输入n并回车一次
 ... skipping.
 
Reload privilege tables now? [Y/n] y  ##这里输入y并回车一次
 ... Success!
Thanks for using MariaDB!

3.创建zabbix所需的数据库、用户

MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> create user zabbix@localhost identified by '你的密码';
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
MariaDB [(none)]> exit
#在上面第三行中的“你的密码”写上用户zabbix的数据库密码,等会要用到

4.导入初始架构和数据

zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
#可能需要你输入密码

5.修改zabbix server的主配置文件、连接数据库信息

cp /etc/zabbix/zabbix_server.conf{,.bak}
grep -i "^DB" /etc/zabbix/zabbix_server.conf
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
#将【DBPassword=】 修改为 【DBPassword=你的密码】然后保存退出
#注释:这里的密码就是刚才设置的数据库用户zabbix的密码,要保持一致

6.需要修改配置时区信息

cp /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf{,.bak}
vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
#将; php_value[date.timezone] = Europe/Riga 修改为 php_value[date.timezone] = Asia/Shanghai

#如果这行配置前面有#或者;,请删掉,然后保存退出即可

7.启动zabbix server 及相关服务,并设置为开机自启

systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm

8.验证zabbix是否安装成功

[root@zabbix ~]# netstat -ntlup |grep zabbix
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      10753/zabbix_agentd 
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      16598/zabbix_server 
tcp6       0      0 :::10050                :::*                    LISTEN      10753/zabbix_agentd 
tcp6       0      0 :::10051                :::*                    LISTEN      16598/zabbix_server
注释:zabbix server使用的端口是10051,zabbix agent的端口是10050,这非常重要。

如果发现没有10050或者10051端口,那么请检查zabbix的日志。从日志中你将能很快定位问题点

tail -f /var/log/zabbix/zabbix_server.log

还可以使用命令mysql -u zabbix -p检查数据库是否正确

9.初始化zabbix server 的页面

打开浏览器,输入地址【http://本机IP/zabbix】

大概是第一页是zabbix的前端检查各个组件是否ok,必须全部是绿色打钩的

然后输入数据库的密码,密码就是数据库用户zabbix的密码

zabbix页面登录
用户Admin
密码zabbix

四、在客户端服务器上安装zabbix agent

1.基础准备工作

systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
 
hostnamectl set-hostname zbxserver
 
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

2.安装zabbix源

rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm

3.修改zabbix源地址为阿里云的zabbix镜像地址

vi /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
 
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/frontend
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
 
[zabbix-debuginfo]
name=Zabbix Official Repository debuginfo - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/debuginfo/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
gpgcheck=0
 
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/x86_64/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=0

4.在centos客户端服务器上安装 zabbix agent程序

yum install zabbix-agent -y

5.修改agent的配置文件zabbix_agentd.conf

cp /etc/zabbix/zabbix_agentd.conf{,.bak}
vim /etc/zabbix/zabbix_agentd.conf
#修改 【Server=127.0.0.1】 修改为 【Server=10.0.0.110】,注:这里写zabbix server 的ip地址

#修改 【ServerActive=127.0.0.1】 修改为 【ServerActive=10.0.0.110,注,这里写zabbix server 的ip地址

#修改【Hostname=Zabbix server】 修改为 【Hostname=zabbix】,注:可随便写

6.重启 zabbix agent服务,并设置为开机自启

systemctl restart zabbix-agent.service 
systemctl enable zabbix-agent.service

7.检验客户端的agent是否安装成功

[root@agent ~]# netstat -ntlup |grep zabbix
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      21215/zabbix_agentd 
tcp6       0      0 :::10050                :::*                    LISTEN      21215/zabbix_agentd 

#zabbix agent用的端口默认是10050

上一篇 下一篇

猜你喜欢

热点阅读