Zabbix部署

Zabbix部署

鲜花的主人 736 2020-04-28

关闭防火墙并关闭开机启动

systemctl stop firewalld.service
systemctl disable firewalld.service

关闭SELinux安全机制(为避免出现不必要麻烦)

1.临时关闭:
setenforce 0       
##(设置SELinux 成为permissive模式)
##(setenforce 1 设置SELinux 成为enforcing模式)
2.永久关闭(修改配置文件需要重启机器):
修改/etc/selinux/config
文件将SELINUX=enforcing改为SELINUX=disabled
重启机器即可

搭建zabbix所需要的lamp环境

#首先将YUM源更新到最新,我这边更换到阿里云
#备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
#下载新的CentOS-Base.repo 到/etc/yum.repos.d/
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
运行yum makecache生成缓存

在开始安装之前,还需要说明下centos7自带的mysql是mariadb,我们可以通过如下命令查看

yum search mysql|tac

LAMP环境的安装

yum -y install mariadb mariadb-server php php-mysql httpd

配置数据库

将mariadb加入开机启动,并启动

systemctl enable mariadb
systemctl start mariadb

初始化mysql数据库,并配置root用户密码

mysql_secure_installation

zabbix1.png
mysql初始化完毕后,创建zabbix数据库及其用户,使用如下命令

mysql -uroot -proot -e "create database zabbix default character set utf8 collate utf8_bin;"
mysql -uroot -proot -e "grant all on zabbix.* to 'zabbix'@'%' identified by 'zabbix';"

测试刚刚创建的zabbix用户,是否可以连接mysql数据库,如下

[root@base ~]# mysql -uzabbix -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 380
Server version: 5.5.60-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 databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| zabbix             |
+--------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]> 

apache加入开机启动,并启动,以及开放80端口

systemctl enable httpd
systemctl start httpd

安装zabbix server

rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
#安装zabbix
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
#安装完成后导入zabbix数据结构
cd /usr/share/doc/zabbix-server-mysql-3.2.11/
zcat create.sql.gz | mysql -uroot -proot zabbix
#数据库导入完成以后,修改zabbix server配置文件
vi /etc/zabbix/zabbix_server.conf
#添加如下配置
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
#修改PHP的zabbix配置文件
vi /etc/httpd/conf.d/zabbix.conf
将php_value date.timezone Asia/Shanghai注释去掉并修改为Asia/Shanghai
#将zabbix server加入开机启动,并启动
systemctl enable zabbix-server
systemctl start zabbix-server

重启apache

systemctl restart httpd

打开浏览器访问zabbix,地址:

http://serverIP/zabbix
zabbix2.png

出现以上页面即可正常登陆,默认超级管理员登陆账户:Admin 密码:zabbix

客户端zabbix-agent安装(centos7)

导入YUM源

rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm

YUM安装zabbix-agent

yum -y install zabbix-agent

修改zabbix-agent配置文件
zabbix agent的配置很简单,只需要修改zabbix agent配置文件中的Server、ServerActive和Hostname这三项即可。
其中Server、ServerActive是zabbix server服务器的IP地址,Hostname修改为网页里面添加的Hostname,需要保持一致:Hostname=Zabbix server

[root@zabbix ~]# cat /etc/zabbix/zabbix_agentd.conf  |grep -v '^#'|grep -v '^$'
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix server 
Include=/etc/zabbix/zabbix_agentd.d/*.conf

将zabbix-agent设置开机启动,并启动

systemctl enable zabbix-agent
systemctl start zabbix-agent

然后进入zabbix web界面配置相关信息