注:本实验环境在centos7mini下实验,具体相关软件版本最好一致,避免依赖关系缺失。
当然也可以新建用户zabbix(不使用root,避免安全隐患),在zabbix下执行操作,加sudo提升权限
1、准备工作
1.1配置 yum 源
cd /etc/yum.repos.d/
vim CentOS7-Base.repo //找寻7大版本就可以
1.2 配置zabbix源
vim zabbix.repo //实际操作中使用zabbix/3.2/rhel/7/x86_64
yum clean all //清理yum缓存
yum makecache //更新yum缓存
1.3禁用防火墙
systemctl stop firewalld.service //停止防火墙
firewall-cmd --state //查看防火墙状态
systemctl disable firewalld.service //设置防火墙开机不启动
sestatus //查看selinux状态
setenforce 0 //修改selinux的运行状态为permisivv
sed -i “s/^SELINUX=enforcing/SELINUX=disabled/” /etc/selinux/config //修改开启启动状态不可用
2、 安装Mysql数据库(5.7.24)
2.1查看本机是否已经安装了mysql/mariadb
rpm -qa | grep -i mariadb rpm -qa | grep -i mysql
若有则将其卸载rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
根目录下查找未删除的mariadb文件夹 find / -name *mariadb*
执行删除指令 rm -rf 找到的文件或文件夹(如/usr/share/mysql/)
2.2安装
下载mysql安装包https://dev.mysql.com/downloads/mysql/5.7.html#downloads
根据自己的操作系统选择下载版本,此处下载mysql-5.7.24-1.el7.x86_64.rpm-bundle.tar(捆绑包)。下载好后传到待安装主机上(随便放在哪个文件夹,一般放在根目录)
解压 tar -xvf mysql-5.7.24-1.el7.x86_64.rpm-bundle.tar
安装
由于mysql的server端需要perl语言的支持,因此我们还需要在系统中安装perl支持:
yum install perl -y
yum install net-tools //mysql server安装需要次依赖关系
下载iksemel-1.4-6.sdl7.x86_64.rpm
安装 yum localinstall iksemel-1.4-6.sdl7.x86_64.rpm
Yum install net-tools (mysql-commit-serverxuyao)
后面安装的时候需要iksemel-1.4-6.sdl7.x86_64.rpm依赖(及时配置了epel源,也无法解决)
由于上面解压出来的几个rpm包有依赖关系,所以我们需要按照顺序执行安装:
rpm -ivh mysql-community-common-5.7.24-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.24-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.24-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.24-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.24-1.el7.x86_64.rpm
启动mysql服务 systemctl start mysqld.service
查看mysql的初始root密码 cat /var/log/mysqld.log
修改root密码 mysql -u root -p
输入初始密码
设置新的root密码 set password = password('newpassword');
设置外部远程访问权限:
grant all privileges on *.* to 'root' @'%' identified by 'newpassword';
flush privileges;
创建zabbix数据库并本机访问该库的授权
grant all on zabbix.* to zabbix@'localhost' identified by 'newpassword';
create database zabbix charset 'utf8';
flush privileges;
exit;
设置mysql开机启动
systemctl enable mysqld
3、zabbix-server安装
3.1 yum install zabbix-server-mysql
导入zabbix-server需要的数据库表
rpm -ql zabbix-server-mysql
cd /usr/share/doc/zabbix-server-mysql-3.2.3/
zcat create.sql.gz |mysql -uroot -pnewpassword zabbix
Zcat语句替换下面两条语句
###gunzip create.sql.gz
###mysql -uroot -p -Dzabbix < create.sql
查看是否导入成功(也可通过数据库可视化工具查看,如navicat、sqlyog等)
mysql -u zabbix -p
show tables
修改zabbix-server配置文件
vim /etc/zabbix/zabbix_server.conf
只需修改以下几个即可
ListenPort=10051
SourceIP=10.46.182.39(改成你自己的)
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=1qaz@WSX
DBPort=3306
启动zabbix-server并查看10051端口是否启动systemctl start zabbix-server.service
Systemctl enable zabbix-server
3.2 安装zabbix-web
yum install httpd php php-mysql php-mbstring php-gd php-bcmath php-ldap php-xml
yum install zabbix-web zabbix-web-mysql
Zabbix-web端配置文件修改
vim /etc/httpd/conf.d/zabbix.conf
此处只修改时区
启动zabbix-web服务
systemctl start httpd.service
Systemctl enble httpd.service
至此配置工作准备完成,现在可以在网页输入你zabbix-web所安装的主机地址进行管理(如http://10.46.182.39/zabbix)
3.4 验证api是否可用
curl -s -X POST -H 'Conten","params": {"user": "Admin","password": "zabbix"},"id": 1,"auth": null}' http://10.43.33.90/zabbix/api_jsonrpc.php