前言:
技术组件构成:zabbix+php+httpd+mysql+其他工具组件。
依赖组件构成:参考官网文档地址入下:
https://www.zabbix.com/documentation/current/manual/installation/requirements 设备系统要求:
跨平台:
数据库软件要求:
前端软件要求:
服务端软件要求以及可选组件:
客户端的组件要求:
Java相关监控组件要求:
一、环境准备
查看系统版本:
cat /proc/version --------#查看CentOS存放与内核相关的文件。
uname -a --------------查看CentOS版本。
cat /etc/redhat-release --------------查看CentOS版本详情。
1、关闭防火墙。(永久)
查看防火墙的状态:
systemctl status firewallld
关闭防火墙:
systemctl stop firewalld
禁用防火墙开机自启:
systemctl disable firewalld
vi /etc/selinux/config,SELINUX=enforcing改为SELINUX=disabled:
查看修改的结果:
1、查看selinux状态
#getenforce
Enforcing —表示已启动
2、下载wegt、vim工具。
yum -y install wget vim
3、更换yum源。
#更换yum源为国内的阿里云的yum源:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#更换epel源:
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
4、系统时间同步并设置开机自启。
yum install ntp -y && systemctl enable ntpd.service && systemctl start ntpd.service
然后更新yum:
yum clean all && yum makecache
[root@localhost ~]# echo $? -------打印上一个命令执行有多少错误。
0 -----------返回是0表示命令执行没有问题。
yum -y update ------升级yum版本
5、安装依赖包。
卸载之前安装的zabbix,先查看,如果有安装,卸载:
rpm -e --nodeps 包名
同样的方法卸载php或者httpd,mysql。
这里介绍一下按照开发环境的依赖包:
yum -y install epel-release
yum groups install "Development Tools"
通过yum groups info "Development Tools"进行查看安装的依赖。
二、安装部署。
1、安装php
yum -y install php
查看版本:
php -v
2、安装apache。
yum -y install httpd
查看安装版本:
httpd -v
启动并设置开机自启:
systemctl start httpd
查看启动状态:
systemctl status httpd
开机自启:
systemctl enable httpd
3、安装mysql。
yum -y install mariadb-server或者yum -y install mariadb-server.x86_64
启动数据库设置开机自启:
systemctl start mariadb
systemctl status mariadb
systemctl enable mariadb
初始化:mysql_secure_installation
按照提示操作:
[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):
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
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
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
... 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] 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] 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!
4、安装zabbix。
安装zabbix的镜像源:
https://www.zabbix.com/cn/download? zabbix=4.4&os_distribution=centos&os_version=7&db=my sql&ws=apache
rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0- 2.el7.noarch.rpm
yum clean all
1、yum -y install zabbix40-server-mysql.x86_64
2、yum -y install zabbix40-web-mysql.noarch
reboot
三、配置修改。
1、数据库中操作。
创建数据库
mysql -uroot -p
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix@2020';
导入zabbix数据表结构:
<1、这种是下载zabbix源码包解压后的sql路径,我这里的源码包是在root的家目录下直接解压的:mysql -uzabbix -pzabbix@2020 zabbix < /root/zabbix-4.0.18/database/mysql/schema.sql
mysql -uzabbix -pzabbix@2020 zabbix < /root/zabbix-4.0.18/database/mysql/images.sql
mysql -uzabbix -pzabbix@2020 zabbix < /root/zabbix-4.0.18/database/mysql/data.sql >
<2、如果是用yum安装的,初始化zabbix的表:zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -pzabbix@2020 zabbix>
没有找到对应的包的sql,所以执行第一种。
导入zabbix:
[root@localhost mysql]# mysql -uzabbix -pzabbix@2020 zabbix < /root/zabbix-4.0.18/database/mysql/schema.sql
[root@localhost mysql]# mysql -uzabbix -pzabbix@2020 zabbix < /root/zabbix-4.0.18/database/mysql/images.sql
[root@localhost mysql]# mysql -uzabbix -pzabbix@2020 zabbix < /root/zabbix-4.0.18/database/mysql/data.sq
查看表:use zabbix 然后show tables结果如下:
2、zabbix_server的操作。
vim /etc/zabbix/zabbix_server.conf
修改zabbix_server的配置文件:
修改zabbix_server_config:
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix@2020
改成:
启动Zabbix Server
systemctl start zabbix-server.service
systemctl status zabbix-server.service
启动失败:
more /var/log/zabbix/zabbix_server.log
《如果使用源码安装的需要先指定zabbix的启动配置文件,/usr/local/zabbix/sbin/zabbix_server -h
查看如何指定:-c来指定,默认是/usr/local/zabbix/sbin/zabbix_server,
如果我们的zabbix不是安装在默认环境下,那么可以指定安装的位置:
如在安装路径下的zabbix_server -c /安装的路径/zabbix_server,如下:
/usr/local/zabbix/sbin/zabbix_server -c /usr/local/zabbix/sbin/zabbix_server
启动:/usr/local/zabbix/sbin/zabbix_server
zabbxi的日志目录:
要启动之后才有日志目录文件,所以得先启动。位置不知道在哪里,可以查看:find / -name zabbix_server.log
然后结果是在/tmp/zabbix_server.log
查看日志最后一百行:tailf /tmp/zabbix_server.log
可以看到zabbix server的启动状态。started》
3、前端网页显示操作。
配置Zabbix frontend
vim /etc/php.ini
vim /etc/php.ini:
memory_limit = 256M(默认是128M)
post_max_size = 24M(默认是8M)
upload_max_filesize = 6M(默认是2M)
max_execution_time = 300(默认是30s)
max_input_time = 300(默认是60)
date.timezone = "Asia/Shanghai(默认是没有时区)
max_input_vars = 10000(默认是1000)
always_populate_raw_post_data = -1(默认是On)
启动httpd服务:
systemctl start httpd.service
systemctl status httpd.service
四、前端验证。http://IP/zabbix/setup.php
下一步:
下一步:
下一步:
server启动日志查看:
下一步:
下一步:
进入登录页面:
账号:
Admin
密码:
zabbix
恭喜结果已经如期而至。刚刚在查看日志的时候,zabbix server是没有启动,所以去解决这个问题:
发现我在导入数据库的时候,对应的版本不一致。
然后下载一个对应的版本的数据库表结构试试:
看看结果会不会是这个版本的原因导致:
重启数据库:
systemctl restart mariadb
虽然没有解决问题,但是没有报版本错误了,说明还是有点小影响的。
接下来可以看看安装的zabbix-server-mysql.service failed:
猜想就是zabbix-server-mysql这个安装有问题,因为zabbix-web-mysql端是没有问题的。
但是我们是用yum工具安装的,应该不是安装错误,而是版本选择错误。
全部卸载:rpm -qa | grep zabbix
rpm -e --nodeps zabbix40-dbfiles-mysql-4.0.17-1.el7.noarch
rpm -e --nodeps zabbix40-server-mysql-4.0.17-1.el7.x86_64
rpm -e --nodeps zabbix-release-4.0-2.el7.noarch
rpm -e --nodeps zabbix40-server-4.0.17-1.el7.noarch
rpm -e --nodeps zabbix40-web-mysql-4.0.17-1.el7.noarch
rpm -e --nodeps zabbix40-4.0.17-1.el7.x86_64
rpm -e --nodeps zabbix40-web-4.0.17-1.el7.noarch
用yum search zabbix看一下:重新卸载然后安装:
yum -y install zabbix40-dbfiles-mysql-4.0.17-1.el7.noarch zabbix40-server-mysql-4.0.17-1.el7.x86_64 zabbix40-server-4.0.17-1.el7.noarch
然后重新配置一下zabbix_server即可。修改zabbix为IP直接访问:vim httpd.conf
如图: