zabbix监控LAMP全教程

一、安装前准备
A、下载yum源
1、备份/etc/yum.repos.d/CentOS-Base.repo ,在备份之前,要先安装wget 插件
#mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
//备份到 /etc/yum.repos.d/CentOS-Base.repo.backup 目录下,这个目录本来是没有的,需要新建CentOS-Base.repo.backup

2、选择yum源

163yum源地址
#wget http://mirrors.163.com/.help/CentOS7-Base-163.repo -P /etc/yum.repos.d/

阿里yum源地址
#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
//因为我的虚拟机镜像是Centos 7,所以我选择了 阿里的这镜像。按道理两个都应该是可以的。

3、生成缓存
#yum clear all
#yum makecache

B、防火墙配置
1、可以开启防火墙:
#firewall-cmd --permanent --add-service=http
success
#firewall-cmd --permanent --add-service=https
success
#firewall-cmd --reload
success
#systemctl enable firewalld.service

2、如果感觉麻烦可以考虑关闭防火墙:
#systemctl stop firewalld.service
# systemctl disable firewalld.service

C、关闭SELINUX
为减少不必要的麻烦,这里需要关闭setlinux
1、查看SElinux状态
#/usr/sbin/setatus -v
SELinux status: enabled
# getenforce
Disabled
2、关闭SELINUX
#setenforce 0 //临时关闭


永久关闭
#vim /etc/selinux/config //修改之后,需要重新启动服务器
将SELINUX=enforcing改为SELINUX=disabled

二、开始安装Zabbix,安装如果始终不能成功,可以选择更换DNS。
1、安装zabbix数据库
#rpm -Uvh https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-release-4.2-1.el7.noarch.rpm

2、安装Zabbix包
#yum -y install zabbix-server-mysql zabbix-web-mysql

3、我们在服务器上也装上客户端
#yum -y install zabbix-agent

4、安装数据库sql,在最新的系统里面,mysql已经被mariadb代替,所以,这里我也安装mariadb数据库
#yum install -y mariadb-server
#systemctl start mariadb.service //启动数据库服务
#systemctl status mariadb.service //检查数据库是否启动

(1)初始化数据库
#mysql //进入mysql
创建一个名为 zabbix 的数据库 字符集为 UTF-8
mysql> create database zabbix character set utf8 collate utf8_bin;

给用户授权,在这个地方,可以多执行几次这个命令,多加几个用户 , localhost 是本地,可以更改为ip地址 ,默认密码为'password'
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'password';
mysql> quit;

(2)导入初始架构和数据,系统将提示您输入新创建的密码
#zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix

有两点需要注意:
1、这是一个压缩包,需要先解压;
2、导入之前,可以先 进入压缩包的目录查看一下,看看有没有其他版本的;
导入之后,可以打开数据库,检查一下 show databases; show tables;

(3)配置服务器和客户端文件
#vi /etc/zabbix/zabbix-server.conf
DBPassword=password //修改数据库的密码

# vi /etc/zabbix/zabbix_agentd.conf
Server=192.168.140.133 //服务器的IP地址
ServerActive=192.168.140.133
Hostname=Zabbix server

(4)启动Zabbix并设置开机自启
#systemctl start zabbix-server
#systemctl enable zabbix-server

5、为Zabbix前端配置PHP
(1)前端web配置
#vi /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai //修改日期为 亚洲/上海

(2)启动httpd并设置开机自启
#systemctl restart zabbix-server zabbix-agent httpd
#systemctl enable zabbix-server zabbix-agent httpd

#netstat -na|grep 10051 //侦听端口

6、查看zabbix-server日志
[root@zabbix-server ~]# tailf /var/log/zabbix/zabbix_server.log
21375:20190920:131553.735 server #36 started [lld worker #2]
21369:20190920:131553.740 server #30 started [preprocessing manager #1]
21354:20190920:131553.740 server #18 started [poller #5]
21356:20190920:131553.740 server #20 started [trapper #1]
21360:20190920:131553.741 server #23 started [trapper #4]
21362:20190920:131553.741 server #25 started [icmp pinger #1]
21372:20190920:131554.175 server #33 started [preprocessing worker #3]
21371:20190920:131554.175 server #32 started [preprocessing worker #2]
21370:20190920:131554.176 server #31 started [preprocessing worker #1]
21355:20190920:131658.137 enabling Zabbix agent checks on host "Zabbix server": host became available
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
####################################到这个阶段,服务器端的配置基本结束,剩下的就是在web端进行机器的添加了########################################################
-----------------------------------------------------------------------------------------------------------------------------------------------------------------

7、zabbix基本配置情况
[root@zabbix-server ~]# more /etc/zabbix/web/zabbix.conf.php
// Zabbix GUI configuration file.
global $DB;

$DB['TYPE'] = 'MYSQL';
$DB['SERVER'] = 'localhost';
$DB['PORT'] = '0';
$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'zabbix';
$DB['PASSWORD'] = 'password';

// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';

$ZBX_SERVER = 'localhost';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = 'Zabbix-Study';

$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;

8、解决图形乱码问题
从windows本机随便选择一个中文的字体,传到zabbix的服务器,/usr/share/zabbix/ 目录下;

查找Zabbix所使用的语言包,操作之前记得备份;
# find / -name *font* -print | grep zabbix
/etc/alternatives/zabbix-web-font
/var/lib/alternatives/zabbix-web-font
/usr/share/zabbix/assets/fonts
/usr/share/zabbix/assets/fonts/graphfont.ttf
# ll `find / -name *font* -print | grep zabbix`
lrwxrwxrwx 1 root root 38 Sep 20 12:20 /etc/alternatives/zabbix-web-font -> /usr/share/fonts/dejavu/DejaVuSans.ttf
lrwxrwxrwx 1 root root 33 Sep 20 12:20 /usr/share/zabbix/assets/fonts/graphfont.ttf -> /etc/alternatives/zabbix-web-font
-rw-r--r-- 1 root root 93 Sep 20 12:20 /var/lib/alternatives/zabbix-web-font
/usr/share/zabbix/assets/fonts:
total 0
lrwxrwxrwx 1 root root 33 Sep 20 12:20 graphfont.ttf -> /etc/alternatives/zabbix-web-font


备份原来的语言包
# mv /usr/share/fonts/dejavu/DejaVuSans.ttf /usr/share/fonts/dejavu/DejaVuSans.ttf.bak
替换成Windows的语言包
#cd /usr/share/zabbix/
# mv simkai.ttf /usr/share/fonts/dejavu/DejaVuSans.ttf
---------------------------------------------------------------------------------------------------------------------------------------------------------------
这时图形就不是乱码了。
##########################################################接下来需要学习的就是怎么配置监控项了。################################################################

---------------------------------------------------------------------------------------------------------------------------------------------------------------

你可能感兴趣的:(zabbix监控LAMP全教程)