CentOS7安装部署zabbix4.0
一、zabbix简介
zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案
二、安装前提
1.关闭selinux 2.关闭防火墙 3.节点情况
三、安装环境
1.安装mariadb数据库
1)获取mariadb的yum源(中科大yum源)
vim /etc/yum.repos.d/MariaDB.repo [mariadb] name = MariaDB baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.1/centos7-amd64/ gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB gpgcheck=1
2)安装mariadb及依赖包
yum -y install MariaDB-server MariaDB-client MariaDB-devel
2.安装httpd和PHP
yum -y install httpd php
3.安装PHP插件
yum install -y php-mysql php-snmp php-xml php-ldap php-gd php-mbstring php-posix
4.修改httpd配置文件,使其支持PHP
vim /etc/httpd/conf.d/php.conf 添加: LoadModule php5_module modules/libphp5.so AddHandler php5-script .php
5.启动httpd,测试PHP
1)编写测试网页
vim /var/www/html/index.php <?php phpinfo() ?>
2)浏览器访问
6.启动mariadb,测试httpd、PHP、mariadb的协同
1)初始化数据库
mysql_secure_installation
2)编写测试网页
vim /var/www/html/test.php <?php $link=mysql_connect("localhost","root","密码"); if($link){echo "ok!!!!!";}else{echo "error";} ?>
显示ok成功,error则是错误
四、安装zabbix
1.获取zabbix yum源(阿里云)
vim /etc/yum.repo.d/zabbix.repo [zabbix] name=Zabbix Official Repository - $basearch baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 [zabbix-non-supported] name=Zabbix Official Repository non-supported - $basearch baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/$basearch/ enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX gpgcheck=1
下载秘钥
curl https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 -o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 curl https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX -o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
2.安装
yum install -y zabbix-server-mysql zabbix-get zabbix-web zabbix-web-mysql zabbix-agent zabbix-sender
3.创建数据库
mysql -uroot -p123456 create database zabbix character set utf8 collate utf8_bin; grant all privileges on zabbix.* to zabbix@localhost identified by 123456;
4.导入表
cd /usr/share/doc/zabbix-server-mysql-3.2.10/ gunzip create.sql.gz mysql -uroot -p123456 use zabix; source create.sql
5.修改配置文件
vim /etc/zabbix/zabbix_server.conf DBHost=localhost DBName=zabbix 数据库名 DBUser=zabbix 数据库用户名 DBPassword=123456 数据库密码 DBSocket=/var/lib/mysql/mysql.sock
6.启动zabbix并设置开机启动
systemctl start zabbix-server systemctl start zabbix-agent systemctl enable zabbix-server systemctl enable zabbix-agent
7.修改PHP时区
vim /etc/httpd/conf.d/zabbix.conf php_value date.timezone Asia/Shanghai
8.重启httpd
9.登录zabbix网页
五、使用zabbix
1.添加被控主机
被控端安装zabbix-agent 1)从监控主机获取yum源和秘钥
scp root@192.168.11.116:/etc/yum.repos.d/zabbix.repo /etc/yum.repo.d/ scp root@192.168.11.116:/etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX /etc/pki/rpm-gpg/ scp root@192.168.11.116:/etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 /etc/pki/rpm-gpg/
2)安装zabbix-agent
yum -y install zabbix-agent
3)修改zabbix-agent的配置文件
vim /etc/zabbix/zabbix_agentd.conf Server=192.168.110.150 #98行 zaibbix-server的IP ServerActive=192.168.110.150 #139行启动 zabbix-server的IP
4)启动zabbix-agent
systemctl start zabbix-agent systemctl enable zabbix-agent
5)添加被控主机 6)在模板中选择要监控的服务
2.解决乱码问题
从Windows的字体文件复制到监控主机的/usr/share/zabbix/assets/fonts/目录,并将文件名改为监控主机上原有的文件名,刷新网页即可