当前位置: > Linux服务器 > 监控工具 >

(最全的)zabbix监控搭建(亲测)

时间:2018-12-02 22:01来源:blog.csdn.net 作者:blog.csdn.net
1.系统环境配置
 
1.1 关闭防火墙
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
 
1.2 关闭SeLinux
vi /etc/selinux/config
#SELINUX=enforcing 去掉#并修改为 SELINUX=disabled
#SELINUXTYPE=targeted 去掉#
:wq! #保存退出
 
(或者 sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/’ /etc/selinux/config)
 
setenforce 0 #使配置立即生效
 
2.安装LAMP环境
 
2.1 安装apache
yum install httpd –y
systemctl start httpd #启动apache
systemctl enable httpd #设置apache开机启动
 
在客户端浏览器中打开服务器IP地址,会出现网站画面,说明apache安装成功
 
2.2.1 安装数据库MariaDB
yum install mariadb-bench mariadb-devel mariadb-libs mariadb-server
sudo yum search mariadb
systemctl start mariadb #启动MariaDB
systemctl enable mariadb #设置开机启动
cp /usr/share/mysql/my-huge.cnf /etc/my.cnf #拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可)
 
2.2.2 设置数据库密码
mysql_secure_installation 默认密码为空,根据提示输入Y设置新密码
之后根据提示都选择Y,也可以根据自己需要设置。最后出现:Thanks for using MariaDB!,密码设置完成。
systemctl restart mariadb #重启MariaDB
登录数据库mysql -uroot -p,出现MariaDB [(none)]>明安装成功。
 
2.3 安装PHP
yum install php –y
安装组件支持
yum install php-mysql php-gd libjpeg* php-ldap php-odbcphp-pear php-xml php-xmlrpc php-mbstr。ing php-bcmath php-mhash –y
 
systemctl restart mariadb #重启MariaDB
rm -f /etc/httpd/conf.d/welcome.conf/var/www/error/noindex.html #删除apache默认测试页
 
systemctl restart httpd #重启apache
 
设置PHP时区
vi /etc/php.ini #编辑
date.timezone = PRC #把前面的分号去掉,改为date.timezone= PRC
 
测试cd /var/www/html
vi index.php
输入如下内容
 
<?php phpinfo(); ?>
:wq保存退出
权限设置:chown apache.apache -R /var/www/html
 
systemctl restart mariadb #重启MariaDB
systemctl restart httpd #重启apache
客户端浏览器输入ip地址
 
3.安装Zabbix
3.1 引入yum源 配置仓库包
rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
 
yum install zabbix-server-mysql zabbix-web-mysql
 
3.2 创建zabbix数据库
mysql -uroot -p
MariaDB [(none)]> create database zabbix character set utf8;
 
zabbix数据库可以和zabbix服务器分离,采用用专门的mysql服务器存储数据,此时要给zabbix数据库受相应的权限。
 
注:ip为zabbix服务器的IP地址。
MariaDB [(none)]> grant all privileges on zabbix.* to root@111.111.111.111(服务器地址) identified by ‘hfjy’;
导入数据库
 
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uroot -p zabbix
配置zabbix_server.conf
vi
 
vi /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=root
DBPassword=123123
 
systemctl start zabbix-server #启动zabbix-server
systemctl enable zabbix-server #设置zabbix-server开机启动
3.3 配置PHP
vi /etc/httpd/conf.d/zabbix.conf
更改时区设置
php_value date.timezone Asia/Shanghai
 
(或sed -i.ori ‘18a php_value date.timezone Asia/Shanghai‘ /etc/httpd/conf.d/zabbix.conf)
 
重启数据库,httpd和zabbix-server
[root@localhost conf.d]# systemctl restart mariadb
[root@localhost conf.d]# systemctl restart httpd
[root@localhost conf.d]# systemctl restart zabbix-server
 
3.4. web配置
客户端浏览器输入http://<server_ip_or_name>/zabbix
 
点击Next step根据提示完成配置
 
登陆账号密码 Admin/zabbix
 
至此zabbix安装完成。
 
(责任编辑:IT)
------分隔线----------------------------